32 lines
949 B
TypeScript
32 lines
949 B
TypeScript
|
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))
|
||
|
});
|
||
|
}
|