mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-11 08:06:33 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
154 lines
6.2 KiB
Plaintext
154 lines
6.2 KiB
Plaintext
GENERAL_PROTECT_DATUM(/datum/controller/subsystem/admin_verbs)
|
|
|
|
SUBSYSTEM_DEF(admin_verbs)
|
|
name = "Admin Verbs"
|
|
ss_flags = SS_NO_FIRE
|
|
init_stage = INITSTAGE_EARLY
|
|
/// A list of all admin verbs indexed by their type.
|
|
var/list/datum/admin_verb/admin_verbs_by_type = list()
|
|
/// A list of all admin verbs indexed by their visibility flag.
|
|
var/list/list/datum/admin_verb/admin_verbs_by_visibility_flag = list()
|
|
/// A map of all assosciated admins and their visibility flags.
|
|
var/list/admin_visibility_flags = list()
|
|
/// A list of all admins that are pending initialization of this SS.
|
|
var/list/admins_pending_subsytem_init = list()
|
|
|
|
/datum/controller/subsystem/admin_verbs/Initialize()
|
|
setup_verb_list()
|
|
process_pending_admins()
|
|
return SS_INIT_SUCCESS
|
|
|
|
/datum/controller/subsystem/admin_verbs/Recover()
|
|
admin_verbs_by_type = SSadmin_verbs.admin_verbs_by_type
|
|
|
|
/datum/controller/subsystem/admin_verbs/stat_entry(msg)
|
|
msg = "V:[length(admin_verbs_by_type)]"
|
|
return ..()
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/process_pending_admins()
|
|
var/list/pending_admins = admins_pending_subsytem_init
|
|
admins_pending_subsytem_init = null
|
|
for(var/admin_ckey in pending_admins)
|
|
assosciate_admin(GLOB.directory[admin_ckey])
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/setup_verb_list()
|
|
if(length(admin_verbs_by_type))
|
|
CRASH("Attempting to setup admin verbs twice!")
|
|
for(var/datum/admin_verb/verb_type as anything in subtypesof(/datum/admin_verb))
|
|
var/datum/admin_verb/verb_singleton = new verb_type
|
|
if(!verb_singleton.__avd_check_should_exist())
|
|
qdel(verb_singleton, force = TRUE)
|
|
continue
|
|
|
|
admin_verbs_by_type[verb_type] = verb_singleton
|
|
if(verb_singleton.visibility_flag)
|
|
if(!(verb_singleton.visibility_flag in admin_verbs_by_visibility_flag))
|
|
admin_verbs_by_visibility_flag[verb_singleton.visibility_flag] = list()
|
|
admin_verbs_by_visibility_flag[verb_singleton.visibility_flag] |= list(verb_singleton)
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/get_valid_verbs_for_admin(client/admin)
|
|
if(isnull(admin.holder))
|
|
CRASH("Why are we checking a non-admin for their valid... ahem... admin verbs?")
|
|
|
|
var/list/has_permission = list()
|
|
for(var/permission_flag in GLOB.bitflags)
|
|
if(admin.holder.check_for_rights(permission_flag))
|
|
has_permission["[permission_flag]"] = TRUE
|
|
|
|
var/list/valid_verbs = list()
|
|
for(var/datum/admin_verb/verb_type as anything in admin_verbs_by_type)
|
|
var/datum/admin_verb/verb_singleton = admin_verbs_by_type[verb_type]
|
|
if(!verify_visibility(admin, verb_singleton))
|
|
continue
|
|
|
|
var/verb_permissions = verb_singleton.permissions
|
|
if(verb_permissions == R_NONE)
|
|
valid_verbs |= list(verb_singleton)
|
|
else for(var/permission_flag in bitfield_to_list(verb_permissions))
|
|
if(!has_permission["[permission_flag]"])
|
|
continue
|
|
valid_verbs |= list(verb_singleton)
|
|
|
|
return valid_verbs
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/verify_visibility(client/admin, datum/admin_verb/verb_singleton)
|
|
var/needed_flag = verb_singleton.visibility_flag
|
|
return !needed_flag || (needed_flag in admin_visibility_flags[admin.ckey])
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/update_visibility_flag(client/admin, flag, state)
|
|
if(state)
|
|
admin_visibility_flags[admin.ckey] |= list(flag)
|
|
assosciate_admin(admin)
|
|
return
|
|
|
|
admin_visibility_flags[admin.ckey] -= list(flag)
|
|
// they lost the flag, iterate over verbs with that flag and yoink em
|
|
for(var/datum/admin_verb/verb_singleton as anything in admin_verbs_by_visibility_flag[flag])
|
|
verb_singleton.unassign_from_client(admin)
|
|
admin.init_verbs()
|
|
|
|
/datum/controller/subsystem/admin_verbs/proc/dynamic_invoke_verb(client/admin, datum/admin_verb/verb_type, ...)
|
|
if(IsAdminAdvancedProcCall())
|
|
message_admins("PERMISSION ELEVATION: [key_name_admin(admin)] attempted to dynamically invoke admin verb '[verb_type]'.")
|
|
return
|
|
|
|
if(ismob(admin))
|
|
var/mob/mob = admin
|
|
admin = mob.client
|
|
|
|
if(!ispath(verb_type, /datum/admin_verb) || verb_type == /datum/admin_verb)
|
|
CRASH("Attempted to dynamically invoke admin verb with invalid typepath '[verb_type]'.")
|
|
if(isnull(admin.holder))
|
|
CRASH("Attempted to dynamically invoke admin verb '[verb_type]' with a non-admin.")
|
|
|
|
var/list/verb_args = args.Copy()
|
|
verb_args.Cut(2, 3)
|
|
var/datum/admin_verb/verb_singleton = admin_verbs_by_type[verb_type] // this cannot be typed because we need to use `:`
|
|
if(isnull(verb_singleton))
|
|
CRASH("Attempted to dynamically invoke admin verb '[verb_type]' that doesn't exist.")
|
|
|
|
if(!admin.holder.check_for_rights(verb_singleton.permissions))
|
|
to_chat(admin, span_adminnotice("You lack the permissions to do this."))
|
|
return
|
|
|
|
var/old_usr = usr
|
|
usr = admin.mob
|
|
// THE MACRO ENSURES THIS EXISTS. IF IT EVER DOESNT EXIST SOMEONE DIDNT USE THE DAMN MACRO!
|
|
verb_singleton.__avd_do_verb(arglist(verb_args))
|
|
usr = old_usr
|
|
SSblackbox.record_feedback("tally", "dynamic_admin_verb_invocation", 1, "[verb_type]")
|
|
|
|
/**
|
|
* Assosciates and/or resyncs an admin with their accessible admin verbs.
|
|
*/
|
|
/datum/controller/subsystem/admin_verbs/proc/assosciate_admin(client/admin)
|
|
if(IsAdminAdvancedProcCall())
|
|
return
|
|
|
|
if(!isnull(admins_pending_subsytem_init)) // if the list exists we are still initializing
|
|
to_chat(admin, span_big(span_green("Admin Verbs are still initializing. Please wait and you will be automatically assigned your verbs when it is complete.")))
|
|
admins_pending_subsytem_init |= list(admin.ckey)
|
|
return
|
|
|
|
// refresh their verbs
|
|
admin_visibility_flags[admin.ckey] ||= list()
|
|
if(admin.is_localhost())
|
|
admin_visibility_flags[admin.ckey] |= list(ADMIN_VERB_VISIBLITY_FLAG_LOCALHOST)
|
|
for(var/datum/admin_verb/verb_singleton as anything in get_valid_verbs_for_admin(admin))
|
|
verb_singleton.assign_to_client(admin)
|
|
admin.init_verbs()
|
|
|
|
/**
|
|
* Unassosciates an admin from their admin verbs.
|
|
* Goes over all admin verbs because we don't know which ones are assigned to the admin's mob without a bunch of extra bookkeeping.
|
|
* This might be a performance issue in the future if we have a lot of admin verbs.
|
|
*/
|
|
/datum/controller/subsystem/admin_verbs/proc/deassosciate_admin(client/admin)
|
|
if(IsAdminAdvancedProcCall())
|
|
return
|
|
|
|
UnregisterSignal(admin, COMSIG_CLIENT_MOB_LOGIN)
|
|
for(var/datum/admin_verb/verb_type as anything in admin_verbs_by_type)
|
|
admin_verbs_by_type[verb_type].unassign_from_client(admin)
|
|
admin_visibility_flags -= list(admin.ckey)
|