diff --git a/code/__defines/subsystems.dm b/code/__defines/subsystems.dm
index d0a5d72c86..801d11a4d7 100644
--- a/code/__defines/subsystems.dm
+++ b/code/__defines/subsystems.dm
@@ -52,6 +52,7 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
// Subsystem init_order, from highest priority to lowest priority
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.
+#define INIT_ORDER_DBCORE 41 //CHOMPEdit
#define INIT_ORDER_SQLITE 40
#define INIT_ORDER_CHEMISTRY 35
#define INIT_ORDER_SKYBOX 30
diff --git a/code/_helpers/logging.dm b/code/_helpers/logging.dm
index 154349c217..1e6ca481b9 100644
--- a/code/_helpers/logging.dm
+++ b/code/_helpers/logging.dm
@@ -68,44 +68,45 @@
//Log the message to in-game dialogue logs, as well.
if(speaker.client)
//speaker.dialogue_log += "([time_stamp()]) ([speaker]/[speaker.client]) SAY: - [text]"
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'say', '[html_decode(text)]')")
- query_insert.Execute()
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'say', '[html_decode(text)]')")
+ if(!query_insert.Execute())
+ log_debug(query_insert.ErrorMsg())
//GLOB.round_text_log += "([time_stamp()]) ([speaker]/[speaker.client]) SAY: - [text]"
/proc/log_ooc(text, client/user)
if (config.log_ooc)
WRITE_LOG(diary, "OOC: [user.simple_info_line()]: [html_decode(text)]")
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'ooc', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'ooc', '[html_decode(text)]')")
query_insert.Execute()
//GLOB.round_text_log += "([time_stamp()]) ([user]) OOC: - [text]"
/proc/log_aooc(text, client/user)
if (config.log_ooc)
WRITE_LOG(diary, "AOOC: [user.simple_info_line()]: [html_decode(text)]")
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert =dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'aooc', '[html_decode(text)]')")
+ var/DBQuery/query_insert =SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'aooc', '[html_decode(text)]')")
query_insert.Execute()
//GLOB.round_text_log += "([time_stamp()]) ([user]) AOOC: - [text]"
/proc/log_looc(text, client/user)
if (config.log_ooc)
WRITE_LOG(diary, "LOOC: [user.simple_info_line()]: [html_decode(text)]")
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'looc', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[user.ckey]', '[user.mob.real_name]', 'looc', '[html_decode(text)]')")
query_insert.Execute()
//GLOB.round_text_log += "([time_stamp()]) ([user]) LOOC: - [text]"
@@ -116,11 +117,11 @@
if(speaker.client)
//speaker.dialogue_log += "([time_stamp()]) ([speaker]/[speaker.client]) SAY: - [text]"
//GLOB.round_text_log += "([time_stamp()]) ([speaker]/[speaker.client]) SAY: - [text]"
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'whisper', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'whisper', '[html_decode(text)]')")
query_insert.Execute()
@@ -131,11 +132,11 @@
if(speaker.client)
//speaker.dialogue_log += "([time_stamp()]) ([speaker]/[speaker.client]) EMOTE: - [text]"
//GLOB.round_text_log += "([time_stamp()]) ([speaker]/[speaker.client]) EMOTE: - [text]"
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'emote', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'emote', '[html_decode(text)]')")
query_insert.Execute()
//CHOMPEdit End
@@ -160,11 +161,11 @@
WRITE_LOG(diary, "DEADCHAT: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'deadsay', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'deadsay', '[html_decode(text)]')")
query_insert.Execute()
//speaker.dialogue_log += "([time_stamp()]) ([speaker]/[speaker.client]) DEADSAY: - [text]"
//GLOB.round_text_log += "([time_stamp()]) ([src]/[speaker.client]) DEADSAY: - [text]"
@@ -175,11 +176,11 @@
WRITE_LOG(diary, "DEADEMOTE: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'deademote', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'deademote', '[html_decode(text)]')")
query_insert.Execute()
//CHOMPEdit End
@@ -192,11 +193,11 @@
WRITE_LOG(diary, "PDA: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'pda', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'pda', '[html_decode(text)]')")
query_insert.Execute()
//speaker.dialogue_log += "([time_stamp()]) ([speaker]/[speaker.client]) MSG: - [text]"
diff --git a/code/_helpers/logging_vr.dm b/code/_helpers/logging_vr.dm
index 0b4b2a447c..b473390d16 100644
--- a/code/_helpers/logging_vr.dm
+++ b/code/_helpers/logging_vr.dm
@@ -3,11 +3,11 @@
WRITE_LOG(diary, "NSAY (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'nsay', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'nsay', '[html_decode(text)]')")
query_insert.ErrorMsg()
//CHOMPEdit End
@@ -16,11 +16,11 @@
WRITE_LOG(diary, "NME (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'nme', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'nme', '[html_decode(text)]')")
query_insert.Execute()
//CHOMPEdit End
@@ -29,10 +29,10 @@
WRITE_LOG(diary, "SUBTLE: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin
if(speaker.client)
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected())
return null
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'subtle', '[html_decode(text)]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_dialog (mid, time, ckey, mob, type, message) VALUES (null, Now(), '[speaker.ckey]', '[speaker.real_name]', 'subtle', '[html_decode(text)]')")
query_insert.Execute()
//CHOMPEdit End
diff --git a/code/_helpers/text.dm b/code/_helpers/text.dm
index 2d59fa6b6a..a6473ddab2 100644
--- a/code/_helpers/text.dm
+++ b/code/_helpers/text.dm
@@ -14,9 +14,11 @@
*/
// Run all strings to be used in an SQL query through this proc first to properly escape out injection attempts.
-/proc/sanitizeSQL(var/t as text)
- var/sqltext = dbcon.Quote(t);
- return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that
+/proc/sanitizeSQL(var/t as text)
+ //var/sqltext = dbcon.Quote(t); //CHOMPEdit Begin
+ //return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that
+ return t
+ //CHOMPEdit End
/*
* Text sanitization
diff --git a/code/controllers/subsystems/dbcore.dm b/code/controllers/subsystems/dbcore.dm
new file mode 100644
index 0000000000..09dce0c13c
--- /dev/null
+++ b/code/controllers/subsystems/dbcore.dm
@@ -0,0 +1,370 @@
+SUBSYSTEM_DEF(dbcore)
+ name = "Database"
+ flags = SS_BACKGROUND
+ wait = 1 MINUTES
+ init_order = INIT_ORDER_DBCORE
+ var/failed_connection_timeout = 0
+
+ var/schema_mismatch = 0
+ var/db_minor = 0
+ var/db_major = 0
+ var/failed_connections = 0
+
+ var/last_error
+ var/list/active_queries = list()
+
+ var/connection // Arbitrary handle returned from rust_g.
+
+/datum/controller/subsystem/dbcore/Initialize()
+ return ..()
+
+/datum/controller/subsystem/dbcore/fire()
+ for(var/I in active_queries)
+ var/DBQuery/Q = I
+ if(world.time - Q.last_activity_time > (5 MINUTES))
+ message_admins("Found undeleted query, please check the server logs and notify coders.")
+ log_debug("Undeleted query: \"[Q.sql]\" LA: [Q.last_activity] LAT: [Q.last_activity_time]")
+ qdel(Q)
+ if(MC_TICK_CHECK)
+ return
+
+/datum/controller/subsystem/dbcore/Recover()
+ connection = SSdbcore.connection
+
+/datum/controller/subsystem/dbcore/Shutdown()
+ //This is as close as we can get to the true round end before Disconnect() without changing where it's called, defeating the reason this is a subsystem
+ if(IsConnected())
+ Disconnect()
+
+//nu
+/datum/controller/subsystem/dbcore/can_vv_get(var_name)
+ return var_name != NAMEOF(src, connection) && var_name != NAMEOF(src, active_queries) && ..()
+
+/datum/controller/subsystem/dbcore/vv_edit_var(var_name, var_value)
+ if(var_name == NAMEOF(src, connection))
+ return FALSE
+ return ..()
+
+/datum/controller/subsystem/dbcore/proc/Connect()
+ if(IsConnected())
+ return TRUE
+
+ if(failed_connection_timeout <= world.time) //it's been more than 5 seconds since we failed to connect, reset the counter
+ failed_connections = 0
+
+ if(failed_connections > 5) //If it failed to establish a connection more than 5 times in a row, don't bother attempting to connect for 5 seconds.
+ failed_connection_timeout = world.time + 50
+ return FALSE
+
+ if(!config.sql_enabled)
+ return FALSE
+
+ var/user = sqlfdbklogin
+ var/pass = sqlfdbkpass
+ var/db = sqlfdbkdb
+ var/address = sqladdress
+ var/port = text2num(sqlport)
+ var/timeout = 10
+ var/thread_limit = 50
+
+ var/result = json_decode(rustg_sql_connect_pool(json_encode(list(
+ "host" = address,
+ "port" = port,
+ "user" = user,
+ "pass" = pass,
+ "db_name" = db,
+ "read_timeout" = timeout,
+ "write_timeout" = timeout,
+ "max_threads" = thread_limit,
+ ))))
+ . = (result["status"] == "ok")
+ if (.)
+ connection = result["handle"]
+ else
+ connection = null
+ last_error = result["data"]
+ log_world("Connect() failed | [last_error]")
+ ++failed_connections
+
+/datum/controller/subsystem/dbcore/proc/CheckSchemaVersion()
+ if(config.sql_enabled)
+ if(Connect())
+ log_world("Database connection established.")
+ else
+ log_debug("Your server failed to establish a connection with the database.")
+ else
+ log_debug("Database is not enabled in configuration.")
+
+/*/datum/controller/subsystem/dbcore/proc/SetRoundID()
+ if(!Connect())
+ return
+ var/DBQuery/query_round_initialize = SSdbcore.NewQuery(
+ "INSERT INTO [format_table_name("round")] (initialize_datetime, server_ip, server_port) VALUES (Now(), INET_ATON(:internet_address), :port)",
+ list("internet_address" = world.internet_address || "0", "port" = "[world.port]")
+ )
+ query_round_initialize.Execute(async = FALSE)
+ GLOB.round_id = "[query_round_initialize.last_insert_id]"
+ qdel(query_round_initialize)
+
+/datum/controller/subsystem/dbcore/proc/SetRoundStart()
+ if(!Connect())
+ return
+ var/DBQuery/query_round_start = SSdbcore.NewQuery(
+ "UPDATE [format_table_name("round")] SET start_datetime = Now() WHERE id = :round_id",
+ list("round_id" = GLOB.round_id)
+ )
+ query_round_start.Execute()
+ qdel(query_round_start)
+
+/datum/controller/subsystem/dbcore/proc/SetRoundEnd()
+ if(!Connect())
+ return
+ var/DBQuery/query_round_end = SSdbcore.NewQuery(
+ "UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = :game_mode_result, station_name = :station_name WHERE id = :round_id",
+ list("game_mode_result" = SSticker.mode_result, "station_name" = station_name(), "round_id" = GLOB.round_id)
+ )
+ query_round_end.Execute()
+ qdel(query_round_end)*/
+
+/datum/controller/subsystem/dbcore/proc/Disconnect()
+ failed_connections = 0
+ if (connection)
+ rustg_sql_disconnect_pool(connection)
+ connection = null
+
+/datum/controller/subsystem/dbcore/proc/IsConnected()
+ if (!config.sql_enabled)
+ return FALSE
+ if (!connection)
+ return FALSE
+ return json_decode(rustg_sql_connected(connection))["status"] == "online"
+
+/datum/controller/subsystem/dbcore/proc/ErrorMsg()
+ if(!config.sql_enabled)
+ return "Database disabled by configuration"
+ return last_error
+
+/datum/controller/subsystem/dbcore/proc/ReportError(error)
+ last_error = error
+
+/datum/controller/subsystem/dbcore/proc/NewQuery(sql_query, arguments)
+ if(IsAdminAdvancedProcCall())
+ message_admins("ERROR: Advanced admin proc call led to sql query. Query has been blocked")
+ return FALSE
+ return new /DBQuery(connection, sql_query, arguments)
+
+/datum/controller/subsystem/dbcore/proc/QuerySelect(list/querys, warn = FALSE, qdel = FALSE)
+ if (!islist(querys))
+ if (!istype(querys, /DBQuery))
+ CRASH("Invalid query passed to QuerySelect: [querys]")
+ querys = list(querys)
+
+ for (var/thing in querys)
+ var/DBQuery/query = thing
+ if (warn)
+ INVOKE_ASYNC(query, /DBQuery.proc/warn_execute)
+ else
+ INVOKE_ASYNC(query, /DBQuery.proc/Execute)
+
+ for (var/thing in querys)
+ var/DBQuery/query = thing
+ UNTIL(!query.in_progress)
+ if (qdel)
+ qdel(query)
+
+
+
+/*
+Takes a list of rows (each row being an associated list of column => value) and inserts them via a single mass query.
+Rows missing columns present in other rows will resolve to SQL NULL
+You are expected to do your own escaping of the data, and expected to provide your own quotes for strings.
+The duplicate_key arg can be true to automatically generate this part of the query
+ or set to a string that is appended to the end of the query
+Ignore_errors instructes mysql to continue inserting rows if some of them have errors.
+ the erroneous row(s) aren't inserted and there isn't really any way to know why or why errored
+Delayed insert mode was removed in mysql 7 and only works with MyISAM type tables,
+ It was included because it is still supported in mariadb.
+ It does not work with duplicate_key and the mysql server ignores it in those cases
+*/
+/datum/controller/subsystem/dbcore/proc/MassInsert(table, list/rows, duplicate_key = FALSE, ignore_errors = FALSE, delayed = FALSE, warn = FALSE, async = TRUE, special_columns = null)
+ if (!table || !rows || !istype(rows))
+ return
+
+ // Prepare column list
+ var/list/columns = list()
+ var/list/has_question_mark = list()
+ for (var/list/row in rows)
+ for (var/column in row)
+ columns[column] = "?"
+ has_question_mark[column] = TRUE
+ for (var/column in special_columns)
+ columns[column] = special_columns[column]
+ has_question_mark[column] = findtext(special_columns[column], "?")
+
+ // Prepare SQL query full of placeholders
+ var/list/query_parts = list("INSERT")
+ if (delayed)
+ query_parts += " DELAYED"
+ if (ignore_errors)
+ query_parts += " IGNORE"
+ query_parts += " INTO "
+ query_parts += table
+ query_parts += "\n([columns.Join(", ")])\nVALUES"
+
+ var/list/arguments = list()
+ var/has_row = FALSE
+ for (var/list/row in rows)
+ if (has_row)
+ query_parts += ","
+ query_parts += "\n ("
+ var/has_col = FALSE
+ for (var/column in columns)
+ if (has_col)
+ query_parts += ", "
+ if (has_question_mark[column])
+ var/name = "p[arguments.len]"
+ query_parts += replacetext(columns[column], "?", ":[name]")
+ arguments[name] = row[column]
+ else
+ query_parts += columns[column]
+ has_col = TRUE
+ query_parts += ")"
+ has_row = TRUE
+
+ if (duplicate_key == TRUE)
+ var/list/column_list = list()
+ for (var/column in columns)
+ column_list += "[column] = VALUES([column])"
+ query_parts += "\nON DUPLICATE KEY UPDATE [column_list.Join(", ")]"
+ else if (duplicate_key != FALSE)
+ query_parts += duplicate_key
+
+ var/DBQuery/Query = NewQuery(query_parts.Join(), arguments)
+ if (warn)
+ . = Query.warn_execute(async)
+ else
+ . = Query.Execute(async)
+ qdel(Query)
+
+/DBQuery
+ // Inputs
+ var/connection
+ var/sql
+ var/arguments
+
+ // Status information
+ var/in_progress
+ var/last_error
+ var/last_activity
+ var/last_activity_time
+
+ // Output
+ var/list/list/rows
+ var/next_row_to_take = 1
+ var/affected
+ var/last_insert_id
+
+ var/list/item //list of data values populated by NextRow()
+
+/DBQuery/New(connection, sql, arguments)
+ SSdbcore.active_queries[src] = TRUE
+ Activity("Created")
+ item = list()
+
+ src.connection = connection
+ src.sql = sql
+ src.arguments = arguments
+
+/DBQuery/Destroy()
+ Close()
+ SSdbcore.active_queries -= src
+ return ..()
+
+/DBQuery/CanProcCall(proc_name)
+ //fuck off kevinz
+ return FALSE
+
+/DBQuery/proc/Activity(activity)
+ last_activity = activity
+ last_activity_time = world.time
+
+/DBQuery/proc/warn_execute(async = TRUE)
+ . = Execute(async)
+ if(!.)
+ to_chat(usr, "A SQL error occurred during this operation, check the server logs.")
+
+/DBQuery/proc/Execute(async = TRUE, log_error = TRUE)
+ Activity("Execute")
+ if(in_progress)
+ CRASH("Attempted to start a new query while waiting on the old one")
+
+ if(!SSdbcore.IsConnected())
+ last_error = "No connection!"
+ return FALSE
+
+ var/start_time
+ if(!async)
+ start_time = REALTIMEOFDAY
+ Close()
+ . = run_query(async)
+ var/timed_out = !. && findtext(last_error, "Operation timed out")
+ if(!. && log_error)
+ log_debug("[last_error] | Query used: [sql] | Arguments: [json_encode(arguments)]")
+ if(!async && timed_out)
+ log_debug("Query execution started at [start_time]")
+ log_debug("Query execution ended at [REALTIMEOFDAY]")
+ log_debug("Slow query timeout detected.")
+ log_debug("Query used: [sql]")
+ slow_query_check()
+
+/DBQuery/proc/run_query(async)
+ var/job_result_str
+
+ if (async)
+ var/job_id = rustg_sql_query_async(connection, sql, json_encode(arguments))
+ in_progress = TRUE
+ UNTIL((job_result_str = rustg_sql_check_query(job_id)) != RUSTG_JOB_NO_RESULTS_YET)
+ in_progress = FALSE
+
+ if (job_result_str == RUSTG_JOB_ERROR)
+ last_error = job_result_str
+ return FALSE
+ else
+ job_result_str = rustg_sql_query_blocking(connection, sql, json_encode(arguments))
+
+ var/result = json_decode(job_result_str)
+ switch (result["status"])
+ if ("ok")
+ rows = result["rows"]
+ affected = result["affected"]
+ last_insert_id = result["last_insert_id"]
+ return TRUE
+ if ("err")
+ last_error = result["data"]
+ return FALSE
+ if ("offline")
+ last_error = "offline"
+ return FALSE
+
+/DBQuery/proc/RowCount()
+ return rows.len
+
+/DBQuery/proc/slow_query_check()
+ message_admins("HEY! A database query timed out.")
+
+/DBQuery/proc/NextRow(async = TRUE)
+ Activity("NextRow")
+
+ if (rows && next_row_to_take <= rows.len)
+ item = rows[next_row_to_take]
+ next_row_to_take++
+ return !!item
+ else
+ return FALSE
+
+/DBQuery/proc/ErrorMsg()
+ return last_error
+
+/DBQuery/proc/Close()
+ rows = null
+ item = null
\ No newline at end of file
diff --git a/code/controllers/subsystems/persist_vr.dm b/code/controllers/subsystems/persist_vr.dm
index e87ca93ca3..e8b1e874b2 100644
--- a/code/controllers/subsystems/persist_vr.dm
+++ b/code/controllers/subsystems/persist_vr.dm
@@ -20,7 +20,7 @@ SUBSYSTEM_DEF(persist)
return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
src.currentrun.Cut()
return
if(!resumed)
@@ -84,7 +84,7 @@ SUBSYSTEM_DEF(persist)
var/sql_dpt = sql_sanitize_text(department_earning)
var/sql_bal = text2num("[C.department_hours[department_earning]]")
var/sql_total = text2num("[C.play_hours[department_earning]]")
- var/DBQuery/query = dbcon.NewQuery("INSERT INTO vr_player_hours (ckey, department, hours, total_hours) VALUES ('[sql_ckey]', '[sql_dpt]', [sql_bal], [sql_total]) ON DUPLICATE KEY UPDATE hours = VALUES(hours), total_hours = VALUES(total_hours)")
+ var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO vr_player_hours (ckey, department, hours, total_hours) VALUES ('[sql_ckey]', '[sql_dpt]', [sql_bal], [sql_total]) ON DUPLICATE KEY UPDATE hours = VALUES(hours), total_hours = VALUES(total_hours)") //CHOMPEdit TGSQL
if(!query.Execute()) //CHOMPEdit
log_admin(query.ErrorMsg()) //CHOMPEdit
diff --git a/code/defines/procs/statistics.dm b/code/defines/procs/statistics.dm
index 9ea9023de4..61fd8fc6ed 100644
--- a/code/defines/procs/statistics.dm
+++ b/code/defines/procs/statistics.dm
@@ -7,11 +7,11 @@ proc/sql_poll_population()
if(M.client)
playercount += 1
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during population polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
- var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO `tgstation`.`population` (`playercount`, `admincount`, `time`) VALUES ([playercount], [admincount], '[sqltime]')")
+ var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO `population` (`playercount`, `admincount`, `time`) VALUES ([playercount], [admincount], '[sqltime]')") //CHOMPEdit TGSQL
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during population polling. Error : \[[err]\]\n")
@@ -50,10 +50,10 @@ proc/sql_report_death(var/mob/living/carbon/human/H)
var/coord = "[H.x], [H.y], [H.z]"
//to_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.getFireLoss()], [H.brainloss], [H.getOxyLoss()])")
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during death reporting. Failed to connect.")
else
- var/DBQuery/query = dbcon.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')")
+ var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')") //CHOMPEdit TGSQL
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
@@ -84,10 +84,10 @@ proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
var/coord = "[H.x], [H.y], [H.z]"
//to_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.getFireLoss()], [H.brainloss], [H.getOxyLoss()])")
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during death reporting. Failed to connect.")
else
- var/DBQuery/query = dbcon.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')")
+ var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')") //CHOMPEdit TGSQL
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
@@ -115,11 +115,11 @@ proc/sql_commit_feedback()
return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during feedback reporting. Failed to connect.")
else
- var/DBQuery/max_query = dbcon.NewQuery("SELECT MAX(roundid) AS max_round_id FROM erro_feedback")
+ var/DBQuery/max_query = SSdbcore.NewQuery("SELECT MAX(roundid) AS max_round_id FROM erro_feedback") //CHOMPEdit TGSQL
max_query.Execute()
var/newroundid
@@ -139,7 +139,7 @@ proc/sql_commit_feedback()
var/variable = item.get_variable()
var/value = item.get_value()
- var/DBQuery/query = dbcon.NewQuery("INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, [newroundid], Now(), '[variable]', '[value]')")
+ var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, [newroundid], Now(), '[variable]', '[value]')") //CHOMPEdit TGSQL
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
diff --git a/code/game/world.dm b/code/game/world.dm
index 45ca1567e1..d87f0eb25f 100644
--- a/code/game/world.dm
+++ b/code/game/world.dm
@@ -564,13 +564,21 @@ var/failed_old_db_connections = 0
/hook/startup/proc/connectDB()
if(!config.sql_enabled)
to_world_log("SQL connection disabled in config.")
- else if(!setup_database_connection())
- to_world_log("Your server failed to establish a connection with the feedback database.")
- else
+ else if(establish_db_connection())//CHOMPEdit Begin
to_world_log("Feedback database connection established.")
+ var/DBQuery/query_truncate = SSdbcore.NewQuery("TRUNCATE erro_dialog")
+ var/num_tries = 0
+ while(!query_truncate.Execute() && num_tries<5)
+ num_tries++
+
+ if(num_tries==5)
+ log_admin("ERROR TRYING TO CLEAR erro_dialog")
+ else
+ to_world_log("Feedback database connection failed.")
+ //CHOMPEdit End
return 1
-proc/setup_database_connection()
+/*proc/setup_database_connection() CHOMPEdit TGSQL
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
@@ -601,30 +609,25 @@ proc/setup_database_connection()
failed_db_connections++ //If it failed, increase the failed connections counter.
to_world_log(dbcon.ErrorMsg())
- return .
+ return .*/
//This proc ensures that the connection to the feedback database (global variable dbcon) is established
-proc/establish_db_connection()
- if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF)
- return 0
-
- if(!dbcon || !dbcon.IsConnected())
- return setup_database_connection()
- else
- return 1
+proc/establish_db_connection() //CHOMPEdit TGSQL
+ return SSdbcore.Connect()
/hook/startup/proc/connectOldDB()
if(!config.sql_enabled)
to_world_log("SQL connection disabled in config.")
- else if(!setup_old_database_connection())
- to_world_log("Your server failed to establish a connection with the SQL database.")
- else
+ else if(establish_old_db_connection()) //CHOMPEdit Begin
to_world_log("SQL database connection established.")
+ else
+ to_world_log("SQL database connection failed")
+ //CHOMPEdit End
return 1
//These two procs are for the old database, while it's being phased out. See the tgstation.sql file in the SQL folder for more information.
-proc/setup_old_database_connection()
+/*proc/setup_old_database_connection() //CHOMPStation TGSQL
if(failed_old_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
@@ -646,17 +649,11 @@ proc/setup_old_database_connection()
failed_old_db_connections++ //If it failed, increase the failed connections counter.
to_world_log(dbcon.ErrorMsg())
- return .
+ return .*/
//This proc ensures that the connection to the feedback database (global variable dbcon) is established
proc/establish_old_db_connection()
- if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF)
- return 0
-
- if(!dbcon_old || !dbcon_old.IsConnected())
- return setup_old_database_connection()
- else
- return 1
+ return SSdbcore.Connect()
// Things to do when a new z-level was just made.
/world/proc/max_z_changed()
diff --git a/code/global.dm b/code/global.dm
index 3dc4e9f7c2..750d0272b8 100644
--- a/code/global.dm
+++ b/code/global.dm
@@ -131,8 +131,8 @@ var/custom_event_msg = null
// Database connections. A connection is established on world creation.
// Ideally, the connection dies when the server restarts (After feedback logging.).
-var/DBConnection/dbcon = new() // Feedback database (New database)
-var/DBConnection/dbcon_old = new() // /tg/station database (Old database) -- see the files in the SQL folder for information on what goes where.
+//var/DBConnection/dbcon = new() // Feedback database (New database) //CHOMPEdit Switching to TG SQL
+//var/DBConnection/dbcon_old = new() // /tg/station database (Old database) -- see the files in the SQL folder for information on what goes where. //CHOMPEdit Switching to TG SQL
// Added for Xenoarchaeology, might be useful for other stuff.
var/global/list/alphabet_uppercase = list("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
diff --git a/code/modules/admin/DB ban/functions.dm b/code/modules/admin/DB ban/functions.dm
index 9edad6c4d0..78efe306c8 100644
--- a/code/modules/admin/DB ban/functions.dm
+++ b/code/modules/admin/DB ban/functions.dm
@@ -5,7 +5,7 @@ datum/admins/proc/DB_ban_record(var/bantype, var/mob/banned_mob, var/duration =
if(!check_rights(R_MOD,0) && !check_rights(R_BAN)) return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return
var/serverip = "[world.internet_address]:[world.port]"
@@ -44,7 +44,7 @@ datum/admins/proc/DB_ban_record(var/bantype, var/mob/banned_mob, var/duration =
computerid = bancid
ip = banip
- var/DBQuery/query = dbcon.NewQuery("SELECT id FROM erro_player WHERE ckey = '[ckey]'")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT id FROM erro_player WHERE ckey = '[ckey]'") //CHOMPEdit TGSQL
query.Execute()
var/validckey = 0
if(query.NextRow())
@@ -81,7 +81,7 @@ datum/admins/proc/DB_ban_record(var/bantype, var/mob/banned_mob, var/duration =
reason = sql_sanitize_text(reason)
var/sql = "INSERT INTO erro_ban (`id`,`bantime`,`serverip`,`bantype`,`reason`,`job`,`duration`,`rounds`,`expiration_time`,`ckey`,`computerid`,`ip`,`a_ckey`,`a_computerid`,`a_ip`,`who`,`adminwho`,`edits`,`unbanned`,`unbanned_datetime`,`unbanned_ckey`,`unbanned_computerid`,`unbanned_ip`) VALUES (null, Now(), '[serverip]', '[bantype_str]', '[reason]', '[job]', [(duration)?"[duration]":"0"], [(rounds)?"[rounds]":"0"], Now() + INTERVAL [(duration>0) ? duration : 0] MINUTE, '[ckey]', '[computerid]', '[ip]', '[a_ckey]', '[a_computerid]', '[a_ip]', '[who]', '[adminwho]', '', null, null, null, null, null)"
- var/DBQuery/query_insert = dbcon.NewQuery(sql)
+ var/DBQuery/query_insert = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query_insert.Execute()
to_chat(usr, "Ban saved to database.")
message_admins("[key_name_admin(usr)] has added a [bantype_str] for [ckey] [(job)?"([job])":""] [(duration > 0)?"([duration] minutes)":""] with the reason: \"[reason]\" to the ban database.",1)
@@ -124,13 +124,13 @@ datum/admins/proc/DB_ban_unban(var/ckey, var/bantype, var/job = "")
sql += " AND job = '[job]'"
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return
var/ban_id
var/ban_number = 0 //failsafe
- var/DBQuery/query = dbcon.NewQuery(sql)
+ var/DBQuery/query = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query.Execute()
while(query.NextRow())
ban_id = query.item[1]
@@ -160,7 +160,7 @@ datum/admins/proc/DB_ban_edit(var/banid = null, var/param = null)
to_chat(usr, "Cancelled")
return
- var/DBQuery/query = dbcon.NewQuery("SELECT ckey, duration, reason FROM erro_ban WHERE id = [banid]")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT ckey, duration, reason FROM erro_ban WHERE id = [banid]") //CHOMPEdit TGSQL
query.Execute()
var/eckey = usr.ckey //Editing admin ckey
@@ -188,7 +188,7 @@ datum/admins/proc/DB_ban_edit(var/banid = null, var/param = null)
to_chat(usr, "Cancelled")
return
- var/DBQuery/update_query = dbcon.NewQuery("UPDATE erro_ban SET reason = '[value]', edits = CONCAT(edits,'- [eckey] changed ban reason from \\\"[reason]\\\" to \\\"[value]\\\"
') WHERE id = [banid]")
+ var/DBQuery/update_query = SSdbcore.NewQuery("UPDATE erro_ban SET reason = '[value]', edits = CONCAT(edits,'- [eckey] changed ban reason from \\\"[reason]\\\" to \\\"[value]\\\"
') WHERE id = [banid]") //CHOMPEdit TGSQL
update_query.Execute()
message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s reason from [reason] to [value]",1)
if("duration")
@@ -198,7 +198,7 @@ datum/admins/proc/DB_ban_edit(var/banid = null, var/param = null)
to_chat(usr, "Cancelled")
return
- var/DBQuery/update_query = dbcon.NewQuery("UPDATE erro_ban SET duration = [value], edits = CONCAT(edits,'- [eckey] changed ban duration from [duration] to [value]
'), expiration_time = DATE_ADD(bantime, INTERVAL [value] MINUTE) WHERE id = [banid]")
+ var/DBQuery/update_query = SSdbcore.NewQuery("UPDATE erro_ban SET duration = [value], edits = CONCAT(edits,'- [eckey] changed ban duration from [duration] to [value]
'), expiration_time = DATE_ADD(bantime, INTERVAL [value] MINUTE) WHERE id = [banid]") //CHOMPEdit TGSQL
message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s duration from [duration] to [value]",1)
update_query.Execute()
if("unban")
@@ -215,13 +215,13 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
var/sql = "SELECT ckey FROM erro_ban WHERE id = [id]"
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return
var/ban_number = 0 //failsafe
var/pckey
- var/DBQuery/query = dbcon.NewQuery(sql)
+ var/DBQuery/query = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query.Execute()
while(query.NextRow())
pckey = query.item[1]
@@ -245,7 +245,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
var/sql_update = "UPDATE erro_ban SET unbanned = 1, unbanned_datetime = Now(), unbanned_ckey = '[unban_ckey]', unbanned_computerid = '[unban_computerid]', unbanned_ip = '[unban_ip]' WHERE id = [id]"
message_admins("[key_name_admin(usr)] has lifted [pckey]'s ban.",1)
- var/DBQuery/query_update = dbcon.NewQuery(sql_update)
+ var/DBQuery/query_update = SSdbcore.NewQuery(sql_update) //CHOMPEdit TGSQL
query_update.Execute()
@@ -267,7 +267,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
if(!check_rights(R_BAN)) return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "Failed to establish database connection")
return
@@ -396,7 +396,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
else
bantypesearch += "'PERMABAN' "
- var/DBQuery/select_query = dbcon.NewQuery("SELECT id, bantime, bantype, reason, job, duration, expiration_time, ckey, a_ckey, unbanned, unbanned_ckey, unbanned_datetime, edits, ip, computerid FROM erro_ban WHERE 1 [playersearch] [adminsearch] [ipsearch] [cidsearch] [bantypesearch] ORDER BY bantime DESC LIMIT 100")
+ var/DBQuery/select_query = SSdbcore.NewQuery("SELECT id, bantime, bantype, reason, job, duration, expiration_time, ckey, a_ckey, unbanned, unbanned_ckey, unbanned_datetime, edits, ip, computerid FROM erro_ban WHERE 1 [playersearch] [adminsearch] [ipsearch] [cidsearch] [bantypesearch] ORDER BY bantime DESC LIMIT 100") //CHOMPEdit TGSQL
select_query.Execute()
var/now = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss") // MUST BE the same format as SQL gives us the dates in, and MUST be least to most specific (i.e. year, month, day not day, month, year)
diff --git a/code/modules/admin/IsBanned.dm b/code/modules/admin/IsBanned.dm
index e28c4fd570..e90eacacfa 100644
--- a/code/modules/admin/IsBanned.dm
+++ b/code/modules/admin/IsBanned.dm
@@ -52,7 +52,7 @@ world/IsBanned(key,address,computer_id)
failedcid = 0
cidquery = " OR computerid = '[computer_id]' "
- var/DBQuery/query = dbcon.NewQuery("SELECT ckey, ip, computerid, a_ckey, reason, expiration_time, duration, bantime, bantype FROM erro_ban WHERE (ckey = '[ckeytext]' [ipquery] [cidquery]) AND (bantype = 'PERMABAN' OR (bantype = 'TEMPBAN' AND expiration_time > Now())) AND isnull(unbanned)")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT ckey, ip, computerid, a_ckey, reason, expiration_time, duration, bantime, bantype FROM erro_ban WHERE (ckey = '[ckeytext]' [ipquery] [cidquery]) AND (bantype = 'PERMABAN' OR (bantype = 'TEMPBAN' AND expiration_time > Now())) AND isnull(unbanned)") //CHOMPEdit TGSQL
query.Execute()
diff --git a/code/modules/admin/admin_ranks.dm b/code/modules/admin/admin_ranks.dm
index d1696839bc..b223c7e6d5 100644
--- a/code/modules/admin/admin_ranks.dm
+++ b/code/modules/admin/admin_ranks.dm
@@ -112,14 +112,14 @@ var/list/admin_ranks = list() //list of all ranks with associated rights
//The current admin system uses SQL
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
error("Failed to connect to database in load_admins(). Reverting to legacy system.")
log_misc("Failed to connect to database in load_admins(). Reverting to legacy system.")
config.admin_legacy_system = 1
load_admins()
return
- var/DBQuery/query = dbcon.NewQuery("SELECT ckey, rank, level, flags FROM erro_admin")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT ckey, rank, level, flags FROM erro_admin") //CHOMPEdit TGSQL
query.Execute()
while(query.NextRow())
var/ckey = query.item[1]
diff --git a/code/modules/admin/admin_tools.dm b/code/modules/admin/admin_tools.dm
index 44e094f897..c8160873de 100644
--- a/code/modules/admin/admin_tools.dm
+++ b/code/modules/admin/admin_tools.dm
@@ -45,7 +45,7 @@
//CHOMPEdit Begin
/*for(var/d in M.dialogue_log)
dat += "[d]
"*/
- var/DBQuery/query = dbcon.NewQuery("SELECT mid,time,ckey,mob,type,message from erro_dialog WHERE ckey = '[M.ckey]'")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT mid,time,ckey,mob,type,message from erro_dialog WHERE ckey = '[M.ckey]'")
if(!query.Execute())
dat += "Database query error"
else
diff --git a/code/modules/admin/banjob.dm b/code/modules/admin/banjob.dm
index 0bfa4e516a..2bfe3f1654 100644
--- a/code/modules/admin/banjob.dm
+++ b/code/modules/admin/banjob.dm
@@ -77,7 +77,7 @@ DEBUG
return
//Job permabans
- var/DBQuery/query = dbcon.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_PERMABAN' AND isnull(unbanned)")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_PERMABAN' AND isnull(unbanned)") //CHOMPEdit TGSQL
query.Execute()
while(query.NextRow())
@@ -87,7 +87,7 @@ DEBUG
jobban_keylist.Add("[ckey] - [job]")
//Job tempbans
- var/DBQuery/query1 = dbcon.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_TEMPBAN' AND isnull(unbanned) AND expiration_time > Now()")
+ var/DBQuery/query1 = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_TEMPBAN' AND isnull(unbanned) AND expiration_time > Now()") //CHOMPEdit TGSQL
query1.Execute()
while(query1.NextRow())
diff --git a/code/modules/admin/permissionverbs/permissionedit.dm b/code/modules/admin/permissionverbs/permissionedit.dm
index 6a579b96af..178587133f 100644
--- a/code/modules/admin/permissionverbs/permissionedit.dm
+++ b/code/modules/admin/permissionverbs/permissionedit.dm
@@ -56,7 +56,7 @@
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "Failed to establish database connection")
return
@@ -71,7 +71,7 @@
if(!istext(adm_ckey) || !istext(new_rank))
return
- var/DBQuery/select_query = dbcon.NewQuery("SELECT id FROM erro_admin WHERE ckey = '[adm_ckey]'")
+ var/DBQuery/select_query = SSdbcore.NewQuery("SELECT id FROM erro_admin WHERE ckey = '[adm_ckey]'") //CHOMPEdit TGSQL
select_query.Execute()
var/new_admin = 1
@@ -81,16 +81,16 @@
admin_id = text2num(select_query.item[1])
if(new_admin)
- var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO `erro_admin` (`id`, `ckey`, `rank`, `level`, `flags`) VALUES (null, '[adm_ckey]', '[new_rank]', -1, 0)")
+ var/DBQuery/insert_query = SSdbcore.NewQuery("INSERT INTO `erro_admin` (`id`, `ckey`, `rank`, `level`, `flags`) VALUES (null, '[adm_ckey]', '[new_rank]', -1, 0)") //CHOMPEdit TGSQL
insert_query.Execute()
- var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added new admin [adm_ckey] to rank [new_rank]');")
+ var/DBQuery/log_query = SSdbcore.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added new admin [adm_ckey] to rank [new_rank]');") //CHOMPEdit TGSQL
log_query.Execute()
to_chat(usr, "New admin added.")
else
if(!isnull(admin_id) && isnum(admin_id))
- var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET rank = '[new_rank]' WHERE id = [admin_id]")
+ var/DBQuery/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET rank = '[new_rank]' WHERE id = [admin_id]") //CHOMPEdit TGSQL
insert_query.Execute()
- var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Edited the rank of [adm_ckey] to [new_rank]');")
+ var/DBQuery/log_query = SSdbcore.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Edited the rank of [adm_ckey] to [new_rank]');") //CHOMPEdit TGSQL
log_query.Execute()
to_chat(usr, "Admin rank changed.")
@@ -105,7 +105,7 @@
return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "Failed to establish database connection")
return
@@ -123,7 +123,7 @@
if(!istext(adm_ckey) || !isnum(new_permission))
return
- var/DBQuery/select_query = dbcon.NewQuery("SELECT id, flags FROM erro_admin WHERE ckey = '[adm_ckey]'")
+ var/DBQuery/select_query = SSdbcore.NewQuery("SELECT id, flags FROM erro_admin WHERE ckey = '[adm_ckey]'") //CHOMPEdit TGSQL
select_query.Execute()
var/admin_id
@@ -136,14 +136,14 @@
return
if(admin_rights & new_permission) //This admin already has this permission, so we are removing it.
- var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET flags = [admin_rights & ~new_permission] WHERE id = [admin_id]")
+ var/DBQuery/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = [admin_rights & ~new_permission] WHERE id = [admin_id]") //CHOMPEdit TGSQL
insert_query.Execute()
- var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Removed permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]');")
+ var/DBQuery/log_query = SSdbcore.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Removed permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]');") //CHOMPEdit TGSQL
log_query.Execute()
to_chat(usr, "Permission removed.")
else //This admin doesn't have this permission, so we are adding it.
- var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET flags = '[admin_rights | new_permission]' WHERE id = [admin_id]")
+ var/DBQuery/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = '[admin_rights | new_permission]' WHERE id = [admin_id]") //CHOMPEdit TGSQL
insert_query.Execute()
- var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]')")
+ var/DBQuery/log_query = SSdbcore.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]')") //CHOMPEdit TGSQL
log_query.Execute()
to_chat(usr, "Permission added.")
\ No newline at end of file
diff --git a/code/modules/admin/verbs/check_customitem_activity.dm b/code/modules/admin/verbs/check_customitem_activity.dm
index 80bbfccc12..ec4f66b0f4 100644
--- a/code/modules/admin/verbs/check_customitem_activity.dm
+++ b/code/modules/admin/verbs/check_customitem_activity.dm
@@ -30,7 +30,7 @@ var/inactive_keys = "None
"
return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return
//grab all ckeys associated with custom items
@@ -55,7 +55,7 @@ var/inactive_keys = "None
"
//run a query to get all ckeys inactive for over 2 months
var/list/inactive_ckeys = list()
if(ckeys_with_customitems.len)
- var/DBQuery/query_inactive = dbcon.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60")
+ var/DBQuery/query_inactive = SSdbcore.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60") //CHOMPEdit TGSQL
query_inactive.Execute()
while(query_inactive.NextRow())
var/cur_ckey = query_inactive.item[1]
@@ -67,7 +67,7 @@ var/inactive_keys = "None
"
//if there are ckeys left over, check whether they have a database entry at all
if(ckeys_with_customitems.len)
for(var/cur_ckey in ckeys_with_customitems)
- var/DBQuery/query_inactive = dbcon.NewQuery("SELECT ckey FROM erro_player WHERE ckey = '[cur_ckey]'")
+ var/DBQuery/query_inactive = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ckey = '[cur_ckey]'") //CHOMPEdit TGSQL
query_inactive.Execute()
if(!query_inactive.RowCount())
inactive_ckeys += cur_ckey
diff --git a/code/modules/admin/verbs/panicbunker.dm b/code/modules/admin/verbs/panicbunker.dm
index 85ca43f447..497e1db7b8 100644
--- a/code/modules/admin/verbs/panicbunker.dm
+++ b/code/modules/admin/verbs/panicbunker.dm
@@ -12,7 +12,7 @@
config.panic_bunker = (!config.panic_bunker)
log_and_message_admins("[key_name(usr)] has toggled the Panic Bunker, it is now [(config.panic_bunker?"on":"off")].")
- if (config.panic_bunker && (!dbcon || !dbcon.IsConnected()))
+ if (config.panic_bunker && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
message_admins("The database is not connected! Panic bunker will not work until the connection is reestablished.")
feedback_add_details("admin_verb","PANIC") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -26,7 +26,7 @@
config.paranoia_logging = (!config.paranoia_logging)
log_and_message_admins("[key_name(usr)] has toggled Paranoia Logging, it is now [(config.paranoia_logging?"on":"off")].")
- if (config.paranoia_logging && (!dbcon || !dbcon.IsConnected()))
+ if (config.paranoia_logging && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
message_admins("The database is not connected! Paranoia logging will not be able to give 'player age' (time since first connection) warnings, only Byond account warnings.")
feedback_add_details("admin_verb","PARLOG") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -40,6 +40,6 @@
config.ip_reputation = (!config.ip_reputation)
log_and_message_admins("[key_name(usr)] has toggled IP reputation checks, it is now [(config.ip_reputation?"on":"off")].")
- if (config.ip_reputation && (!dbcon || !dbcon.IsConnected()))
+ if (config.ip_reputation && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
message_admins("The database is not connected! IP reputation logging will not be able to allow existing players to bypass the reputation checks (if that is enabled).")
feedback_add_details("admin_verb","IPREP") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm
index d05b2d28b0..ca8151e833 100644
--- a/code/modules/client/client procs.dm
+++ b/code/modules/client/client procs.dm
@@ -95,7 +95,7 @@
var/sql_discord = sql_sanitize_text(their_id)
var/sql_ckey = sql_sanitize_text(ckey)
- var/DBQuery/query = dbcon.NewQuery("UPDATE erro_player SET discord_id = '[sql_discord]' WHERE ckey = '[sql_ckey]'")
+ var/DBQuery/query = SSdbcore.NewQuery("UPDATE erro_player SET discord_id = '[sql_discord]' WHERE ckey = '[sql_ckey]'") //CHOMPEdit TGSQL
if(query.Execute())
to_chat(src, "Registration complete! Thank you for taking the time to register your Discord ID.")
log_and_message_admins("[ckey] has registered their Discord ID. Their Discord snowflake ID is: [their_id]") //YW EDIT
@@ -274,12 +274,12 @@
/proc/get_player_age(key)
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return null
var/sql_ckey = sql_sanitize_text(ckey(key))
- var/DBQuery/query = dbcon.NewQuery("SELECT datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'") //CHOMPEdit TGSQL
query.Execute()
if(query.NextRow())
@@ -294,12 +294,12 @@
return
establish_db_connection()
- if(!dbcon.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return
var/sql_ckey = sql_sanitize_text(src.ckey)
- var/DBQuery/query = dbcon.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'")
+ var/DBQuery/query = SSdbcore.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'") //CHOMPEdit TGSQL
query.Execute()
var/sql_id = 0
player_age = 0 // New players won't have an entry so knowing we have a connection we set this to zero to be updated if their is a record.
@@ -309,19 +309,19 @@
break
account_join_date = sanitizeSQL(findJoinDate())
- if(account_join_date && dbcon.IsConnected())
- var/DBQuery/query_datediff = dbcon.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')")
+ if(account_join_date && SSdbcore.IsConnected()) //CHOMPEdit TGSQL
+ var/DBQuery/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')") //CHOMPEdit TGSQL
if(query_datediff.Execute() && query_datediff.NextRow())
account_age = text2num(query_datediff.item[1])
- var/DBQuery/query_ip = dbcon.NewQuery("SELECT ckey FROM erro_player WHERE ip = '[address]'")
+ var/DBQuery/query_ip = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ip = '[address]'") //CHOMPEdit TGSQL
query_ip.Execute()
related_accounts_ip = ""
while(query_ip.NextRow())
related_accounts_ip += "[query_ip.item[1]], "
break
- var/DBQuery/query_cid = dbcon.NewQuery("SELECT ckey FROM erro_player WHERE computerid = '[computer_id]'")
+ var/DBQuery/query_cid = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE computerid = '[computer_id]'") //CHOMPEdit TGSQL
query_cid.Execute()
related_accounts_cid = ""
while(query_cid.NextRow())
@@ -376,7 +376,7 @@
log_admin("Couldn't perform IP check on [key] with [address]")
// VOREStation Edit Start - Department Hours
- var/DBQuery/query_hours = dbcon.NewQuery("SELECT department, hours, total_hours FROM vr_player_hours WHERE ckey = '[sql_ckey]'")
+ var/DBQuery/query_hours = SSdbcore.NewQuery("SELECT department, hours, total_hours FROM vr_player_hours WHERE ckey = '[sql_ckey]'") //CHOMPEdit TGSQL
if(query_hours.Execute())
while(query_hours.NextRow())
department_hours[query_hours.item[1]] = text2num(query_hours.item[2])
@@ -390,16 +390,16 @@
if(sql_id)
//Player already identified previously, we need to just update the 'lastseen', 'ip' and 'computer_id' variables
- var/DBQuery/query_update = dbcon.NewQuery("UPDATE erro_player SET lastseen = Now(), ip = '[sql_ip]', computerid = '[sql_computerid]', lastadminrank = '[sql_admin_rank]' WHERE id = [sql_id]")
+ var/DBQuery/query_update = SSdbcore.NewQuery("UPDATE erro_player SET lastseen = Now(), ip = '[sql_ip]', computerid = '[sql_computerid]', lastadminrank = '[sql_admin_rank]' WHERE id = [sql_id]") //CHOMPEdit TGSQL
query_update.Execute()
else
//New player!! Need to insert all the stuff
- var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_player (id, ckey, firstseen, lastseen, ip, computerid, lastadminrank) VALUES (null, '[sql_ckey]', Now(), Now(), '[sql_ip]', '[sql_computerid]', '[sql_admin_rank]')")
+ var/DBQuery/query_insert = SSdbcore.NewQuery("INSERT INTO erro_player (id, ckey, firstseen, lastseen, ip, computerid, lastadminrank) VALUES (null, '[sql_ckey]', Now(), Now(), '[sql_ip]', '[sql_computerid]', '[sql_admin_rank]')") //CHOMPEdit TGSQL
query_insert.Execute()
//Logging player access
var/serverip = "[world.internet_address]:[world.port]"
- var/DBQuery/query_accesslog = dbcon.NewQuery("INSERT INTO `erro_connection_log`(`id`,`datetime`,`serverip`,`ckey`,`ip`,`computerid`) VALUES(null,Now(),'[serverip]','[sql_ckey]','[sql_ip]','[sql_computerid]');")
+ var/DBQuery/query_accesslog = SSdbcore.NewQuery("INSERT INTO `erro_connection_log`(`id`,`datetime`,`serverip`,`ckey`,`ip`,`computerid`) VALUES(null,Now(),'[serverip]','[sql_ckey]','[sql_ip]','[sql_computerid]');") //CHOMPEdit TGSQL
query_accesslog.Execute()
#undef TOPIC_SPAM_DELAY
diff --git a/code/modules/library/lib_machines.dm b/code/modules/library/lib_machines.dm
index 9a226b836d..45108b4d89 100644
--- a/code/modules/library/lib_machines.dm
+++ b/code/modules/library/lib_machines.dm
@@ -44,7 +44,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
\[Start Search\]
"}
if(1)
establish_old_db_connection()
- if(!dbcon_old.IsConnected())
+ if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
dat += "ERROR: Unable to contact External Archive. Please contact your system administrator for assistance.
"
else if(!SQLquery)
dat += "ERROR: Malformed search request. Please contact your system administrator for assistance.
"
@@ -52,7 +52,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
dat += {"