From 7e1f0d2285ea43d846d959f2c7dcf8fd20e19acb Mon Sep 17 00:00:00 2001 From: skull132 Date: Sun, 26 Mar 2017 16:29:08 +0300 Subject: [PATCH] Convert database configs to JSON (#1998) This is get over the shortcomings and failures of the old config system. Currently only applied to the DB configs because they're the ones fucking up. --- code/world.dm | 33 +++++++++++---------------------- config/example/dbconfig.json | 11 +++++++++++ config/example/dbconfig.txt | 23 ----------------------- 3 files changed, 22 insertions(+), 45 deletions(-) create mode 100644 config/example/dbconfig.json delete mode 100644 config/example/dbconfig.txt diff --git a/code/world.dm b/code/world.dm index e4e69960763..686918158d7 100644 --- a/code/world.dm +++ b/code/world.dm @@ -410,7 +410,7 @@ var/inerror = 0 /hook/startup/proc/load_databases() //Construct the database object from an init file. - dbcon = initialize_database_object("config/dbconfig.txt") + dbcon = initialize_database_object("config/dbconfig.json") if (!setup_database_connection(dbcon)) world.log << "Your server failed to establish a connection with the feedback database." @@ -425,31 +425,20 @@ var/inerror = 0 var/list/data = list("address", "port", "database", "login", "password") - var/list/Lines = file2list(filename) + var/list/Lines - if (!Lines) + try + Lines = json_decode(file2text(filename)) + catch(var/exception/e) + error("Error reading database config file '[filename]': [e]") + return new/DBConnection() + + if (!Lines || !Lines.len) // Return dummy object for safety. return new/DBConnection() - 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 - - name = lowertext(copytext(t, 1, pos)) - value = copytext(t, pos + 1) - - if (!name) - continue + for (var/name in Lines) + var/value = Lines[name] if (name in data) data[name] = value diff --git a/config/example/dbconfig.json b/config/example/dbconfig.json new file mode 100644 index 00000000000..47c15659a02 --- /dev/null +++ b/config/example/dbconfig.json @@ -0,0 +1,11 @@ +{ + // This config file is JSON-ed, to permit the usage of long names. The old + // config parser was throwing errors. + // All fields are self-planitory, fill them out and plop this in. + // BECAUSE DM JSON IS SIMPLE, REMOVE THIS COMMENT BLOCK! + "address": "yourwebserver.com", + "port": 3306, + "database": "ss13", + "login": "databaseuser", + "password": "databasepassword" +} diff --git a/config/example/dbconfig.txt b/config/example/dbconfig.txt deleted file mode 100644 index 2e2ac8ed331..00000000000 --- a/config/example/dbconfig.txt +++ /dev/null @@ -1,23 +0,0 @@ -# MySQL Connection Configuration - -# 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 population, death, karma, etc. tables may be found in -DATABASE tgstation - -# Username/Login used to access the database -LOGIN mylogin - -# Password used to access the database -PASSWORD mypassword - -# The following information is for feedback tracking via the blackbox server - -# Track population and death statistics -# Comment this out to disable -#ENABLE_STAT_TRACKING