From c0c76c3f05ae7af2d35bfba80ae175f509ce5ccd Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 7 Apr 2023 04:31:52 -0500 Subject: [PATCH] [NO GBP] Fix minigames UI not removing inactive clients (#74391) ## About The Pull Request Fixes #74260 The UI for the basketball menu was not properly updating when clients would disconnect. This would allow someone to signup twice leading to silly situations as detailed in the issue report. This issue also affected the mafia minigame due to both UIs having similar code. The fix is simple, just check the signups when the tgui menu has interactions and also check to make sure the signups use a boolean instead of a client for the value part of the key/value list. Why? After a client would disconnect, the list would change and remove the client object since it no longer exists. The solution is to keep the ckey as a key, but use a boolean for the value. ## Why It's Good For The Game Less bugs, more stability. ## Changelog :cl: fix: Fix basketball and mafia minigame UI not removing inactive clients /:cl: --------- Co-authored-by: Fikou <23585223+Fikou@users.noreply.github.com> --- code/modules/basketball/controller.dm | 15 +++++++++------ code/modules/mafia/controller.dm | 10 ++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/code/modules/basketball/controller.dm b/code/modules/basketball/controller.dm index 3fdb746a33e..f5cc286ba2a 100644 --- a/code/modules/basketball/controller.dm +++ b/code/modules/basketball/controller.dm @@ -313,14 +313,15 @@ GLOBAL_VAR(basketball_game) */ /datum/basketball_controller/proc/check_signups() for(var/bad_key in GLOB.basketball_bad_signup) - if(GLOB.directory[bad_key]) //they have reconnected if we can search their key and get a client + var/client/signup_client = GLOB.directory[bad_key] + if(signup_client) //they have reconnected if we can search their key and get a client GLOB.basketball_bad_signup -= bad_key - GLOB.basketball_signup += bad_key + GLOB.basketball_signup[bad_key] = TRUE for(var/key in GLOB.basketball_signup) var/client/signup_client = GLOB.directory[key] if(!signup_client) //vice versa but in a variable we use later GLOB.basketball_signup -= key - GLOB.basketball_bad_signup += key + GLOB.basketball_bad_signup[key] = TRUE continue if(!isobserver(signup_client.mob)) //they are back to playing the game, remove them from the signups @@ -341,6 +342,7 @@ GLOBAL_VAR(basketball_game) return GLOB.always_state /datum/basketball_controller/ui_interact(mob/user, datum/tgui/ui) + check_signups() ui = SStgui.try_update_ui(user, src, ui) if(!ui) ui = new(user, src, "BasketballPanel") @@ -378,11 +380,12 @@ GLOBAL_VAR(basketball_game) switch(action) if("basketball_signup") - if(GLOB.basketball_signup[ghost_client.ckey]) - GLOB.basketball_signup -= ghost_client.ckey // double check this works? + if(GLOB.basketball_signup[ghost_client.ckey] || GLOB.basketball_bad_signup[ghost_client.ckey]) + GLOB.basketball_signup -= ghost_client.ckey + GLOB.basketball_bad_signup -= ghost_client.ckey to_chat(ghost_client, span_notice("You unregister from basketball.")) else - GLOB.basketball_signup[ghost_client.ckey] = ghost_client + GLOB.basketball_signup[ghost_client.ckey] = TRUE to_chat(ghost_client, span_notice("You sign up for basketball.")) check_signups() diff --git a/code/modules/mafia/controller.dm b/code/modules/mafia/controller.dm index 6062aff18fe..0ab3cc49e92 100644 --- a/code/modules/mafia/controller.dm +++ b/code/modules/mafia/controller.dm @@ -624,9 +624,7 @@ for(var/key in GLOB.mafia_signup + GLOB.mafia_bad_signup) var/list/lobby_member = list() lobby_member["name"] = key - lobby_member["status"] = "Ready" - if(key in GLOB.mafia_bad_signup) - lobby_member["status"] = "Disconnected" + lobby_member["status"] = (key in GLOB.mafia_bad_signup) ? "Disconnected" : "Ready" lobby_member["spectating"] = "Ghost" if(key in spectators) lobby_member["spectating"] = "Spectator" @@ -744,7 +742,7 @@ to_chat(usr, span_notice("You unregister from Mafia.")) return TRUE else - GLOB.mafia_signup[C.ckey] = C + GLOB.mafia_signup[C.ckey] = TRUE to_chat(usr, span_notice("You sign up for Mafia.")) if(phase == MAFIA_PHASE_SETUP) check_signups() @@ -1065,12 +1063,12 @@ for(var/bad_key in GLOB.mafia_bad_signup) if(GLOB.directory[bad_key])//they have reconnected if we can search their key and get a client GLOB.mafia_bad_signup -= bad_key - GLOB.mafia_signup += bad_key + GLOB.mafia_signup[bad_key] = TRUE for(var/key in GLOB.mafia_signup) var/client/C = GLOB.directory[key] if(!C)//vice versa but in a variable we use later GLOB.mafia_signup -= key - GLOB.mafia_bad_signup += key + GLOB.mafia_bad_signup[key] = TRUE continue if(!isobserver(C.mob)) //they are back to playing the game, remove them from the signups