significant optimzations
This commit is contained in:
parent
3ce6ded308
commit
37b516faee
5 changed files with 71 additions and 20 deletions
24
index.js
24
index.js
|
@ -1,6 +1,7 @@
|
|||
import express from "express";
|
||||
import expressW from "express-ws";
|
||||
import Game from "./game.js";
|
||||
import NPC from "./common/npc.js";
|
||||
import Player from "./common/player.js";
|
||||
|
||||
var app = express();
|
||||
|
@ -21,7 +22,8 @@ app.ws('/', function (ws, req) {
|
|||
game.entities[playerI] = player;
|
||||
|
||||
ws.active = true;
|
||||
|
||||
ws.ent = player;
|
||||
|
||||
// This will only work under NGINX.
|
||||
console.log(`A player ${player.you} joined under IP ${req.headers["x-real-ip"]}`)
|
||||
|
||||
|
@ -31,18 +33,24 @@ app.ws('/', function (ws, req) {
|
|||
data = JSON.parse(msg);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
data = {};
|
||||
data = [];
|
||||
}
|
||||
let { vel, dir, you, ticks, isMenu, r, playing } = data;
|
||||
let data2 = { vel, dir, you, ticks, isMenu, r, playing };
|
||||
|
||||
let you2 = game.entities[playerI].you;
|
||||
let newEnt = game.entities[playerI];
|
||||
|
||||
let {you} = newEnt;
|
||||
|
||||
let props = player.legalProps;
|
||||
|
||||
for (let i in props) {
|
||||
newEnt[props[i]] = data[i];
|
||||
}
|
||||
|
||||
let you2 = newEnt.you;
|
||||
|
||||
if (you != you2) {
|
||||
console.log(`A player ${you2} now identifies as ${you}`);
|
||||
console.log(`A player ${you} now identifies as ${you2}`);
|
||||
}
|
||||
|
||||
game.entities[playerI] = Object.assign(game.entities[playerI], data2);
|
||||
})
|
||||
|
||||
ws.on('close', function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue