diff options
Diffstat (limited to 'server.js')
-rwxr-xr-x | server.js | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -145,27 +145,40 @@ io.on("connection", socket => { } console.log(`new socket connection id=${socket_id} (nc=${num_connected})`); + let logged_in = false; + socket.on("disconnect", () => { num_connected--; console.log(`disconnect id=${socket_id} (nc=${num_connected})`); }); + socket.on("login", pass => { + if (pass == fs.readFileSync(__dirname + "/password.txt").toString().trim()) { + console.log(`login id=${socket_id}`); + logged_in = true; + socket.emit("init", database.get()); + } else { + socket.emit("unauth"); + } + }); + socket.on("new", string => { + if (!logged_in) { socket.emit("unauth"); return; } const res = database.add_new(string); if (res != null) socket.emit("error", res); }); socket.on("set_votes", (string, votes) => { + if (!logged_in) { socket.emit("unauth"); return; } const res = database.set_votes(string, votes); if (res != null) socket.emit("error", res); }); socket.on("delete", string =>{ + if (!logged_in) { socket.emit("unauth"); return; } const res = database.remove(string); if (res != null) socket.emit("error", res); }); - - socket.emit("init", database.get()); }); |