Add logs
This commit is contained in:
parent
bd6fe0340c
commit
ed27b49205
29
index.js
29
index.js
@ -20,6 +20,23 @@ const io = socketio(socketHTTPSServer, {
|
|||||||
secure: true
|
secure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getCurrentTime() {
|
||||||
|
|
||||||
|
function addZero(i) {
|
||||||
|
if (i < 10) {
|
||||||
|
i = "0" + i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var d = new Date();
|
||||||
|
var h = addZero(d.getHours());
|
||||||
|
var m = addZero(d.getMinutes());
|
||||||
|
var s = addZero(d.getSeconds());
|
||||||
|
return h + ":" + m + ":" + s;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
usersConnected = 0;
|
usersConnected = 0;
|
||||||
lastUsername = 0;
|
lastUsername = 0;
|
||||||
|
|
||||||
@ -27,24 +44,28 @@ io.on("connection", (client) => {
|
|||||||
|
|
||||||
usersConnected++;
|
usersConnected++;
|
||||||
io.sockets.emit("update-count", {value: usersConnected});
|
io.sockets.emit("update-count", {value: usersConnected});
|
||||||
|
|
||||||
client.on("disconnect", () => {
|
client.on("disconnect", () => {
|
||||||
usersConnected--;
|
usersConnected--;
|
||||||
io.sockets.emit("update-count", {value: usersConnected});
|
io.sockets.emit("update-count", {value: usersConnected});
|
||||||
|
console.log(getCurrentTime() + ": Client disconnection")
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("message", (data) => {
|
client.on("message", (data) => {
|
||||||
if(data.message.toLowerCase().includes("denis")) {
|
if(data.message.toLowerCase().includes("denis")) {
|
||||||
io.sockets.emit("new-message", {author: client.usernameDenis, message: data.message});
|
io.sockets.emit("new-message", {author: client.usernameDenis, message: data.message});
|
||||||
|
console.log(getCurrentTime() + ": (" + client.usernameDenis + ") : " + data.message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
client.emit("warning");
|
client.emit("warning");
|
||||||
|
console.log(getCurrentTime() + ": (" + client.usernameDenis + ") : " + data.message + "(invalid)");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
lastUsername++;
|
lastUsername++;
|
||||||
client.usernameDenis = "DenisFan" + lastUsername;
|
client.usernameDenis = "DenisFan" + lastUsername;
|
||||||
client.emit("username", {username: "DenisFan" + lastUsername});
|
client.emit("username", {username: "DenisFan" + lastUsername});
|
||||||
|
console.log(getCurrentTime() + ": Client connection (" + client.usernameDenis + ")");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,13 +74,13 @@ app.use(express.static("src"));
|
|||||||
|
|
||||||
|
|
||||||
app.listen(80, () => {
|
app.listen(80, () => {
|
||||||
console.log("Web server started on port 80")
|
console.log(getCurrentTime() + ": Web server started on port 80")
|
||||||
});
|
});
|
||||||
|
|
||||||
webHTTPSServer.listen(443, () => {
|
webHTTPSServer.listen(443, () => {
|
||||||
console.log("Web HTTPS server started on port 443");
|
console.log(getCurrentTime() + ": Web HTTPS server started on port 443");
|
||||||
});
|
});
|
||||||
|
|
||||||
socketHTTPSServer.listen(3000, () => {
|
socketHTTPSServer.listen(3000, () => {
|
||||||
console.log("Socket HTTPS server started on port 3000");
|
console.log(getCurrentTime() + ": Socket HTTPS server started on port 3000");
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user