mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] Moving the database to a subsystem (#9963)
Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
26ff936832
commit
40e935a774
@@ -30,7 +30,7 @@ var/inactive_keys = "None<br>"
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
|
||||
if(!SSdbcore.IsConnected())
|
||||
return
|
||||
|
||||
//grab all ckeys associated with custom items
|
||||
@@ -55,7 +55,7 @@ var/inactive_keys = "None<br>"
|
||||
//run a query to get all ckeys inactive for over 2 months
|
||||
var/list/inactive_ckeys = list()
|
||||
if(ckeys_with_customitems.len)
|
||||
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60") //CHOMPEdit TGSQL
|
||||
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60")
|
||||
query_inactive.Execute()
|
||||
while(query_inactive.NextRow())
|
||||
var/cur_ckey = query_inactive.item[1]
|
||||
@@ -63,16 +63,16 @@ var/inactive_keys = "None<br>"
|
||||
if(ckeys_with_customitems.Find(cur_ckey))
|
||||
ckeys_with_customitems.Remove(cur_ckey)
|
||||
inactive_ckeys[cur_ckey] = "last seen on [query_inactive.item[2]]"
|
||||
qdel(query_inactive) //CHOMPEdit TGSQL
|
||||
qdel(query_inactive)
|
||||
|
||||
//if there are ckeys left over, check whether they have a database entry at all
|
||||
if(ckeys_with_customitems.len)
|
||||
for(var/cur_ckey in ckeys_with_customitems)
|
||||
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ckey = :t_ckey", list("t_ckey" = cur_ckey)) //CHOMPEdit TGSQL
|
||||
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ckey = '[cur_ckey]'")
|
||||
query_inactive.Execute()
|
||||
if(!length(query_inactive.rows)) //CHOMPEdit TGSQL
|
||||
if(!query_inactive.rows)
|
||||
inactive_ckeys += cur_ckey
|
||||
qdel(query_inactive) //CHOMPEdit TGSQL
|
||||
qdel(query_inactive)
|
||||
if(inactive_ckeys.len)
|
||||
inactive_keys = ""
|
||||
for(var/cur_key in inactive_ckeys)
|
||||
|
||||
39
code/modules/admin/verbs/dbcon_fix.dm
Normal file
39
code/modules/admin/verbs/dbcon_fix.dm
Normal file
@@ -0,0 +1,39 @@
|
||||
// Will hoepfully fix the database when it breaks
|
||||
// Use case: if the server is left in the lobby for long enough, players that join will see player_age = 0, restricting them from all age-locked jobs.
|
||||
/client/proc/dbcon_fix()
|
||||
set name = "Fix Database Connection"
|
||||
set category = "Server"
|
||||
set desc = "Experimental: Will hopefully perform a one-button fix for a database connection that has timed out."
|
||||
|
||||
if(!check_rights(R_ADMIN|R_DEBUG|R_FUN))
|
||||
to_chat(src, "You must be an admin to do this.")
|
||||
return FALSE
|
||||
|
||||
log_admin("Attempting to fix database connection")
|
||||
if(SSdbcore.IsConnected())
|
||||
SSdbcore.Disconnect()
|
||||
else
|
||||
log_admin("Database already disconnected")
|
||||
|
||||
establish_db_connection()
|
||||
var/errno = SSdbcore.ErrorMsg()
|
||||
if(errno)
|
||||
log_admin("Database connection returned error message `[errno]`. Aborting.")
|
||||
return FALSE
|
||||
if(!SSdbcore.IsConnected())
|
||||
log_admin("Database could not be reconnected! Aborting.")
|
||||
return FALSE
|
||||
log_admin("Database reconnected. Fixing player ages...")
|
||||
|
||||
var/num = 0
|
||||
for(var/client/C in GLOB.clients)
|
||||
C.log_client_to_db()
|
||||
errno = SSdbcore.ErrorMsg()
|
||||
if(errno)
|
||||
log_admin("Database connection returned error message `[errno]` after adjusting player ages for [num] players. [C] was being updated when the error struck. Aborting.")
|
||||
return FALSE
|
||||
if(C.player_age)
|
||||
num++
|
||||
|
||||
log_admin("Successfully updated non-0 player age for [num] clients.")
|
||||
return FALSE
|
||||
@@ -12,7 +12,7 @@
|
||||
CONFIG_SET(flag/panic_bunker, !CONFIG_GET(flag/panic_bunker))
|
||||
|
||||
log_and_message_admins("has toggled the Panic Bunker, it is now [(CONFIG_GET(flag/panic_bunker) ? "on":"off")].", src)
|
||||
if (CONFIG_GET(flag/panic_bunker) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
|
||||
if (CONFIG_GET(flag/panic_bunker) && (!SSdbcore || !SSdbcore.IsConnected()))
|
||||
message_admins("The database is not connected! Panic bunker will not work until the connection is reestablished.")
|
||||
feedback_add_details("admin_verb","PANIC") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
CONFIG_SET(flag/paranoia_logging, !CONFIG_GET(flag/paranoia_logging))
|
||||
|
||||
log_and_message_admins("has toggled Paranoia Logging, it is now [(CONFIG_GET(flag/paranoia_logging) ? "on":"off")].", src)
|
||||
if (CONFIG_GET(flag/paranoia_logging) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
|
||||
if (CONFIG_GET(flag/paranoia_logging) && (!SSdbcore || !SSdbcore.IsConnected()))
|
||||
message_admins("The database is not connected! Paranoia logging will not be able to give 'player age' (time since first connection) warnings, only Byond account warnings.")
|
||||
feedback_add_details("admin_verb","PARLOG") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
|
||||
|
||||
@@ -40,6 +40,6 @@
|
||||
CONFIG_SET(flag/ip_reputation, !CONFIG_GET(flag/ip_reputation))
|
||||
|
||||
log_and_message_admins("has toggled IP reputation checks, it is now [(CONFIG_GET(flag/ip_reputation) ? "on":"off")].", src)
|
||||
if (CONFIG_GET(flag/ip_reputation) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
|
||||
if (CONFIG_GET(flag/ip_reputation) && (!SSdbcore || !SSdbcore.IsConnected()))
|
||||
message_admins("The database is not connected! IP reputation logging will not be able to allow existing players to bypass the reputation checks (if that is enabled).")
|
||||
feedback_add_details("admin_verb","IPREP") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
|
||||
|
||||
Reference in New Issue
Block a user