1
0

Updated the server.js

This commit is contained in:
Mathias Wagner 2023-11-22 14:04:18 +01:00
parent b6c72a2a68
commit 33199439ab
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -116,6 +116,11 @@ io.on("connection", (socket) => {
socket.on("UPDATE_CAPITAL", (data, callback = () => {}) => {
const {id, capital} = data;
if (rooms[getRoomCodeBySocketId(socket.id)].host !== socket.id) {
callback(false);
return;
}
if (!id || capital === undefined) {
callback(false);
return;
@ -125,7 +130,11 @@ io.on("connection", (socket) => {
if (capital < 5000) {
socket.emit("LEFT", {id: socket.id});
io.sockets.sockets.get(id).disconnect();
rooms[getRoomCodeBySocketId(socket.id)].players = rooms[getRoomCodeBySocketId(socket.id)].players
.filter((player) => player.id !== socket.id);
io.to(id).emit("GAME_OVER");
}
callback(true);