// CCBDB = CentCom Ban DB
// This file contains procs for handling all requests to the CCBDB API, hosted by Bobbahbrown
// API Documentation: https://centcom.melonmesa.com/swagger/index.html
// Please refer to said documentation before editing any of the stuff in here, otherwise it will likely break
/**
* CCBDB Lookup Initiator
*
* Checks the configuration before invoking the request to the CCBDB server.
*
* Arguments:
* * ckey - ckey to be looked up
*/
/datum/admins/proc/create_ccbdb_lookup(ckey)
// Bail if disabled
if(!GLOB.configuration.url.centcom_ban_db_url)
to_chat(usr, "The CentCom Ban DB lookup is disabled. Please inform a maintainer or server host.")
return
// Bail if no ckey is supplied
if(!ckey)
return
var/datum/callback/cb = CALLBACK(src, /datum/admins/.proc/ccbdb_lookup_callback, usr, ckey)
SShttp.create_async_request(RUSTG_HTTP_METHOD_GET, "[GLOB.configuration.url.centcom_ban_db_url][ckey]", proc_callback=cb)
/**
* CCBDB Lookup Callback
*
* Callback assigned in [/datum/admins/proc/create_ccbdb_lookup] for async operations without a sleep()
*
* Arguments:
* * user - Mob calling the lookup so the UI can be opened
* * ckey - Ckey being looked up
* * response - [/datum/http_response] passed through from [SShttp]
*/
/datum/admins/proc/ccbdb_lookup_callback(mob/user, ckey, datum/http_response/response)
// If the admin DC'd during the lookup, dont try and do things
if(!user)
return
// Bail if it errored
if(response.errored)
to_chat(user, "Error connecting to CentCom Ban DB. Please inform a maintainer or server host.")
return
// Bail if the code isnt 200
if(response.status_code != 200)
to_chat(user, "Error performing CentCom Ban DB lookup (Code: [response.status_code])")
return
var/list/popup_data = list()
// A body of "[]" means there were no bans on record for the user
if(response.body == "\[]")
popup_data += "
0 bans detected for [ckey]
"
else
var/list/bans = list()
// Wrap this in try/catch because JSON is a finnicky bastard
try
bans = json_decode(response.body)
// Yes I threw a ternary in because I am that obsessed over OCD
popup_data += "[length(bans)] ban[length(bans) == 1 ? "" : "s"] detected for [ckey]
"
// These vars are also just for OCD (Adding a
between each ban but the last)
var/total_bans = length(bans)
var/index = 0
for(var/list/ban in bans)
index++
// For anyone else who edits this. SANITIZE ALL THE DATA. OTHER SERVERS MAY HAVE BAD ACTORS WHO TRY AND XSS PEOPLE.
popup_data += "Server: [sanitize(ban["sourceName"])] ([sanitize(ban["sourceRoleplayLevel"])] RP)
"
var/ban_status
// If the ban is active, its, well, active
if(ban["active"] == TRUE) // The == TRUE is intentional here. Dont remove it.
ban_status = "Ban Active"
// If they have an entry of being unbanned by someone, its been appealed
else if(ban["unbannedBy"])
ban_status = "Ban Appealed"
else
ban_status = "Ban Expired"
popup_data += "Status: [ban_status]
"
// All the other stats
popup_data += "Ban Type: [sanitize(ban["type"])]
"
popup_data += "Banning Admin: [sanitize(ban["bannedBy"])]
"
popup_data += "Ban Date: [sanitize(ban["bannedOn"])]
"
var/expiration = ban["expires"]
popup_data += "Expires: [expiration ? "[sanitize(expiration)]" : "Permanent"]
"
popup_data += "Ban Reason: [sanitize(ban["reason"])]
"
// If its a job ban, tell the admin the job list
if(ban["type"] == "Job")
var/list/jobs = ban["jobs"]
popup_data += "Jobs: [sanitize(english_list(jobs))]
"
// Add a newline between bans if its not the last one
if(index != total_bans)
popup_data += "
"
catch
to_chat(user, "Error parsing JSON data from CentCom Ban DB lookup. Please inform a maintainer.")
return
var/datum/browser/popup = new(user, "ccbdblookup-[ckey]", "CC Ban DB Lookup - [ckey]
", 700, 600)
popup.set_content(popup_data.Join())
popup.open(FALSE)
// Just a simple verb so admins can do manual lookups
/client/proc/ccbdb_lookup_ckey()
set name = "Global Ban DB Lookup"
set category = "Admin"
if(!check_rights(R_ADMIN))
return
var/input_ckey = input(usr, "Please enter a ckey to lookup", "Global Ban DB Lookup")
holder.create_ccbdb_lookup(input_ckey)