Skip to content

Commit ffedcdc

Browse files
authored
REOPEN: Allow viewing account link code without panic bunker (#1098)
* Proto: Allow viewing account link code without panic bunker * Let's do this better. * I may be stupid
1 parent 78038f7 commit ffedcdc

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

code/modules/admin/verbs/admingame.dm

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
4646
body += "<br>\[<b>Byond version:</b> [full_version]\]<br>"
4747
body += "<br><b>Input Mode:</b> [M.client.hotkeys ? "Using Hotkeys" : "Using Classic Input"]<br>"
48+
if(isnull(M.client.linked_discord_account))
49+
body += "<br><b>Linked Discord ID:</b> <code>MISSING RESPONSE DATUM, HAVE THEY JUST JOINED OR IS SQL DISABLED?</code><br>"
50+
else
51+
body += "<br><b>Linked Discord ID:</b> <code>[M.client.linked_discord_account.valid ? M.client.linked_discord_account.discord_id : "NONE"]</code><br>"
4852

4953

5054
body += "<br><br>\[ "

code/modules/client/client_defines.dm

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
var/account_join_date = null
112112
///Age of byond account in days
113113
var/account_age = -1
114+
///Linked Discord account ID. Null is valid if the bunker is disabled.
115+
var/datum/discord_link_record/linked_discord_account = null
116+
114117

115118
preload_rsc = PRELOAD_RSC
116119

code/modules/client/client_procs.dm

+3
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
533533
//Clear the credits browser if it's left over the from the previous round
534534
clear_credits()
535535

536+
//Open to moving this: Pull the player's discord link if one exists:
537+
discord_read_linked_id()
538+
536539
view_size = new(src, getScreenSize(prefs.read_preference(/datum/preference/toggle/widescreen)))
537540
view_size.resetFormat()
538541
view_size.setZoomMode()

code/modules/discord/discord_helpers.dm

+24
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,27 @@
5252
if(link)
5353
return link.valid
5454
return FALSE
55+
56+
/**
57+
* Checks if the the given ckey has a valid discord link. This also updates the client's linked account var.
58+
* Returns: TRUE if valid, FALSE if invalid or missing.
59+
*/
60+
/client/proc/discord_read_linked_id()
61+
var/datum/discord_link_record/link = find_discord_link_by_ckey(ckey, timebound = FALSE) //We need their persistent link.
62+
if(!link)
63+
64+
//No link history *at all?*, let's quietly create a blank one for them and check again.
65+
discord_generate_one_time_token(ckey)
66+
link = find_discord_link_by_ckey(ckey, timebound = FALSE)
67+
68+
if(!link)
69+
//Fuck it, I give up. Set return value and stack.
70+
. = FALSE
71+
CRASH("Could not coerce a valid discord link record for [ckey].")
72+
73+
linked_discord_account = link
74+
75+
if(link.valid && link.discord_id)
76+
return TRUE
77+
78+
return FALSE

code/modules/mob/dead/new_player/new_player_panel.dm

+28-10
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323
if(!parent.client)
2424
return
2525

26-
if(parent.client.restricted_mode)
27-
if(href_list["verify"])
28-
show_otp_menu()
29-
return TRUE
3026

31-
if(href_list["link_to_discord"])
32-
var/_link = CONFIG_GET(string/panic_bunker_discord_link)
33-
if(_link)
34-
parent << link(_link)
35-
return TRUE
27+
if(href_list["verify"])
28+
show_otp_menu()
29+
return TRUE
3630

31+
if(href_list["link_to_discord"])
32+
var/_link = CONFIG_GET(string/panic_bunker_discord_link)
33+
if(_link)
34+
parent << link(_link)
35+
return TRUE
36+
37+
//Restricted clients can't do anything else.
38+
if(parent.client.restricted_mode)
3739
return TRUE
3840

3941
if(href_list["npp_options"])
@@ -218,6 +220,9 @@
218220
<div>
219221
>[LINKIFY_CONSOLE_OPTION("lore_primer.txt", "view_primer=1")]
220222
</div>
223+
<div>
224+
>[LINKIFY_CONSOLE_OPTION("discord_link.lnk", "verify=1")]
225+
</div>
221226
[poll]
222227
<br>
223228
<div>
@@ -330,6 +335,18 @@
330335
if(!parent.client)
331336
return
332337

338+
if(!CONFIG_GET(flag/sql_enabled))
339+
alert(parent.client, "No database to link to, bud. Scream at the host.", "Writing to Nowhere.")
340+
return
341+
342+
if(isnull(parent.client.linked_discord_account))
343+
alert(parent.client, "You haven't fully loaded, please wait...", "Please Wait")
344+
return
345+
346+
if(parent.client.linked_discord_account?.valid)
347+
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")
348+
return
349+
333350
var/discord_otp = parent.client.discord_get_or_generate_one_time_token_for_ckey(parent.ckey)
334351
var/discord_prefix = CONFIG_GET(string/discordbotcommandprefix)
335352
var/browse_body = {"
@@ -348,7 +365,8 @@
348365
"}
349366

350367
var/datum/browser/popup = new(parent, "discordauth", "<center><div>Verification</div></center>", 660, 270)
351-
popup.set_window_options("can_close=0;focus=true;can_resize=0")
368+
//If we aren't in restricted mode, let them close the window.
369+
popup.set_window_options("can_close=[!parent.client.restricted_mode];focus=true;can_resize=0")
352370
popup.set_content(browse_body)
353371
popup.open()
354372

0 commit comments

Comments
 (0)