Skip to content

Commit

Permalink
[MIRROR] Admin Verb Datums MkIII | Now with functional command bar (#…
Browse files Browse the repository at this point in the history
…2902)

* [MIRROR] Admin Verb Datums MkIII | Now with functional command bar (#1950)

* Admin Verb Datums MkIII | Now with functional command bar

* Update subsystems.dm

* EASY FIXES

The rest of these are.....uhhhhhhhhh

* Update fix_air.dm

* Converts our verbs to macros

* Update tools.dm

---------

Co-authored-by: Zephyr <[email protected]>
Co-authored-by: Bloop <[email protected]>
Co-authored-by: SomeRandomOwl <[email protected]>

* mc resolve

* admin verb added

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Zephyr <[email protected]>
Co-authored-by: Bloop <[email protected]>
Co-authored-by: SomeRandomOwl <[email protected]>
Co-authored-by: Iajret <[email protected]>
  • Loading branch information
6 people authored Apr 16, 2024
1 parent 1de73f7 commit 66e7198
Show file tree
Hide file tree
Showing 127 changed files with 2,013 additions and 3,600 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
},
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"editor.insertSpaces": false,
"git.branchProtection": ["master"],
"gitlens.advanced.blame.customArguments": ["-w"],
"tgstationTestExplorer.project.resultsType": "json",
Expand Down
3 changes: 2 additions & 1 deletion code/__DEFINES/_protect.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
return FALSE;\
}\
##Path/Read(savefile/savefile){\
qdel(src);\
del(src);\
}\
##Path/Write(savefile/savefile){\
return;\
}
#else
#define GENERAL_PROTECT_DATUM(Path)
#endif
// we del instead of qdel because for security reasons we must ensure the datum does not exist if Read is called. qdel will not enforce this.
3 changes: 2 additions & 1 deletion code/__DEFINES/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define BANTYPE_ANY_JOB 9

//Admin Permissions
/// Used for signifying that all admins can use this regardless of actual permissions
#define R_NONE NONE
#define R_BUILD (1<<0)
#define R_ADMIN (1<<1)
#define R_BAN (1<<2)
Expand Down Expand Up @@ -177,4 +179,3 @@ GLOBAL_VAR_INIT(ghost_role_flags, ALL)
/// Used in logging uses of admin verbs (and sometimes some non-admin or debug verbs) to the blackbox
/// Only pass it a string key, the verb being used.
#define BLACKBOX_LOG_ADMIN_VERB(the_verb) SSblackbox.record_feedback("tally", "admin_verb", 1, the_verb)

92 changes: 92 additions & 0 deletions code/__DEFINES/admin_verb.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/client/CanProcCall(procname)
if(findtext(procname, "__avd_") == 1)
message_admins("[key_name_admin(usr)] attempted to directly call admin verb '[procname]'.")
log_admin("[key_name(usr)] attempted to directly call admin verb '[procname]'.")
return FALSE
return ..()

/**
* This is the only macro you should use to define admin verbs.
* It will define the verb and the verb holder for you.
* Using it is very simple:
* ADMIN_VERB(verb_path, R_PERM, "Name", "Description", "Admin.Category", args...)
* This sets up all of the above and also acts as syntatic sugar as a verb delcaration for the verb itself.
* Note that the verb args have an injected `client/user` argument that is the user that called the verb.
* Do not use usr in your verb; technically you can but I'll kill you.
*/
#define _ADMIN_VERB(verb_path_name, verb_permissions, verb_name, verb_desc, verb_category, show_in_context_menu, verb_args...) \
/datum/admin_verb/##verb_path_name \
{ \
name = ##verb_name; \
description = ##verb_desc; \
category = ##verb_category; \
permissions = ##verb_permissions; \
verb_path = /client/proc/__avd_##verb_path_name; \
}; \
/client/proc/__avd_##verb_path_name(##verb_args) \
{ \
set name = ##verb_name; \
set desc = ##verb_desc; \
set hidden = FALSE; /* this is explicitly needed as the proc begins with an underscore */ \
set popup_menu = ##show_in_context_menu; \
set category = ##verb_category; \
var/list/_verb_args = list(usr, /datum/admin_verb/##verb_path_name); \
_verb_args += args; \
SSadmin_verbs.dynamic_invoke_verb(arglist(_verb_args)); \
}; \
/datum/admin_verb/##verb_path_name/__avd_do_verb(client/user, ##verb_args)

#define ADMIN_VERB(verb_path_name, verb_permissions, verb_name, verb_desc, verb_category, verb_args...) \
_ADMIN_VERB(verb_path_name, verb_permissions, verb_name, verb_desc, verb_category, FALSE, ##verb_args)

#define ADMIN_VERB_ONLY_CONTEXT_MENU(verb_path_name, verb_permissions, verb_name, verb_args...) \
_ADMIN_VERB(verb_path_name, verb_permissions, verb_name, ADMIN_VERB_NO_DESCRIPTION, ADMIN_CATEGORY_HIDDEN, TRUE, ##verb_args)

#define ADMIN_VERB_AND_CONTEXT_MENU(verb_path_name, verb_permissions, verb_name, verb_desc, verb_category, verb_args...) \
_ADMIN_VERB(verb_path_name, verb_permissions, verb_name, verb_desc, verb_category, TRUE, ##verb_args)

/// Used to define a special check to determine if the admin verb should exist at all. Useful for verbs such as play sound which require configuration.
#define ADMIN_VERB_CUSTOM_EXIST_CHECK(verb_path_name) \
/datum/admin_verb/##verb_path_name/__avd_check_should_exist()

/// Used to define the visibility flag of the verb. If the admin does not have this flag enabled they will not see the verb.
#define ADMIN_VERB_VISIBILITY(verb_path_name, verb_visibility) /datum/admin_verb/##verb_path_name/visibility_flag = ##verb_visibility

// These are put here to prevent the "procedure override precedes definition" error.
/datum/admin_verb/proc/__avd_get_verb_path()
CRASH("__avd_get_verb_path not defined. use the macro")
/datum/admin_verb/proc/__avd_do_verb(...)
CRASH("__avd_do_verb not defined. use the macro")
/datum/admin_verb/proc/__avd_check_should_exist()
return TRUE

/*
* This is an example of how to use the above macro:
* ```
* ADMIN_VERB(name_of_verb, R_ADMIN, "Verb Name", "Verb Desc", "Verb Category", mob/target in world)
* to_chat(user, "Hello!")
* ```
* Note the implied `client/user` argument that is injected into the verb.
* Also note that byond is shit and you cannot multi-line the macro call.
*/

/// Use this to mark your verb as not having a description. Should ONLY be used if you are also hiding the verb!
#define ADMIN_VERB_NO_DESCRIPTION ""
/// Used to verbs you do not want to show up in the master verb panel.
#define ADMIN_CATEGORY_HIDDEN null

// Admin verb categories
#define ADMIN_CATEGORY_MAIN "Admin"
#define ADMIN_CATEGORY_EVENTS "Admin.Events"
#define ADMIN_CATEGORY_FUN "Admin.Fun"
#define ADMIN_CATEGORY_GAME "Admin.Game"

// Special categories that are seperated
#define ADMIN_CATEGORY_DEBUG "Debug"
#define ADMIN_CATEGORY_SERVER "Server"
#define ADMIN_CATEGORY_OBJECT "Object"
#define ADMIN_CATEGORY_MAPPING "Mapping"
#define ADMIN_CATEGORY_PROFILE "Profile"

// Visibility flags
#define ADMIN_VERB_VISIBLITY_FLAG_MAPPING_DEBUG "Map-Debug"
3 changes: 2 additions & 1 deletion code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@
#define INIT_ORDER_DBCORE 95
#define INIT_ORDER_BLACKBOX 94
#define INIT_ORDER_SERVER_MAINT 93
#define INIT_ORDER_PLAYER_RANKS 86 // NOVA EDIT ADDITION - Player Ranks Subsystem
#define INIT_ORDER_INPUT 85
#define INIT_ORDER_PLAYER_RANKS 84 // NOVA EDIT - Player Ranks Subsystem
#define INIT_ORDER_ADMIN_VERBS 84 // needs to be pretty high, admins cant do much without it
#define INIT_ORDER_SOUNDS 83
#define INIT_ORDER_INSTRUMENTS 82
#define INIT_ORDER_GREYSCALE 81
Expand Down
8 changes: 2 additions & 6 deletions code/__HELPERS/hallucinations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ GLOBAL_LIST_INIT(random_hallucination_weighted_list, generate_hallucination_weig
to_chat(usr, span_boldnotice("The total weight of the hallucination weighted list is [total_weight]."))
return total_weight

/// Debug verb for getting the weight of each distinct type within the random_hallucination_weighted_list
/client/proc/debug_hallucination_weighted_list_per_type()
set name = "Show Hallucination Weights"
set category = "Debug"

ADMIN_VERB(debug_hallucination_weighted_list_per_type, R_DEBUG, "Show Hallucination Weights", "View the weight of each hallucination subtype in the random weighted list.", ADMIN_CATEGORY_DEBUG)
var/header = "<tr><th>Type</th> <th>Weight</th> <th>Percent</th>"

var/total_weight = debug_hallucination_weighted_list()
Expand Down Expand Up @@ -153,7 +149,7 @@ GLOBAL_LIST_INIT(random_hallucination_weighted_list, generate_hallucination_weig

var/page_style = "<style>table, th, td {border: 1px solid black;border-collapse: collapse;}</style>"
var/page_contents = "[page_style]<table style=\"width:100%\">[header][jointext(assoc_to_keys(all_weights), "")]</table>"
var/datum/browser/popup = new(mob, "hallucinationdebug", "Hallucination Weights", 600, 400)
var/datum/browser/popup = new(user.mob, "hallucinationdebug", "Hallucination Weights", 600, 400)
popup.set_content(page_contents)
popup.open()

Expand Down
26 changes: 8 additions & 18 deletions code/_onclick/hud/movable_screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,30 @@
offset[2] += y_off
return offset_to_screen_loc(offset[1], offset[2], our_client?.view)

//Debug procs
/client/proc/test_movable_UI()
set category = "Debug"
set name = "Spawn Movable UI Object"

var/atom/movable/screen/movable/M = new()
ADMIN_VERB(test_movable_UI, R_DEBUG, "Spawn Movable UI Object", "Spawn a movable UI object for testing.", ADMIN_CATEGORY_DEBUG)
var/atom/movable/screen/movable/M = new
M.name = "Movable UI Object"
M.icon_state = "block"
M.maptext = MAPTEXT("Movable")
M.maptext_width = 64

var/screen_l = input(usr,"Where on the screen? (Formatted as 'X,Y' e.g: '1,1' for bottom left)","Spawn Movable UI Object") as text|null
var/screen_l = input(user, "Where on the screen? (Formatted as 'X,Y' e.g: '1,1' for bottom left)","Spawn Movable UI Object") as text|null
if(!screen_l)
return

M.screen_loc = screen_l
user.screen += M

screen += M


/client/proc/test_snap_UI()
set category = "Debug"
set name = "Spawn Snap UI Object"

var/atom/movable/screen/movable/snap/S = new()
ADMIN_VERB(test_snap_ui, R_DEBUG, "Spawn Snap UI Object", "Spawn a snap UI object for testing.", ADMIN_CATEGORY_DEBUG)
var/atom/movable/screen/movable/snap/S = new
S.name = "Snap UI Object"
S.icon_state = "block"
S.maptext = MAPTEXT("Snap")
S.maptext_width = 64

var/screen_l = input(usr,"Where on the screen? (Formatted as 'X,Y' e.g: '1,1' for bottom left)","Spawn Snap UI Object") as text|null
var/screen_l = input(user,"Where on the screen? (Formatted as 'X,Y' e.g: '1,1' for bottom left)","Spawn Snap UI Object") as text|null
if(!screen_l)
return

S.screen_loc = screen_l

screen += S
user.screen += S
25 changes: 5 additions & 20 deletions code/controllers/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,7 @@ INITIALIZE_IMMEDIATE(/obj/effect/statclick)
usr.client.debug_variables(target)
message_admins("Admin [key_name_admin(usr)] is debugging the [target] [class].")


// Debug verbs.
/client/proc/restart_controller(controller in list("Master", "Failsafe"))
set category = "Debug"
set name = "Restart Controller"
set desc = "Restart one of the various periodic loop controllers for the game (be careful!)"

if(!holder)
return
ADMIN_VERB(restart_controller, R_DEBUG, "Restart Controller", "Restart one of the various periodic loop controllers for the game (be careful!)", ADMIN_CATEGORY_DEBUG, controller in list("Master", "Failsafe"))
switch(controller)
if("Master")
Recreate_MC()
Expand All @@ -61,16 +53,9 @@ INITIALIZE_IMMEDIATE(/obj/effect/statclick)
new /datum/controller/failsafe()
BLACKBOX_LOG_ADMIN_VERB("Restart Failsafe Controller")

message_admins("Admin [key_name_admin(usr)] has restarted the [controller] controller.")

/client/proc/debug_controller()
set category = "Debug"
set name = "Debug Controller"
set desc = "Debug the various periodic loop controllers for the game (be careful!)"

if(!holder)
return
message_admins("Admin [key_name_admin(user)] has restarted the [controller] controller.")

ADMIN_VERB(debug_controller, R_DEBUG, "Debug Controller", "Debug the various periodic loop controllers for the game (be careful!)", ADMIN_CATEGORY_DEBUG)
var/list/controllers = list()
var/list/controller_choices = list()

Expand All @@ -85,7 +70,7 @@ INITIALIZE_IMMEDIATE(/obj/effect/statclick)

if (!istype(controller))
return
debug_variables(controller)
SSadmin_verbs.dynamic_invoke_verb(user, /datum/admin_verb/debug_variables, controller)

BLACKBOX_LOG_ADMIN_VERB("Debug Controller")
message_admins("Admin [key_name_admin(usr)] is debugging the [controller] controller.")
message_admins("Admin [key_name_admin(user)] is debugging the [controller] controller.")
Loading

0 comments on commit 66e7198

Please sign in to comment.