Skip to content

Commit

Permalink
code cleanup + additional stickyban panel tool to find matching stick…
Browse files Browse the repository at this point in the history
…ybans
  • Loading branch information
harryob committed Feb 5, 2024
1 parent f00d0f5 commit d5779fe
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
54 changes: 36 additions & 18 deletions code/controllers/subsystem/stickyban.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion code/modules/admin/NewBan.dm
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ GLOBAL_DATUM(Banlist, /savefile)

/datum/admins/proc/stickypanel()
var/add_sticky = "<a href='?src=\ref[src];[HrefToken()];sticky=1;new_sticky=1'>Add Sticky Ban</a>"
var/find_sticky = "<a href='?src=\ref[src];[HrefToken()];sticky=1;find_sticky=1'>Find Sticky Ban</a>"

var/data = "<hr><b>Sticky Bans:</b> [add_sticky] <table border=1 rules=all frame=void cellspacing=0 cellpadding=3>"
var/data = "<hr><b>Sticky Bans:</b> [add_sticky] [find_sticky] <table border=1 rules=all frame=void cellspacing=0 cellpadding=3>"

var/list/datum/view_record/stickyban/stickies = DB_VIEW(/datum/view_record/stickyban,
DB_COMP("active", DB_EQUALS, TRUE)
Expand Down
17 changes: 17 additions & 0 deletions code/modules/admin/topic/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d5779fe

Please sign in to comment.