From 310a716304d4c6bcabd617d23855460d818e2d2c Mon Sep 17 00:00:00 2001
From: Thayol
Date: Sun, 13 Jun 2021 12:34:56 +0200
Subject: [PATCH] Introduced shutdown privilege.
---
templates.js | 2 +-
unalike.py | 16 ++++++++++++----
updater.js | 4 ++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/templates.js b/templates.js
index fccabbe..0b8a5a3 100644
--- a/templates.js
+++ b/templates.js
@@ -19,7 +19,7 @@ var buttonsIfOffline = `
`;
var buttonsIfOnline = `
-
+
🔌
Shut down
diff --git a/unalike.py b/unalike.py
index c729f77..0dab6f8 100644
--- a/unalike.py
+++ b/unalike.py
@@ -85,6 +85,8 @@ local_secret = "unset"
current_shutdown_timer = 0
+global_session_admin = ""
+
# folder structure setup
os.makedirs(lobbies_dir, exist_ok=True)
@@ -421,6 +423,9 @@ while running:
for request in request_json:
if "type" in request:
+ if global_session_admin == "" and "issuer" in request and "username" in request["issuer"]:
+ global_session_admin = request["issuer"]["username"]
+
if request["type"] == "invite" and "target" in request:
the_filter = False
if "filter" in request:
@@ -455,9 +460,11 @@ while running:
elif request["type"] == "register" and "target" in request:
print("Registering lobby: " + str(request["target"]))
irc_start_managing(request["target"], join=True)
- # elif request["type"] == "shutdown":
- # running = False
- # break
+ elif request["type"] == "shutdown":
+ if global_session_admin != "" and "issuer" in request and "username" in request["issuer"] and global_session_admin == request["issuer"]["username"]:
+ running = False
+ break
+
for line in lines:
if line.cmd in [ "001" ]:
@@ -727,7 +734,8 @@ while running:
temp_output["boot"] = boot_timestamp
temp_output["delay"] = global_irc_send_timeout
temp_output["maxLobbies"] = global_max_lobbies
- temp_output["current_mapset"] = current_mapset
+ temp_output["currentMapset"] = current_mapset
+ temp_output["sessionAdmin"] = global_session_admin
# uncomment to expose commands to the public
# temp_output["command_queue"] = global_irc_send_queue
diff --git a/updater.js b/updater.js
index a2a0be7..e0997ee 100644
--- a/updater.js
+++ b/updater.js
@@ -136,6 +136,10 @@ function updateUnalikeDisplay(unalikeJson) {
if (unalikeJson.shutdownTimer) {
newStatus += "
If nothing happens, Unalike will shut down in " + unalikeJson.shutdownTimer + " seconds.";
}
+
+ if (unalikeJson.sessionAdmin) {
+ newStatus += "
" + unalikeJson.sessionAdmin + " was the first to interact with Unalike. Only he/she can shut it down on command.";
+ }
// dynamicJsonElement = document.getElementById("dynamic-json");
// dynamicJsonElement.innerHTML = JSON.stringify(unalikeJson);