Refactor SocketUser class location and update imports; add new ClientHandler for game management

This commit is contained in:
2025-03-27 22:50:08 +01:00
parent 031fd65332
commit f4cfe1e111
8 changed files with 51 additions and 8 deletions

View File

@@ -0,0 +1,37 @@
const socketIO = require("socket.io");
const SocketUser = require("../Classes/SocketUser");
const LobbyManager = require("../LobbyManager/LobbyManager");
class ClientHandler {
/** @param {socketIO.Socket} socket @param {LobbyManager} lobbyManager */
constructor(socket, lobbyManager) {
this.socket = socket;
this.lobbyManager = lobbyManager;
this.user = new SocketUser(
this.socket.request.session.user.id,
this.socket.request.session.user.username,
this.socket
);
this.socket.on("disconnect", () => { this.defaultDisconnect() })
this.checkForLobby();
}
checkForLobby(){
const isUserInLobby = this.lobbyManager.oldLobbys.some((lobby) =>
lobby.users.some((user) => user.id === this.user.id)
);
if (!isUserInLobby) {
this.socket.disconnect();
}
}
defaultDisconnect(){
}
}
module.exports = ClientHandler;