summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2022-08-29 10:45:26 +0200
committerTom Smeding <t.j.smeding@uu.nl>2022-08-29 10:45:26 +0200
commit0116c966d3d6ea914ec4b9e3e5ec6e405d37f22d (patch)
tree27f515e059e4dbe16615eaf846a0ddb95232a5fd /server.js
parenta3bdfe58867d57b39cf139fe7134c020fc9dcb44 (diff)
login
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());
});