diff --git a/static/admin.html b/static/admin.html index 685dda8..550a40c 100644 --- a/static/admin.html +++ b/static/admin.html @@ -52,6 +52,7 @@ + @@ -80,7 +81,7 @@ ////////////////////////////////////////////////////////////////////////////// // UPDATE MAP - socket = io({rejectUnauthorized: false, auth: {type:"Admin"}}); + socket = io({rejectUnauthorized: false, auth: {type:"Admin"}}); setup_socket_common(); @@ -92,6 +93,7 @@ function sendUpdate(id){ var state = {}; + state.mallette = document.getElementById(`${id}.mallette`).checked; state.invisibility = document.getElementById(`${id}.invisibility`).checked; state.blurred = document.getElementById(`${id}.blurred`).checked; state.tracker = document.getElementById(`${id}.tracker`).checked; @@ -103,6 +105,9 @@ var id = data.id; if(!(id in equipes)){ var row = ``; + row += `` row += `` @@ -129,6 +134,7 @@ info_table.innerHTML += `${row}` for(i in equipes){ var equipe = equipes[i]; + document.getElementById(`${i}.mallette`).checked = equipe.state.mallette; document.getElementById(`${i}.invisibility`).checked = equipe.state.invisibility; document.getElementById(`${i}.blurred`).checked = equipe.state.blurred; document.getElementById(`${i}.tracker`).checked = equipe.state.tracker; @@ -136,6 +142,7 @@ } } equipes[id] = data; + document.getElementById(`${id}.mallette`).checked = data.state.mallette; document.getElementById(`${id}.invisibility`).checked = data.state.invisibility; document.getElementById(`${id}.blurred`).checked = data.state.blurred; document.getElementById(`${id}.tracker`).checked = data.state.tracker; diff --git a/traque.js b/traque.js index e44ca35..005edf2 100644 --- a/traque.js +++ b/traque.js @@ -7,7 +7,8 @@ "invisibilty" : bool, "blurred": bool, "tracker" : bool, - "npc" : int + "npc" : int, + "mallette": bool }, "codes" : { "invisiblity" : int, @@ -129,12 +130,24 @@ io.use(function(socket, next){ } }); +async function join_leave(team_id, join, leave){ + var sockets = await io.in(team_id).fetchSockets(); + for(s of sockets){ + for(r of join) + s.join(r); + for(r of leave) + s.leave(r); + } +} + ///////////////// // Tracking room // // Everyone in this room is located // sub-rooms : // * "npc" room for non-player +// * "Tracker" room for trackers +// * "mallette" room for player with a mallette // * "%ID" room of a team // // To join : @@ -144,6 +157,8 @@ io.use(function(socket, next){ // } // "conscrit" are classical player, "vieux" are npcs (they can become tracker when needed) var tracking = io.to("Tracking"); +var tracker = io.to("Tracker"); +var mallette = io.to("mallette"); ///////////////// // Admin room @@ -157,14 +172,20 @@ var admin = io.to("Admin"); // visible color of a team function color(team){ + if(team.state.tracker) return 1; + if(team.state.npc != 0) return team.state.npc - 0 + 2; + return 0; +} + +function admin_color(team){ if(team.state.invisibility) return 2; if(team.state.tracker) return 1; if(team.state.npc != 0) return team.state.npc - 0 + 2; return 0; } -// apparent information of a team, for other only -function apparent_info(equipe){ +// apparent information of a team, for tracker only +function apparent_info_tracker(equipe){ if(equipe.state.invisibility) return {"id": equipe.id, "color": color(equipe), "position": [0,0]}; if(equipe.state.blurred) @@ -174,11 +195,31 @@ function apparent_info(equipe){ return {"id": equipe.id, "color": color(equipe), "position": equipe.pos}; } +// apparent information of a team, for mallette only +function apparent_info_mallette(equipe){ + if(equipe.state.npc == 0 && !equipe.state.tracker) + return {"id": equipe.id, "color": color(equipe), "position": equipe.pos}; + return apparent_info_agent(equipe); +} + +// apparent information of a team, for agent only +function apparent_info_agent(equipe){ + if(equipe.state.mallette) + return {"id": equipe.id, "color": color(equipe), "position": equipe.pos}; + if(equipe.state.npc == 0 && !equipe.state.tracker) + return {"id": equipe.id, "color": color(equipe), "position": [0,0]}; + return apparent_info_tracker(equipe); +} + function emit_update(team_id) { var equipe = equipes[team_id]; - tracking.except(team_id).emit('moving', apparent_info(equipe)); - // the team and the admins always have the real informations - admin.to(team_id).emit('moving', {"id": team_id, "color": color(equipe), "position": equipe.pos}); + tracker.except(team_id).emit('moving', apparent_info_tracker(equipe)); + mallette.except(team_id).emit('moving', apparent_info_mallette(equipe)); + tracking.except("Tracker").except("mallette").except(team_id).emit('moving', apparent_info_agent(equipe)); + + // the team, the npcs and the admins always have the real informations + admin.to("npc").to(team_id) + .emit('moving', {"id": team_id, "color": admin_color(equipe), "position": equipe.pos}); admin.emit('update', equipe); } @@ -189,6 +230,7 @@ function default_team(team_id, valid) { state.blurred = false; state.tracker = false; state.npc = valid; + state.mallette = false; var codes = {}; codes.blurred = 0; @@ -203,15 +245,36 @@ function default_team(team_id, valid) { return equipe; } +function send_update(team){ + io.to(team.id).emit('moving', {"id": team.id, "color": color(team), "position": team.pos}); + for(other_id in equipes) + if(other_id != team.id){ + if(team.state.tracker) + io.to(team.id).emit('moving', apparent_info_tracker(equipes[other_id])); + else if(team.state.mallette) + io.to(team.id).emit('moving', apparent_info_mallette(equipes[other_id])); + else if(team.state.npc != 0) + io.to(team.id).emit('moving', {"id": team_id, "color": admin_color(equipe), "position": equipe.pos}); + else + io.to(team.id).emit('moving', apparent_info_agent(equipes[other_id])); + } +} + // connect a socket to the room corresponding to its team and send it infos function team_join(team, socket){ socket.join(team.id); - var state = team.state; - if(state.npc != 0) socket.join("npc"); socket.emit('moving', {"id": team.id, "color": color(team), "position": team.pos}); for(other_id in equipes) - if(other_id != team.id) - socket.emit('moving', apparent_info(equipes[other_id])); + if(other_id != team.id){ + if(team.state.tracker) + socket.emit('moving', apparent_info_tracker(equipes[other_id])); + else if(team.state.mallette) + socket.emit('moving', apparent_info_mallette(equipes[other_id])); + else if(team.state.npc != 0) + socket.emit('moving', {"id": team_id, "color": admin_color(equipe), "position": equipe.pos}); + else + socket.emit('moving', apparent_info_agent(equipes[other_id])); + } } console.log("Setup handlers"); @@ -220,6 +283,10 @@ io.on('connection', function(socket){ var id = socket.handshake.auth.id; var equipe = equipes[id] socket.join("Tracking"); + if(equipe.state.tracker) + socket.join("Tracker"); + if(equipe.state.mallette) + socket.join("mallette"); team_join(equipe, socket); socket.on("useCode", function(code){ @@ -240,7 +307,7 @@ io.on('connection', function(socket){ if(socket.handshake.auth.type == "vieux"){ var id = socket.handshake.auth.id; var equipe = equipes[id] - socket.join("Tracking"); + socket.join("npc"); team_join(equipe, socket); socket.on('changeState', function(d){ @@ -271,6 +338,19 @@ io.on('connection', function(socket){ socket.on('setState', function(d){ equipes[d.id].state = d.state; + var join = []; + var leave = []; + if(d.state.tracker) + join.push("Tracker"); + else + leave.push("Tracker"); + if(d.state.mallette){ + join.push("mallette"); + } else{ + leave.push("mallette"); + } + join_leave(d.id, join, leave); + send_update(equipes[d.id]); emit_update(d.id); if(equipes[d.id].vieux) io.to(d.id).emit('newState', d.state); @@ -282,39 +362,6 @@ io.on('connection', function(socket){ socket.emit('update', equipe); } } - - -//ici essentiellement tout est a refaire -// socket.on('message', function(d){ -// d.content = d.content.toLowerCase(); -// if(d.content == PWD_TRACKED){ -// d.color = 0; -// socket.emit('popup', {"content": MSG_TRACKED}); -// } else if(d.content == PWD_TRACKER){ -// 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 -// socket.color = d.color - 0; -// if(d.color == -1) -// socket.shown = false; -// else{ -// if(!socket.shown) -// for(i in equipes) -// equipes[i].emit('moving', {"id": socket.id, "position": socket.position}); -// socket.shown = true; -// } -// for(i in equipes) -// equipes[i].emit('changeColor', {"id": socket.id, "color": d.color}); -// }); -// socket.on("disconnect", function(_){ -// console.log(socket.id + " disconnect"); -// socket.shown = false; -// for(i in equipes) -// equipes[i].emit('remove', {"id": socket.id}); -// }); }); console.log("Launch server");
IDMallette Invisible Brouillé Tracker${id}