From d5779fe88b56743b1af35a8a3442ec3e20dd6665 Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:02:45 +0000 Subject: [PATCH] code cleanup + additional stickyban panel tool to find matching stickybans --- code/controllers/subsystem/stickyban.dm | 54 ++++++++++++++++--------- code/modules/admin/NewBan.dm | 3 +- code/modules/admin/topic/topic.dm | 17 ++++++++ 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/code/controllers/subsystem/stickyban.dm b/code/controllers/subsystem/stickyban.dm index 268922fc000a..48e934addc1a 100644 --- a/code/controllers/subsystem/stickyban.dm +++ b/code/controllers/subsystem/stickyban.dm @@ -18,28 +18,13 @@ SUBSYSTEM_DEF(stickyban) /datum/controller/subsystem/stickyban/proc/check_for_sticky_ban(ckey, address, computer_id) var/list/stickyban_ids = list() - var/list/datum/view_record/stickyban_matched_ckey/ckeys = DB_VIEW(/datum/view_record/stickyban_matched_ckey, - DB_AND( - DB_COMP("ckey", DB_EQUALS, ckey), - DB_COMP("whitelisted", DB_EQUALS, FALSE) - ) - ) - - for(var/datum/view_record/stickyban_matched_ckey/matched_ckey as anything in ckeys) + for(var/datum/view_record/stickyban_matched_ckey/matched_ckey as anything in get_impacted_ckey_records(ckey)) stickyban_ids += matched_ckey.linked_stickyban - var/list/datum/view_record/stickyban_matched_cid/cids = DB_VIEW(/datum/view_record/stickyban_matched_cid, - DB_COMP("cid", DB_EQUALS, computer_id) - ) - - for(var/datum/view_record/stickyban_matched_cid/matched_cid as anything in cids) + for(var/datum/view_record/stickyban_matched_cid/matched_cid as anything in get_impacted_cid_records(computer_id)) stickyban_ids += matched_cid.linked_stickyban - var/list/datum/view_record/stickyban_matched_cid/ips = DB_VIEW(/datum/view_record/stickyban_matched_ip, - DB_COMP("ip", DB_EQUALS, address) - ) - - for(var/datum/view_record/stickyban_matched_ip/matched_ip as anything in ips) + for(var/datum/view_record/stickyban_matched_ip/matched_ip as anything in get_impacted_ip_records(address)) stickyban_ids += matched_ip.linked_stickyban if(!length(stickyban_ids)) @@ -183,6 +168,21 @@ SUBSYSTEM_DEF(stickyban) whitelisted_ckey.save() +/** + * Returns a [/list] of [/datum/view_record/stickyban_matched_ckey] where the ckey provided has not been + * whitelisted from the stickyban, and would be prevented from joining - provided that the stickyban itself + * remains active. + */ +/datum/controller/subsystem/stickyban/proc/get_impacted_ckey_records(key) + key = ckey(key) + + return DB_VIEW(/datum/view_record/stickyban_matched_ckey, + DB_AND( + DB_COMP("ckey", DB_EQUALS, key), + DB_COMP("whitelisted", DB_EQUALS, FALSE) + ) + ) + /** * Returns a [/list] of [/datum/view_record/stickyban_matched_ckey] which have been manually whitelisted by an admin and matches the provided existing_ban_id and key. */ @@ -197,6 +197,24 @@ SUBSYSTEM_DEF(stickyban) ) ) +/** + * Returns a [/list] of [/datum/view_record/stickyban_matched_cid] where the impacted CID matches the CID provided. + * Connections matching this CID will be blocked - provided the linked stickyban is active. + */ +/datum/controller/subsystem/stickyban/proc/get_impacted_cid_records(cid) + return DB_VIEW(/datum/view_record/stickyban_matched_cid, + DB_COMP("cid", DB_EQUALS, cid) + ) + +/** + * Returns a [/list] of [/datum/view_record/stickyban_matched_ip] where the impacted IP matches the IP provided. + * Connections matchin this IP will be blocked - provided the linked stickyban is active. + */ +/datum/controller/subsystem/stickyban/proc/get_impacted_ip_records(ip) + return DB_VIEW(/datum/view_record/stickyban_matched_ip, + DB_COMP("ip", DB_EQUALS, ip) + ) + /// Legacy import from pager bans to database bans. /datum/controller/subsystem/stickyban/proc/import_sticky(identifier, list/ban_data) WAIT_DB_READY diff --git a/code/modules/admin/NewBan.dm b/code/modules/admin/NewBan.dm index 9d55e361f819..ee9c533193ad 100644 --- a/code/modules/admin/NewBan.dm +++ b/code/modules/admin/NewBan.dm @@ -195,8 +195,9 @@ GLOBAL_DATUM(Banlist, /savefile) /datum/admins/proc/stickypanel() var/add_sticky = "Add Sticky Ban" + var/find_sticky = "Find Sticky Ban" - var/data = "
Sticky Bans: [add_sticky] " + var/data = "
Sticky Bans: [add_sticky] [find_sticky]
" var/list/datum/view_record/stickyban/stickies = DB_VIEW(/datum/view_record/stickyban, DB_COMP("active", DB_EQUALS, TRUE) diff --git a/code/modules/admin/topic/topic.dm b/code/modules/admin/topic/topic.dm index 39f928d1e9f4..fb9b0ee5d67a 100644 --- a/code/modules/admin/topic/topic.dm +++ b/code/modules/admin/topic/topic.dm @@ -288,6 +288,23 @@ show_browser(owner, english_list(ips), "Stickyban IPs", "stickycips") return + if(href_list["find_sticky"]) + var/ckey = ckey(tgui_input_text(owner, "Which CKEY should we attempt to find stickybans for?", "FindABan")) + if(!ckey) + return + + var/list/datum/view_record/stickyban/stickies = SSstickyban.check_for_sticky_ban(ckey) + if(!stickies) + to_chat(owner, SPAN_ADMIN("Could not locate any stickbans impacting [ckey].")) + return + + var/list/impacting_stickies = list() + + for(var/datum/view_record/stickyban/sticky as anything in stickies) + impacting_stickies += sticky.identifier + + to_chat(owner, SPAN_ADMIN("Found the following stickybans for [ckey]: [english_list(impacting_stickies)]")) + if(!check_rights_for(owner, R_BAN)) return