From cd09e532fb03332f39e9d6e661d665bc80e23dcf Mon Sep 17 00:00:00 2001 From: Sylvain Gay Date: Tue, 13 Sep 2022 13:59:20 +0200 Subject: [PATCH] =?UTF-8?q?ajout=C3=A9=20client=20conscrit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/{map.html => vieilleux.html} | 0 traque.js | 38 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) rename static/{map.html => vieilleux.html} (100%) diff --git a/static/map.html b/static/vieilleux.html similarity index 100% rename from static/map.html rename to static/vieilleux.html diff --git a/traque.js b/traque.js index 4e49b14..3b209bc 100644 --- a/traque.js +++ b/traque.js @@ -17,6 +17,15 @@ Les messages à transmettre par le serveur : - setName(id, name) */ +// Textes d'interaction avec les conscrits +var PWD_TRACKED = "tracked"; +var PWD_TRACKER = "tracker"; +var PWD_INVISIBLE = "invisible"; +var MSG_BAD = "La base n'a pas compris votre message..."; +var MSG_TRACKED = "Vous êtes maintenant traqué.e.s !" +var MSG_TRACKER = "Vous pouvez maintenant traquer !"; +var MSG_INVISIBLE = "Les autres équipes ne peuvent plus vous voir !"; + var equipes = []; // require = include @@ -39,7 +48,7 @@ var server = http.createServer(option, function(req, res){ if(q.pathname.includes("..")) filename = "static/dotdot.html"; if(q.pathname == "/") - filename = "static/map.html"; + filename = "static/conscrit.html"; fs.readFile(filename, function(err, data) { if (err) { console.log("404: ", q.pathname, filename); @@ -85,6 +94,33 @@ io.sockets.on('connection', function(socket){ for(i in equipes) equipes[i].emit('changeColor', {"id": socket.id, "color": d.color}); }); + socket.on('message', function(d){ + 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.emit('popup', {"content": MSG_BAD}); + return; + } + 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('setName', function(d){ socket.name = d.name; for(i in equipes)