From 98e8ac05bba2d0c68d433d38eecc4961524a9435 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Tue, 28 Apr 2020 13:50:50 +0200 Subject: [PATCH] Changed the console loggings --- src/index.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index 6f5d659..14cdc50 100644 --- a/src/index.js +++ b/src/index.js @@ -7,14 +7,11 @@ const port = 3000; var colours = require("colors"); colours.enable(); colours.setTheme({ - verbose: "cyan", - prompt: "grey", - info: "green", - data: "grey", - help: "cyan", - warn: "yellow", - debug: "blue", - error: "red" + request: "green", + connect: "cyan", + disconnect: ["red", "dim"], + room: ["brightWhite"], + data: "grey" }); const traffic = { @@ -46,7 +43,11 @@ io.on("connection", (socket) => { io.in(room).emit("roomUpdate", playerUpdate); - console.log(traffic.out + colours.warn(`User ${String(socket.id)} disconnected from room ${room}`)); + 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 @@ -54,7 +55,7 @@ io.on("connection", (socket) => { // Wait for identification socket.on("identification", (data) => { - console.log(traffic.in + colours.info(`User ${String(socket.id)} playing ${data.gameID} is trying to join a room with ${data.playersMax} players max`)); + console.log(traffic.in + colours.request(`User ${String(socket.id)} playing ${data.gameID} is trying to join a room with ${data.playersMax} players max`)); // Define room to be joined var join = ""; @@ -68,7 +69,7 @@ io.on("connection", (socket) => { if (Object.keys(io.sockets.adapter.rooms[room].sockets).length < data.playersMax) { join += room; } else { - console.log(traffic.int + colours.warn(`Room ${room} is full, skipping.`)); + console.log(traffic.int + colours.room(`Room ${room} is full, skipping.`)); } } } @@ -86,14 +87,14 @@ io.on("connection", (socket) => { }); join = data.gameID + "_" + data.playersMax + "_" + count; - console.log(traffic.int + colours.warn(`There is no room available for the requested game, making ${join}`)); + console.log(traffic.int + colours.room(`There is no room available for the requested game, making room ${join}`)); } socket.join(join); - + // Start game if the max number of players is reached if (Object.keys(io.sockets.adapter.rooms[join].sockets).length == data.playersMax) { - console.log(traffic.int + colours.warn(`Room ${join} has reached the maximum amount of players, starting game`)); + console.log(traffic.int + colours.room(`Room ${join} has reached the maximum amount of players, starting game`)); io.in(join).emit("gameStart"); } @@ -109,7 +110,7 @@ io.on("connection", (socket) => { io.in(join).emit("roomUpdate", playerUpdate); - console.log(traffic.in + colours.help(`User ${String(socket.id)} connected to room ${join}`)); + console.log(traffic.in + colours.connect(`User ${String(socket.id)} connected to room ${join}`)); }); socket.on("update", (data) => {