significant optimzations

This commit is contained in:
biglyderv 2024-11-25 14:14:20 -05:00
parent 3ce6ded308
commit 37b516faee
5 changed files with 71 additions and 20 deletions

View file

@ -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 () {