Compare commits

..

No commits in common. "cf607fa060dc0b6b814000709371964984f691d5" and "8459e7df2134e05acabead786d9cbfffeb7d0122" have entirely different histories.

View File

@ -1,13 +1,9 @@
const timeoutTickRate = 1; //timeout check every x seconds
const timeoutLength = 5000; //timeout length in ms
var gameObjectStore = {}; //object which stores CSNCgameobjects for each client
//below is an example of the structure of gameobjectstore
/**
* {
* "2c0a48e9-40c6-4139-9697-992397773b12":
* time: Date.now(),
* gameObjects: [
* "2c0a48e9-40c6-4139-9697-992397773b12": [
* {
"type": "razorblade",
"transform": {
@ -46,21 +42,6 @@ var gameObjectStore = {}; //object which stores CSNCgameobjects for each client
*
*/
/**
* @param {string} uuid
*/
function removePlayer(uuid) {
delete gameObjectStore[uuid];
}
function checkTimeout() {
for (let key in gameObjectStore) {
if (Date.now() - gameObjectStore[key].time > timeoutLength) {
removePlayer(key);
}
}
}
/**
* @param {http.ServerResponse<http.IncomingMessage>} res
* @param {string} req
@ -72,7 +53,9 @@ async function handleResponse(res, req) {
var request = JSON.parse(req);
let gameObjects = request.gameObjects;
gameObjectStore[request.uuid] = {gameObjects: gameObjects, time: Date.now()}; //store gameobjects to send to other players
gameObjectStore[request.uuid] = gameObjects; //store gameobjects to send to other players
res.writeHead(200);
res.write(JSON.stringify(responseObjectHelper(request.uuid)));
@ -85,7 +68,6 @@ async function handleResponse(res, req) {
}
}
//preps and returns data to send back to client
function responseObjectHelper(uuid) {
var responseObject = {
@ -94,11 +76,9 @@ function responseObjectHelper(uuid) {
for (let key in gameObjectStore) {
if (key == uuid) continue; //dont send back players own data
responseObject.gameObjects = responseObject.gameObjects.concat(gameObjectStore[key].gameObjects);
responseObject.gameObjects = responseObject.gameObjects.concat(gameObjectStore[key]);
}
return responseObject;
}
setInterval(checkTimeout, timeoutTickRate * 1000);
exports.handleResponse = handleResponse;