Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REOPEN: Allow viewing account link code without panic bunker #1098

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code/modules/admin/verbs/admingame.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
body += "<br>\[<b>Byond version:</b> [full_version]\]<br>"
body += "<br><b>Input Mode:</b> [M.client.hotkeys ? "Using Hotkeys" : "Using Classic Input"]<br>"
if(isnull(M.client.linked_discord_account))
body += "<br><b>Linked Discord ID:</b> <code>MISSING RESPONSE DATUM, HAVE THEY JUST JOINED OR IS SQL DISABLED?</code><br>"
else
body += "<br><b>Linked Discord ID:</b> <code>[M.client.linked_discord_account.valid ? M.client.linked_discord_account.discord_id : "NONE"]</code><br>"


body += "<br><br>\[ "
Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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/datum/discord_link_record/linked_discord_account = null


preload_rsc = PRELOAD_RSC

Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
discord_read_linked_id()

view_size = new(src, getScreenSize(prefs.read_preference(/datum/preference/toggle/widescreen)))
view_size.resetFormat()
view_size.setZoomMode()
Expand Down
24 changes: 24 additions & 0 deletions code/modules/discord/discord_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 28 additions & 10 deletions code/modules/mob/dead/new_player/new_player_panel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -218,6 +220,9 @@
<div>
>[LINKIFY_CONSOLE_OPTION("lore_primer.txt", "view_primer=1")]
</div>
<div>
>[LINKIFY_CONSOLE_OPTION("discord_link.lnk", "verify=1")]
</div>
[poll]
<br>
<div>
Expand Down Expand Up @@ -330,6 +335,18 @@
if(!parent.client)
return

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)
var/discord_prefix = CONFIG_GET(string/discordbotcommandprefix)
var/browse_body = {"
Expand All @@ -348,7 +365,8 @@
"}

var/datum/browser/popup = new(parent, "discordauth", "<center><div>Verification</div></center>", 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()

Expand Down
Loading