forked from arne/TanksJS-Server
Changed the console loggings
This commit is contained in:
parent
b351b281bd
commit
98e8ac05bb
29
src/index.js
29
src/index.js
@ -7,14 +7,11 @@ const port = 3000;
|
|||||||
var colours = require("colors");
|
var colours = require("colors");
|
||||||
colours.enable();
|
colours.enable();
|
||||||
colours.setTheme({
|
colours.setTheme({
|
||||||
verbose: "cyan",
|
request: "green",
|
||||||
prompt: "grey",
|
connect: "cyan",
|
||||||
info: "green",
|
disconnect: ["red", "dim"],
|
||||||
data: "grey",
|
room: ["brightWhite"],
|
||||||
help: "cyan",
|
data: "grey"
|
||||||
warn: "yellow",
|
|
||||||
debug: "blue",
|
|
||||||
error: "red"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const traffic = {
|
const traffic = {
|
||||||
@ -46,7 +43,11 @@ io.on("connection", (socket) => {
|
|||||||
|
|
||||||
io.in(room).emit("roomUpdate", playerUpdate);
|
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
|
// Request identification
|
||||||
@ -54,7 +55,7 @@ io.on("connection", (socket) => {
|
|||||||
|
|
||||||
// Wait for identification
|
// Wait for identification
|
||||||
socket.on("identification", (data) => {
|
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
|
// Define room to be joined
|
||||||
var join = "";
|
var join = "";
|
||||||
@ -68,7 +69,7 @@ io.on("connection", (socket) => {
|
|||||||
if (Object.keys(io.sockets.adapter.rooms[room].sockets).length < data.playersMax) {
|
if (Object.keys(io.sockets.adapter.rooms[room].sockets).length < data.playersMax) {
|
||||||
join += room;
|
join += room;
|
||||||
} else {
|
} 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;
|
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);
|
socket.join(join);
|
||||||
|
|
||||||
// Start game if the max number of players is reached
|
// Start game if the max number of players is reached
|
||||||
if (Object.keys(io.sockets.adapter.rooms[join].sockets).length == data.playersMax) {
|
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");
|
io.in(join).emit("gameStart");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ io.on("connection", (socket) => {
|
|||||||
|
|
||||||
io.in(join).emit("roomUpdate", playerUpdate);
|
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) => {
|
socket.on("update", (data) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user