Merge branch '4-client-server-missing-password-to-change-color' into 'master'

ajouté client conscrit

Closes #4

See merge request sgay/traque!8
This commit is contained in:
Sylvain Gay 2022-09-13 14:00:03 +02:00
commit 38b1b699e2
2 changed files with 37 additions and 1 deletions

View file

@ -17,6 +17,15 @@ Les messages à transmettre par le serveur :
- setName(id, name) - 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 = []; var equipes = [];
// require = include // require = include
@ -39,7 +48,7 @@ var server = http.createServer(option, function(req, res){
if(q.pathname.includes("..")) if(q.pathname.includes(".."))
filename = "static/dotdot.html"; filename = "static/dotdot.html";
if(q.pathname == "/") if(q.pathname == "/")
filename = "static/map.html"; filename = "static/conscrit.html";
fs.readFile(filename, function(err, data) { fs.readFile(filename, function(err, data) {
if (err) { if (err) {
console.log("404: ", q.pathname, filename); console.log("404: ", q.pathname, filename);
@ -85,6 +94,33 @@ io.sockets.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('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.on('setName', function(d){
socket.name = d.name; socket.name = d.name;
for(i in equipes) for(i in equipes)