Moves various things to the new DBCore (#21544)

```
- server: "Changed the synthsprites to use the new DBCore"
- server: "Changed the MalfAI to use the new DBCore"
- server: "Changed the Alien Whitelists to use the new DBCore"
- server: "Changed the Requests Console to use the new DBCore"
- server: "Changed the Contracts Uplink to use the new DBCore"
- server: "Changed the Admin Ranks to use the new DBCore"
- server: "Changed the Job Bans to use the new DBCore"
- server: "Changed the Tickets to use the new DBCore"
- server: "Changed the Create Command Report to use the new DBCore"
- server: "Changed the WebInterface interconnect to use the new DBCore"
- server: "Changed the CCIA Recorder to use the new DBCore"
- server: "Changed the IPCTags to use the new DBCore"
- server: "Changed the Main Menu Poll-Check to use the new DBCore"
- server: "Changed the Client-Procs to use the new DBCore"
```

---------

Co-authored-by: Werner <Arrow768@users.noreply.github.com>
This commit is contained in:
Arrow768
2026-04-13 22:45:29 +02:00
committed by GitHub
parent 17721ddae4
commit 03f313a19d
33 changed files with 717 additions and 384 deletions
+3 -2
View File
@@ -180,7 +180,7 @@ GLOBAL_PROTECT(jobban_keylist)
*/
/proc/jobban_loaddatabase()
// No database. Weee.
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
log_world("ERROR: Database connection failed. Reverting to the legacy ban system.")
log_misc("Database connection failed. Reverting to the legacy ban system.")
GLOB.config.ban_legacy_system = 1
@@ -188,7 +188,7 @@ GLOBAL_PROTECT(jobban_keylist)
return
// All jobbans in one query. Because we don't actually care.
var/DBQuery/query = GLOB.dbcon.NewQuery("SELECT id, ckey, job, reason FROM ss13_ban WHERE isnull(unbanned) AND ((bantype = 'JOB_PERMABAN') OR (bantype = 'JOB_TEMPBAN' AND expiration_time > Now()))")
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, ckey, job, reason FROM ss13_ban WHERE isnull(unbanned) AND ((bantype = 'JOB_PERMABAN') OR (bantype = 'JOB_TEMPBAN' AND expiration_time > Now()))")
query.Execute()
while (query.NextRow())
@@ -207,6 +207,7 @@ GLOBAL_PROTECT(jobban_keylist)
else
// Woups. What happened here...?
log_and_message_admins("JOBBANS: Duplicate jobban entry in MySQL for [ckey]. Ban ID: #[query.item[1]]")
qdel(query)
/**
* Saves the current bans into the data/job_full.ban file.
+19 -107
View File
@@ -1,15 +1,34 @@
/**
* # IPIntel datum
*
* Holds the result of an IPIntel lookup for a given IP address.
* Created by [/datum/controller/subsystem/ipintel/proc/get_ip_intel] and delivered to its `on_complete` callback.
*/
/datum/ipintel
/// The IP address that was looked up
var/ip
/// The raw intel score returned by the API (0.01.0), or -1 on error
var/intel = 0
/// Whether this result came from cache (memory or database) rather than a live API call
var/cache = FALSE
/// How many minutes ago the cached entry was written
var/cacheminutesago = 0
/// SQL timestamp of when the cache entry was written
var/cachedate = ""
/// world.realtime equivalent of the cache write time, used for in-memory cache expiry
var/cacherealtime = 0
/datum/ipintel/New()
cachedate = SQLtime()
cacherealtime = world.realtime
/**
* Returns TRUE if this cached result is still within its configured validity window.
*
* Good results (below [/datum/configuration/var/ipintel_rating_bad]) are kept for
* [/datum/configuration/var/ipintel_save_good] hours; bad results are kept for
* [/datum/configuration/var/ipintel_save_bad] hours. Returns FALSE for error results (intel < 0).
*/
/datum/ipintel/proc/is_valid()
. = FALSE
if (intel < 0)
@@ -20,110 +39,3 @@
else
if (world.realtime < cacherealtime+(GLOB.config.ipintel_save_bad*60*60*10))
return TRUE
/proc/get_ip_intel(ip, bypasscache = FALSE, updatecache = TRUE)
var/datum/ipintel/res = new()
res.ip = ip
. = res
if (!ip || !GLOB.config.ipintel_email || !SSipintel.enabled)
return
if (!bypasscache)
var/datum/ipintel/cachedintel = SSipintel.cache[ip]
if (cachedintel && cachedintel.is_valid())
cachedintel.cache = TRUE
return cachedintel
if(establish_db_connection(GLOB.dbcon))
var/DBQuery/query_get_ip_intel = GLOB.dbcon.NewQuery({"
SELECT date, intel, TIMESTAMPDIFF(MINUTE,date,NOW())
FROM ss13_ipintel
WHERE
ip = INET6_ATON('[ip]')
AND ((
intel < [GLOB.config.ipintel_rating_bad]
AND
date + INTERVAL [GLOB.config.ipintel_save_good] HOUR > NOW()
) OR (
intel >= [GLOB.config.ipintel_rating_bad]
AND
date + INTERVAL [GLOB.config.ipintel_save_bad] HOUR > NOW()
))
"})
if(!query_get_ip_intel.Execute())
return
if (query_get_ip_intel.NextRow())
res.cache = TRUE
res.cachedate = query_get_ip_intel.item[1]
res.intel = text2num(query_get_ip_intel.item[2])
res.cacheminutesago = text2num(query_get_ip_intel.item[3])
res.cacherealtime = world.realtime - (text2num(query_get_ip_intel.item[3])*10*60)
SSipintel.cache[ip] = res
return
res.intel = ip_intel_query(ip)
if (updatecache && res.intel >= 0)
SSipintel.cache[ip] = res
if(establish_db_connection(GLOB.dbcon))
var/DBQuery/query_add_ip_intel = GLOB.dbcon.NewQuery("INSERT INTO ss13_ipintel (ip, intel) VALUES (INET6_ATON('[ip]'), [res.intel]) ON DUPLICATE KEY UPDATE intel = VALUES(intel), date = NOW()")
query_add_ip_intel.Execute()
/proc/ip_intel_query(ip, var/retryed=0)
. = -1 //default
if (!ip)
return
if (SSipintel.throttle > world.timeofday)
return
if (!SSipintel.enabled)
return
var/list/http[] = world.Export("http://[GLOB.config.ipintel_domain]/check.php?ip=[ip]&contact=[GLOB.config.ipintel_email]&format=json&flags=f")
if (http)
var/status = text2num(http["STATUS"])
if (status == 200)
var/response = json_decode(file2text(http["CONTENT"]))
if (response)
if (response["status"] == "success")
var/intelnum = text2num(response["result"])
if (isnum(intelnum))
return text2num(response["result"])
else
ipintel_handle_error("Bad intel from server: [response["result"]].", ip, retryed)
if (!retryed)
sleep(25)
return .(ip, 1)
else
ipintel_handle_error("Bad response from server: [response["status"]].", ip, retryed)
if (!retryed)
sleep(25)
return .(ip, 1)
else if (status == 429)
ipintel_handle_error("Error #429: We have exceeded the rate limit.", ip, 1)
return
else
ipintel_handle_error("Unknown status code: [status].", ip, retryed)
if (!retryed)
sleep(25)
return .(ip, 1)
else
ipintel_handle_error("Unable to connect to API.", ip, retryed)
if (!retryed)
sleep(25)
return .(ip, 1)
/proc/ipintel_handle_error(error, ip, retryed)
if (retryed)
SSipintel.errors++
error += " Could not check [ip]. Disabling IPINTEL for [SSipintel.errors] minute\s"
SSipintel.throttle = world.timeofday + (10 * 120 * SSipintel.errors)
else
error += " Attempting retry on [ip]."
log_ipintel(error)
/proc/log_ipintel(text)
log_game("IPINTEL: [text]")
LOG_DEBUG("IPINTEL: [text]")
+19 -16
View File
@@ -162,25 +162,28 @@ GLOBAL_LIST_EMPTY(ticket_panels)
if (status != TICKET_CLOSED)
return
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
return
var/DBQuery/Q = GLOB.dbcon.NewQuery({"INSERT INTO ss13_tickets
var/datum/db_query/query = SSdbcore.NewQuery({"INSERT INTO ss13_tickets
(game_id, message_count, admin_count, admin_list, opened_by, taken_by, closed_by, response_delay, opened_at, closed_at)
VALUES
(:g_id:, :m_count:, :a_count:, :a_list:, :opened_by:, :taken_by:, :closed_by:, :delay:, :opened_at:, :closed_at:)"})
Q.Execute(list(
"g_id" = GLOB.round_id,
"m_count" = length(msgs),
"a_count" = length(assigned_admins),
"a_list" = json_encode(assigned_admins),
"opened_by" = owner,
"taken_by" = length(assigned_admins) ? assigned_admins[1] : null,
"closed_by" = closed_by,
"delay" = response_time || -1,
"opened_at" = SQLtime(opened_rt),
"closed_at" = SQLtime(closed_rt)
))
VALUES (:g_id, :m_count, :a_count, :a_list, :opened_by, :taken_by, :closed_by, :delay, :opened_at, :closed_at)"},
list(
"g_id" = GLOB.round_id,
"m_count" = length(msgs),
"a_count" = length(assigned_admins),
"a_list" = json_encode(assigned_admins),
"opened_by" = owner,
"taken_by" = length(assigned_admins) ? assigned_admins[1] : null,
"closed_by" = closed_by,
"delay" = response_time || -1,
"opened_at" = SQLtime(opened_rt),
"closed_at" = SQLtime(closed_rt)
),
TRUE
)
query.SetSuccessCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
query.Execute()
/datum/ticket/proc/append_message(m_from, m_to, msg)
msgs += new /datum/ticket_msg(m_from, m_to, msg)
+3 -1
View File
@@ -620,7 +620,7 @@ Traitors and the like can also be revived with the previous role mostly intact.
if (!establish_db_connection(GLOB.dbcon))
to_chat(src, SPAN_NOTICE("Unable to connect to the database."))
return
var/DBQuery/query = GLOB.dbcon.NewQuery("SELECT title, message FROM ss13_ccia_general_notice_list WHERE deleted_at IS NULL")
var/datum/db_query/query = SSdbcore.NewQuery("SELECT title, message FROM ss13_ccia_general_notice_list WHERE deleted_at IS NULL")
query.Execute()
var/list/template_names = list()
@@ -630,6 +630,8 @@ Traitors and the like can also be revived with the previous role mostly intact.
template_names += query.item[1]
templates[query.item[1]] = query.item[2]
qdel(query)
// Catch empty list
if (!templates.len)
to_chat(src, SPAN_NOTICE("There are no templates in the database."))
+33 -20
View File
@@ -243,34 +243,47 @@
* Called by /datum/preferences/proc/gather_notifications() in preferences.dm
*/
/client/proc/warnings_gather()
var/count = 0
var/count_expire = 0
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
return
var/list/client_details = list("ckey" = ckey, "computer_id" = computer_id, "address" = address)
var/DBQuery/expire_query = GLOB.dbcon.NewQuery("SELECT id FROM ss13_warnings WHERE (acknowledged = 1 AND expired = 0 AND DATE_SUB(CURDATE(),INTERVAL 3 MONTH) > time) AND (ckey = :ckey: OR computerid = :computer_id: OR ip = :address:)")
expire_query.Execute(client_details)
while (expire_query.NextRow())
var/warning_id = text2num(expire_query.item[1])
var/DBQuery/update_query = GLOB.dbcon.NewQuery("UPDATE ss13_warnings SET expired = 1 WHERE id = :warning_id:")
update_query.Execute(list("warning_id" = warning_id))
count_expire++
var/datum/db_query/expire_query = SSdbcore.NewQuery(
"SELECT id FROM ss13_warnings WHERE (acknowledged = 1 AND expired = 0 AND DATE_SUB(CURDATE(),INTERVAL 3 MONTH) > time) AND (ckey = :ckey OR computerid = :computer_id OR ip = :address)",
client_details)
expire_query.SetSuccessCallback(CALLBACK(src, PROC_REF(_warnings_expire_cb)))
expire_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
expire_query.ExecuteNoSleep(TRUE)
var/DBQuery/query = GLOB.dbcon.NewQuery("SELECT id FROM ss13_warnings WHERE (visible = 1 AND acknowledged = 0 AND expired = 0) AND (ckey = :ckey: OR computerid = :computer_id: OR ip = :address:)")
query.Execute(client_details)
var/datum/db_query/count_query = SSdbcore.NewQuery(
"SELECT id FROM ss13_warnings WHERE (visible = 1 AND acknowledged = 0 AND expired = 0) AND (ckey = :ckey OR computerid = :computer_id OR ip = :address)",
client_details)
count_query.SetSuccessCallback(CALLBACK(src, PROC_REF(_warnings_count_cb)))
count_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
count_query.ExecuteNoSleep(TRUE)
/client/proc/_warnings_expire_cb(datum/db_query/query)
var/count_expire = 0
while (query.NextRow())
var/warning_id = text2num(query.item[1])
var/datum/db_query/update_query = SSdbcore.NewQuery(
"UPDATE ss13_warnings SET expired = 1 WHERE id = :warning_id",
list("warning_id" = warning_id))
update_query.SetSuccessCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
update_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
update_query.ExecuteNoSleep(TRUE)
count_expire++
qdel(query)
if (count_expire)
prefs?.new_notification("info", "[count_expire] of your warnings have expired.")
/client/proc/_warnings_count_cb(datum/db_query/query)
var/count = 0
while (query.NextRow())
count++
var/list/data = list("unread" = "", "expired" = "")
qdel(query)
if (count)
data["unread"] = "You have <b>[count] unread warning\s!</b> Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!"
if (count_expire)
data["expired"] = "[count_expire] of your warnings have expired."
return data
prefs?.new_notification("danger", "You have <b>[count] unread warning\s!</b> Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!", 1)
/**
* A proc used to gather if someone has Unacknowledged Warnings