You've already forked KF-MMO-Server
Backend refactor, player-user decoupling
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { lobbyMessage } from "../Classes/lobbyMessage";
|
||||
import { playerData } from "../Classes/playerData"
|
||||
import { playerInventory } from "../Classes/playerInventory";
|
||||
import { userData } from "../Classes/userData";
|
||||
import { game } from "../game";
|
||||
|
||||
export function registerLobbyCallbacks(socket){
|
||||
@@ -11,16 +10,10 @@ export function registerLobbyCallbacks(socket){
|
||||
let buff = Buffer.from(data, 'base64');
|
||||
let data1 : playerData = JSON.parse(buff.toString('utf-8'));
|
||||
|
||||
let pd = new playerData()
|
||||
pd.socketId = socket.id
|
||||
pd.userName = socket.user.login
|
||||
pd.characterId = data1.characterId;
|
||||
pd.inventory = data1.inventory;
|
||||
socket.user.playerData = pd
|
||||
|
||||
game.lobbyState.players.push(socket.user.playerData)
|
||||
socket.player.characterId = data1.characterId
|
||||
game.lobbyState.addUser(socket.user, socket.player)
|
||||
game.socketIO.emit("lobby/playerJoin", JSON.stringify(game.lobbyState))
|
||||
socket.emit('lobby/messages', JSON.stringify(game.messages))
|
||||
game.addMessage(new lobbyMessage(socket.user.login + " joined"))
|
||||
});
|
||||
|
||||
socket.on('lobby/playerUpdate', (data) => {
|
||||
@@ -28,14 +21,13 @@ export function registerLobbyCallbacks(socket){
|
||||
|
||||
let buff = Buffer.from(data, 'base64');
|
||||
let data1 : playerData = JSON.parse(buff.toString('utf-8'));
|
||||
data1.socketId = socket.id
|
||||
|
||||
let idx = game.lobbyState.players.findIndex((pl) => pl.socketId == socket.id)
|
||||
if(idx == -1){
|
||||
let player = game.lobbyState.findPlayer(socket.user.id)
|
||||
if(player == null){
|
||||
console.log("Error! Player not spawned!")
|
||||
}
|
||||
else{
|
||||
game.lobbyState.players[idx].rigidbody = data1.rigidbody
|
||||
player.rigidbody = data1.rigidbody
|
||||
}
|
||||
});
|
||||
|
||||
@@ -54,10 +46,11 @@ export function registerLobbyCallbacks(socket){
|
||||
let buff = Buffer.from(data, 'base64');
|
||||
let data1 : playerData = JSON.parse(buff.toString('utf-8'));
|
||||
|
||||
socket.user.playerData.inventory = data1.inventory
|
||||
playerInventory.validate(socket.user.playerData.inventory)
|
||||
let player = game.lobbyState.findPlayer(socket.user.id)
|
||||
player.inventory = data1.inventory
|
||||
playerInventory.validate(player.inventory)
|
||||
|
||||
game.socketIO.emit("lobby/loadoutChanged", JSON.stringify(socket.user.playerData))
|
||||
game.socketIO.emit("lobby/loadoutChanged", JSON.stringify(player))
|
||||
});
|
||||
|
||||
socket.on('lobby/message', (data) => {
|
||||
|
||||
Reference in New Issue
Block a user