You've already forked KF-MMO-Server
Init
This commit is contained in:
6
Lobby/lobbyMessageData.ts
Normal file
6
Lobby/lobbyMessageData.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export class lobbyMessageData{
|
||||
Id: number;
|
||||
User: string;
|
||||
Timestamp: string;
|
||||
Content: string;
|
||||
}
|
||||
32
Lobby/lobbySocket.ts
Normal file
32
Lobby/lobbySocket.ts
Normal 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))
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user