Fixed issue TanksJS-Server service
This commit is contained in:
parent
8f4545ed27
commit
745ba4d903
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user