repaired admin page, and invisibility code

This commit is contained in:
catvayor 2023-06-08 22:14:41 +02:00
parent c6498211fe
commit eb92a797cd
4 changed files with 61 additions and 124 deletions

View file

@ -49,32 +49,7 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// UPDATE MAP // UPDATE MAP
socket.on("yourId", function(data){ socket = io({rejectUnauthorized: false, auth: {type:"Admin"}});
console.log("yourId", data);
id = data.id;
if(!(id in colors))
colors[id] = 0;
if(id in markers)
markers[id].setIcon(self_icons[colors[id]]);
socket.emit("admin");
});
socket.on("changeColor", function(data){
console.log("changeColor", data);
if(data.id in colors && colors[data.id] == -1 && data.id in markers)
markers[data.id].addTo(map);
colors[data.id] = data.color;
if(data.id in markers){
if(data.id == id)
markers[data.id].setOpacity(0);
else
if(data.color == -1)
markers[data.id].setIcon(self_invisible);
else
markers[data.id].setIcon(icons[data.color]);
}
});
setup_socket_common(); setup_socket_common();

View file

@ -56,7 +56,7 @@
document.querySelector('#sendMessage').addEventListener('click', function(){ document.querySelector('#sendMessage').addEventListener('click', function(){
const input = document.querySelector('#message'); const input = document.querySelector('#message');
socket.emit("code", {"content": input.value}); socket.emit("code", {"code": input.value});
}); });
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -17,12 +17,11 @@ var CircleIcon = L.Icon.extend({
var icons = [ var icons = [
new CircleIcon({ iconUrl: '/def.png' }), new CircleIcon({ iconUrl: '/def.png' }),
new CircleIcon({ iconUrl: '/track.png' }), new CircleIcon({ iconUrl: '/track.png' }),
new CircleIcon({ iconUrl: '/invi.png' }),
new CircleIcon({ iconUrl: '/purple.png' }), new CircleIcon({ iconUrl: '/purple.png' }),
new CircleIcon({ iconUrl: '/green.png' }), new CircleIcon({ iconUrl: '/green.png' }),
new CircleIcon({ iconUrl: '/orange.png' }) new CircleIcon({ iconUrl: '/orange.png' })
]; ];
var self_icons = icons;
var self_invisible = new CircleIcon({ iconUrl: '/invi.png' });
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// INIT MAP // INIT MAP
@ -54,6 +53,21 @@ function setup_map(){
// SOCKET // SOCKET
function setup_socket_common(){ function setup_socket_common(){
socket.on("moving", function(data){
console.log("moving", data);
if(!(data.id in markers)){
markers[data.id] = L.marker(data.position, {"icon": icons[data.color]}).addTo(map);
markers[data.id].color = data.color; //do we really need to store this ?
if(data.id == id)
markers[data.id].setZIndexOffset(10000);
markers[data.id].bindPopup(data.id);
} else{
markers[data.id].setLatLng(data.position);
markers[data.id].color = data.color;
markers[data.id].setIcon(icons[data.color]);
}
});
socket.on("popup", function(data){ socket.on("popup", function(data){
alert(data.content); alert(data.content);
}); });
@ -69,35 +83,7 @@ function setup_socket_common(){
} }
function setup_socket_not_admin(){ function setup_socket_not_admin(){
socket = io({rejectUnauthorized: false, auth: {id: id, type:type}}, socket = io({rejectUnauthorized: false, auth: {id: id, type:type}});
protocol+"//"+server+":"+port);
socket.on("moving", function(data){
console.log("moving", data);
if(!(data.id in markers)){
var icon;
if(data.id == id)
icon = self_icons[data.color];
else
icon = icons[data.color];
markers[data.id] = L.marker(data.position, {"icon": icon}).addTo(map);
markers[data.id].color = data.color; //do we really need to store this ?
if(data.id == id)
markers[data.id].setZIndexOffset(10000);
markers[data.id].bindPopup(data.id);
} else{
markers[data.id].setLatLng(data.position);
markers[data.id].color = data.color;
if(data.id == id)
if(data.color == -1)
markers[data.id].setIcon(self_invisible);
else
markers[data.id].setIcon(self_icons[data.color]);
else
if(data.color != -1)
markers[data.id].setIcon(icons[data.color]);
}
});
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

100
traque.js
View file

@ -153,16 +153,15 @@ function default_team(team_id) {
} }
// connect a socket to the room corresponding to its team and send it infos // connect a socket to the room corresponding to its team and send it infos
function team_join(team_id, socket){ function team_join(team, socket){
socket.join(team_id); socket.join(team.id);
var equipe = equipes[team_id] var state = team.state;
var state = equipe.state;
if(state.tracker) socket.join("tracker"); if(state.tracker) socket.join("tracker");
if(state.tracked) socket.join("tracked"); if(state.tracked) socket.join("tracked");
if(state.npc) socket.join("npc"); if(state.npc) socket.join("npc");
socket.emit('moving', {"id": team_id, "color": equipe.color, "position": equipe.pos}); socket.emit('moving', {"id": team.id, "color": team.color, "position": team.pos});
for(other_id in equipes) for(other_id in equipes)
if(other_id != team_id) if(other_id != team.id)
socket.emit('moving', apparent_info(equipes[other_id])); socket.emit('moving', apparent_info(equipes[other_id]));
} }
@ -176,9 +175,28 @@ io.on('connection', function(socket){
socket.join("Tracking"); socket.join("Tracking");
if(!(id in equipes)) if(!(id in equipes))
equipes[id] = default_team(id); equipes[id] = default_team(id);
team_join(id, socket); var equipe = equipes[id]
team_join(equipe, socket);
socket.on("code", function(d){ /*TODO*/ }); socket.on("code", function(d){
var code = d.code;
if((code in invisi) && invisi[code]){
invisi[code] = false;
var old_color = equipe.color;
equipe.color = 2;
equipe.state.shown = false;
io.to(id).emit('popup', {"content": MSG_INVISIBLE});
emit_update(id);
setTimeout(function(eq, oc){
eq.color = oc;
eq.state.shown = true;
emit_update(eq.id);
}, invisible_delay, equipe, old_color);
} else {
socket.emit('popup', {"content": MSG_BAD});
return;
}
});
} }
if(socket.handshake.auth.type == "vieux"){ if(socket.handshake.auth.type == "vieux"){
@ -189,6 +207,17 @@ io.on('connection', function(socket){
socket.join("Admin"); socket.join("Admin");
//TODO //TODO
socket.on('newCode', function(d){
invisi[d.code] = true;
});
socket.on('popup', function(d){
tracking.emit('popup', {"content": d.content});
});
socket.on('newTracker', function(d){
io.emit('newTracker', d);
});
for(i in equipes){ for(i in equipes){
var equipe = equipes[i]; var equipe = equipes[i];
@ -198,23 +227,6 @@ io.on('connection', function(socket){
//ici essentiellement tout est a refaire //ici essentiellement tout est a refaire
// socket.id = equipes.length;
// equipes.push(socket);
// socket.shown = true;
// socket.admin = false;
// socket.color = 0;
// socket.position = [0,0];
// socket.on('admin', function(){
// socket.admin = true;
// socket.shown = false;
// admins.push(socket);
// for(i in equipes)
// equipes[i].emit('changeColor', {"id": socket.id, "color": -1});
// socket.on('newTracker', function(d){
// for(i in equipes)
// equipes[i].emit('newTracker', d);
// });
// });
// socket.on('changeColor', function(d){ // socket.on('changeColor', function(d){
// socket.color = d.color - 0; // socket.color = d.color - 0;
// if(d.color == -1) // if(d.color == -1)
@ -239,22 +251,7 @@ io.on('connection', function(socket){
// } else if(d.content == PWD_INVISIBLE){ // } else if(d.content == PWD_INVISIBLE){
// d.color = -1; // d.color = -1;
// socket.emit('popup', {"content": MSG_INVISIBLE}); // socket.emit('popup', {"content": MSG_INVISIBLE});
// } else if((d.content in invisi) && invisi[d.content]){ // } else
// invisi[d.content] = false;
// old_color = socket.color;
// d.color = -1;
// socket.emit('popup', {"content": MSG_INVISIBLE});
// setTimeout(function(s,c){
// for(i in equipes){
// equipes[i].emit('moving', {"id": s.id, "position": s.position});
// equipes[i].emit('changeColor', {"id": s.id, "color": c, "debug": "timeout"});
// }
// s.color = c;
// }, invisible_delay, socket, old_color);
// } else {
// socket.emit('popup', {"content": MSG_BAD});
// return;
// }
// socket.color = d.color - 0; // socket.color = d.color - 0;
// if(d.color == -1) // if(d.color == -1)
// socket.shown = false; // socket.shown = false;
@ -267,33 +264,12 @@ io.on('connection', function(socket){
// for(i in equipes) // for(i in equipes)
// equipes[i].emit('changeColor', {"id": socket.id, "color": d.color}); // equipes[i].emit('changeColor', {"id": socket.id, "color": d.color});
// }); // });
// socket.on('popup', function(d){
// for(i in equipes)
// equipes[i].emit('popup', {"content": d.content});
// });
// socket.on('setName', function(d){
// socket.name = d.name;
// for(i in equipes)
// equipes[i].emit('setName', {"id": socket.id, "name": d.name});
// });
// socket.on('newCode', function(d){
// invisi[d.code] = true;
// });
// socket.on("disconnect", function(_){ // socket.on("disconnect", function(_){
// console.log(socket.id + " disconnect"); // console.log(socket.id + " disconnect");
// socket.shown = false; // socket.shown = false;
// for(i in equipes) // for(i in equipes)
// equipes[i].emit('remove', {"id": socket.id}); // equipes[i].emit('remove', {"id": socket.id});
// }); // });
//
// socket.emit('yourId', {"id": socket.id});
// for(i in equipes){
// if(!equipes[i].shown)
// continue;
// socket.emit('setName', {"id": i, "name": equipes[i].name});
// socket.emit('changeColor', {"id": i, "color": equipes[i].color});
// socket.emit('moving', {"id": i, "position": equipes[i].position});
// }
}); });
console.log("Launch server"); console.log("Launch server");