diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index 1be413f065..2d5e69f149 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -470,3 +470,5 @@ /datum/config_entry/flag/minimaps_enabled config_entry_value = TRUE + +/datum/config_entry/string/centcom_ban_db // URL for the CentCom Galactic Ban DB API diff --git a/code/datums/http.dm b/code/datums/http.dm new file mode 100644 index 0000000000..2a9b53f131 --- /dev/null +++ b/code/datums/http.dm @@ -0,0 +1,74 @@ +/datum/http_request + var/id + var/in_progress = FALSE + + var/method + var/body + var/headers + var/url + + var/_raw_response + +/datum/http_request/proc/prepare(method, url, body = "", list/headers) + if (!length(headers)) + headers = "" + else + headers = json_encode(headers) + + src.method = method + src.url = url + src.body = body + src.headers = headers + +/datum/http_request/proc/execute_blocking() + _raw_response = rustg_http_request_blocking(method, url, body, headers) + +/datum/http_request/proc/begin_async() + if (in_progress) + CRASH("Attempted to re-use a request object.") + + id = rustg_http_request_async(method, url, body, headers) + + if (isnull(text2num(id))) + stack_trace("Proc error: [id]") + _raw_response = "Proc error: [id]" + else + in_progress = TRUE + +/datum/http_request/proc/is_complete() + if (isnull(id)) + return TRUE + + if (!in_progress) + return TRUE + + var/r = rustg_http_check_request(id) + + if (r == RUSTG_JOB_NO_RESULTS_YET) + return FALSE + else + _raw_response = r + in_progress = FALSE + return TRUE + +/datum/http_request/proc/into_response() + var/datum/http_response/R = new() + + try + var/list/L = json_decode(_raw_response) + R.status_code = L["status_code"] + R.headers = L["headers"] + R.body = L["body"] + catch + R.errored = TRUE + R.error = _raw_response + + return R + +/datum/http_response + var/status_code + var/body + var/list/headers + + var/errored = FALSE + var/error diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index a2e2b3c122..8cfae3820a 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -40,6 +40,11 @@ if(M.client) body += "
\[First Seen: [M.client.player_join_date]\]\[Byond account registered on: [M.client.account_join_date]\]" + body += "

CentCom Galactic Ban DB: " + if(CONFIG_GET(string/centcom_ban_db)) + body += "Search" + else + body += "Disabled" body += "

Show related accounts by: " body += "\[ CID | " body += "IP \]" diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 1e3d1e93e3..41c3fe5105 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -2834,6 +2834,60 @@ usr << browse(dat.Join("
"), "window=related_[C];size=420x300") + else if(href_list["centcomlookup"]) + if(!check_rights(R_ADMIN)) + return + + if(!CONFIG_GET(string/centcom_ban_db)) + to_chat(usr, "Centcom Galactic Ban DB is disabled!") + return + + var/ckey = href_list["centcomlookup"] + + // 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"]) + dat += "
[bans.len] ban\s detected for [ckey]
" + for(var/list/ban in bans) + 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) + else if(href_list["modantagrep"]) if(!check_rights(R_ADMIN)) return diff --git a/config/config.txt b/config/config.txt index d6d0097c21..46f9a0cdc4 100644 --- a/config/config.txt +++ b/config/config.txt @@ -525,3 +525,7 @@ FAIL2TOPIC_RULE_NAME _dd_fail2topic ## Enable automatic profiling - Byond 513.1506 and newer only. #AUTO_PROFILE + +## Uncomment to enable global ban DB using the provided URL. The API should expect to receive a ckey at the end of the URL. +## More API details can be found here: https://centcom.melonmesa.com +CENTCOM_BAN_DB https://centcom.melonmesa.com/ban/search diff --git a/tgstation.dme b/tgstation.dme index a63d1db60a..56aefc8e29 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -377,6 +377,7 @@ #include "code\datums\explosion.dm" #include "code\datums\forced_movement.dm" #include "code\datums\holocall.dm" +#include "code\datums\http.dm" #include "code\datums\hud.dm" #include "code\datums\mind.dm" #include "code\datums\mutable_appearance.dm"