From 745ba4d903a9ff2d7f8edf43b33155b63e3c2ca1 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Fri, 27 Nov 2020 20:17:40 +0100 Subject: [PATCH] Fixed issue TanksJS-Server service --- src/services/tanks.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/services/tanks.js b/src/services/tanks.js index fe58f7a..94b7d1d 100644 --- a/src/services/tanks.js +++ b/src/services/tanks.js @@ -24,8 +24,8 @@ function handle(io, socket) { const room = players[socket.id].room; var playerUpdate = {}; - if (io.sockets.adapter.rooms.get(room)) { - io.sockets.adapter.rooms.get(room).forEach((id) => { + if (io.adapter.rooms.get(room)) { + io.adapter.rooms.get(room).forEach((id) => { playerUpdate[id] = players[id]; }); } @@ -34,7 +34,7 @@ function handle(io, socket) { console.log(traffic.out + colours.disconnect(`User ${String(socket.id)} disconnected from room ${room}`)); - if (io.sockets.adapter.rooms.get(room) == undefined) { + if (io.adapter.rooms.get(room) == undefined) { console.log(traffic.int + colours.room(`Room ${room} has been deleted due to a lack of players`)); delete rooms[room]; } @@ -57,12 +57,12 @@ function handle(io, socket) { var join = ""; // Check if there are any available rooms for the requested game and check if they aren't full - io.sockets.adapter.rooms.forEach((set, room) => { + io.adapter.rooms.forEach((set, room) => { if (/[0-9]_[0-9].*/i.test(room)) { var roomId = room.split("_"); if (roomId[0] == data.gameID) { if (roomId[1] == data.playersMax) { - if (io.sockets.adapter.rooms.get(room).size < data.playersMax) { + if (io.adapter.rooms.get(room).size < data.playersMax) { if (!rooms[room].started) { join += room; } else { @@ -80,7 +80,7 @@ function handle(io, socket) { if (join == "") { var count = 0; var regex = new RegExp(data.gameID + "_" + data.playersMax + "_[0-9].*"); - io.sockets.adapter.rooms.forEach((set, room) => { + io.adapter.rooms.forEach((set, room) => { if (regex.test(room)) { count++; } @@ -98,7 +98,7 @@ function handle(io, socket) { socket.join(join); // Start game if the max number of players is reached - if (io.sockets.adapter.rooms.get(join).size == data.playersMax) { + if (io.adapter.rooms.get(join).size == data.playersMax) { console.log(traffic.int + colours.room(`Room ${join} has reached the maximum amount of players, starting game`)); io.in(join).emit("gameStart"); rooms[join].started = true; @@ -110,7 +110,7 @@ function handle(io, socket) { }; var playerUpdate = {}; - io.sockets.adapter.rooms.get(join).forEach((id) => { + io.adapter.rooms.get(join).forEach((id) => { playerUpdate[id] = players[id]; }); @@ -129,7 +129,7 @@ function handle(io, socket) { }); socket.on("spectate", (data) => { - if (io.sockets.adapter.rooms.has(data)) { + if (io.adapter.rooms.has(data)) { console.log(traffic.in + colours.connect(`User ${String(socket.id)} is spectating room ${data}`)); socket.join(data); }