summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rwxr-xr-xserver.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/server.js b/server.js
index 791a227..e9d0761 100755
--- a/server.js
+++ b/server.js
@@ -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());
});