diff --git a/code/game/world.dm b/code/game/world.dm index 98ad8d05a88..bad01f2a082 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -572,7 +572,6 @@ var/failed_old_db_connections = 0 return 1 /proc/setup_database_connection() - if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF) //If it failed to establish a connection more than 5 times in a row, don't bother attempting to conenct anymore. return 0 @@ -650,6 +649,32 @@ var/failed_old_db_connections = 0 else return 1 +// Cleans up DB connections and recreates them +/proc/reset_database_connections() + var/list/results = list("-- Resetting DB connections --") + failed_db_connections = 0 + + if(dbcon?.IsConnected()) + dbcon.Disconnect() + results += "dbcon was connected and asked to disconnect" + else + results += "dbcon was not connected" + + if(dbcon_old?.IsConnected()) + results += "WARNING: dbcon_old is connected, not touching it, but is this intentional?" + + if(!config.sql_enabled) + results += "stopping because config.sql_enabled = false" + else + . = setup_database_connection() + if(.) + results += "SUCCESS: set up a connection successfully with setup_database_connection()" + else + results += "FAIL: failed to connect to the database with setup_database_connection()" + + results += "-- DB Reset End --" + to_world_log(results.Join("\n")) + // Things to do when a new z-level was just made. /world/proc/max_z_changed() if(!istype(GLOB.players_by_zlevel, /list))