Compare commits
No commits in common. "da4e41870794dd03190dbad085bcd26a3b5a39cf" and "98e8ac05bba2d0c68d433d38eecc4961524a9435" have entirely different histories.
da4e418707
...
98e8ac05bb
@ -29,7 +29,6 @@ module.exports = {
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"no-mixed-spaces-and-tabs": "off"
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
34
src/index.js
34
src/index.js
@ -31,27 +31,23 @@ app.get("/", (req, res) => {
|
||||
io.on("connection", (socket) => {
|
||||
// Handle disconnection
|
||||
socket.on("disconnect", () => {
|
||||
|
||||
if (players[socket.id]) {
|
||||
const room = players[socket.id].room;
|
||||
const room = players[socket.id].room;
|
||||
delete players[socket.id];
|
||||
|
||||
var playerUpdate = {};
|
||||
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);
|
||||
|
||||
console.log(traffic.out + colours.disconnect(`User ${String(socket.id)} disconnected from room ${room}`));
|
||||
|
||||
if (io.sockets.adapter.rooms[room] == undefined) {
|
||||
console.log(traffic.int + colours.room(`Room ${room} has been deleted due to a lack of players`));
|
||||
}
|
||||
var playerUpdate = {};
|
||||
if (io.sockets.adapter.rooms[room]) {
|
||||
for (const id in io.sockets.adapter.rooms[room].sockets) {
|
||||
playerUpdate[id] = players[id];
|
||||
}
|
||||
}
|
||||
|
||||
delete players[socket.id];
|
||||
io.in(room).emit("roomUpdate", playerUpdate);
|
||||
|
||||
console.log(traffic.out + colours.disconnect(`User ${String(socket.id)} disconnected from room ${room}`));
|
||||
|
||||
if (io.sockets.adapter.rooms[room] == undefined) {
|
||||
console.log(traffic.int + colours.room(`Room ${room} has been deleted due to a lack of players`));
|
||||
}
|
||||
});
|
||||
|
||||
// Request identification
|
||||
@ -129,4 +125,4 @@ io.on("connection", (socket) => {
|
||||
|
||||
http.listen(port, () => {
|
||||
console.log(colours.data(`\nServer ready, listening on port ${port}\n`));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user