diff --git a/code/_global_vars/sensitive.dm b/code/_global_vars/sensitive.dm index d4eda095ade..701d5942ce9 100644 --- a/code/_global_vars/sensitive.dm +++ b/code/_global_vars/sensitive.dm @@ -1,11 +1,11 @@ // MySQL configuration -GLOBAL_REAL_VAR(sqladdress) = "localhost" -GLOBAL_REAL_VAR(sqlport) = "3306" -GLOBAL_REAL_VAR(sqldb) = "tgstation" -GLOBAL_REAL_VAR(sqllogin) = "root" +GLOBAL_REAL_VAR(sqladdress) = "" +GLOBAL_REAL_VAR(sqlport) = "" +GLOBAL_REAL_VAR(sqldb) = "" +GLOBAL_REAL_VAR(sqllogin) = "" GLOBAL_REAL_VAR(sqlpass) = "" // Feedback gathering sql connection -GLOBAL_REAL_VAR(sqlfdbkdb) = "test" -GLOBAL_REAL_VAR(sqlfdbklogin) = "root" +GLOBAL_REAL_VAR(sqlfdbkdb) = "" +GLOBAL_REAL_VAR(sqlfdbklogin) = "" GLOBAL_REAL_VAR(sqlfdbkpass) = "" -GLOBAL_REAL_VAR(sqllogging) = 0 // Should we log deaths, population stats, etc.? \ No newline at end of file +GLOBAL_REAL_VAR(sqllogging) = 0 // Should we log deaths, population stats, etc.? diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index f2addca5427..3fcea0996a8 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -1065,47 +1065,6 @@ var/global/list/gamemode_cache = list() else log_misc("Unknown setting in configuration: '[name]'") -/datum/configuration/proc/loadforumsql(filename) // -- TLE - var/list/Lines = file2list(filename) - for(var/t in Lines) - if(!t) continue - - t = trim(t) - if (length(t) == 0) - continue - else if (copytext(t, 1, 2) == "#") - continue - - var/pos = findtext(t, " ") - var/name = null - var/value = null - - if (pos) - name = lowertext(copytext(t, 1, pos)) - value = copytext(t, pos + 1) - else - name = lowertext(t) - - if (!name) - continue - - switch (name) - if ("address") - forumsqladdress = value - if ("port") - forumsqlport = value - if ("database") - forumsqldb = value - if ("login") - forumsqllogin = value - if ("password") - forumsqlpass = value - if ("activatedgroup") - forum_activated_group = value - if ("authenticatedgroup") - forum_authenticated_group = value - else - log_misc("Unknown setting in configuration: '[name]'") /datum/configuration/proc/pick_mode(mode_name) // I wish I didn't have to instance the game modes in order to look up diff --git a/code/controllers/subsystems/misc_slow.dm b/code/controllers/subsystems/misc_slow.dm new file mode 100644 index 00000000000..419d356de9a --- /dev/null +++ b/code/controllers/subsystems/misc_slow.dm @@ -0,0 +1,96 @@ +SUBSYSTEM_DEF(misc_slow) + name = "Misc Slow" + flags = SS_NO_INIT + runlevels = RUNLEVEL_LOBBY | RUNLEVEL_GAME | RUNLEVEL_POSTGAME + wait = 5 MINUTES + + /// The number of times dbcon can fail in a row before being considered dead + var/static/const/DB_RECONNECTS_ALLOWED = 3 + + /// a list of (reconnects succeeded, reconnects failed) for dbcon + var/static/db_status = list(0, 0) + + /// A convenience cache of db_status for stat_entry + var/static/db_info = "-" + + /// The number of times dbcon_old can fail in a row before being considered dead + var/static/const/DB_OLD_RECONNECTS_ALLOWED = 3 + + /// a list of (reconnects succeeded, reconnects failed) for dbcon_old + var/static/db_old_status = list(0, 0) + + /// A convenience cache of db_old_status for stat_entry + var/static/db_old_info = "-" + + +/datum/controller/subsystem/misc_slow/VV_static() + return ..() + list( + "DB_RECONNECTS_ALLOWED", + "DB_OLD_RECONNECTS_ALLOWED" + ) + + +/datum/controller/subsystem/misc_slow/Recover() + RecoverDoReconnects() + + +/datum/controller/subsystem/misc_slow/stat_entry(msg) + ..(list( + msg, "sql: [config.sql_enabled ? "Y" : "N"] | DB: [db_info] | DB Old: [db_old_info]" + ).Join(null)) + + +/datum/controller/subsystem/misc_slow/fire(resumed, no_mc_tick) + DoReconnects() + + +/// Clear the state of members related to db connection maintenance +/datum/controller/subsystem/misc_slow/proc/RecoverDoReconnects() + db_status = list(0, 0) + db_info = "-" + db_old_status = list(0, 0) + db_old_info = "-" + + +/// Run connection maintenance for dbcon and dbcon_old, if sql is enabled correct(ish). +/datum/controller/subsystem/misc_slow/proc/DoReconnects() + if (!config.sql_enabled) + return + if (!sqladdress || !sqlport || !sqllogin || !sqldb || !sqlfdbklogin || !sqlfdbkdb) + log_debug("SS [name]: SQL credentials misconfigured.") + return + var/db_dsn = "dbi:mysql:[sqlfdbkdb]:[sqladdress]:[sqlport]" + ReconnectDB("DB", dbcon, db_dsn, sqlfdbklogin, sqlfdbkpass, db_status, DB_RECONNECTS_ALLOWED) + db_info = "DEAD" + if (db_status[2] < DB_RECONNECTS_ALLOWED) + db_info = "R[db_status[1]],F[db_status[2]]" + var/db_old_dsn = "dbi:mysql:[sqldb]:[sqladdress]:[sqlport]" + ReconnectDB("Old DB", dbcon_old, db_old_dsn, sqllogin, sqlpass, db_old_status, DB_OLD_RECONNECTS_ALLOWED) + db_old_info = "DEAD" + if (db_old_status[2] < DB_OLD_RECONNECTS_ALLOWED) + db_old_info = "R[db_old_status[1]],F[db_old_status[2]]" + + +/// An ugly proc that attempts to reopen the passed database's connection if it has timed out or been lost. +/datum/controller/subsystem/misc_slow/proc/ReconnectDB(log_name, DBConnection/db, dsn, user, pass, list/status, limit) + if (status[2] >= limit) // We've failed too many times. + return + if (!isnull(db._db_con)) + if (_dm_db_is_connected(db._db_con)) + var/query = _dm_db_new_query() // Do a little dance to keep the connection interested. + if (_dm_db_execute(query, "SELECT 1;", db._db_con, null, null)) + return + log_debug("SS [name]: [log_name] reconnecting.") + _dm_db_close(dbcon._db_con) + dbcon._db_con = null + var/connection = _dm_db_new_con() + var/success = _dm_db_connect(connection, dsn, user, pass, null, null) + if (success) + log_debug("SS [name]: [log_name] reconnected ([++status[1]]\th time).") + db._db_con = connection + status[2] = 0 + return + log_debug("SS [name]: [log_name] reconnect failed ([++status[2]]\th time).") + if (status[1] < limit) + return + log_debug("SS [name]: [log_name] reconnect failed too many times. No more attempts will be made.") diff --git a/code/game/world.dm b/code/game/world.dm index 7e825f1bb24..dd7e5ba9656 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -435,7 +435,6 @@ var/global/world_topic_spam_protect_time = world.timeofday config.load("config/config.txt") config.load("config/game_options.txt","game_options") config.loadsql("config/dbconfig.txt") - config.loadforumsql("config/forumdbconfig.txt") /hook/startup/proc/loadMods() world.load_mods() @@ -580,6 +579,8 @@ var/global/failed_old_db_connections = 0 //This proc ensures that the connection to the feedback database (global variable dbcon) is established /proc/establish_db_connection() + if (!config.sql_enabled) + return 0 if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF) return 0 @@ -625,6 +626,8 @@ var/global/failed_old_db_connections = 0 //This proc ensures that the connection to the feedback database (global variable dbcon) is established /proc/establish_old_db_connection() + if (!config.sql_enabled) + return 0 if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF) return 0 diff --git a/code/global.dm b/code/global.dm index 80d3a617af3..e96f6abe7d6 100644 --- a/code/global.dm +++ b/code/global.dm @@ -108,15 +108,6 @@ var/global/datum/metric/metric = new() // Metric datum, used to keep track of th var/global/list/awaydestinations = list() // Away missions. A list of landmarks that the warpgate can take you to. -// Forum MySQL configuration. (for use with forum account/key authentication) -// These are all default values that will load should the forumdbconfig.txt file fail to read for whatever reason. -var/global/forumsqladdress = "localhost" -var/global/forumsqlport = "3306" -var/global/forumsqldb = "tgstation" -var/global/forumsqllogin = "root" -var/global/forumsqlpass = "" -var/global/forum_activated_group = "2" -var/global/forum_authenticated_group = "10" // For FTP requests. (i.e. downloading runtime logs.) // However it'd be ok to use for accessing attack logs and such too, which are even laggier. diff --git a/code/modules/admin/view_variables/view_variables_global.dm b/code/modules/admin/view_variables/view_variables_global.dm index 3d7302caf27..1797ddba339 100644 --- a/code/modules/admin/view_variables/view_variables_global.dm +++ b/code/modules/admin/view_variables/view_variables_global.dm @@ -45,11 +45,6 @@ GLOBAL_DATUM(debug_real_globals, /debug_real_globals) // :3c /debug_real_globals/VV_hidden() return list( - "forumsqladdress", - "forumsqldb", - "forumsqllogin", - "forumsqlpass", - "forumsqlport", "sqladdress", "sqldb", "sqllogin", diff --git a/config/example/forumdbconfig.txt b/config/example/forumdbconfig.txt deleted file mode 100644 index 61a2a2d6ecd..00000000000 --- a/config/example/forumdbconfig.txt +++ /dev/null @@ -1,19 +0,0 @@ -# This configuration file is for the forum database, if you need to set up -# population, death, etc. tracking see 'dbconfig.txt' -# The login credentials for this will likely differ from those in dbconfig.txt! - -# Server the MySQL database can be found at -# Examples: localhost, 200.135.5.43, www.mysqldb.com, etc. -ADDRESS localhost - -# MySQL server port (default is 3306) -PORT 3306 - -# Database the forum data may be found in -DATABASE tgstation13 - -# Username/Login used to access the database -LOGIN mylogin - -# Password used to access the database -PASSWORD mypassword \ No newline at end of file diff --git a/polaris.dme b/polaris.dme index 683e5a97586..3e815674188 100644 --- a/polaris.dme +++ b/polaris.dme @@ -229,6 +229,7 @@ #include "code\controllers\subsystems\lighting.dm" #include "code\controllers\subsystems\machines.dm" #include "code\controllers\subsystems\mapping.dm" +#include "code\controllers\subsystems\misc_slow.dm" #include "code\controllers\subsystems\mobs.dm" #include "code\controllers\subsystems\nanoui.dm" #include "code\controllers\subsystems\nightshift.dm"