From 65bdf635860832b0c105a5d2ebde83b6e947dcfa Mon Sep 17 00:00:00 2001
From: Francinum <5572280+francinum@users.noreply.github.com>
Date: Fri, 9 Aug 2024 21:58:21 -0400
Subject: [PATCH 1/3] Proto: Allow viewing account link code without panic
bunker
---
code/modules/admin/verbs/admingame.dm | 1 +
code/modules/client/client_defines.dm | 3 ++
code/modules/client/client_procs.dm | 3 ++
.../mob/dead/new_player/new_player_panel.dm | 30 ++++++++++++-------
4 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/code/modules/admin/verbs/admingame.dm b/code/modules/admin/verbs/admingame.dm
index 6d4a585060f8..d50a34162461 100644
--- a/code/modules/admin/verbs/admingame.dm
+++ b/code/modules/admin/verbs/admingame.dm
@@ -45,6 +45,7 @@
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
body += "
\[Byond version: [full_version]\]
"
body += "
Input Mode: [M.client.hotkeys ? "Using Hotkeys" : "Using Classic Input"]
"
+ body += "
Linked Discord ID: [M.client.linked_discord_account ? M.client.linked_discord_account : "NONE"]
"
body += "
\[ "
diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm
index 257ee7802f1a..2a61eba072de 100644
--- a/code/modules/client/client_defines.dm
+++ b/code/modules/client/client_defines.dm
@@ -111,6 +111,9 @@
var/account_join_date = null
///Age of byond account in days
var/account_age = -1
+ ///Linked Discord account ID. Null is valid if the bunker is disabled.
+ var/linked_discord_account = null
+
preload_rsc = PRELOAD_RSC
diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm
index 64f4982e6596..9f2858efc389 100644
--- a/code/modules/client/client_procs.dm
+++ b/code/modules/client/client_procs.dm
@@ -533,6 +533,9 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
//Clear the credits browser if it's left over the from the previous round
clear_credits()
+ //Open to moving this: Pull the player's discord link if one exists:
+ linked_discord_account = discord_lookup_id(ckey)
+
view_size = new(src, getScreenSize(prefs.read_preference(/datum/preference/toggle/widescreen)))
view_size.resetFormat()
view_size.setZoomMode()
diff --git a/code/modules/mob/dead/new_player/new_player_panel.dm b/code/modules/mob/dead/new_player/new_player_panel.dm
index 529df727fe45..447c0c22377c 100644
--- a/code/modules/mob/dead/new_player/new_player_panel.dm
+++ b/code/modules/mob/dead/new_player/new_player_panel.dm
@@ -23,17 +23,19 @@
if(!parent.client)
return
- if(parent.client.restricted_mode)
- if(href_list["verify"])
- show_otp_menu()
- return TRUE
- if(href_list["link_to_discord"])
- var/_link = CONFIG_GET(string/panic_bunker_discord_link)
- if(_link)
- parent << link(_link)
- return TRUE
+ if(href_list["verify"])
+ show_otp_menu()
+ return TRUE
+ if(href_list["link_to_discord"])
+ var/_link = CONFIG_GET(string/panic_bunker_discord_link)
+ if(_link)
+ parent << link(_link)
+ return TRUE
+
+ //Restricted clients can't do anything else.
+ if(parent.client.restricted_mode)
return TRUE
if(href_list["npp_options"])
@@ -218,6 +220,9 @@
@@ -330,6 +335,10 @@
if(!parent.client)
return
+ if(parent.client.linked_discord_account)
+ alert(parent.client, "Your discord account is already linked.\nIf you believe this is in error, please contact staff.\nLinked ID: [parent.client.linked_discord_account]", "Already Linked")
+ return
+
var/discord_otp = parent.client.discord_get_or_generate_one_time_token_for_ckey(parent.ckey)
var/discord_prefix = CONFIG_GET(string/discordbotcommandprefix)
var/browse_body = {"
@@ -348,7 +357,8 @@
"}
var/datum/browser/popup = new(parent, "discordauth", "
Verification
", 660, 270)
- popup.set_window_options("can_close=0;focus=true;can_resize=0")
+ //If we aren't in restricted mode, let them close the window.
+ popup.set_window_options("can_close=[!parent.client.restricted_mode];focus=true;can_resize=0")
popup.set_content(browse_body)
popup.open()
From 240541e7d6aafefc4ae371a4b4ac00ec28bbde11 Mon Sep 17 00:00:00 2001
From: Francinum <5572280+francinum@users.noreply.github.com>
Date: Fri, 9 Aug 2024 22:34:59 -0400
Subject: [PATCH 2/3] Let's do this better.
---
code/modules/admin/verbs/admingame.dm | 5 +++-
code/modules/client/client_defines.dm | 2 +-
code/modules/client/client_procs.dm | 2 +-
code/modules/discord/discord_helpers.dm | 24 +++++++++++++++++++
.../mob/dead/new_player/new_player_panel.dm | 12 ++++++++--
5 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/code/modules/admin/verbs/admingame.dm b/code/modules/admin/verbs/admingame.dm
index d50a34162461..8e12c1386fec 100644
--- a/code/modules/admin/verbs/admingame.dm
+++ b/code/modules/admin/verbs/admingame.dm
@@ -45,7 +45,10 @@
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
body += "
\[
Byond version: [full_version]\]
"
body += "
Input Mode: [M.client.hotkeys ? "Using Hotkeys" : "Using Classic Input"]
"
- body += "
Linked Discord ID: [M.client.linked_discord_account ? M.client.linked_discord_account : "NONE"]
"
+ if(isnull(M.client.linked_discord_account))
+ body += "
Linked Discord ID: MISSING RESPONSE DATUM, HAVE THEY JUST JOINED OR IS SQL DISABLED?
"
+ else
+ body += "
Linked Discord ID: [M.client.linked_discord_account.valid ? M.client.linked_discord_account.discord_id : "NONE"]
"
body += "
\[ "
diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm
index 2a61eba072de..ae9dea3a4c67 100644
--- a/code/modules/client/client_defines.dm
+++ b/code/modules/client/client_defines.dm
@@ -112,7 +112,7 @@
///Age of byond account in days
var/account_age = -1
///Linked Discord account ID. Null is valid if the bunker is disabled.
- var/linked_discord_account = null
+ var/datum/discord_link_record/linked_discord_account = NULL
preload_rsc = PRELOAD_RSC
diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm
index 9f2858efc389..a93bc0add6b3 100644
--- a/code/modules/client/client_procs.dm
+++ b/code/modules/client/client_procs.dm
@@ -534,7 +534,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
clear_credits()
//Open to moving this: Pull the player's discord link if one exists:
- linked_discord_account = discord_lookup_id(ckey)
+ discord_read_linked_id()
view_size = new(src, getScreenSize(prefs.read_preference(/datum/preference/toggle/widescreen)))
view_size.resetFormat()
diff --git a/code/modules/discord/discord_helpers.dm b/code/modules/discord/discord_helpers.dm
index c4cf1432e6fc..b2168998105d 100644
--- a/code/modules/discord/discord_helpers.dm
+++ b/code/modules/discord/discord_helpers.dm
@@ -52,3 +52,27 @@
if(link)
return link.valid
return FALSE
+
+/**
+ * Checks if the the given ckey has a valid discord link. This also updates the client's linked account var.
+ * Returns: TRUE if valid, FALSE if invalid or missing.
+ */
+/client/proc/discord_read_linked_id()
+ var/datum/discord_link_record/link = find_discord_link_by_ckey(ckey, timebound = FALSE) //We need their persistent link.
+ if(!link)
+
+ //No link history *at all?*, let's quietly create a blank one for them and check again.
+ discord_generate_one_time_token(ckey)
+ link = find_discord_link_by_ckey(ckey, timebound = FALSE)
+
+ if(!link)
+ //Fuck it, I give up. Set return value and stack.
+ . = FALSE
+ CRASH("Could not coerce a valid discord link record for [ckey].")
+
+ linked_discord_account = link
+
+ if(link.valid && link.discord_id)
+ return TRUE
+
+ return FALSE
diff --git a/code/modules/mob/dead/new_player/new_player_panel.dm b/code/modules/mob/dead/new_player/new_player_panel.dm
index 447c0c22377c..d699fc2c85c7 100644
--- a/code/modules/mob/dead/new_player/new_player_panel.dm
+++ b/code/modules/mob/dead/new_player/new_player_panel.dm
@@ -335,8 +335,16 @@
if(!parent.client)
return
- if(parent.client.linked_discord_account)
- alert(parent.client, "Your discord account is already linked.\nIf you believe this is in error, please contact staff.\nLinked ID: [parent.client.linked_discord_account]", "Already Linked")
+ if(!CONFIG_GET(flag/sql_enabled))
+ alert(parent.client, "No database to link to, bud. Scream at the host.", "Writing to Nowhere.")
+ return
+
+ if(isnull(parent.client.linked_discord_account))
+ alert(parent.client, "You haven't fully loaded, please wait...", "Please Wait")
+ return
+
+ if(parent.client.linked_discord_account?.valid)
+ alert(parent.client, "Your discord account is already linked.\nIf you believe this is in error, please contact staff.\nLinked ID: [parent.client.linked_discord_account.discord_id]", "Already Linked")
return
var/discord_otp = parent.client.discord_get_or_generate_one_time_token_for_ckey(parent.ckey)
From d7ab94851e37deeb620b728f24ae5a4458a9ed31 Mon Sep 17 00:00:00 2001
From: Francinum <5572280+francinum@users.noreply.github.com>
Date: Fri, 9 Aug 2024 22:41:38 -0400
Subject: [PATCH 3/3] I may be stupid
---
code/modules/client/client_defines.dm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm
index ae9dea3a4c67..441a71405cb3 100644
--- a/code/modules/client/client_defines.dm
+++ b/code/modules/client/client_defines.dm
@@ -112,7 +112,7 @@
///Age of byond account in days
var/account_age = -1
///Linked Discord account ID. Null is valid if the bunker is disabled.
- var/datum/discord_link_record/linked_discord_account = NULL
+ var/datum/discord_link_record/linked_discord_account = null
preload_rsc = PRELOAD_RSC