Files
Bubberstation/code/modules/admin/centcom.dm
John Willard ff1972c1d3 Interviews now lets you see centcom bans directly (#90423)
## About The Pull Request

There's now a button in Interviews that lets you directly jump to a
person's centcom ban database, which also works if the client
disconnects.
The button is red (idk if we have any flashing color to make it REALLY
stand out) and has special tooltip if they have any server permabans in
the database.

## Why It's Good For The Game

There's an admin request to allow servers to ban bad players from the
centcom database meant for streamer servers to avoid griefers, which I
wasn't the biggest fan of. Instead I thought this would be a harmless
addition, letting admins see if a player joining their server is a known
griefer BEFORE letting them in, directly from the interview menu- while
letting them know if they have a permaban without having to even click
anything. Gives admins an easier time in finding griefers before they
log on without automation that may cause false positives.

## Changelog

🆑
admin: Interviews now has a button to open a player's Centcom ban list,
which will be in red if they have existing server permabans.
/🆑
2025-04-06 21:06:58 +02:00

101 lines
3.4 KiB
Plaintext

///Gets the centcom bans of the given ckey.
/datum/admins/proc/open_centcom_bans(ckey)
if(!check_rights(R_ADMIN))
return
if(!CONFIG_GET(string/centcom_ban_db))
to_chat(usr, span_warning("Centcom Galactic Ban DB is disabled!"))
return
// Make the request
var/datum/http_request/request = new()
request.prepare(RUSTG_HTTP_METHOD_GET, "[CONFIG_GET(string/centcom_ban_db)]/[ckey]", "", "")
request.begin_async()
UNTIL(request.is_complete() || !usr)
if (!usr)
return
var/datum/http_response/response = request.into_response()
var/list/bans
var/list/dat = list("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><body>")
if(response.errored)
dat += "<br>Failed to connect to CentCom."
else if(response.status_code != 200)
dat += "<br>Failed to connect to CentCom. Status code: [response.status_code]"
else
if(response.body == "[]")
dat += "<center><b>0 bans detected for [ckey]</b></center>"
else
bans = json_decode(response.body)
//Ignore bans from non-whitelisted sources, if a whitelist exists
var/list/valid_sources
if(CONFIG_GET(string/centcom_source_whitelist))
valid_sources = splittext(CONFIG_GET(string/centcom_source_whitelist), ",")
dat += "<center><b>Bans detected for [ckey]</b></center>"
else
//Ban count is potentially inaccurate if they're using a whitelist
dat += "<center><b>[bans.len] ban\s detected for [ckey]</b></center>"
for(var/list/ban in bans)
if(valid_sources && !(ban["sourceName"] in valid_sources))
continue
dat += "<b>Server: </b> [sanitize(ban["sourceName"])]<br>"
dat += "<b>RP Level: </b> [sanitize(ban["sourceRoleplayLevel"])]<br>"
dat += "<b>Type: </b> [sanitize(ban["type"])]<br>"
dat += "<b>Banned By: </b> [sanitize(ban["bannedBy"])]<br>"
dat += "<b>Reason: </b> [sanitize(ban["reason"])]<br>"
dat += "<b>Datetime: </b> [sanitize(ban["bannedOn"])]<br>"
var/expiration = ban["expires"]
dat += "<b>Expires: </b> [expiration ? "[sanitize(expiration)]" : "Permanent"]<br>"
if(ban["type"] == "job")
dat += "<b>Jobs: </b> "
var/list/jobs = ban["jobs"]
dat += sanitize(jobs.Join(", "))
dat += "<br>"
dat += "<hr>"
dat += "<br></body>"
var/datum/browser/popup = new(usr, "centcomlookup-[ckey]", "<div align='center'>Central Command Galactic Ban Database</div>", 700, 600)
popup.set_content(dat.Join())
popup.open(0)
///Returns the amount of permabans they have on centcom.
/datum/admins/proc/check_centcom_permabans(ckey)
if(!check_rights(R_ADMIN))
return
if(!CONFIG_GET(string/centcom_ban_db))
to_chat(usr, span_warning("Centcom Galactic Ban DB is disabled!"))
return
// Make the request
var/datum/http_request/request = new()
request.prepare(RUSTG_HTTP_METHOD_GET, "[CONFIG_GET(string/centcom_ban_db)]/[ckey]", "", "")
request.begin_async()
UNTIL(request.is_complete() || !usr)
if (!usr)
return
var/datum/http_response/response = request.into_response()
var/list/bans
var/total_permabans
if(response.body == "[]")
return
bans = json_decode(response.body)
//Ignore bans from non-whitelisted sources, if a whitelist exists
var/list/valid_sources
if(CONFIG_GET(string/centcom_source_whitelist))
valid_sources = splittext(CONFIG_GET(string/centcom_source_whitelist), ",")
for(var/list/ban in bans)
if(valid_sources && !(ban["sourceName"] in valid_sources))
continue
if(!ban["expires"] && (sanitize(ban["type"]) == "Server")) //server permabans only
total_permabans++
return total_permabans