Compare commits

..

No commits in common. "44b3a6ff60d7f56b3993861218d481057037be34" and "462bbac9ceb15333d3384f8c48db298ea485839d" have entirely different histories.

View File

@ -21,7 +21,6 @@ const traffic = {
};
var players = {};
var rooms = {};
// Send players json object
app.get("/", (req, res) => {
@ -36,10 +35,10 @@ io.on("connection", (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.sockets.adapter.rooms[room]) {
for (const id in io.sockets.adapter.rooms[room].sockets) {
playerUpdate[id] = players[id];
});
}
}
io.in(room).emit("roomUpdate", playerUpdate);
@ -48,7 +47,6 @@ io.on("connection", (socket) => {
if (io.sockets.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];
}
}
@ -75,11 +73,7 @@ io.on("connection", (socket) => {
if (roomId[0] == data.gameID) {
if (roomId[1] == data.playersMax) {
if (io.sockets.adapter.rooms.get(room).size < data.playersMax) {
if (!rooms[room].started) {
join += room;
} else {
console.log(traffic.int + colours.room(`Room ${room} has already started, skipping.`));
}
join += room;
} else {
console.log(traffic.int + colours.room(`Room ${room} is full, skipping.`));
}
@ -99,11 +93,6 @@ io.on("connection", (socket) => {
});
join = data.gameID + "_" + data.playersMax + "_" + count;
rooms[join] = {
started: false
};
console.log(traffic.int + colours.room(`There is no room available for the requested game, making room ${join}`));
}
@ -113,7 +102,6 @@ io.on("connection", (socket) => {
if (io.sockets.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;
}
players[socket.id] = {
@ -121,6 +109,8 @@ io.on("connection", (socket) => {
room: join
};
console.log(players);
var playerUpdate = {};
io.sockets.adapter.rooms.get(join).forEach((id) => {
playerUpdate[id] = players[id];