Skip to content

Commit

Permalink
[no gbp] Fixes deathmatch observers (#82931)
Browse files Browse the repository at this point in the history
## About The Pull Request
Got a little ahead of myself. My apologies. Fixes some cases in the
deathmatch UI that cause blue screens / improper perms.

I've also made deathmatch send an actual array rather than an object.
Don't make javascript iterate object.keys please. Fixed the types
surrounding this.
## Why It's Good For The Game
Fixes #82926
## Changelog
:cl:
fix: Fixes a bluescreen in the deathmatch lobby UI.
/:cl:
  • Loading branch information
jlsnow301 committed Apr 30, 2024
1 parent f407c49 commit 46354b0
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 167 deletions.
156 changes: 108 additions & 48 deletions code/modules/deathmatch/deathmatch_lobby.dm
Original file line number Diff line number Diff line change
Expand Up @@ -341,70 +341,54 @@


/datum/deathmatch_lobby/ui_data(mob/user)
. = list()
var/list/data = list()

var/is_player = !isnull(players[user.ckey])
var/is_host = (user.ckey == host)
var/is_admin = check_rights_for(user.client, R_ADMIN)
.["self"] = user.ckey
.["host"] = is_host
.["admin"] = is_admin
.["playing"] = playing
.["loadouts"] = list("Randomize")
var/has_auth = is_host || is_admin

data["active_mods"] = "No modifiers selected"
data["admin"] = is_admin
data["host"] = is_host
data["loadouts"] = list("Randomize")

for (var/datum/outfit/deathmatch_loadout/loadout as anything in loadouts)
.["loadouts"] += initial(loadout.display_name)
.["map"] = list()
.["map"]["name"] = map.name
.["map"]["desc"] = map.desc
.["map"]["time"] = map.automatic_gameend_time
.["map"]["min_players"] = map.min_players
.["map"]["max_players"] = map.max_players

.["mod_menu_open"] = FALSE
if((is_host || is_admin) && mod_menu_open)
.["mod_menu_open"] = TRUE
for(var/modpath in GLOB.deathmatch_game.modifiers)
var/datum/deathmatch_modifier/mod = GLOB.deathmatch_game.modifiers[modpath]
.["modifiers"] += list(list(
"name" = mod.name,
"desc" = mod.description,
"modpath" = "[modpath]",
"selected" = (modpath in modifiers),
"selectable" = is_host && mod.selectable(src),
))
.["active_mods"] = "No modifiers selected"
data["loadouts"] += loadout::display_name

data["map"] = list()
data["map"]["name"] = map.name
data["map"]["desc"] = map.desc
data["map"]["time"] = map.automatic_gameend_time
data["map"]["min_players"] = map.min_players
data["map"]["max_players"] = map.max_players

data["mod_menu_open"] = FALSE
data["modifiers"] = has_auth ? list() : get_modifier_list(is_host, mod_menu_open)
data["observers"] = get_observer_list()
data["players"] = get_player_list()
data["playing"] = playing
data["self"] = user.ckey

if(length(modifiers))
var/list/mod_names = list()
for(var/datum/deathmatch_modifier/modpath as anything in modifiers)
mod_names += initial(modpath.name)
.["active_mods"] = "Selected modifiers: [english_list(mod_names)]"
mod_names += modpath::name
data["active_mods"] = "Selected modifiers: [english_list(mod_names)]"

if(is_player && !isnull(players[user.ckey]["loadout"]))
var/datum/outfit/deathmatch_loadout/loadout = players[user.ckey]["loadout"]
.["loadoutdesc"] = initial(loadout.desc)
data["loadoutdesc"] = loadout::desc
else
.["loadoutdesc"] = "You are an observer! As an observer, you can hear lobby announcements."
.["players"] = list()
for (var/player_key in players)
var/list/player_info = players[player_key]
var/mob/player_mob = player_info["mob"]
if (isnull(player_mob) || !player_mob.client)
leave(player_key)
continue
.["players"][player_key] = player_info.Copy()
var/datum/outfit/deathmatch_loadout/dm_loadout = player_info["loadout"]
.["players"][player_key]["loadout"] = initial(dm_loadout.display_name)
.["observers"] = list()
for (var/observer_key in observers)
var/mob/observer = observers[observer_key]["mob"]
if (isnull(observer) || !observer.client)
leave(observer_key)
continue
.["observers"][observer_key] = observers[observer_key]
data["loadoutdesc"] = "You are an observer! As an observer, you can hear lobby announcements."

return data

/datum/deathmatch_lobby/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(. || !isobserver(usr))
return

switch(action)
if ("start_game")
if (usr.ckey != host)
Expand All @@ -414,13 +398,15 @@
return FALSE
start_game()
return TRUE

if ("leave_game")
if (playing)
return FALSE
leave(usr.ckey)
ui.close()
GLOB.deathmatch_game.ui_interact(usr)
return TRUE

if ("change_loadout")
if (playing)
return FALSE
Expand All @@ -435,6 +421,7 @@
players[params["player"]]["loadout"] = possible_loadout
break
return TRUE

if ("observe")
if (playing)
return FALSE
Expand All @@ -446,16 +433,19 @@
remove_ckey_from_play(usr.ckey)
add_player(usr, loadouts[1], host == usr.ckey)
return TRUE

if ("ready")
players[usr.ckey]["ready"] ^= 1 // Toggle.
ready_count += (players[usr.ckey]["ready"] * 2) - 1 // scared?
if (ready_count >= players.len && players.len >= map.min_players)
start_game()
return TRUE

if ("host") // Host functions
if (playing || (usr.ckey != host && !check_rights(R_ADMIN)))
return FALSE
var/uckey = params["id"]

switch (params["func"])
if ("Kick")
leave(uckey)
Expand Down Expand Up @@ -484,12 +474,15 @@
return FALSE
change_map(params["map"])
return TRUE

if("open_mod_menu")
mod_menu_open = TRUE
return TRUE

if("exit_mod_menu")
mod_menu_open = FALSE
return TRUE

if("toggle_modifier")
var/datum/deathmatch_modifier/modpath = text2path(params["modpath"])
if(!ispath(modpath))
Expand All @@ -505,6 +498,7 @@
chosen_modifier.on_select(src)
modifiers += modpath
return TRUE

if ("admin") // Admin functions
if (!check_rights(R_ADMIN))
message_admins("[usr.key] has attempted to use admin functions in a deathmatch lobby!")
Expand All @@ -515,7 +509,73 @@
log_admin("[key_name(usr)] force started deathmatch lobby [host].")
start_game()

return FALSE


/datum/deathmatch_lobby/ui_close(mob/user)
. = ..()
if(user.ckey == host)
mod_menu_open = FALSE

/// Helper proc to get modifier data
/datum/deathmatch_lobby/proc/get_modifier_list(is_host, mod_menu_open)
var/list/modifier_list = list()

if(!mod_menu_open)
return modifier_list

for(var/modpath in GLOB.deathmatch_game.modifiers)
var/datum/deathmatch_modifier/mod = GLOB.deathmatch_game.modifiers[modpath]

UNTYPED_LIST_ADD(modifier_list, list(
"name" = mod.name,
"desc" = mod.description,
"modpath" = "[modpath]",
"selected" = (modpath in modifiers),
"selectable" = is_host && mod.selectable(src),
))

return modifier_list


/// Helper proc for getting observer data
/datum/deathmatch_lobby/proc/get_observer_list()
var/list/observer_list = list()

for (var/observer_key in observers)
var/list/observer_info = observers[observer_key]
var/mob/observer_mob = observer_info["mob"]

if (isnull(observer_mob) || !observer_mob.client)
leave(observer_key)
continue

var/list/observer = observer_info.Copy()
observer["key"] = observer_key

UNTYPED_LIST_ADD(observer_list, observer)

return observer_list


/// Helper proc for getting player data
/datum/deathmatch_lobby/proc/get_player_list()
var/list/player_list = list()

for (var/player_key in players)
var/list/player_info = players[player_key]
var/mob/player_mob = player_info["mob"]

if (isnull(player_mob) || !player_mob.client)
leave(player_key)
continue

var/list/player = player_info.Copy()

var/datum/outfit/deathmatch_loadout/dm_loadout = player_info["loadout"]
player["loadout"] = dm_loadout::display_name
player["key"] = player_key

UNTYPED_LIST_ADD(player_list, player)

return player_list

0 comments on commit 46354b0

Please sign in to comment.