srv
This commit is contained in:
parent
86d3bb86d8
commit
49e9add522
1 changed files with 23 additions and 2 deletions
|
@ -105,17 +105,38 @@ wss.on('connection', (socket, req) => {
|
|||
socket.on('message', (message) => {
|
||||
message = JSON.parse(message);
|
||||
if (message.type == "ping") {
|
||||
|
||||
socket.send("pong");
|
||||
|
||||
}else if(message.type=="update") {
|
||||
|
||||
for (var i = players.length - 1; i >= 0; i--) {
|
||||
if(players[i].id == message.data.id){
|
||||
players[i]=message.data;
|
||||
}
|
||||
}
|
||||
broadcast(JSON.stringify(message), socket.id);
|
||||
|
||||
} else if(message.type=="newBullet"){
|
||||
console.log(message);
|
||||
|
||||
broadcast(JSON.stringify(message), socket.id);
|
||||
|
||||
} else if(message.type=="died"){
|
||||
|
||||
broadcast(JSON.stringify(message), socket.id);
|
||||
for (var i = players.length - 1; i >= 0; i--) {
|
||||
|
||||
if(players[i].id == message.data.id){
|
||||
let pos = generatePosition();
|
||||
players[i].x=pos[0];
|
||||
players[i].y=pos[1];
|
||||
|
||||
broadcast(JSON.stringify({
|
||||
type:"update",
|
||||
data: players[i]
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue