From 16a9d54f2aa09672d172f1a36052b60b90d19618 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sun, 12 Mar 2017 08:10:51 +0100 Subject: [PATCH] Profiler and reboot for admins with +SERVER/+DEBUG, client skin stuff. (#14255) * Client skin buttons for reconnect, profiler and reboot. All admins get profiler and reboot if they have the correct flags. * Update vgstation13.dme --- __DEFINES/world.dm | 5 ++++ code/modules/admin/admin_ranks.dm | 16 +++++++++++ code/modules/admin/holder2.dm | 25 ++++++++++++++++- code/modules/admin/topic.dm | 5 ++++ code/modules/client/client defines.dm | 2 +- code/modules/client/client procs.dm | 1 + code/world.dm | 20 +++++++++++--- interface/skin.dmf | 39 ++++++++++++++++++++++----- vgstation13.dme | 1 + 9 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 __DEFINES/world.dm diff --git a/__DEFINES/world.dm b/__DEFINES/world.dm new file mode 100644 index 00000000000..22c80c782d5 --- /dev/null +++ b/__DEFINES/world.dm @@ -0,0 +1,5 @@ +// These are the world/Reboot reason codes as defined in the reference. +#define REBOOT_CODE 0 +#define REBOOT_HOST 1 +#define REBOOT_TOPIC 2 +#define REBOOT_SIGUSR1 3 diff --git a/code/modules/admin/admin_ranks.dm b/code/modules/admin/admin_ranks.dm index 84124a5c957..c1ed55afe73 100644 --- a/code/modules/admin/admin_ranks.dm +++ b/code/modules/admin/admin_ranks.dm @@ -86,6 +86,10 @@ var/list/admin_ranks = list() //list of all ranks with associated rights C.holder = null admins.len = 0 + // Clear profiler and debug access. + for(var/A in world.GetConfig("admin")) + world.SetConfig("APP/admin", A, null) + if(config.admin_legacy_system) load_admin_ranks() @@ -123,6 +127,8 @@ var/list/admin_ranks = list() //list of all ranks with associated rights //find the client for a ckey if they are connected and associate them with the new admin datum D.associate(directory[ckey]) + if(D.rights & (R_DEBUG|R_SERVER)) // Grant profile/reboot access + world.SetConfig("APP/admin", ckey, "role=admin") else //The current admin system uses SQL @@ -149,6 +155,10 @@ var/list/admin_ranks = list() //list of all ranks with associated rights //find the client for a ckey if they are connected and associate them with the new admin datum D.associate(directory[ckey]) + + if(D.rights & (R_DEBUG|R_SERVER)) // Grant profile/reboot access + world.SetConfig("APP/admin", ckey, "role=admin") + if(!admin_datums) world.log << "The database query in load_admins() resulted in no admins being added to the list. Reverting to legacy system." diary << "The database query in load_admins() resulted in no admins being added to the list. Reverting to legacy system." @@ -187,3 +197,9 @@ var/list/admin_ranks = list() //list of all ranks with associated rights holder.associate(src) #endif + +/proc/update_byond_admin(var/ckey) + var/datum/admins/D = admin_datums[ckey] + world.SetConfig("APP/admin", ckey, null) + if (D && D.rights & (R_SERVER|R_DEBUG)) + world.SetConfig("APP/admin", ckey, "role=admin") diff --git a/code/modules/admin/holder2.dm b/code/modules/admin/holder2.dm index fac5ee93578..235445756b5 100644 --- a/code/modules/admin/holder2.dm +++ b/code/modules/admin/holder2.dm @@ -32,13 +32,36 @@ var/list/admin_datums = list() admins |= C owner.verbs -= /client/proc/readmin + add_menu_items() + /datum/admins/proc/disassociate() if(owner) admins -= owner owner.remove_admin_verbs() owner.holder = null + + remove_menu_items() + owner = null + +/datum/admins/proc/add_menu_items() + if (owner && rights & (R_DEBUG|R_SERVER)) + winset(owner, "server_menu", "is-disabled=false") + + if (rights & R_SERVER) + winset(owner, "reboot_menu_item", "is-disabled=false") + +/datum/admins/proc/remove_menu_items() + if (owner) + winset(owner, "server_menu", "is-disabled=true") + winset(owner, "reboot_menu_item", "is-disabled=true") + +/datum/admins/proc/update_menu_items() + if (owner) + remove_menu_items() + add_menu_items() + /* checks if usr is an admin with at least ONE of the flags in rights_required. (Note, they don't need all the flags) if rights_required == 0, then it simply checks if they are an admin. @@ -122,4 +145,4 @@ you will have to do something like if(client.rights & R_ADMIN) yourself. query=dbcon.NewQuery("INSERT INTO admin_sessions (sessID,ckey,expires, IP) VALUES (UUID(), '[owner.ckey]', DATE_ADD(NOW(), INTERVAL 24 HOUR), '[owner.address]')") query.Execute() - return checkSessionKey(recurse) \ No newline at end of file + return checkSessionKey(recurse) diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 47cfcdf99f6..65b2a3730f8 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -237,6 +237,7 @@ return admin_datums -= adm_ckey D.disassociate() + update_byond_admin(adm_ckey) message_admins("[key_name_admin(usr)] removed [adm_ckey] from the admins list") log_admin("[key_name(usr)] removed [adm_ckey] from the admins list") @@ -282,6 +283,7 @@ var/client/C = directory[adm_ckey] //find the client with the specified ckey (if they are logged in) D.associate(C) //link up with the client and add verbs + update_byond_admin(adm_ckey) message_admins("[key_name_admin(usr)] edited the admin rank of [adm_ckey] to [new_rank]") log_admin("[key_name(usr)] edited the admin rank of [adm_ckey] to [new_rank]") @@ -298,6 +300,9 @@ return D.rights ^= permissionlist[new_permission] + update_byond_admin(adm_ckey) + D.update_menu_items() + message_admins("[key_name_admin(usr)] toggled the [new_permission] permission of [adm_ckey]") log_admin("[key_name(usr)] toggled the [new_permission] permission of [adm_ckey]") log_admin_permission_modification(adm_ckey, permissionlist[new_permission]) diff --git a/code/modules/client/client defines.dm b/code/modules/client/client defines.dm index 9197313bacb..09244ee8a9b 100644 --- a/code/modules/client/client defines.dm +++ b/code/modules/client/client defines.dm @@ -35,7 +35,7 @@ var/next_allowed_topic_time = 10 // comment out the line below when debugging locally to enable the options & messages menu // CONTROL_FREAK_MACROS allows new macros to be made, but won't permit overriding skin-defined ones. http://www.byond.com/forum/?post=2219001#comment22205313 - control_freak = CONTROL_FREAK_ALL | CONTROL_FREAK_MACROS + // control_freak = CONTROL_FREAK_ALL | CONTROL_FREAK_MACROS //////////////////////////////////// diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 34905e3d927..2820af2c451 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -195,6 +195,7 @@ if(holder) add_admin_verbs() admin_memo_show() + holder.add_menu_items() log_client_to_db() diff --git a/code/world.dm b/code/world.dm index 2458edb3a03..a3c24844cfb 100644 --- a/code/world.dm +++ b/code/world.dm @@ -233,10 +233,22 @@ var/savefile/panicfile /world/Reboot(reason) - if(reason == 1) - if(usr && usr.client) - if(!usr.client.holder) - return 0 + if(reason == REBOOT_HOST) + if(usr) + if (!check_rights(R_SERVER)) + log_admin("[key_name(usr)] Attempted to reboot world via client debug tools, but they do not have +SERVER and were denied.") + message_admins("[key_name_admin(usr)] Attempted to reboot world via client debug tools, but they do not have +SERVER and were denied.") + return + + log_admin("[key_name(usr)] Has requested an immediate world restart via client side debugging tools.") + message_admins("[key_name_admin(usr)] Has requested an immediate world restart via client side debugging tools.") + // To prevent the server shutting down before logs get to the admins or some nonsense. + sleep(1) + + to_chat(world, "Rebooting World immediately due to host request!") + ..() + return + for(var/datum/html_interface/D in html_interfaces) D.closeAll() if(config.map_voting) diff --git a/interface/skin.dmf b/interface/skin.dmf index d56fdbb2067..a1cae5f3f79 100644 --- a/interface/skin.dmf +++ b/interface/skin.dmf @@ -385,29 +385,34 @@ macro "hotkeymode" menu "menu" - elem - name = "&File" + elem "client_menu" + name = "&Client" command = "" saved-params = "is-checked" elem name = "&Quick screenshot\tF2" command = ".screenshot auto" - category = "&File" + category = "&Client" saved-params = "is-checked" elem name = "&Save screenshot as...\tShift+F2" command = ".screenshot" - category = "&File" + category = "&Client" saved-params = "is-checked" elem name = "" command = "" - category = "&File" + category = "&Client" + saved-params = "is-checked" + elem + name = "Reconnect" + command = ".reconnect" + category = "&Client" saved-params = "is-checked" elem name = "&Quit" command = ".quit" - category = "&File" + category = "&Client" saved-params = "is-checked" elem name = "&Icons" @@ -490,6 +495,27 @@ menu "menu" command = "swapsides" category = "Skin" saved-params = "is-checked" + elem "server_menu" + name = "Server" + command = "" + is-disabled = true + saved-params = "is-checked" + elem + name = "Profiler" + command = ".profile" + category = "Server" + saved-params = "is-checked" + elem + name = "" + command = "" + category = "Server" + saved-params = "is-checked" + elem "reboot_menu_item" + name = "EMERGENCY REBOOT" + command = ".reboot" + category = "Server" + is-disabled = true + saved-params = "is-checked" window "Telecomms IDE" @@ -1026,6 +1052,7 @@ window "window1" size = 640x480 anchor1 = none anchor2 = none + background-color = none is-visible = false border = sunken saved-params = "pos;size;is-minimized;is-maximized" diff --git a/vgstation13.dme b/vgstation13.dme index 103ba938796..e9daab6e384 100644 --- a/vgstation13.dme +++ b/vgstation13.dme @@ -32,6 +32,7 @@ #include "__DEFINES\stylesheet.dm" #include "__DEFINES\subsystem.dm" #include "__DEFINES\tick.dm" +#include "__DEFINES\world.dm" #include "code\_secrets.dm" #include "code\hub.dm" #include "code\names.dm"