diff --git a/static/admin.html b/static/admin.html
index 3928d35..c888fc4 100644
--- a/static/admin.html
+++ b/static/admin.html
@@ -49,32 +49,7 @@
//////////////////////////////////////////////////////////////////////////////
// UPDATE MAP
- socket.on("yourId", function(data){
- 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]);
- }
- });
+ socket = io({rejectUnauthorized: false, auth: {type:"Admin"}});
setup_socket_common();
diff --git a/static/tracking/conscrit.html b/static/tracking/conscrit.html
index f0883be..b624ca7 100644
--- a/static/tracking/conscrit.html
+++ b/static/tracking/conscrit.html
@@ -56,7 +56,7 @@
document.querySelector('#sendMessage').addEventListener('click', function(){
const input = document.querySelector('#message');
- socket.emit("code", {"content": input.value});
+ socket.emit("code", {"code": input.value});
});
//////////////////////////////////////////////////////////////////////////////
diff --git a/static/utils.js b/static/utils.js
index 954f094..5286bef 100644
--- a/static/utils.js
+++ b/static/utils.js
@@ -17,12 +17,11 @@ var CircleIcon = L.Icon.extend({
var icons = [
new CircleIcon({ iconUrl: '/def.png' }),
new CircleIcon({ iconUrl: '/track.png' }),
+ new CircleIcon({ iconUrl: '/invi.png' }),
new CircleIcon({ iconUrl: '/purple.png' }),
new CircleIcon({ iconUrl: '/green.png' }),
new CircleIcon({ iconUrl: '/orange.png' })
];
-var self_icons = icons;
-var self_invisible = new CircleIcon({ iconUrl: '/invi.png' });
//////////////////////////////////////////////////////////////////////////////
// INIT MAP
@@ -54,6 +53,21 @@ function setup_map(){
// SOCKET
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){
alert(data.content);
});
@@ -69,35 +83,7 @@ function setup_socket_common(){
}
function setup_socket_not_admin(){
- 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]);
- }
- });
+ socket = io({rejectUnauthorized: false, auth: {id: id, type:type}});
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/traque.js b/traque.js
index 20e46b0..7d56102 100644
--- a/traque.js
+++ b/traque.js
@@ -80,7 +80,7 @@ var server = http.createServer(option, function(req, res){
fs.readFile(filename, function(err, data) {
if (err) {
console.log("404: ", q.pathname, filename);
- res.writeHead(404, {'Content-Type': 'text/html'});
+ res.writeHead(404, {'Content-Type': 'text/html'});
return res.end("404 Not Found");
}
res.writeHead(200, {'Content-Type': 'text/html'});
@@ -153,16 +153,15 @@ function default_team(team_id) {
}
// connect a socket to the room corresponding to its team and send it infos
-function team_join(team_id, socket){
- socket.join(team_id);
- var equipe = equipes[team_id]
- var state = equipe.state;
+function team_join(team, socket){
+ socket.join(team.id);
+ var state = team.state;
if(state.tracker) socket.join("tracker");
if(state.tracked) socket.join("tracked");
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)
- if(other_id != team_id)
+ if(other_id != team.id)
socket.emit('moving', apparent_info(equipes[other_id]));
}
@@ -176,9 +175,28 @@ io.on('connection', function(socket){
socket.join("Tracking");
if(!(id in equipes))
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"){
@@ -189,6 +207,17 @@ io.on('connection', function(socket){
socket.join("Admin");
//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){
var equipe = equipes[i];
@@ -198,23 +227,6 @@ io.on('connection', function(socket){
//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.color = d.color - 0;
// if(d.color == -1)
@@ -229,7 +241,7 @@ io.on('connection', function(socket){
// equipes[i].emit('changeColor', {"id": socket.id, "color": d.color});
// });
// socket.on('message', function(d){
-// d.content = d.content.toLowerCase();
+// d.content = d.content.toLowerCase();
// if(d.content == PWD_TRACKED){
// d.color = 0;
// socket.emit('popup', {"content": MSG_TRACKED});
@@ -237,24 +249,9 @@ io.on('connection', function(socket){
// d.color = 1;
// socket.emit('popup', {"content": MSG_TRACKER});
// } else if(d.content == PWD_INVISIBLE){
-// d.color = -1;
-// socket.emit('popup', {"content": MSG_INVISIBLE});
-// } else if((d.content in invisi) && invisi[d.content]){
-// 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;
-// }
+// } else
// socket.color = d.color - 0;
// if(d.color == -1)
// socket.shown = false;
@@ -267,33 +264,12 @@ io.on('connection', function(socket){
// for(i in equipes)
// 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(_){
-// console.log(socket.id + " disconnect");
-// socket.shown = false;
+// console.log(socket.id + " disconnect");
+// socket.shown = false;
// for(i in equipes)
// 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");