diff --git a/code/datums/configuration.dm b/code/datums/configuration.dm
index 4c6fb4fdc0b..69e99c3000b 100644
--- a/code/datums/configuration.dm
+++ b/code/datums/configuration.dm
@@ -173,6 +173,57 @@
else
diary << "Unknown setting in configuration: '[name]'"
+/datum/configuration/proc/loadsql(filename) // -- TLE
+ var/text = file2text(filename)
+
+ if (!text)
+ diary << "No dbconfig.txt file found, retaining defaults"
+ world << "No dbconfig.txt file found, retaining defaults"
+ return
+
+ diary << "Reading database configuration file [filename]"
+
+ var/list/CL = dd_text2list(text, "\n")
+
+ for (var/t in CL)
+ 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")
+ sqladdress = value
+ if ("port")
+ sqlport = value
+ if ("database")
+ sqldb = value
+ if ("login")
+ sqllogin = value
+ if ("password")
+ sqlpass = value
+ if ("enable_stat_tracking")
+ sqllogging = 1
+ else
+ diary << "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
// their information, but it is the only way (at least that I know of).
diff --git a/code/defines/global.dm b/code/defines/global.dm
index f9829f4595a..d839b123f15 100644
--- a/code/defines/global.dm
+++ b/code/defines/global.dm
@@ -41,7 +41,7 @@ var
diary = null
station_name = null
- game_version = "Goon Dev Station 13"
+ game_version = "/tg/ Station 13"
datum/air_tunnel/air_tunnel1/SS13_airtunnel = null
going = 1.0
@@ -163,3 +163,15 @@ var
const/shuttle_time_in_station = 1800 // 3 minutes in the station
const/shuttle_time_to_arrive = 6000 // 10 minutes to arrive
+
+
+
+ // MySQL configuration
+
+ sqladdress = "localhost"
+ sqlport = "3306"
+ sqldb = "tgstation"
+ sqllogin = "root"
+ sqlpass = ""
+
+ sqllogging = 0 // Should we log deaths, population stats, etc?
diff --git a/code/defines/procs/dbcore.dm b/code/defines/procs/dbcore.dm
index 8a032847bfa..ff63a1d6dec 100644
--- a/code/defines/procs/dbcore.dm
+++ b/code/defines/procs/dbcore.dm
@@ -35,10 +35,12 @@
#define BLOB 14
// TODO: Investigate more recent type additions and see if I can handle them. - Nadrew
-
+// Deprecated! See global.dm for new configuration vars
+/*
var
DB_SERVER = "" // This is the location of your MySQL server (localhost is USUALLY fine)
DB_PORT = 3306 // This is the port your MySQL server is running on (3306 is the default)
+*/
DBConnection
New(dbi_handler,username,password_handler,cursor_handler)
@@ -63,7 +65,8 @@ DBConnection
ErrorMsg() return _dm_db_error_msg(_db_con)
SelectDB(database_name,dbi)
if(IsConnected()) Disconnect()
- return Connect("[dbi?"[dbi]":"dbi:mysql:[database_name]:[DB_SERVER]:[DB_PORT]"]",user,password)
+ //return Connect("[dbi?"[dbi]":"dbi:mysql:[database_name]:[DB_SERVER]:[DB_PORT]"]",user,password)
+ return Connect("[dbi?"[dbi]":"dbi:mysql:[database_name]:[sqladdress]:[sqlport]"]",user,password)
NewQuery(sql_query,cursor_handler=src.default_cursor) return new/DBQuery(sql_query,src,cursor_handler)
var
diff --git a/code/defines/procs/statistics.dm b/code/defines/procs/statistics.dm
index 37f9cf4b362..dda6e43a00c 100644
--- a/code/defines/procs/statistics.dm
+++ b/code/defines/procs/statistics.dm
@@ -1,21 +1,12 @@
-#define SQL_ADDRESS "yourserver.com"
-#define SQL_DB "yourdbname"
-#define SQL_PORT "3306" // 3306 is default
-#define SQL_LOGIN "yourlogin"
-#define SQL_PASS "yourpassword"
-
-
-#define STATLOGGING 0 // Should use #ifdef here
-
proc/sql_poll_players()
- if(!STATLOGGING)
+ if(!sqllogging)
return
var/playercount = 0
for(var/mob/M in world)
if(M.client)
playercount += 1
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
log_game("SQL ERROR during player polling. Failed to connect.")
else
@@ -28,14 +19,14 @@ proc/sql_poll_players()
proc/sql_poll_admins()
- if(!STATLOGGING)
+ if(!sqllogging)
return
var/admincount = 0
for (var/mob/M in world)
if(M && M.client && M.client.holder && M.client.authenticated)
admincount += 1
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
log_game("SQL ERROR during admin polling. Failed to connect.")
else
@@ -47,14 +38,16 @@ proc/sql_poll_admins()
dbcon.Disconnect()
proc/sql_report_round_start()
- if(!STATLOGGING)
+ // TODO
+ if(!sqllogging)
return
proc/sql_report_round_end()
- if(!STATLOGGING)
+ // TODO
+ if(!sqllogging)
return
proc/sql_report_karma(var/mob/spender, var/mob/receiver, var/isnegative = 1)
- if(!STATLOGGING)
+ if(!sqllogging)
return
var/sqlspendername = spender.name
var/sqlspenderkey = spender.key
@@ -78,7 +71,7 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver, var/isnegative = 1)
sqlreceiverrole = receiver.mind.assigned_role
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
log_game("SQL ERROR during karma logging. Failed to connect.")
else
@@ -123,7 +116,7 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver, var/isnegative = 1)
proc/sql_report_death(var/mob/living/carbon/human/H)
- if(!STATLOGGING)
+ if(!sqllogging)
return
if(!H)
return
@@ -148,7 +141,7 @@ proc/sql_report_death(var/mob/living/carbon/human/H)
var/coord = "[H.x], [H.y], [H.z]"
//world << "INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.bruteloss], [H.fireloss], [H.brainloss], [H.oxyloss])"
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
@@ -160,7 +153,7 @@ proc/sql_report_death(var/mob/living/carbon/human/H)
proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
- if(!STATLOGGING)
+ if(!sqllogging)
return
if(!H)
return
@@ -185,7 +178,7 @@ proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
var/coord = "[H.x], [H.y], [H.z]"
//world << "INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.bruteloss], [H.fireloss], [H.brainloss], [H.oxyloss])"
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
@@ -197,7 +190,7 @@ proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
proc/statistic_cycle()
- if(!STATLOGGING)
+ if(!sqllogging)
return
while(1)
sql_poll_players()
diff --git a/code/game/cellautomata.dm b/code/game/cellautomata.dm
index 9754747497e..cf2f2a9dbe5 100644
--- a/code/game/cellautomata.dm
+++ b/code/game/cellautomata.dm
@@ -64,6 +64,7 @@
/world/proc/load_configuration()
config = new /datum/configuration()
config.load("config/config.txt")
+ config.loadsql("config/dbconfig.txt")
// apply some settings from config..
abandon_allowed = config.respawn
diff --git a/code/game/magic/library.dm b/code/game/magic/library.dm
index 62d3c66529b..ef0d0cf5f8f 100644
--- a/code/game/magic/library.dm
+++ b/code/game/magic/library.dm
@@ -4,11 +4,14 @@
//
//*******************************
+// Deprecated! See global.dm for new SQL config vars -- TLE
+/*
#define SQL_ADDRESS ""
#define SQL_DB ""
#define SQL_PORT "3306"
#define SQL_LOGIN ""
#define SQL_PASS ""
+*/
//*******************************
// Requires Dantom.DB library ( http://www.byond.com/developer/Dantom/DB )
@@ -285,7 +288,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
dat += "\[Start Search\]
"
if(1)
var/DBConnection/dbcon = new()
- dbcon.Connect("dbi:mysql:[SQL_DB]:[SQL_ADDRESS]:[SQL_PORT]","[SQL_LOGIN]","[SQL_PASS]")
+ dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
dat += "ERROR: Unable to contact External Archive. Please contact your system administrator for assistance.
"
else if(!SQLquery)
@@ -416,7 +419,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
if(4)
dat += "