1
0

Fixed a bug in the server.js

This commit is contained in:
Mathias Wagner 2023-11-23 07:55:43 +01:00
parent 4e542068d2
commit 8f13c5d080
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -125,6 +125,9 @@ io.on("connection", (socket) => {
socket.on("SUBMIT", (data, callback = () => {}) => { socket.on("SUBMIT", (data, callback = () => {}) => {
const {price, amount} = data; const {price, amount} = data;
const roomCode = getRoomCodeBySocketId(socket.id);
if (!roomCode) return;
if (price === undefined || amount === undefined) { if (price === undefined || amount === undefined) {
callback(false); callback(false);
@ -144,13 +147,12 @@ io.on("connection", (socket) => {
return; return;
} }
if (price < 0 || price > rooms[getRoomCodeBySocketId(socket.id)].settings.maxPrice || if (price < 0 || price > rooms[roomCode].settings.maxPrice ||
amount < 0 || amount > rooms[getRoomCodeBySocketId(socket.id)].settings.maxProduction) { amount < 0 || amount > rooms[roomCode].settings.maxProduction) {
callback(false); callback(false);
return; return;
} }
const roomCode = getRoomCodeBySocketId(socket.id);
const playerName = getPlayerName(socket.id, roomCode); const playerName = getPlayerName(socket.id, roomCode);
io.to(rooms[roomCode].host).emit("RECEIVED", {id: socket.id, name: playerName, price, amount}); io.to(rooms[roomCode].host).emit("RECEIVED", {id: socket.id, name: playerName, price, amount});