From 5a6ff98e2a8f7f82d84dbf807c9abf50a62446c0 Mon Sep 17 00:00:00 2001 From: san7890 Date: Sat, 25 May 2024 16:57:29 -0600 Subject: [PATCH] Cleans up some admin-related stuff in client `Destroy()` and `adminGreet()` (#83427) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## About The Pull Request It made me really mad to see a huge list in the middle of client/Destroy for something that doesn't even run for 95% of users so I split it out into another proc so the fingerprint of the very important `Destroy()` stuff could be as minimal as possible without a big `pick()` so the server can send the "I need a man 🥺" message could be punted off to where no-one would care for it. It was already doing the async TGS operation so it doesn't matter anyways as far as proc overhead in my books. I also fixed up the code for `adminGreet()` as well because that was being really weird with not having proper booleans and running `pick()` on things with literally one value (as well as excess stringification)... it wasn't good so I just cleaned all that up too. Ideally this all means we take up a little less CPU time but the aim of this PR is to just clean it all up for modern coding standards. alphabetized lists and early returns galore. ## Why It's Good For The Game Code is better to read and less idented, and better yet it's no longer necessary to read all the softie messages in the middle of `Destroy()` ## Changelog Irrelevant --- code/modules/admin/admin.dm | 25 ++++++++------- code/modules/client/client_procs.dm | 48 +++++++++++++++++++---------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 10b9a58b870..5f40de037f4 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -286,14 +286,17 @@ ADMIN_VERB(create_or_modify_area, R_DEBUG, "Create Or Modify Area", "Create of m return TRUE -/client/proc/adminGreet(logout) - if(SSticker.HasRoundStarted()) - var/string - if(logout && CONFIG_GET(flag/announce_admin_logout)) - string = pick( - "Admin logout: [key_name(src)]") - else if(!logout && CONFIG_GET(flag/announce_admin_login) && (prefs.toggles & ANNOUNCE_LOGIN)) - string = pick( - "Admin login: [key_name(src)]") - if(string) - message_admins("[string]") +/// Sends a message to adminchat when anyone with a holder logs in or logs out. +/// Is dependent on admin preferences and configuration settings, which means that this proc can fire without sending a message. +/client/proc/adminGreet(logout = FALSE) + if(!SSticker.HasRoundStarted()) + return + + if(logout && CONFIG_GET(flag/announce_admin_logout)) + message_admins("Admin logout: [key_name(src)]") + return + + if(!logout && CONFIG_GET(flag/announce_admin_login) && (prefs.toggles & ANNOUNCE_LOGIN)) + message_admins("Admin login: [key_name(src)]") + return + diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 924eb3abe41..1d92bde9dfb 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -597,26 +597,10 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( if(credits) QDEL_LIST(credits) if(holder) - adminGreet(1) holder.owner = null GLOB.admins -= src - if (!GLOB.admins.len && SSticker.IsRoundInProgress()) //Only report this stuff if we are currently playing. - var/cheesy_message = pick( - "I have no admins online!",\ - "I'm all alone :(",\ - "I'm feeling lonely :(",\ - "I'm so lonely :(",\ - "Why does nobody love me? :(",\ - "I want a man :(",\ - "Where has everyone gone?",\ - "I need a hug :(",\ - "Someone come hold me :(",\ - "I need someone on me :(",\ - "What happened? Where has everyone gone?",\ - "Forever alone :("\ - ) + handle_admin_logout() - send2adminchat("Server", "[cheesy_message] (No admins online)") QDEL_LIST_ASSOC_VAL(char_render_holders) SSambience.remove_ambience_client(src) @@ -1272,6 +1256,36 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( screen -= object +/// Handles any "fluff" or supplementary procedures related to an admin logout event. Should not have anything critically related cleaning up an admin's logout. +/client/proc/handle_admin_logout() + adminGreet(logout = TRUE) + if(length(GLOB.admins) > 0 || !SSticker.IsRoundInProgress()) // We only want to report this stuff if we are currently playing. + return + + var/list/message_to_send = list() + var/static/list/cheesy_messages = null + + if (isnull(cheesy_messages)) + cheesy_messages = list( + "Forever alone :(", + "I have no admins online!", + "I need a hug :(", + "I need someone on me :(", + "I want a man :(", + "I'm all alone :(", + "I'm feeling lonely :(", + "I'm so lonely :(", + "Someone come hold me :(", + "What happened? Where has everyone gone?", + "Where has everyone gone?", + "Why does nobody love me? :(", + ) + + message_to_send += pick(cheesy_messages) + message_to_send += "(No admins online)" + + send2adminchat("Server", jointext(message_to_send, " ")) + #undef ADMINSWARNED_AT #undef CURRENT_MINUTE #undef CURRENT_SECOND