///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("
")
if(response.errored)
dat += "
Failed to connect to CentCom."
else if(response.status_code != 200)
dat += "
Failed to connect to CentCom. Status code: [response.status_code]"
else
if(response.body == "[]")
dat += "0 bans detected for [ckey]"
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 += "Bans detected for [ckey]"
else
//Ban count is potentially inaccurate if they're using a whitelist
dat += "[bans.len] ban\s detected for [ckey]"
for(var/list/ban in bans)
if(valid_sources && !(ban["sourceName"] in valid_sources))
continue
dat += "Server: [sanitize(ban["sourceName"])]
"
dat += "RP Level: [sanitize(ban["sourceRoleplayLevel"])]
"
dat += "Type: [sanitize(ban["type"])]
"
dat += "Banned By: [sanitize(ban["bannedBy"])]
"
dat += "Reason: [sanitize(ban["reason"])]
"
dat += "Datetime: [sanitize(ban["bannedOn"])]
"
var/expiration = ban["expires"]
dat += "Expires: [expiration ? "[sanitize(expiration)]" : "Permanent"]
"
if(ban["type"] == "job")
dat += "Jobs: "
var/list/jobs = ban["jobs"]
dat += sanitize(jobs.Join(", "))
dat += "
"
dat += "
"
dat += "
"
var/datum/browser/popup = new(usr, "centcomlookup-[ckey]", "Central Command Galactic Ban Database
", 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