This commit is contained in:
2023-09-14 10:59:21 +02:00
commit 77ffe04e2f
14 changed files with 1982 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
export class lobbyMessageData{
Id: number;
User: string;
Timestamp: string;
Content: string;
}

32
Lobby/lobbySocket.ts Normal file
View File

@@ -0,0 +1,32 @@
import { game } from "../game";
export function registerLobbyCallbacks(socket){
socket.on('lobby/playerUpdate', (data) => {
let buff = Buffer.from(data, 'base64');
data = JSON.parse(buff.toString('utf-8'));
if (game.DBPlayers.hasOwnProperty(socket.id)){
game.DBPlayers[socket.id].position = data["position"]
}
else{
console.log("got incorrect request")
}
});
socket.on('lobby/message', (data) => {
let buff = Buffer.from(data, 'base64');
data = JSON.parse(buff.toString('utf-8'));
console.log(socket.conn.transport.name);
console.log("received message: " + JSON.stringify(data))
while(game.messages.length >= 20){
game.messages.pop();
}
console.log("broadcastin");
game.messages.unshift(data)
socket.io.emit('lobby/messages', JSON.stringify(game.messages))
});
}