Porting TG's SQL

This commit is contained in:
Cadyn
2021-01-25 23:37:49 -08:00
parent b379c65606
commit 76ed115e37
24 changed files with 545 additions and 174 deletions

View File

@@ -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 // Subsystem init_order, from highest priority to lowest priority
// Subsystems shutdown in the reverse of the order they initialize in // Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise. // The numbers just define the ordering, they are meaningless otherwise.
#define INIT_ORDER_DBCORE 41 //CHOMPEdit
#define INIT_ORDER_SQLITE 40 #define INIT_ORDER_SQLITE 40
#define INIT_ORDER_CHEMISTRY 35 #define INIT_ORDER_CHEMISTRY 35
#define INIT_ORDER_SKYBOX 30 #define INIT_ORDER_SKYBOX 30

View File

@@ -68,44 +68,45 @@
//Log the message to in-game dialogue logs, as well. //Log the message to in-game dialogue logs, as well.
if(speaker.client) if(speaker.client)
//speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:#32cd32\">[text]</span>" //speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:#32cd32\">[text]</span>"
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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)]')") 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)]')")
query_insert.Execute() if(!query_insert.Execute())
log_debug(query_insert.ErrorMsg())
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:#32cd32\">[text]</span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:#32cd32\">[text]</span>"
/proc/log_ooc(text, client/user) /proc/log_ooc(text, client/user)
if (config.log_ooc) if (config.log_ooc)
WRITE_LOG(diary, "OOC: [user.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "OOC: [user.simple_info_line()]: [html_decode(text)]")
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>OOC:</u> - <span style=\"color:blue\"><b>[text]</b></span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>OOC:</u> - <span style=\"color:blue\"><b>[text]</b></span>"
/proc/log_aooc(text, client/user) /proc/log_aooc(text, client/user)
if (config.log_ooc) if (config.log_ooc)
WRITE_LOG(diary, "AOOC: [user.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "AOOC: [user.simple_info_line()]: [html_decode(text)]")
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>AOOC:</u> - <span style=\"color:red\"><b>[text]</b></span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>AOOC:</u> - <span style=\"color:red\"><b>[text]</b></span>"
/proc/log_looc(text, client/user) /proc/log_looc(text, client/user)
if (config.log_ooc) if (config.log_ooc)
WRITE_LOG(diary, "LOOC: [user.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "LOOC: [user.simple_info_line()]: [html_decode(text)]")
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>LOOC:</u> - <span style=\"color:orange\"><b>[text]</b></span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[user]</b>) <u>LOOC:</u> - <span style=\"color:orange\"><b>[text]</b></span>"
@@ -116,11 +117,11 @@
if(speaker.client) if(speaker.client)
//speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:gray\"><i>[text]</i></span>" //speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:gray\"><i>[text]</i></span>"
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:gray\"><i>[text]</i></span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>SAY:</u> - <span style=\"color:gray\"><i>[text]</i></span>"
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
@@ -131,11 +132,11 @@
if(speaker.client) if(speaker.client)
//speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>EMOTE:</u> - <span style=\"color:#CCBADC\">[text]</span>" //speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>EMOTE:</u> - <span style=\"color:#CCBADC\">[text]</span>"
//GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>EMOTE:</u> - <span style=\"color:#CCBADC\">[text]</span>" //GLOB.round_text_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>EMOTE:</u> - <span style=\"color:#CCBADC\">[text]</span>"
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//CHOMPEdit End //CHOMPEdit End
@@ -160,11 +161,11 @@
WRITE_LOG(diary, "DEADCHAT: [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "DEADCHAT: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>DEADSAY:</u> - <span style=\"color:green\">[text]</span>" //speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>DEADSAY:</u> - <span style=\"color:green\">[text]</span>"
//GLOB.round_text_log += "<font size=1><span style=\"color:#7e668c\"><b>([time_stamp()])</b> (<b>[src]/[speaker.client]</b>) <u>DEADSAY:</u> - [text]</span></font>" //GLOB.round_text_log += "<font size=1><span style=\"color:#7e668c\"><b>([time_stamp()])</b> (<b>[src]/[speaker.client]</b>) <u>DEADSAY:</u> - [text]</span></font>"
@@ -175,11 +176,11 @@
WRITE_LOG(diary, "DEADEMOTE: [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "DEADEMOTE: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//CHOMPEdit End //CHOMPEdit End
@@ -192,11 +193,11 @@
WRITE_LOG(diary, "PDA: [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "PDA: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>MSG:</u> - <span style=\"color:[COLOR_GREEN]\">[text]</span>" //speaker.dialogue_log += "<b>([time_stamp()])</b> (<b>[speaker]/[speaker.client]</b>) <u>MSG:</u> - <span style=\"color:[COLOR_GREEN]\">[text]</span>"

View File

@@ -3,11 +3,11 @@
WRITE_LOG(diary, "NSAY (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "NSAY (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.ErrorMsg()
//CHOMPEdit End //CHOMPEdit End
@@ -16,11 +16,11 @@
WRITE_LOG(diary, "NME (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "NME (NIF:[inside]): [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//CHOMPEdit End //CHOMPEdit End
@@ -29,10 +29,10 @@
WRITE_LOG(diary, "SUBTLE: [speaker.simple_info_line()]: [html_decode(text)]") WRITE_LOG(diary, "SUBTLE: [speaker.simple_info_line()]: [html_decode(text)]")
//CHOMPEdit Begin //CHOMPEdit Begin
if(speaker.client) if(speaker.client)
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected())
return null 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() query_insert.Execute()
//CHOMPEdit End //CHOMPEdit End

View File

@@ -15,8 +15,10 @@
// Run all strings to be used in an SQL query through this proc first to properly escape out injection attempts. // 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) /proc/sanitizeSQL(var/t as text)
var/sqltext = dbcon.Quote(t); //var/sqltext = dbcon.Quote(t); //CHOMPEdit Begin
return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that //return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that
return t
//CHOMPEdit End
/* /*
* Text sanitization * Text sanitization

View File

@@ -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, "<span class='danger'>A SQL error occurred during this operation, check the server logs.</span>")
/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

View File

@@ -20,7 +20,7 @@ SUBSYSTEM_DEF(persist)
return return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
src.currentrun.Cut() src.currentrun.Cut()
return return
if(!resumed) if(!resumed)
@@ -84,7 +84,7 @@ SUBSYSTEM_DEF(persist)
var/sql_dpt = sql_sanitize_text(department_earning) var/sql_dpt = sql_sanitize_text(department_earning)
var/sql_bal = text2num("[C.department_hours[department_earning]]") var/sql_bal = text2num("[C.department_hours[department_earning]]")
var/sql_total = text2num("[C.play_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 if(!query.Execute()) //CHOMPEdit
log_admin(query.ErrorMsg()) //CHOMPEdit log_admin(query.ErrorMsg()) //CHOMPEdit

View File

@@ -7,11 +7,11 @@ proc/sql_poll_population()
if(M.client) if(M.client)
playercount += 1 playercount += 1
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during population polling. Failed to connect.") log_game("SQL ERROR during population polling. Failed to connect.")
else else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss") 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()) if(!query.Execute())
var/err = query.ErrorMsg() var/err = query.ErrorMsg()
log_game("SQL ERROR during population polling. Error : \[[err]\]\n") 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]" 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()])") //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() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during death reporting. Failed to connect.") log_game("SQL ERROR during death reporting. Failed to connect.")
else 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()) if(!query.Execute())
var/err = query.ErrorMsg() var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n") 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]" 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()])") //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() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during death reporting. Failed to connect.") log_game("SQL ERROR during death reporting. Failed to connect.")
else 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()) if(!query.Execute())
var/err = query.ErrorMsg() var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n") log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
@@ -115,11 +115,11 @@ proc/sql_commit_feedback()
return return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
log_game("SQL ERROR during feedback reporting. Failed to connect.") log_game("SQL ERROR during feedback reporting. Failed to connect.")
else 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() max_query.Execute()
var/newroundid var/newroundid
@@ -139,7 +139,7 @@ proc/sql_commit_feedback()
var/variable = item.get_variable() var/variable = item.get_variable()
var/value = item.get_value() 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()) if(!query.Execute())
var/err = query.ErrorMsg() var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n") log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")

View File

@@ -564,13 +564,21 @@ var/failed_old_db_connections = 0
/hook/startup/proc/connectDB() /hook/startup/proc/connectDB()
if(!config.sql_enabled) if(!config.sql_enabled)
to_world_log("SQL connection disabled in config.") to_world_log("SQL connection disabled in config.")
else if(!setup_database_connection()) else if(establish_db_connection())//CHOMPEdit Begin
to_world_log("Your server failed to establish a connection with the feedback database.")
else
to_world_log("Feedback database connection established.") 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 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. 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 return 0
@@ -601,30 +609,25 @@ proc/setup_database_connection()
failed_db_connections++ //If it failed, increase the failed connections counter. failed_db_connections++ //If it failed, increase the failed connections counter.
to_world_log(dbcon.ErrorMsg()) to_world_log(dbcon.ErrorMsg())
return . return .*/
//This proc ensures that the connection to the feedback database (global variable dbcon) is established //This proc ensures that the connection to the feedback database (global variable dbcon) is established
proc/establish_db_connection() proc/establish_db_connection() //CHOMPEdit TGSQL
if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF) return SSdbcore.Connect()
return 0
if(!dbcon || !dbcon.IsConnected())
return setup_database_connection()
else
return 1
/hook/startup/proc/connectOldDB() /hook/startup/proc/connectOldDB()
if(!config.sql_enabled) if(!config.sql_enabled)
to_world_log("SQL connection disabled in config.") to_world_log("SQL connection disabled in config.")
else if(!setup_old_database_connection()) else if(establish_old_db_connection()) //CHOMPEdit Begin
to_world_log("Your server failed to establish a connection with the SQL database.")
else
to_world_log("SQL database connection established.") to_world_log("SQL database connection established.")
else
to_world_log("SQL database connection failed")
//CHOMPEdit End
return 1 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. //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. 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 return 0
@@ -646,17 +649,11 @@ proc/setup_old_database_connection()
failed_old_db_connections++ //If it failed, increase the failed connections counter. failed_old_db_connections++ //If it failed, increase the failed connections counter.
to_world_log(dbcon.ErrorMsg()) to_world_log(dbcon.ErrorMsg())
return . return .*/
//This proc ensures that the connection to the feedback database (global variable dbcon) is established //This proc ensures that the connection to the feedback database (global variable dbcon) is established
proc/establish_old_db_connection() proc/establish_old_db_connection()
if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF) return SSdbcore.Connect()
return 0
if(!dbcon_old || !dbcon_old.IsConnected())
return setup_old_database_connection()
else
return 1
// Things to do when a new z-level was just made. // Things to do when a new z-level was just made.
/world/proc/max_z_changed() /world/proc/max_z_changed()

View File

@@ -131,8 +131,8 @@ var/custom_event_msg = null
// Database connections. A connection is established on world creation. // Database connections. A connection is established on world creation.
// Ideally, the connection dies when the server restarts (After feedback logging.). // Ideally, the connection dies when the server restarts (After feedback logging.).
var/DBConnection/dbcon = new() // Feedback database (New database) //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. //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. // 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") 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")

View File

@@ -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 if(!check_rights(R_MOD,0) && !check_rights(R_BAN)) return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/serverip = "[world.internet_address]:[world.port]" 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 computerid = bancid
ip = banip 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() query.Execute()
var/validckey = 0 var/validckey = 0
if(query.NextRow()) 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) 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/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() query_insert.Execute()
to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Ban saved to database.</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Ban saved to database.</font></span>")
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) 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]'" sql += " AND job = '[job]'"
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/ban_id var/ban_id
var/ban_number = 0 //failsafe var/ban_number = 0 //failsafe
var/DBQuery/query = dbcon.NewQuery(sql) var/DBQuery/query = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
ban_id = query.item[1] 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") to_chat(usr, "Cancelled")
return 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() query.Execute()
var/eckey = usr.ckey //Editing admin ckey 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") to_chat(usr, "Cancelled")
return return
var/DBQuery/update_query = dbcon.NewQuery("UPDATE erro_ban SET reason = '[value]', edits = CONCAT(edits,'- [eckey] changed ban reason from <cite><b>\\\"[reason]\\\"</b></cite> to <cite><b>\\\"[value]\\\"</b></cite><BR>') WHERE id = [banid]") var/DBQuery/update_query = SSdbcore.NewQuery("UPDATE erro_ban SET reason = '[value]', edits = CONCAT(edits,'- [eckey] changed ban reason from <cite><b>\\\"[reason]\\\"</b></cite> to <cite><b>\\\"[value]\\\"</b></cite><BR>') WHERE id = [banid]") //CHOMPEdit TGSQL
update_query.Execute() update_query.Execute()
message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s reason from [reason] to [value]",1) message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s reason from [reason] to [value]",1)
if("duration") if("duration")
@@ -198,7 +198,7 @@ datum/admins/proc/DB_ban_edit(var/banid = null, var/param = null)
to_chat(usr, "Cancelled") to_chat(usr, "Cancelled")
return return
var/DBQuery/update_query = dbcon.NewQuery("UPDATE erro_ban SET duration = [value], edits = CONCAT(edits,'- [eckey] changed ban duration from [duration] to [value]<br>'), 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]<br>'), 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) message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s duration from [duration] to [value]",1)
update_query.Execute() update_query.Execute()
if("unban") 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]" var/sql = "SELECT ckey FROM erro_ban WHERE id = [id]"
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/ban_number = 0 //failsafe var/ban_number = 0 //failsafe
var/pckey var/pckey
var/DBQuery/query = dbcon.NewQuery(sql) var/DBQuery/query = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
pckey = query.item[1] 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]" 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) 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() query_update.Execute()
@@ -267,7 +267,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
if(!check_rights(R_BAN)) return if(!check_rights(R_BAN)) return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>")
return return
@@ -396,7 +396,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
else else
bantypesearch += "'PERMABAN' " 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() 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) 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)

View File

@@ -52,7 +52,7 @@ world/IsBanned(key,address,computer_id)
failedcid = 0 failedcid = 0
cidquery = " OR computerid = '[computer_id]' " 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() query.Execute()

View File

@@ -112,14 +112,14 @@ var/list/admin_ranks = list() //list of all ranks with associated rights
//The current admin system uses SQL //The current admin system uses SQL
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
error("Failed to connect to database in load_admins(). Reverting to legacy system.") 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.") log_misc("Failed to connect to database in load_admins(). Reverting to legacy system.")
config.admin_legacy_system = 1 config.admin_legacy_system = 1
load_admins() load_admins()
return 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() query.Execute()
while(query.NextRow()) while(query.NextRow())
var/ckey = query.item[1] var/ckey = query.item[1]

View File

@@ -45,7 +45,7 @@
//CHOMPEdit Begin //CHOMPEdit Begin
/*for(var/d in M.dialogue_log) /*for(var/d in M.dialogue_log)
dat += "[d]<br>"*/ dat += "[d]<br>"*/
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()) if(!query.Execute())
dat += "<i>Database query error</i>" dat += "<i>Database query error</i>"
else else

View File

@@ -77,7 +77,7 @@ DEBUG
return return
//Job permabans //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() query.Execute()
while(query.NextRow()) while(query.NextRow())
@@ -87,7 +87,7 @@ DEBUG
jobban_keylist.Add("[ckey] - [job]") jobban_keylist.Add("[ckey] - [job]")
//Job tempbans //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() query1.Execute()
while(query1.NextRow()) while(query1.NextRow())

View File

@@ -56,7 +56,7 @@
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>")
return return
@@ -71,7 +71,7 @@
if(!istext(adm_ckey) || !istext(new_rank)) if(!istext(adm_ckey) || !istext(new_rank))
return 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() select_query.Execute()
var/new_admin = 1 var/new_admin = 1
@@ -81,16 +81,16 @@
admin_id = text2num(select_query.item[1]) admin_id = text2num(select_query.item[1])
if(new_admin) 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() 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() log_query.Execute()
to_chat(usr, "<span class='filter_adminlog'><font color='blue'>New admin added.</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='blue'>New admin added.</font></span>")
else else
if(!isnull(admin_id) && isnum(admin_id)) 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() 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() log_query.Execute()
to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Admin rank changed.</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Admin rank changed.</font></span>")
@@ -105,7 +105,7 @@
return return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='red'>Failed to establish database connection</font></span>")
return return
@@ -123,7 +123,7 @@
if(!istext(adm_ckey) || !isnum(new_permission)) if(!istext(adm_ckey) || !isnum(new_permission))
return 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() select_query.Execute()
var/admin_id var/admin_id
@@ -136,14 +136,14 @@
return return
if(admin_rights & new_permission) //This admin already has this permission, so we are removing it. 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() 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() log_query.Execute()
to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Permission removed.</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Permission removed.</font></span>")
else //This admin doesn't have this permission, so we are adding it. 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() 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() log_query.Execute()
to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Permission added.</font></span>") to_chat(usr, "<span class='filter_adminlog'><font color='blue'>Permission added.</font></span>")

View File

@@ -30,7 +30,7 @@ var/inactive_keys = "None<br>"
return return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
//grab all ckeys associated with custom items //grab all ckeys associated with custom items
@@ -55,7 +55,7 @@ var/inactive_keys = "None<br>"
//run a query to get all ckeys inactive for over 2 months //run a query to get all ckeys inactive for over 2 months
var/list/inactive_ckeys = list() var/list/inactive_ckeys = list()
if(ckeys_with_customitems.len) 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() query_inactive.Execute()
while(query_inactive.NextRow()) while(query_inactive.NextRow())
var/cur_ckey = query_inactive.item[1] var/cur_ckey = query_inactive.item[1]
@@ -67,7 +67,7 @@ var/inactive_keys = "None<br>"
//if there are ckeys left over, check whether they have a database entry at all //if there are ckeys left over, check whether they have a database entry at all
if(ckeys_with_customitems.len) if(ckeys_with_customitems.len)
for(var/cur_ckey in ckeys_with_customitems) 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() query_inactive.Execute()
if(!query_inactive.RowCount()) if(!query_inactive.RowCount())
inactive_ckeys += cur_ckey inactive_ckeys += cur_ckey

View File

@@ -12,7 +12,7 @@
config.panic_bunker = (!config.panic_bunker) 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")].") 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.") 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! 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) 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")].") 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.") 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! 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) 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")].") 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).") 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! feedback_add_details("admin_verb","IPREP") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!

View File

@@ -95,7 +95,7 @@
var/sql_discord = sql_sanitize_text(their_id) var/sql_discord = sql_sanitize_text(their_id)
var/sql_ckey = sql_sanitize_text(ckey) 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()) if(query.Execute())
to_chat(src, "<span class='notice'>Registration complete! Thank you for taking the time to register your Discord ID.</span>") to_chat(src, "<span class='notice'>Registration complete! Thank you for taking the time to register your Discord ID.</span>")
log_and_message_admins("[ckey] has registered their Discord ID. Their Discord snowflake ID is: [their_id]") //YW EDIT 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) /proc/get_player_age(key)
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return null return null
var/sql_ckey = sql_sanitize_text(ckey(key)) 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() query.Execute()
if(query.NextRow()) if(query.NextRow())
@@ -294,12 +294,12 @@
return return
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/sql_ckey = sql_sanitize_text(src.ckey) 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() query.Execute()
var/sql_id = 0 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. 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 break
account_join_date = sanitizeSQL(findJoinDate()) account_join_date = sanitizeSQL(findJoinDate())
if(account_join_date && dbcon.IsConnected()) if(account_join_date && SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/DBQuery/query_datediff = dbcon.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')") var/DBQuery/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')") //CHOMPEdit TGSQL
if(query_datediff.Execute() && query_datediff.NextRow()) if(query_datediff.Execute() && query_datediff.NextRow())
account_age = text2num(query_datediff.item[1]) 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() query_ip.Execute()
related_accounts_ip = "" related_accounts_ip = ""
while(query_ip.NextRow()) while(query_ip.NextRow())
related_accounts_ip += "[query_ip.item[1]], " related_accounts_ip += "[query_ip.item[1]], "
break 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() query_cid.Execute()
related_accounts_cid = "" related_accounts_cid = ""
while(query_cid.NextRow()) while(query_cid.NextRow())
@@ -376,7 +376,7 @@
log_admin("Couldn't perform IP check on [key] with [address]") log_admin("Couldn't perform IP check on [key] with [address]")
// VOREStation Edit Start - Department Hours // 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()) if(query_hours.Execute())
while(query_hours.NextRow()) while(query_hours.NextRow())
department_hours[query_hours.item[1]] = text2num(query_hours.item[2]) department_hours[query_hours.item[1]] = text2num(query_hours.item[2])
@@ -390,16 +390,16 @@
if(sql_id) if(sql_id)
//Player already identified previously, we need to just update the 'lastseen', 'ip' and 'computer_id' variables //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() query_update.Execute()
else else
//New player!! Need to insert all the stuff //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() query_insert.Execute()
//Logging player access //Logging player access
var/serverip = "[world.internet_address]:[world.port]" 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() query_accesslog.Execute()
#undef TOPIC_SPAM_DELAY #undef TOPIC_SPAM_DELAY

View File

@@ -44,7 +44,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
<A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"} <A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"}
if(1) if(1)
establish_old_db_connection() establish_old_db_connection()
if(!dbcon_old.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>" dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
else if(!SQLquery) else if(!SQLquery)
dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>" dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>"
@@ -52,7 +52,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
dat += {"<table> dat += {"<table>
<tr><td>AUTHOR</td><td>TITLE</td><td>CATEGORY</td><td>SS<sup>13</sup>BN</td></tr>"} <tr><td>AUTHOR</td><td>TITLE</td><td>CATEGORY</td><td>SS<sup>13</sup>BN</td></tr>"}
var/DBQuery/query = dbcon_old.NewQuery(SQLquery) var/DBQuery/query = SSdbcore.NewQuery(SQLquery) //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
@@ -277,13 +277,13 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
//dat += "<h3><font color=red>Warning: System Administrator has slated this archive for removal. Personal uploads should be taken to the NT board of internal literature.</font></h3>" //VOREStation Removal //dat += "<h3><font color=red>Warning: System Administrator has slated this archive for removal. Personal uploads should be taken to the NT board of internal literature.</font></h3>" //VOREStation Removal
if(!dbcon_old.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font>" dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font>"
else else
dat += {"<A href='?src=\ref[src];orderbyid=1'>(Order book by SS<sup>13</sup>BN)</A><BR><BR> dat += {"<A href='?src=\ref[src];orderbyid=1'>(Order book by SS<sup>13</sup>BN)</A><BR><BR>
<table> <table>
<tr><td><A href='?src=\ref[src];sort=author>AUTHOR</A></td><td><A href='?src=\ref[src];sort=title>TITLE</A></td><td><A href='?src=\ref[src];sort=category>CATEGORY</A></td><td></td></tr>"} <tr><td><A href='?src=\ref[src];sort=author>AUTHOR</A></td><td><A href='?src=\ref[src];sort=title>TITLE</A></td><td><A href='?src=\ref[src];sort=category>CATEGORY</A></td><td></td></tr>"}
var/DBQuery/query = dbcon_old.NewQuery("SELECT id, author, title, category FROM library ORDER BY [sortby]") var/DBQuery/query = SSdbcore.NewQuery("SELECT id, author, title, category FROM library ORDER BY [sortby]") //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
@@ -402,7 +402,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
alert("This book has been rejected from the database. Aborting!") alert("This book has been rejected from the database. Aborting!")
else else
establish_old_db_connection() establish_old_db_connection()
if(!dbcon_old.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
alert("Connection to Archive has been severed. Aborting.") alert("Connection to Archive has been severed. Aborting.")
else else
/* /*
@@ -415,7 +415,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
var/sqlauthor = sanitizeSQL(scanner.cache.author) var/sqlauthor = sanitizeSQL(scanner.cache.author)
var/sqlcontent = sanitizeSQL(scanner.cache.dat) var/sqlcontent = sanitizeSQL(scanner.cache.dat)
var/sqlcategory = sanitizeSQL(upload_category) var/sqlcategory = sanitizeSQL(upload_category)
var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO library (author, title, content, category) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]')") var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO library (author, title, content, category) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]')") //CHOMPEdit TGSQL
if(!query.Execute()) if(!query.Execute())
to_chat(usr,query.ErrorMsg()) to_chat(usr,query.ErrorMsg())
else else
@@ -426,7 +426,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
if(href_list["targetid"]) if(href_list["targetid"])
var/sqlid = sanitizeSQL(href_list["targetid"]) var/sqlid = sanitizeSQL(href_list["targetid"])
establish_old_db_connection() establish_old_db_connection()
if(!dbcon_old.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
alert("Connection to Archive has been severed. Aborting.") alert("Connection to Archive has been severed. Aborting.")
if(bibledelay) if(bibledelay)
for (var/mob/V in hearers(src)) for (var/mob/V in hearers(src))
@@ -435,7 +435,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
bibledelay = 1 bibledelay = 1
spawn(6) spawn(6)
bibledelay = 0 bibledelay = 0
var/DBQuery/query = dbcon_old.NewQuery("SELECT * FROM library WHERE id=[sqlid]") var/DBQuery/query = SSdbcore.NewQuery("SELECT * FROM library WHERE id=[sqlid]") //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())

View File

@@ -46,11 +46,11 @@
if(!IsGuestKey(src.key)) if(!IsGuestKey(src.key))
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/isadmin = 0 var/isadmin = 0
if(src.client && src.client.holder) if(src.client && src.client.holder)
isadmin = 1 isadmin = 1
var/DBQuery/query = dbcon.NewQuery("SELECT id FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime AND id NOT IN (SELECT pollid FROM erro_poll_vote WHERE ckey = \"[ckey]\") AND id NOT IN (SELECT pollid FROM erro_poll_textreply WHERE ckey = \"[ckey]\")") var/DBQuery/query = SSdbcore.NewQuery("SELECT id FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime AND id NOT IN (SELECT pollid FROM erro_poll_vote WHERE ckey = \"[ckey]\") AND id NOT IN (SELECT pollid FROM erro_poll_textreply WHERE ckey = \"[ckey]\")") //CHOMPEdit TGSQL
query.Execute() query.Execute()
var/newpoll = 0 var/newpoll = 0
while(query.NextRow()) while(query.NextRow())
@@ -216,12 +216,12 @@
if(href_list["privacy_poll"]) if(href_list["privacy_poll"])
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/voted = 0 var/voted = 0
//First check if the person has not voted yet. //First check if the person has not voted yet.
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'") var/DBQuery/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'") //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
voted = 1 voted = 1
@@ -247,7 +247,7 @@
if(!voted) if(!voted)
var/sql = "INSERT INTO erro_privacy VALUES (null, Now(), '[src.ckey]', '[option]')" var/sql = "INSERT INTO erro_privacy VALUES (null, Now(), '[src.ckey]', '[option]')"
var/DBQuery/query_insert = dbcon.NewQuery(sql) var/DBQuery/query_insert = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query_insert.Execute() query_insert.Execute()
to_chat(usr, "<b>Thank you for your vote!</b>") to_chat(usr, "<b>Thank you for your vote!</b>")
usr << browse(null,"window=privacypoll") usr << browse(null,"window=privacypoll")

View File

@@ -1,11 +1,11 @@
/mob/new_player/proc/handle_privacy_poll() /mob/new_player/proc/handle_privacy_poll()
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
return return
var/voted = 0 var/voted = 0
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'") var/DBQuery/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'") //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
voted = 1 voted = 1
@@ -48,12 +48,12 @@
/mob/new_player/proc/handle_player_polling() /mob/new_player/proc/handle_player_polling()
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/isadmin = 0 var/isadmin = 0
if(src.client && src.client.holder) if(src.client && src.client.holder)
isadmin = 1 isadmin = 1
var/DBQuery/select_query = dbcon.NewQuery("SELECT id, question FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime") var/DBQuery/select_query = SSdbcore.NewQuery("SELECT id, question FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
select_query.Execute() select_query.Execute()
var/output = "<div align='center'><B>Player polls</B>" var/output = "<div align='center'><B>Player polls</B>"
@@ -82,9 +82,9 @@
/mob/new_player/proc/poll_player(var/pollid = -1) /mob/new_player/proc/poll_player(var/pollid = -1)
if(pollid == -1) return if(pollid == -1) return
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid]") var/DBQuery/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid]") //CHOMPEdit TGSQL
select_query.Execute() select_query.Execute()
var/pollstarttime = "" var/pollstarttime = ""
@@ -109,7 +109,7 @@
switch(polltype) switch(polltype)
//Polls that have enumerated options //Polls that have enumerated options
if("OPTION") if("OPTION")
var/DBQuery/voted_query = dbcon.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
var/voted = 0 var/voted = 0
@@ -121,7 +121,7 @@
var/list/datum/polloption/options = list() var/list/datum/polloption/options = list()
var/DBQuery/options_query = dbcon.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") var/DBQuery/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
options_query.Execute() options_query.Execute()
while(options_query.NextRow()) while(options_query.NextRow())
var/datum/polloption/PO = new() var/datum/polloption/PO = new()
@@ -162,7 +162,7 @@
//Polls with a text input //Polls with a text input
if("TEXT") if("TEXT")
var/DBQuery/voted_query = dbcon.NewQuery("SELECT replytext FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT replytext FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
var/voted = 0 var/voted = 0
@@ -204,7 +204,7 @@
//Polls with a text input //Polls with a text input
if("NUMVAL") if("NUMVAL")
var/DBQuery/voted_query = dbcon.NewQuery("SELECT o.text, v.rating FROM erro_poll_option o, erro_poll_vote v WHERE o.pollid = [pollid] AND v.ckey = '[usr.ckey]' AND o.id = v.optionid") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT o.text, v.rating FROM erro_poll_option o, erro_poll_vote v WHERE o.pollid = [pollid] AND v.ckey = '[usr.ckey]' AND o.id = v.optionid") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
var/output = "<div align='center'><B>Player poll</B>" var/output = "<div align='center'><B>Player poll</B>"
@@ -230,7 +230,7 @@
var/minid = 999999 var/minid = 999999
var/maxid = 0 var/maxid = 0
var/DBQuery/option_query = dbcon.NewQuery("SELECT id, text, minval, maxval, descmin, descmid, descmax FROM erro_poll_option WHERE pollid = [pollid]") var/DBQuery/option_query = SSdbcore.NewQuery("SELECT id, text, minval, maxval, descmin, descmid, descmax FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
option_query.Execute() option_query.Execute()
while(option_query.NextRow()) while(option_query.NextRow())
var/optionid = text2num(option_query.item[1]) var/optionid = text2num(option_query.item[1])
@@ -273,7 +273,7 @@
src << browse(output,"window=playerpoll;size=500x500") src << browse(output,"window=playerpoll;size=500x500")
if("MULTICHOICE") if("MULTICHOICE")
var/DBQuery/voted_query = dbcon.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
var/list/votedfor = list() var/list/votedfor = list()
@@ -286,7 +286,7 @@
var/maxoptionid = 0 var/maxoptionid = 0
var/minoptionid = 0 var/minoptionid = 0
var/DBQuery/options_query = dbcon.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") var/DBQuery/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
options_query.Execute() options_query.Execute()
while(options_query.NextRow()) while(options_query.NextRow())
var/datum/polloption/PO = new() var/datum/polloption/PO = new()
@@ -343,9 +343,9 @@
if(!isnum(pollid) || !isnum(optionid)) if(!isnum(pollid) || !isnum(optionid))
return return
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") var/DBQuery/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
select_query.Execute() select_query.Execute()
var/validpoll = 0 var/validpoll = 0
@@ -363,7 +363,7 @@
to_chat(usr, "<font color='red'>Poll is not valid.</font>") to_chat(usr, "<font color='red'>Poll is not valid.</font>")
return return
var/DBQuery/select_query2 = dbcon.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") var/DBQuery/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") //CHOMPEdit TGSQL
select_query2.Execute() select_query2.Execute()
var/validoption = 0 var/validoption = 0
@@ -378,7 +378,7 @@
var/alreadyvoted = 0 var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.NewQuery("SELECT id FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
while(voted_query.NextRow()) while(voted_query.NextRow())
@@ -399,7 +399,7 @@
adminrank = usr.client.holder.rank adminrank = usr.client.holder.rank
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]')") var/DBQuery/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]')") //CHOMPEdit TGSQL
insert_query.Execute() insert_query.Execute()
to_chat(usr, "<font color='blue'>Vote successful.</font>") to_chat(usr, "<font color='blue'>Vote successful.</font>")
@@ -413,9 +413,9 @@
if(!isnum(pollid) || !istext(replytext)) if(!isnum(pollid) || !istext(replytext))
return return
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") var/DBQuery/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
select_query.Execute() select_query.Execute()
var/validpoll = 0 var/validpoll = 0
@@ -432,7 +432,7 @@
var/alreadyvoted = 0 var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
while(voted_query.NextRow()) while(voted_query.NextRow())
@@ -457,7 +457,7 @@
to_chat(usr, "The text you entered was blank, contained illegal characters or was too long. Please correct the text and submit again.") to_chat(usr, "The text you entered was blank, contained illegal characters or was too long. Please correct the text and submit again.")
return return
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO erro_poll_textreply (id ,datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (null, Now(), [pollid], '[usr.ckey]', '[usr.client.address]', '[replytext]', '[adminrank]')") var/DBQuery/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_textreply (id ,datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (null, Now(), [pollid], '[usr.ckey]', '[usr.client.address]', '[replytext]', '[adminrank]')") //CHOMPEdit TGSQL
insert_query.Execute() insert_query.Execute()
to_chat(usr, "<font color='blue'>Feedback logging successful.</font>") to_chat(usr, "<font color='blue'>Feedback logging successful.</font>")
@@ -471,9 +471,9 @@
if(!isnum(pollid) || !isnum(optionid)) if(!isnum(pollid) || !isnum(optionid))
return return
establish_db_connection() establish_db_connection()
if(dbcon.IsConnected()) if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") var/DBQuery/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
select_query.Execute() select_query.Execute()
var/validpoll = 0 var/validpoll = 0
@@ -488,7 +488,7 @@
to_chat(usr, "<font color='red'>Poll is not valid.</font>") to_chat(usr, "<font color='red'>Poll is not valid.</font>")
return return
var/DBQuery/select_query2 = dbcon.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") var/DBQuery/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") //CHOMPEdit TGSQL
select_query2.Execute() select_query2.Execute()
var/validoption = 0 var/validoption = 0
@@ -503,7 +503,7 @@
var/alreadyvoted = 0 var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = '[usr.ckey]'") var/DBQuery/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = '[usr.ckey]'") //CHOMPEdit TGSQL
voted_query.Execute() voted_query.Execute()
while(voted_query.NextRow()) while(voted_query.NextRow())
@@ -519,7 +519,7 @@
adminrank = usr.client.holder.rank adminrank = usr.client.holder.rank
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank, rating) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]', [(isnull(rating)) ? "null" : rating])") var/DBQuery/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank, rating) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]', [(isnull(rating)) ? "null" : rating])") //CHOMPEdit TGSQL
insert_query.Execute() insert_query.Execute()
to_chat(usr, "<font color='blue'>Vote successful.</font>") to_chat(usr, "<font color='blue'>Vote successful.</font>")

View File

@@ -346,10 +346,10 @@ var/obj/machinery/blackbox_recorder/blackbox
round_end_data_gathering() //round_end time logging and some other data processing round_end_data_gathering() //round_end time logging and some other data processing
establish_db_connection() establish_db_connection()
if(!dbcon.IsConnected()) return if(!SSdbcore.IsConnected()) return //CHOMPEdit TGSQL
var/round_id var/round_id
var/DBQuery/query = dbcon.NewQuery("SELECT MAX(round_id) AS round_id FROM erro_feedback") var/DBQuery/query = SSdbcore.NewQuery("SELECT MAX(round_id) AS round_id FROM erro_feedback") //CHOMPEdit TGSQL
query.Execute() query.Execute()
while(query.NextRow()) while(query.NextRow())
round_id = query.item[1] round_id = query.item[1]
@@ -360,7 +360,7 @@ var/obj/machinery/blackbox_recorder/blackbox
for(var/datum/feedback_variable/FV in feedback) for(var/datum/feedback_variable/FV in feedback)
var/sql = "INSERT INTO erro_feedback VALUES (null, Now(), [round_id], \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")" var/sql = "INSERT INTO erro_feedback VALUES (null, Now(), [round_id], \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")"
var/DBQuery/query_insert = dbcon.NewQuery(sql) var/DBQuery/query_insert = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
query_insert.Execute() query_insert.Execute()
// Sanitize inputs to avoid SQL injection attacks // Sanitize inputs to avoid SQL injection attacks

View File

@@ -72,7 +72,7 @@ GLOBAL_LIST_EMPTY(pending_discord_registrations)
/datum/tgs_chat_command/register/Run(datum/tgs_chat_user/sender, params) /datum/tgs_chat_command/register/Run(datum/tgs_chat_user/sender, params)
// Try to find if that ID is registered to someone already // Try to find if that ID is registered to someone already
var/sql_discord = sql_sanitize_text(sender.id) var/sql_discord = sql_sanitize_text(sender.id)
var/DBQuery/query = dbcon.NewQuery("SELECT discord_id FROM erro_player WHERE discord_id = '[sql_discord]'") var/DBQuery/query = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE discord_id = '[sql_discord]'") //CHOMPEdit TGSQL
query.Execute() query.Execute()
if(query.NextRow()) if(query.NextRow())
return "[sender.friendly_name], your Discord ID is already registered to a Byond username. Please contact an administrator if you changed your Byond username or Discord ID." return "[sender.friendly_name], your Discord ID is already registered to a Byond username. Please contact an administrator if you changed your Byond username or Discord ID."
@@ -95,7 +95,7 @@ GLOBAL_LIST_EMPTY(pending_discord_registrations)
return "[sender.friendly_name], I couldn't find a logged-in user with the username of '[key_to_find]', which is what you provided after conversion to Byond's ckey format. Please connect to the game server and try again." return "[sender.friendly_name], I couldn't find a logged-in user with the username of '[key_to_find]', which is what you provided after conversion to Byond's ckey format. Please connect to the game server and try again."
var/sql_ckey = sql_sanitize_text(key_to_find) var/sql_ckey = sql_sanitize_text(key_to_find)
query = dbcon.NewQuery("SELECT discord_id FROM erro_player WHERE ckey = '[sql_ckey]'") query = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE ckey = '[sql_ckey]'") //CHOMPEdit TGSQL
query.Execute() query.Execute()
// We somehow found their client, BUT they don't exist in the database // We somehow found their client, BUT they don't exist in the database

View File

@@ -264,6 +264,7 @@
#include "code\controllers\subsystems\character_setup.dm" #include "code\controllers\subsystems\character_setup.dm"
#include "code\controllers\subsystems\chat.dm" #include "code\controllers\subsystems\chat.dm"
#include "code\controllers\subsystems\circuits.dm" #include "code\controllers\subsystems\circuits.dm"
#include "code\controllers\subsystems\dbcore.dm"
#include "code\controllers\subsystems\dcs.dm" #include "code\controllers\subsystems\dcs.dm"
#include "code\controllers\subsystems\discord.dm" #include "code\controllers\subsystems\discord.dm"
#include "code\controllers\subsystems\events.dm" #include "code\controllers\subsystems\events.dm"
@@ -513,7 +514,6 @@
#include "code\defines\obj\weapon.dm" #include "code\defines\obj\weapon.dm"
#include "code\defines\procs\announce.dm" #include "code\defines\procs\announce.dm"
#include "code\defines\procs\AStar.dm" #include "code\defines\procs\AStar.dm"
#include "code\defines\procs\dbcore.dm"
#include "code\defines\procs\radio.dm" #include "code\defines\procs\radio.dm"
#include "code\defines\procs\sd_Alert.dm" #include "code\defines\procs\sd_Alert.dm"
#include "code\defines\procs\statistics.dm" #include "code\defines\procs\statistics.dm"