forked from arne/TanksJS-Server
Merge pull request 'Fixed a bug which causes the server to crash when a player that wasn't in a room disconnected.' (#1) from corner/TanksJS-Server:no-room-crash into master
This commit is contained in:
commit
da4e418707
@ -29,6 +29,7 @@ module.exports = {
|
|||||||
"semi": [
|
"semi": [
|
||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
]
|
],
|
||||||
|
"no-mixed-spaces-and-tabs": "off"
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -31,8 +31,9 @@ app.get("/", (req, res) => {
|
|||||||
io.on("connection", (socket) => {
|
io.on("connection", (socket) => {
|
||||||
// Handle disconnection
|
// Handle disconnection
|
||||||
socket.on("disconnect", () => {
|
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 = {};
|
var playerUpdate = {};
|
||||||
if (io.sockets.adapter.rooms[room]) {
|
if (io.sockets.adapter.rooms[room]) {
|
||||||
@ -48,6 +49,9 @@ io.on("connection", (socket) => {
|
|||||||
if (io.sockets.adapter.rooms[room] == undefined) {
|
if (io.sockets.adapter.rooms[room] == undefined) {
|
||||||
console.log(traffic.int + colours.room(`Room ${room} has been deleted due to a lack of players`));
|
console.log(traffic.int + colours.room(`Room ${room} has been deleted due to a lack of players`));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete players[socket.id];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request identification
|
// Request identification
|
||||||
|
Loading…
Reference in New Issue
Block a user