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
+1
View File
@@ -36,6 +36,7 @@
var/related_accounts_ip = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this ip
var/related_accounts_cid = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this computer id
var/whitelist_status = 0 //Used to determine what whitelists the player has access to. Uses bitflag values!
var/whitelist_status_loaded = FALSE //Set to TRUE once log_client_to_db() has written whitelist_status from the DB. Prevents false whitelist failures during login before the async query completes.
var/need_saves_migrated = "Requires database" //Used to determine whether or not the ckey needs their saves migrated over to the database. Default is 0 upon successful connection.
var/account_age = -1 // Age on the BYOND account in days.
var/account_join_date = null // Date of the BYOND account creation in ISO 8601 format.
+150 -76
View File
@@ -145,13 +145,13 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
var/request_id = text2num(href_list["linkingrequest"])
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
to_chat(src, SPAN_WARNING("Action failed! Database link could not be established!"))
return
var/DBQuery/check_query = GLOB.dbcon.NewQuery("SELECT player_ckey, status FROM ss13_player_linking WHERE id = :id:")
check_query.Execute(list("id" = request_id))
var/datum/db_query/check_query = SSdbcore.NewQuery("SELECT player_ckey, status FROM ss13_player_linking WHERE id = :id",list("id" = request_id))
check_query.Execute()
if (!check_query.NextRow())
to_chat(src, SPAN_WARNING("No request found!"))
@@ -161,18 +161,20 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
to_chat(src, SPAN_WARNING("Request authentication failed!"))
return
qdel(check_query)
var/query_contents = ""
var/list/query_details = list("new_status", "id")
var/feedback_message = ""
switch (href_list["linkingaction"])
if ("accept")
query_contents = "UPDATE ss13_player_linking SET status = :new_status:, updated_at = NOW() WHERE id = :id:"
query_contents = "UPDATE ss13_player_linking SET status = :new_status, updated_at = NOW() WHERE id = :id"
query_details["new_status"] = "confirmed"
query_details["id"] = request_id
feedback_message = SPAN_DANGER("<b>Account successfully linked!</b>")
if ("deny")
query_contents = "UPDATE ss13_player_linking SET status = :new_status:, deleted_at = NOW() WHERE id = :id:"
query_contents = "UPDATE ss13_player_linking SET status = :new_status, deleted_at = NOW() WHERE id = :id"
query_details["new_status"] = "rejected"
query_details["id"] = request_id
@@ -181,8 +183,9 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
to_chat(src, SPAN_WARNING("Invalid command sent."))
return
var/DBQuery/update_query = GLOB.dbcon.NewQuery(query_contents)
update_query.Execute(query_details)
var/datum/db_query/update_query = SSdbcore.NewQuery(query_contents,query_details)
update_query.Execute()
qdel(update_query)
if (href_list["linkingaction"] == "accept" && alert("To complete the process, you have to visit the website. Do you want to do so now?",,"Yes","No") == "Yes")
process_webint_link("interface/user/link")
@@ -542,21 +545,35 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
..() //Even though we're going to be hard deleted there are still some things that want to know the destroy is happening
return QDEL_HINT_HARDDEL_NOW
// here because it's similar to below
// Returns null if no DB connection can be established, or -1 if the requested key was not found in the database
/**
* Ensures whitelist_status is populated from the database.
*
* Idempotent: returns immediately if already loaded.
* Called by log_client_to_db() as part of the full player record fetch,
* and by the loadout sanitization to block until the status is available.
*/
/client/proc/load_whitelist_status()
if (whitelist_status_loaded)
return
/proc/get_player_age(key)
if(!establish_db_connection(GLOB.dbcon))
return null
if (IsGuestKey(key) || !GLOB.config.sql_whitelists)
whitelist_status_loaded = TRUE
return
var/DBQuery/query = GLOB.dbcon.NewQuery("SELECT datediff(Now(),firstseen) as age FROM ss13_player WHERE ckey = :ckey:")
query.Execute(list("ckey"=ckey(key)))
var/datum/db_query/query = SSdbcore.NewQuery(
"SELECT whitelist_status FROM ss13_player WHERE ckey = :ckey",
list("ckey" = ckey(key))
)
if (!query.Execute())
qdel(query)
whitelist_status_loaded = TRUE
return
if(query.NextRow())
return text2num(query.item[1])
else
return -1
if (query.NextRow())
whitelist_status = text2num(query.item[1])
qdel(query)
whitelist_status_loaded = TRUE
/client/proc/log_client_to_db()
set waitfor = FALSE
@@ -564,16 +581,17 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
if (IsGuestKey(src.key))
return
if(!establish_db_connection(GLOB.dbcon))
return
var/DBQuery/query = GLOB.dbcon.NewQuery("SELECT datediff(Now(),firstseen) as age, whitelist_status, account_join_date, DATEDIFF(NOW(), account_join_date), ckey_is_external FROM ss13_player WHERE ckey = :ckey:")
if(!query.Execute(list("ckey"=ckey(key))))
// --- Main player record lookup ---
var/datum/db_query/query = SSdbcore.NewQuery(
"SELECT datediff(Now(),firstseen), whitelist_status, account_join_date, DATEDIFF(NOW(), account_join_date), ckey_is_external FROM ss13_player WHERE ckey = :ckey",
list("ckey" = ckey(key))
)
if (!query.Execute())
qdel(query)
return
var/found = 0
player_age = 0 // New players won't have an entry so knowing we have a connection we set this to zero to be updated if their is a record.
player_age = 0 // New players won't have an entry; zero signals we have a connection but no record yet.
if (query.NextRow())
found = 1
@@ -583,44 +601,85 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
account_age = text2num(query.item[4])
ckey_is_external = !!text2num(query.item[5])
if (!account_age)
account_join_date = sanitizeSQL(findJoinDate())
account_join_date = findJoinDate()
if (!account_join_date)
account_age = -1
else
var/DBQuery/query_datediff = GLOB.dbcon.NewQuery("SELECT DATEDIFF(NOW(), [account_join_date])")
var/datum/db_query/query_datediff = SSdbcore.NewQuery(
"SELECT DATEDIFF(NOW(), :join_date)",
list("join_date" = account_join_date)
)
if (!query_datediff.Execute())
qdel(query)
qdel(query_datediff)
return
if (query_datediff.NextRow())
account_age = text2num(query_datediff.item[1])
qdel(query_datediff)
qdel(query)
whitelist_status_loaded = TRUE
var/DBQuery/query_ip = GLOB.dbcon.NewQuery("SELECT ckey FROM ss13_player WHERE ip = '[address]'")
// --- Related account lookups ---
var/datum/db_query/query_ip = SSdbcore.NewQuery(
"SELECT ckey FROM ss13_player WHERE ip = :ip",
list("ip" = address)
)
query_ip.Execute()
related_accounts_ip = ""
while(query_ip.NextRow())
related_accounts_ip += "[query_ip.item[1]], "
break
if (query_ip.NextRow())
related_accounts_ip = "[query_ip.item[1]], "
qdel(query_ip)
var/DBQuery/query_cid = GLOB.dbcon.NewQuery("SELECT ckey FROM ss13_player WHERE computerid = '[computer_id]'")
var/datum/db_query/query_cid = SSdbcore.NewQuery(
"SELECT ckey FROM ss13_player WHERE computerid = :computerid",
list("computerid" = computer_id)
)
query_cid.Execute()
related_accounts_cid = ""
while(query_cid.NextRow())
related_accounts_cid += "[query_cid.item[1]], "
break
if (query_cid.NextRow())
related_accounts_cid = "[query_cid.item[1]], "
qdel(query_cid)
// --- Write ---
var/admin_rank = "Player"
if(src.holder)
if (src.holder)
admin_rank = src.holder.rank
if(found)
//Player already identified previously, we need to just update the 'lastseen', 'ip', 'computer_id', 'byond_version' and 'byond_build' variables
var/DBQuery/query_update = GLOB.dbcon.NewQuery("UPDATE ss13_player SET lastseen = Now(), ip = :ip:, computerid = :computerid:, lastadminrank = :lastadminrank:, account_join_date = :account_join_date:, byond_version = :byond_version:, byond_build = :byond_build: WHERE ckey = :ckey:")
query_update.Execute(list("ckey"=ckey(key),"ip"=src.address,"computerid"=src.computer_id,"lastadminrank"=admin_rank,"account_join_date"=account_join_date,"byond_version"=byond_version,"byond_build"=byond_build))
if (found)
var/datum/db_query/query_update = SSdbcore.NewQuery(
"UPDATE ss13_player SET lastseen = Now(), ip = :ip, computerid = :computerid, lastadminrank = :lastadminrank, account_join_date = :account_join_date, byond_version = :byond_version, byond_build = :byond_build WHERE ckey = :ckey",
list(
"ckey" = ckey(key),
"ip" = src.address,
"computerid" = src.computer_id,
"lastadminrank" = admin_rank,
"account_join_date" = account_join_date,
"byond_version" = byond_version,
"byond_build" = byond_build,
)
)
query_update.SetSuccessCallback(CALLBACK(GLOBAL_PROC, /proc/qdel))
query_update.SetFailCallback(CALLBACK(GLOBAL_PROC, /proc/qdel))
query_update.Execute()
else if (!GLOB.config.access_deny_new_players)
//New player!! Need to insert all the stuff
var/DBQuery/query_insert = GLOB.dbcon.NewQuery("INSERT INTO ss13_player (ckey, ckey_is_external, firstseen, lastseen, ip, computerid, lastadminrank, account_join_date, byond_version, byond_build) VALUES (:ckey:, :ckey_is_external:, Now(), Now(), :ip:, :computerid:, :lastadminrank:, :account_join_date:, :byond_version:, :byond_build:)")
query_insert.Execute(list("ckey"=ckey(key), "ckey_is_external"=src.ckey_is_external,"ip"=src.address,"computerid"=src.computer_id,"lastadminrank"=admin_rank,"account_join_date"=account_join_date,"byond_version"=byond_version,"byond_build"=byond_build))
var/datum/db_query/query_insert = SSdbcore.NewQuery(
"INSERT INTO ss13_player (ckey, ckey_is_external, firstseen, lastseen, ip, computerid, lastadminrank, account_join_date, byond_version, byond_build) VALUES (:ckey, :ckey_is_external, Now(), Now(), :ip, :computerid, :lastadminrank, :account_join_date, :byond_version, :byond_build)",
list(
"ckey" = ckey(key),
"ckey_is_external" = src.ckey_is_external,
"ip" = src.address,
"computerid" = src.computer_id,
"lastadminrank" = admin_rank,
"account_join_date" = account_join_date,
"byond_version" = byond_version,
"byond_build" = byond_build,
)
)
query_insert.SetSuccessCallback(CALLBACK(GLOBAL_PROC, /proc/qdel))
query_insert.SetFailCallback(CALLBACK(GLOBAL_PROC, /proc/qdel))
query_insert.Execute()
else
// Flag as -1 to know we have to kiiick them.
// Flag as -1 to signal this player must be kicked (new players denied).
player_age = -1
if (!account_join_date)
@@ -746,18 +805,20 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
if (!GLOB.config.webint_url || !GLOB.config.sql_enabled)
return
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
return
var/list/requests = list()
var/list/query_details = list("ckey" = ckey)
var/DBQuery/select_query = GLOB.dbcon.NewQuery("SELECT id, forum_id, forum_username, datediff(Now(), created_at) as request_age FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey: AND deleted_at IS NULL")
select_query.Execute(query_details)
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id, forum_id, forum_username, datediff(Now(), created_at) as request_age FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey AND deleted_at IS NULL",query_details)
select_query.Execute()
while (select_query.NextRow())
requests.Add(list(list("id" = text2num(select_query.item[1]), "forum_id" = text2num(select_query.item[2]), "forum_username" = select_query.item[3], "request_age" = select_query.item[4])))
qdel(select_query)
if (!requests.len)
return
@@ -783,17 +844,18 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
if (!GLOB.config.webint_url || !GLOB.config.sql_enabled)
return
if (!establish_db_connection(GLOB.dbcon))
if (!SSdbcore.Connect())
return
var/DBQuery/select_query = GLOB.dbcon.NewQuery("SELECT COUNT(*) AS request_count FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey: AND deleted_at IS NULL")
select_query.Execute(list("ckey" = ckey))
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT COUNT(*) AS request_count FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey AND deleted_at IS NULL", list("ckey" = ckey))
select_query.SetSuccessCallback(CALLBACK(src, PROC_REF(_gather_linking_requests_cb)))
select_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
select_query.ExecuteNoSleep(TRUE)
if (select_query.NextRow())
if (text2num(select_query.item[1]) > 0)
return "You have [select_query.item[1]] account linking requests pending review. Click <a href='byond://?JSlink=linking;notification=:src_ref'>here</a> to see them!"
return null
/client/proc/_gather_linking_requests_cb(datum/db_query/query)
if (query.NextRow() && text2num(query.item[1]) > 0)
prefs?.new_notification("info", "You have [query.item[1]] account linking requests pending review. Click <a href='byond://?JSlink=linking;notification=:src_ref'>here</a> to see them!", callback_src = src, callback_proc = "check_linking_requests")
qdel(query)
/client/proc/process_webint_link(var/route, var/attributes)
if (!route)
@@ -838,34 +900,46 @@ GLOBAL_LIST_INIT(localhost_addresses, list(
send_link(src, linkURL)
return
/client/proc/check_ip_intel()
set waitfor = 0 //we sleep when getting the intel, no need to hold up the client connection while we sleep
set waitfor = 0
if (GLOB.config.ipintel_email)
var/datum/ipintel/res = get_ip_intel(address)
if (GLOB.config.ipintel_rating_kick && res.intel >= GLOB.config.ipintel_rating_kick)
if (!holder)
message_admins("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a proxy/VPN. They are being kicked because of this.")
log_admin("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a proxy/VPN. They are being kicked because of this.")
to_chat(src, SPAN_DANGER("Usage of proxies is not permitted by the rules. You are being kicked because of this."))
del(src)
else
message_admins("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a Proxy/VPN.")
else if (res.intel >= GLOB.config.ipintel_rating_bad)
SSipintel.get_ip_intel(address, on_complete = CALLBACK(src, /client/proc/on_ip_intel_result))
/client/proc/on_ip_intel_result(datum/ipintel/res)
if (GLOB.config.ipintel_rating_kick && res.intel >= GLOB.config.ipintel_rating_kick)
if (!holder)
message_admins("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a proxy/VPN. They are being kicked because of this.")
log_admin("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a proxy/VPN. They are being kicked because of this.")
to_chat(src, SPAN_DANGER("Usage of proxies is not permitted by the rules. You are being kicked because of this."))
del(src)
else
message_admins("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a Proxy/VPN.")
ip_intel = res.intel
else if (res.intel >= GLOB.config.ipintel_rating_bad)
message_admins("Proxy Detection: [key_name_admin(src)] IP intel rated [res.intel*100]% likely to be a Proxy/VPN.")
ip_intel = res.intel
/client/proc/findJoinDate()
var/list/http = world.Export("http://byond.com/members/[ckey]?format=text")
if(!http)
var/datum/http_request/req = new()
req.prepare(RUSTG_HTTP_METHOD_GET, "https://byond.com/members/[ckey]?format=text")
req.begin_async()
// Poll RUSTG directly rather than routing through SShttp — this proc can be called
// before SShttp is firing (e.g. during MC init), so we cannot rely on SShttp's fire
// loop to dispatch the callback.
while (!req.is_complete())
sleep(world.tick_lag)
var/datum/http_response/http = req.into_response()
if (http.errored || http.status_code != 200)
LOG_DEBUG("ACCESS CONTROL: Failed to connect to byond age check for [ckey]")
return
var/F = file2text(http["CONTENT"])
if(F)
var/regex/R = regex("joined = \"(\\d{4}-\\d{2}-\\d{2})\"")
if(R.Find(F))
. = R.group[1]
else
CRASH("Age check regex failed for [src.ckey]")
var/regex/R = regex("joined = \"(\\d{4}-\\d{2}-\\d{2})\"")
if (R.Find(http.body))
return R.group[1]
else
CRASH("Age check regex failed for [src.ckey]")
/client/Click(atom/object, atom/location, control, params)
SEND_SIGNAL(src, COMSIG_CLIENT_CLICK, object, location, control, params, usr)
@@ -104,6 +104,8 @@ GLOBAL_LIST_INIT(gear_datums, list())
var/list/whitelist_cache = list()
if(preference_mob)
if(preference_mob.client)
preference_mob.client.load_whitelist_status()
for(var/species in GLOB.all_species)
var/datum/species/S = GLOB.all_species[species]
if(is_alien_whitelisted(preference_mob, S))
+56 -82
View File
@@ -139,113 +139,87 @@
new_notification("info", "You have unread updates in the changelog.")
if (GLOB.config.sql_enabled)
var/list/warnings = user.warnings_gather()
if (warnings["unread"])
new_notification("danger", warnings["unread"], 1)
if (warnings["expired"])
new_notification("info", warnings["expired"])
var/linking = user.gather_linking_requests()
if (linking)
new_notification("info", linking, callback_src = user, callback_proc = "check_linking_requests")
var/cciaa_actions = count_ccia_actions(user)
if (cciaa_actions)
new_notification("info", cciaa_actions)
user.warnings_gather()
user.gather_linking_requests()
count_ccia_actions(user)
add_active_notifications(user)
/datum/preferences/proc/add_active_notifications(var/client/user)
if(!user)
return null
if (!user)
return
if (!establish_db_connection(GLOB.dbcon))
log_world("ERROR: Error initiatlizing database connection while getting notifications.")
return null
if (!SSdbcore.Connect())
return
var/DBQuery/query = GLOB.dbcon.NewQuery({"SELECT
message, type, id
FROM ss13_player_notifications
WHERE acked_at IS NULL AND ckey = :ckey:
"})
query.Execute(list("ckey" = user.ckey))
var/datum/db_query/query = SSdbcore.NewQuery(
"SELECT message, type, id FROM ss13_player_notifications WHERE acked_at IS NULL AND ckey = :ckey",
list("ckey" = user.ckey))
query.SetSuccessCallback(CALLBACK(src, PROC_REF(_add_active_notifications_cb), user))
query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
query.ExecuteNoSleep(TRUE)
var/chat_notification=0
var/panel_notification=0
var/notification_count=0
while(query.NextRow())
var/autoack=0
//Lets loop through the results
/datum/preferences/proc/_add_active_notifications_cb(var/client/user, datum/db_query/query)
var/chat_notification = 0
var/panel_notification = 0
var/notification_count = 0
while (query.NextRow())
var/autoack = 0
switch(query.item[2])
if("player_greeting")
panel_notification=1
panel_notification = 1
notification_count++
if("player_greeting_chat")
chat_notification=1
panel_notification=1
chat_notification = 1
panel_notification = 1
notification_count++
if("admin")
SSdiscord.send_to_admins("Server Notification for [user.ckey]: [query.item[1]]")
SSdiscord.post_webhook_event(WEBHOOK_ADMIN, list("title"="Server Notification for: [user.ckey]", "message"="Server Notification Triggered for [user.ckey]: [query.item[1]]"))
//Immediately ack the notification
autoack=1
autoack = 1
if("ccia")
SSdiscord.send_to_cciaa("Server Notification for [user.ckey]: [query.item[1]]")
SSdiscord.post_webhook_event(WEBHOOK_CCIAA_EMERGENCY_MESSAGE, list("title"="Server Notification for: [user.ckey]", "message"="Server Notification Triggered for [user.ckey]: [query.item[1]]"))
//Immeidately ack the notification
autoack=1
if(autoack)
var/DBQuery/ackquery = GLOB.dbcon.NewQuery({"UPDATE ss13_player_notifications
SET acked_by = 'autoack-server', acked_at = NOW()
WHERE id = :id:
"})
ackquery.Execute(list("id" = query.item[3]))
if(panel_notification)
new_notification("warning","You have <b>[notification_count] unread notifications!</b> Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!")
if(chat_notification)
to_chat(user,SPAN_WARNING("<BIG><B>You have unacknowledged notifications.</B></BIG><br>Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!"))
autoack = 1
if (autoack)
var/datum/db_query/ackquery = SSdbcore.NewQuery(
"UPDATE ss13_player_notifications SET acked_by = 'autoack-server', acked_at = NOW() WHERE id = :id",
list("id" = query.item[3]))
ackquery.SetSuccessCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
ackquery.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
ackquery.ExecuteNoSleep(TRUE)
qdel(query)
if (panel_notification)
new_notification("warning", "You have <b>[notification_count] unread notifications!</b> Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!")
if (chat_notification)
to_chat(user, SPAN_WARNING("<BIG><B>You have unacknowledged notifications.</B></BIG><br>Click <a href='byond://?JSlink=warnings;notification=:src_ref'>here</a> to review and acknowledge them!"))
/*
* Helper proc for getting a count of active CCIA actions against the player's characters.
*/
/datum/preferences/proc/count_ccia_actions(var/client/user)
if (!user)
return null
return
if (!establish_db_connection(GLOB.dbcon))
log_world("ERROR: Error initiatlizing database connection while counting CCIA actions.")
return null
if (!SSdbcore.Connect())
return
var/DBQuery/prep_query = GLOB.dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey = :ckey:")
prep_query.Execute(list("ckey" = user.ckey))
var/list/chars = list()
while (prep_query.NextRow())
chars += text2num(prep_query.item[1])
if (!chars.len)
return null
var/DBQuery/query = GLOB.dbcon.NewQuery({"SELECT
COUNT(act_chr.action_id) AS action_count
FROM ss13_ccia_action_char act_chr
JOIN ss13_characters chr ON act_chr.char_id = chr.id
JOIN ss13_ccia_actions act ON act_chr.action_id = act.id
WHERE
act_chr.char_id IN :char_id: AND
(act.expires_at IS NULL OR act.expires_at >= CURRENT_DATE()) AND
act.deleted_at IS NULL;"})
query.Execute(list("char_id" = chars))
var/datum/db_query/actions_query = SSdbcore.NewQuery(
{"SELECT COUNT(act_chr.action_id) AS action_count
FROM ss13_ccia_action_char act_chr
JOIN ss13_characters chr ON act_chr.char_id = chr.id
JOIN ss13_ccia_actions act ON act_chr.action_id = act.id
WHERE
chr.ckey = :ckey AND
(act.expires_at IS NULL OR act.expires_at >= CURRENT_DATE()) AND
act.deleted_at IS NULL;"},
list("ckey" = user.ckey))
actions_query.SetSuccessCallback(CALLBACK(src, PROC_REF(_count_ccia_actions_cb)))
actions_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel)))
actions_query.ExecuteNoSleep(TRUE)
/datum/preferences/proc/_count_ccia_actions_cb(datum/db_query/query)
if (query.NextRow())
var/action_count = text2num(query.item[1])
if (action_count == 0)
return null
var/string = "There are [action_count] active CCIA actions currently active against your character(s)."
return string
return null
if (action_count > 0)
new_notification("info", "There are [action_count] active CCIA actions currently active against your character(s).")
qdel(query)