From d74dac1821bde93addb43d36dc7990b4a1305049 Mon Sep 17 00:00:00 2001
From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Date: Tue, 24 Nov 2020 15:18:44 +0000
Subject: [PATCH] Ingame CentCom Ban DB Lookup Interface (#14921)
* Ingame CentCom Ban DB Lookup Interface
* Farie Tweaks
---
code/controllers/configuration.dm | 5 ++
code/modules/admin/admin.dm | 5 +-
code/modules/admin/admin_verbs.dm | 3 +-
code/modules/admin/centcom_ban_db.dm | 117 +++++++++++++++++++++++++++
code/modules/admin/topic.dm | 20 ++---
config/example/config.txt | 6 ++
paradise.dme | 1 +
7 files changed, 140 insertions(+), 17 deletions(-)
create mode 100644 code/modules/admin/centcom_ban_db.dm
diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm
index 7c54ef79a06..e58f5619837 100644
--- a/code/controllers/configuration.dm
+++ b/code/controllers/configuration.dm
@@ -265,6 +265,9 @@
/// (This does not mean all ahelps are pinged, only ahelps sent when staff are offline get the ping, regardless of this setting)
var/discord_forward_all_ahelps = FALSE
+ /// URL for the CentCom Ban DB API
+ var/centcom_ban_db_url = null
+
/datum/configuration/New()
for(var/T in subtypesof(/datum/game_mode))
var/datum/game_mode/M = T
@@ -754,6 +757,8 @@
if("discord_forward_all_ahelps")
discord_forward_all_ahelps = TRUE
// End discord stuff
+ if("centcom_ban_db_url")
+ centcom_ban_db_url = value
else
log_config("Unknown setting in configuration: '[name]'")
diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm
index ab9e215fbba..2d338825f22 100644
--- a/code/modules/admin/admin.dm
+++ b/code/modules/admin/admin.dm
@@ -91,7 +91,10 @@ GLOBAL_VAR_INIT(nologevent, 0)
else
body += "\[[M.client.holder ? M.client.holder.rank : "Player"]\] "
body += "\[" + M.client.get_exp_type(EXP_TYPE_CREW) + " as [EXP_TYPE_CREW]\]"
- body += "
BYOND account registration date: [M.client.byondacc_date || "ERROR"] [M.client.byondacc_age <= config.byond_account_age_threshold ? "" : ""]([M.client.byondacc_age] days old)[M.client.byondacc_age <= config.byond_account_age_threshold ? "" : ""]
"
+ body += "
BYOND account registration date: [M.client.byondacc_date || "ERROR"] [M.client.byondacc_age <= config.byond_account_age_threshold ? "" : ""]([M.client.byondacc_age] days old)[M.client.byondacc_age <= config.byond_account_age_threshold ? "" : ""]"
+ body += "
Global Ban DB Lookup: [config.centcom_ban_db_url ? "Lookup" : "Disabled"]"
+
+ body += "
"
if(isnewplayer(M))
body += " Hasn't Entered Game "
diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm
index 5f05df4b6f5..02154b4bdb4 100644
--- a/code/modules/admin/admin_verbs.dm
+++ b/code/modules/admin/admin_verbs.dm
@@ -69,7 +69,8 @@ GLOBAL_LIST_INIT(admin_verbs_admin, list(
/client/proc/reset_all_tcs, /*resets all telecomms scripts*/
/client/proc/toggle_mentor_chat,
/client/proc/toggle_advanced_interaction, /*toggle admin ability to interact with not only machines, but also atoms such as buttons and doors*/
- /client/proc/list_ssds_afks
+ /client/proc/list_ssds_afks,
+ /client/proc/ccbdb_lookup_ckey
))
GLOBAL_LIST_INIT(admin_verbs_ban, list(
/client/proc/ban_panel,
diff --git a/code/modules/admin/centcom_ban_db.dm b/code/modules/admin/centcom_ban_db.dm
new file mode 100644
index 00000000000..6416a1a935b
--- /dev/null
+++ b/code/modules/admin/centcom_ban_db.dm
@@ -0,0 +1,117 @@
+// 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(!config.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, "[config.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 += "