This commit is contained in:
Killian Marty 2023-12-06 09:40:15 +01:00
parent 24b6ba9298
commit 16e959a05c

View file

@ -93,7 +93,7 @@ wss.on('connection', (socket, req) => {
//create new player, send informations to new player and broadcast new player for all //create new player, send informations to new player and broadcast new player for all
let username = url.parse(req.url, true).query.name; let username = url.parse(req.url, true).query.name;
if(username===undefined){ if(username===undefined){
username = "joueur" username = "Soldat Inconnu"
} }
createNewPlayer(socket, username); createNewPlayer(socket, username);
@ -102,11 +102,12 @@ wss.on('connection', (socket, req) => {
if (message.type == "ping") { if (message.type == "ping") {
socket.send("pong"); socket.send("pong");
} else if(message.type=="update") { } else if(message.type=="update") {
players.forEach((player)=>{ for (var i = players.length - 1; i >= 0; i--) {
if(player.id==message.data.id){ if(player[i].id == message.data.id){
player = message.data; console.log(id);
players[i]=message.data;
} }
}) }
broadcast(JSON.stringify(message), socket.id); broadcast(JSON.stringify(message), socket.id);
} }
}); });