mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-22 20:43:10 +01:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user