Merge pull request #8080 from Atermonera/dbcon_onebuttonfix

Adds admin verb to hopefully fix database connection failures
This commit is contained in:
Atermonera
2021-06-06 00:42:26 -07:00
committed by GitHub
3 changed files with 42 additions and 1 deletions

View File

@@ -185,7 +185,8 @@ var/list/admin_verbs_server = list(
/client/proc/panicbunker,
/client/proc/paranoia_logging,
/client/proc/ip_reputation,
/client/proc/debug_global_variables
/client/proc/debug_global_variables,
/client/proc/dbcon_fix
)
var/list/admin_verbs_debug = list(

View 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(dbcon.IsConnected())
dbcon.Disconnect()
else
log_admin("Database already disconnected")
establish_db_connection()
var/errno = dbcon.ErrorMsg()
if(errno)
log_admin("Database connection returned error message `[errno]`. Aborting.")
return FALSE
if(!dbcon.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 = dbcon.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