monke
This commit is contained in:
parent
e84027150e
commit
97ac9cea0b
1 changed files with 11 additions and 2 deletions
13
index.js
13
index.js
|
@ -22,6 +22,9 @@ app.ws('/', function (ws, req) {
|
||||||
|
|
||||||
ws.active = true;
|
ws.active = true;
|
||||||
|
|
||||||
|
console.log(`A player ${player.you} joined under IP ${req.headers["x-real-ip"]}`)
|
||||||
|
// This will only work under NGINX.
|
||||||
|
|
||||||
ws.on('message', function message(msg) {
|
ws.on('message', function message(msg) {
|
||||||
let data = {};
|
let data = {};
|
||||||
try {
|
try {
|
||||||
|
@ -32,15 +35,21 @@ app.ws('/', function (ws, req) {
|
||||||
}
|
}
|
||||||
let { vel, dir, you, ticks } = data;
|
let { vel, dir, you, ticks } = data;
|
||||||
let data2 = { vel, dir, you, ticks };
|
let data2 = { vel, dir, you, ticks };
|
||||||
|
|
||||||
|
let you2 = game.entities[playerI].you;
|
||||||
|
|
||||||
|
if (you != you2) {
|
||||||
|
console.log(`A player ${you2} now identifies as ${you}`);
|
||||||
|
}
|
||||||
|
|
||||||
game.entities[playerI] = Object.assign(game.entities[playerI], data2);
|
game.entities[playerI] = Object.assign(game.entities[playerI], data2);
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.on('close', function () {
|
ws.on('close', function () {
|
||||||
|
console.log(`A player ${you} left`);
|
||||||
ws.active = false;
|
ws.active = false;
|
||||||
player.health = -1;
|
player.health = -1;
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('socket', req.testing);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(process.env.PORT || 3069);
|
app.listen(process.env.PORT || 3069);
|
Loading…
Reference in a new issue