21 lines
842 B
TypeScript
21 lines
842 B
TypeScript
|
import { lobbyMessage } from "../Classes/lobbyMessage";
|
||
|
import { lobbyState } from "../Classes/lobbyState";
|
||
|
import { playerData } from "../Classes/playerData";
|
||
|
import { userData } from "../Classes/userData";
|
||
|
import { game } from "../game";
|
||
|
|
||
|
export function playerJoin(socket, data){
|
||
|
if(!socket.hasOwnProperty("user")) return;
|
||
|
|
||
|
let buff = Buffer.from(data, 'base64');
|
||
|
let data1 : playerData = JSON.parse(buff.toString('utf-8'));
|
||
|
|
||
|
socket.player.characterId = data1.characterId
|
||
|
game.lobbyState.addUser(socket.user, socket.player)
|
||
|
|
||
|
let newLobbyState : lobbyState = Object.assign({}, game.lobbyState);
|
||
|
newLobbyState.users = newLobbyState.users.map(u=> userData.makeSafe(u))
|
||
|
|
||
|
game.socketIO.emit("lobby/playerJoin", JSON.stringify(newLobbyState))
|
||
|
game.addMessage(new lobbyMessage(socket.user.login + " joined"))
|
||
|
}
|