From b44176769379679f9042a32bfd00909996008c93 Mon Sep 17 00:00:00 2001 From: Tkdrg Date: Tue, 9 Feb 2016 12:02:22 -0300 Subject: [PATCH] Improves admin counting for irc This is intended to support future improvements to the #adminbus bot. --- code/controllers/subsystem/ticker.dm | 5 ++-- code/modules/admin/verbs/adminhelp.dm | 39 ++++++++++++--------------- code/world.dm | 28 ++++++++++--------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 13fe30f0070..47d8376fd1a 100644 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -201,8 +201,9 @@ var/datum/subsystem/ticker/ticker if(S.name != "AI") qdel(S) - if(!admins.len) - send2irc("Server", "Round just started with no admins online!") + var/list/adm = get_admin_counts() + if(!adm["present"]) + send2irc("Server", "Round just started with no active admins online!") return 1 diff --git a/code/modules/admin/verbs/adminhelp.dm b/code/modules/admin/verbs/adminhelp.dm index 5215f9cc485..7ce84b6eadc 100644 --- a/code/modules/admin/verbs/adminhelp.dm +++ b/code/modules/admin/verbs/adminhelp.dm @@ -120,32 +120,27 @@ feedback_add_details("admin_verb","AH") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! return -/proc/send2irc_adminless_only(source, msg, requiredflags = R_BAN) - var/admin_number_total = 0 //Total number of admins - var/admin_number_afk = 0 //Holds the number of admins who are afk - var/admin_number_ignored = 0 //Holds the number of admins without +BAN (so admins who are not really admins) - var/admin_number_decrease = 0 //Holds the number of admins with are afk, ignored or both +/proc/get_admin_counts(requiredflags = R_BAN) + . = list("total" = 0, "noflags" = 0, "afk" = 0, "stealth" = 0, "present" = 0) for(var/client/X in admins) - admin_number_total++; - var/invalid = 0 + .["total"]++ if(requiredflags != 0 && !check_rights_for(X, requiredflags)) - admin_number_ignored++ - invalid = 1 - if(X.is_afk()) - admin_number_afk++ - invalid = 1 - if(X.holder.fakekey) - admin_number_ignored++ - invalid = 1 - if(invalid) - admin_number_decrease++ - var/admin_number_present = admin_number_total - admin_number_decrease //Number of admins who are neither afk nor invalid - if(admin_number_present <= 0) - if(!admin_number_afk && !admin_number_ignored) + .["noflags"]++ + else if(X.is_afk()) + .["afk"]++ + else if(X.holder.fakekey) + .["stealth"]++ + else + .["present"]++ + +/proc/send2irc_adminless_only(source, msg, requiredflags = R_BAN) + var/list/adm = get_admin_counts(requiredflags) + . = adm["present"] + if(. <= 0) + if(!adm["afk"] && !adm["stealth"] && !adm["noflags"]) send2irc(source, "[msg] - No admins online") else - send2irc(source, "[msg] - All admins AFK ([admin_number_afk]/[admin_number_total]) or skipped ([admin_number_ignored]/[admin_number_total])") - return admin_number_present + send2irc(source, "[msg] - All admins AFK ([adm["afk"]]/[adm["total"]]), stealthminned ([adm["stealth"]]/[adm["total"]]), or lack [requiredflags] ([adm["noflags"]]/[adm["total"]])") /proc/send2irc(msg,msg2) if(config.useircbot) diff --git a/code/world.dm b/code/world.dm index 0fccf138ac0..36e848d1ac8 100644 --- a/code/world.dm +++ b/code/world.dm @@ -69,11 +69,13 @@ var/global/list/map_transition_config = MAP_TRANSITION_CONFIG return +#define IRC_STATUS_THROTTLE 50 +var/last_irc_status = 0 /world/Topic(T, addr, master, key) diary << "TOPIC: \"[T]\", from:[addr], master:[master], key:[key]" - if (T == "ping") + if(T == "ping") var/x = 1 for (var/client/C in clients) x++ @@ -86,7 +88,14 @@ var/global/list/map_transition_config = MAP_TRANSITION_CONFIG n++ return n - else if (T == "status") + else if(T == "ircstatus") + if(world.time - last_irc_status < IRC_STATUS_THROTTLE) + return + var/list/adm = get_admin_counts() + send2irc("Status", "Admins: [Sum(adm)] (Active: [adm["admins"]] AFK: [adm["afkadmins"]] Stealth: [adm["stealthadmins"]] Skipped: [adm["noflagadmins"]]). Players: [clients.len] (Active: [get_active_player_count()]). Mode: [master_mode].") + last_irc_status = world.time + + else if(T == "status") var/list/s = list() // Please add new status indexes under the old ones, for the server banner (until that gets reworked) s["version"] = game_version @@ -96,26 +105,21 @@ var/global/list/map_transition_config = MAP_TRANSITION_CONFIG s["vote"] = config.allow_vote_mode s["ai"] = config.allow_ai s["host"] = host ? host : null - - var/admins = 0 - for(var/client/C in clients) - if(C.holder) - if(C.holder.fakekey) - continue //so stealthmins aren't revealed by the hub - admins++ - s["active_players"] = get_active_player_count() s["players"] = clients.len s["revision"] = revdata.revision s["revision_date"] = revdata.date - s["admins"] = admins + + var/list/adm = get_admin_counts() + s["admins"] = adm["present"] + adm["afk"] //equivalent to the info gotten from adminwho s["gamestate"] = 1 if(ticker) s["gamestate"] = ticker.current_state s["map_name"] = map_name ? map_name : "Unknown" return list2params(s) - else if (copytext(T,1,9) == "announce") + + else if(copytext(T,1,9) == "announce") var/input[] = params2list(T) if(global.comms_allowed) if(input["key"] != global.comms_key)