mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-13 09:05:11 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
222 lines
7.3 KiB
Plaintext
222 lines
7.3 KiB
Plaintext
SUBSYSTEM_DEF(stickyban)
|
|
name = "PRISM"
|
|
ss_flags = SS_NO_FIRE
|
|
|
|
var/list/cache = list()
|
|
var/list/dbcache = list()
|
|
var/list/confirmed_exempt = list()
|
|
var/dbcacheexpire = 0
|
|
|
|
|
|
/datum/controller/subsystem/stickyban/Initialize()
|
|
if (length(GLOB.stickybanadminexemptions))
|
|
restore_stickybans()
|
|
var/list/bannedkeys = sticky_banned_ckeys()
|
|
//sanitize the sticky ban list
|
|
|
|
//delete db bans that no longer exist in the database and add new legacy bans to the database
|
|
if (SSdbcore.Connect() || length(SSstickyban.dbcache))
|
|
if (length(GLOB.stickybanadminexemptions))
|
|
restore_stickybans()
|
|
for (var/oldban in (world.GetConfig("ban") - bannedkeys))
|
|
var/ckey = ckey(oldban)
|
|
if (ckey != oldban && (ckey in bannedkeys))
|
|
continue
|
|
|
|
var/list/ban = params2list(world.GetConfig("ban", oldban))
|
|
if (ban && !ban["fromdb"])
|
|
if (!import_raw_stickyban_to_db(ckey, ban))
|
|
log_world("Could not import stickyban on [oldban] into the database. Ignoring")
|
|
continue
|
|
dbcacheexpire = 0
|
|
bannedkeys += ckey
|
|
world.SetConfig("ban", oldban, null)
|
|
|
|
if (length(GLOB.stickybanadminexemptions)) //the previous loop can sleep
|
|
restore_stickybans()
|
|
|
|
for (var/bannedkey in bannedkeys)
|
|
var/ckey = ckey(bannedkey)
|
|
var/list/ban = get_stickyban_from_ckey(bannedkey)
|
|
|
|
//byond stores sticky bans by key, that's lame
|
|
if (ckey != bannedkey)
|
|
world.SetConfig("ban", bannedkey, null)
|
|
|
|
//get_stickyban_from_ckey returned null, aka something broke. Notify admins about it
|
|
if (!ban)
|
|
message_admins("Failed to apply stickyban for [bannedkey]. Check the DB for corrupt stickyban entries.")
|
|
log_admin_private ("Failed to apply stickyban for [bannedkey]. Check the DB for corrupt stickyban entries.")
|
|
continue
|
|
|
|
if (!ban["ckey"])
|
|
ban["ckey"] = ckey
|
|
|
|
ban["matches_this_round"] = list()
|
|
ban["existing_user_matches_this_round"] = list()
|
|
ban["admin_matches_this_round"] = list()
|
|
ban["pending_matches_this_round"] = list()
|
|
|
|
cache[ckey] = ban
|
|
world.SetConfig("ban", ckey, list2stickyban(ban))
|
|
|
|
return SS_INIT_SUCCESS
|
|
|
|
/datum/controller/subsystem/stickyban/proc/Populatedbcache()
|
|
var/newdbcache = list() //so if we runtime or the db connection dies we don't kill the existing cache
|
|
|
|
var/datum/db_query/query_stickybans = SSdbcore.NewQuery("SELECT ckey, reason, banning_admin, datetime FROM [format_table_name("stickyban")] ORDER BY ckey")
|
|
var/datum/db_query/query_ckey_matches = SSdbcore.NewQuery("SELECT stickyban, matched_ckey, first_matched, last_matched, exempt FROM [format_table_name("stickyban_matched_ckey")] ORDER BY first_matched")
|
|
var/datum/db_query/query_cid_matches = SSdbcore.NewQuery("SELECT stickyban, matched_cid, first_matched, last_matched FROM [format_table_name("stickyban_matched_cid")] ORDER BY first_matched")
|
|
var/datum/db_query/query_ip_matches = SSdbcore.NewQuery("SELECT stickyban, INET_NTOA(matched_ip), first_matched, last_matched FROM [format_table_name("stickyban_matched_ip")] ORDER BY first_matched")
|
|
|
|
SSdbcore.QuerySelect(list(query_stickybans, query_ckey_matches, query_cid_matches, query_ip_matches))
|
|
|
|
if (query_stickybans.last_error)
|
|
qdel(query_stickybans)
|
|
qdel(query_ckey_matches)
|
|
qdel(query_cid_matches)
|
|
qdel(query_ip_matches)
|
|
return
|
|
|
|
while (query_stickybans.NextRow())
|
|
var/list/ban = list()
|
|
|
|
ban["ckey"] = query_stickybans.item[1]
|
|
ban["message"] = query_stickybans.item[2]
|
|
ban["reason"] = "(InGameBan)([query_stickybans.item[3]])"
|
|
ban["admin"] = query_stickybans.item[3]
|
|
ban["datetime"] = query_stickybans.item[4]
|
|
ban["type"] = list("sticky")
|
|
|
|
newdbcache["[query_stickybans.item[1]]"] = ban
|
|
|
|
|
|
if (!query_ckey_matches.last_error)
|
|
while (query_ckey_matches.NextRow())
|
|
var/list/match = list()
|
|
|
|
match["stickyban"] = query_ckey_matches.item[1]
|
|
match["matched_ckey"] = query_ckey_matches.item[2]
|
|
match["first_matched"] = query_ckey_matches.item[3]
|
|
match["last_matched"] = query_ckey_matches.item[4]
|
|
match["exempt"] = text2num(query_ckey_matches.item[5])
|
|
|
|
var/ban = newdbcache[query_ckey_matches.item[1]]
|
|
if (!ban)
|
|
continue
|
|
var/keys = ban[text2num(query_ckey_matches.item[5]) ? "whitelist" : "keys"]
|
|
if (!keys)
|
|
keys = ban[text2num(query_ckey_matches.item[5]) ? "whitelist" : "keys"] = list()
|
|
keys[query_ckey_matches.item[2]] = match
|
|
|
|
if (!query_cid_matches.last_error)
|
|
while (query_cid_matches.NextRow())
|
|
var/list/match = list()
|
|
|
|
match["stickyban"] = query_cid_matches.item[1]
|
|
match["matched_cid"] = query_cid_matches.item[2]
|
|
match["first_matched"] = query_cid_matches.item[3]
|
|
match["last_matched"] = query_cid_matches.item[4]
|
|
|
|
var/ban = newdbcache[query_cid_matches.item[1]]
|
|
if (!ban)
|
|
continue
|
|
var/computer_ids = ban["computer_id"]
|
|
if (!computer_ids)
|
|
computer_ids = ban["computer_id"] = list()
|
|
computer_ids[query_cid_matches.item[2]] = match
|
|
|
|
|
|
if (!query_ip_matches.last_error)
|
|
while (query_ip_matches.NextRow())
|
|
var/list/match = list()
|
|
|
|
match["stickyban"] = query_ip_matches.item[1]
|
|
match["matched_ip"] = query_ip_matches.item[2]
|
|
match["first_matched"] = query_ip_matches.item[3]
|
|
match["last_matched"] = query_ip_matches.item[4]
|
|
|
|
var/ban = newdbcache[query_ip_matches.item[1]]
|
|
if (!ban)
|
|
continue
|
|
var/IPs = ban["IP"]
|
|
if (!IPs)
|
|
IPs = ban["IP"] = list()
|
|
IPs[query_ip_matches.item[2]] = match
|
|
|
|
dbcache = newdbcache
|
|
dbcacheexpire = world.time+STICKYBAN_DB_CACHE_TIME
|
|
|
|
qdel(query_stickybans)
|
|
qdel(query_ckey_matches)
|
|
qdel(query_cid_matches)
|
|
qdel(query_ip_matches)
|
|
|
|
|
|
/datum/controller/subsystem/stickyban/proc/import_raw_stickyban_to_db(ckey, list/ban)
|
|
. = FALSE
|
|
if (!ban["admin"])
|
|
ban["admin"] = "LEGACY"
|
|
if (!ban["message"])
|
|
ban["message"] = "Evasion"
|
|
|
|
var/datum/db_query/query_create_stickyban = SSdbcore.NewQuery(
|
|
"INSERT IGNORE INTO [format_table_name("stickyban")] (ckey, reason, banning_admin) VALUES (:ckey, :message, :admin)",
|
|
list("ckey" = ckey, "message" = ban["message"], "admin" = ban["admin"])
|
|
)
|
|
if (!query_create_stickyban.warn_execute())
|
|
qdel(query_create_stickyban)
|
|
return
|
|
qdel(query_create_stickyban)
|
|
|
|
var/list/sqlckeys = list()
|
|
var/list/sqlcids = list()
|
|
var/list/sqlips = list()
|
|
|
|
if (ban["keys"])
|
|
var/list/keys = splittext(ban["keys"], ",")
|
|
for (var/key in keys)
|
|
var/list/sqlckey = list()
|
|
sqlckey["stickyban"] = ckey
|
|
sqlckey["matched_ckey"] = ckey(key)
|
|
sqlckey["exempt"] = FALSE
|
|
sqlckeys[++sqlckeys.len] = sqlckey
|
|
|
|
if (ban["whitelist"])
|
|
var/list/keys = splittext(ban["whitelist"], ",")
|
|
for (var/key in keys)
|
|
var/list/sqlckey = list()
|
|
sqlckey["stickyban"] = ckey
|
|
sqlckey["matched_ckey"] = ckey(key)
|
|
sqlckey["exempt"] = TRUE
|
|
sqlckeys[++sqlckeys.len] = sqlckey
|
|
|
|
if (ban["computer_id"])
|
|
var/list/cids = splittext(ban["computer_id"], ",")
|
|
for (var/cid in cids)
|
|
var/list/sqlcid = list()
|
|
sqlcid["stickyban"] = ckey
|
|
sqlcid["matched_cid"] = cid
|
|
sqlcids[++sqlcids.len] = sqlcid
|
|
|
|
if (ban["IP"])
|
|
var/list/ips = splittext(ban["IP"], ",")
|
|
for (var/ip in ips)
|
|
var/list/sqlip = list()
|
|
sqlip["stickyban"] = ckey
|
|
sqlip["matched_ip"] = ip
|
|
sqlips[++sqlips.len] = sqlip
|
|
|
|
if (length(sqlckeys))
|
|
SSdbcore.MassInsert(format_table_name("stickyban_matched_ckey"), sqlckeys, ignore_errors = TRUE)
|
|
|
|
if (length(sqlcids))
|
|
SSdbcore.MassInsert(format_table_name("stickyban_matched_cid"), sqlcids, ignore_errors = TRUE)
|
|
|
|
if (length(sqlips))
|
|
SSdbcore.MassInsert(format_table_name("stickyban_matched_ip"), sqlips, ignore_errors = TRUE)
|
|
|
|
|
|
return TRUE
|