[MIRROR] Moving the database to a subsystem (#9963)

Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-01-29 03:25:00 -07:00
committed by GitHub
parent 26ff936832
commit 40e935a774
33 changed files with 559 additions and 310 deletions

233
SQL/feedback_schema.sql Normal file
View File

@@ -0,0 +1,233 @@
-- Table structure for table `erro_admin`
CREATE TABLE `erro_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) NOT NULL,
`rank` varchar(32) NOT NULL DEFAULT 'Administrator',
`level` int(2) NOT NULL DEFAULT '0',
`flags` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_admin_log`
CREATE TABLE `erro_admin_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`adminckey` varchar(32) NOT NULL,
`adminip` varchar(18) NOT NULL,
`log` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_ban`
CREATE TABLE `erro_ban` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bantime` datetime NOT NULL,
`serverip` varchar(32) NOT NULL,
`bantype` varchar(32) NOT NULL,
`reason` text NOT NULL,
`job` varchar(32) DEFAULT NULL,
`duration` int(11) NOT NULL,
`rounds` int(11) DEFAULT NULL,
`expiration_time` datetime NOT NULL,
`ckey` varchar(32) NOT NULL,
`computerid` varchar(32) NOT NULL,
`ip` varchar(32) NOT NULL,
`a_ckey` varchar(32) NOT NULL,
`a_computerid` varchar(32) NOT NULL,
`a_ip` varchar(32) NOT NULL,
`who` text NOT NULL,
`adminwho` text NOT NULL,
`edits` text,
`unbanned` tinyint(1) DEFAULT NULL,
`unbanned_datetime` datetime DEFAULT NULL,
`unbanned_ckey` varchar(32) DEFAULT NULL,
`unbanned_computerid` varchar(32) DEFAULT NULL,
`unbanned_ip` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_connection_log`
CREATE TABLE `erro_connection_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`serverip` varchar(32) NOT NULL,
`ckey` varchar(32) NOT NULL,
`ip` varchar(32) NOT NULL,
`computerid` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_feedback`
CREATE TABLE `erro_feedback` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` datetime NOT NULL,
`round_id` int(8) NOT NULL,
`var_name` varchar(32) NOT NULL,
`var_value` int(16) DEFAULT NULL,
`details` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_player`
CREATE TABLE `erro_player` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) NOT NULL,
`firstseen` datetime NOT NULL,
`lastseen` datetime NOT NULL,
`ip` varchar(18) NOT NULL,
`computerid` varchar(32) NOT NULL,
`lastadminrank` varchar(32) NOT NULL DEFAULT 'Player',
`discord_id` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ckey` (`ckey`),
KEY `discord_id` (`discord_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_option`
CREATE TABLE `erro_poll_option` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pollid` int(11) NOT NULL,
`text` varchar(255) NOT NULL,
`percentagecalc` tinyint(1) NOT NULL DEFAULT '1',
`minval` int(3) DEFAULT NULL,
`maxval` int(3) DEFAULT NULL,
`descmin` varchar(32) DEFAULT NULL,
`descmid` varchar(32) DEFAULT NULL,
`descmax` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_question`
CREATE TABLE `erro_poll_question` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`polltype` varchar(16) NOT NULL DEFAULT 'OPTION',
`starttime` datetime NOT NULL,
`endtime` datetime NOT NULL,
`question` varchar(255) NOT NULL,
`adminonly` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_textreply`
CREATE TABLE `erro_poll_textreply` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`pollid` int(11) NOT NULL,
`ckey` varchar(32) NOT NULL,
`ip` varchar(18) NOT NULL,
`replytext` text NOT NULL,
`adminrank` varchar(32) NOT NULL DEFAULT 'Player',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_vote`
CREATE TABLE `erro_poll_vote` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`pollid` int(11) NOT NULL,
`optionid` int(11) NOT NULL,
`ckey` varchar(255) NOT NULL,
`ip` varchar(16) NOT NULL,
`adminrank` varchar(32) NOT NULL,
`rating` int(2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_privacy`
CREATE TABLE `erro_privacy` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`ckey` varchar(32) NOT NULL,
`option` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `death`
CREATE TABLE `death` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`pod` TEXT NOT NULL COMMENT 'Place of death' ,
`coord` TEXT NOT NULL COMMENT 'X, Y, Z POD' ,
`tod` DATETIME NOT NULL COMMENT 'Time of death' ,
`job` TEXT NOT NULL ,
`special` TEXT NOT NULL ,
`name` TEXT NOT NULL ,
`byondkey` TEXT NOT NULL ,
`laname` TEXT NOT NULL COMMENT 'Last attacker name' ,
`lakey` TEXT NOT NULL COMMENT 'Last attacker key' ,
`gender` TEXT NOT NULL ,
`bruteloss` INT(11) NOT NULL ,
`brainloss` INT(11) NOT NULL ,
`fireloss` INT(11) NOT NULL ,
`oxyloss` INT(11) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `karma`
CREATE TABLE `karma` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`spendername` TEXT NOT NULL ,
`spenderkey` TEXT NOT NULL ,
`receivername` TEXT NOT NULL ,
`receiverkey` TEXT NOT NULL ,
`receiverrole` TEXT NOT NULL ,
`receiverspecial` TEXT NOT NULL ,
`isnegative` TINYINT(1) NOT NULL ,
`spenderip` TEXT NOT NULL ,
`time` DATETIME NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `karmatotals`
CREATE TABLE `karmatotals` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`byondkey` TEXT NOT NULL ,
`karma` INT(11) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `library`
CREATE TABLE `library` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`author` TEXT NOT NULL ,
`title` TEXT NOT NULL ,
`content` TEXT NOT NULL ,
`category` TEXT NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `population`
CREATE TABLE `population` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`playercount` INT(11) NULL DEFAULT NULL ,
`admincount` INT(11) NULL DEFAULT NULL ,
`time` DATETIME NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `vr_player_hours`
CREATE TABLE `vr_player_hours` (
`ckey` varchar(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`department` varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`hours` double NOT NULL,
`total_hours` double NOT NULL DEFAULT '0',
PRIMARY KEY (`ckey`,`department`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `round` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`initialize_datetime` DATETIME NOT NULL,
`start_datetime` DATETIME NULL,
`shutdown_datetime` DATETIME NULL,
`end_datetime` DATETIME NULL,
`server_ip` INT(10) UNSIGNED NOT NULL,
`server_port` SMALLINT(5) UNSIGNED NOT NULL,
`commit_hash` CHAR(40) NULL,
`game_mode` VARCHAR(32) NULL,
`game_mode_result` VARCHAR(64) NULL,
`end_state` VARCHAR(64) NULL,
`shuttle_name` VARCHAR(64) NULL,
`map_name` VARCHAR(32) NULL,
`station_name` VARCHAR(80) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

View File

@@ -119,9 +119,9 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
#define INIT_ORDER_TITLE 99 //CHOMPEdit
#define INIT_ORDER_SERVER_MAINT 93
#define INIT_ORDER_WEBHOOKS 50
#define INIT_ORDER_DBCORE 41 //CHOMPEdit
#define INIT_ORDER_SQLITE 40
#define INIT_ORDER_GARBAGE 39
#define INIT_ORDER_SQLITE 41
#define INIT_ORDER_GARBAGE 40
#define INIT_ORDER_DBCORE 39
#define INIT_ORDER_MEDIA_TRACKS 38 // Gotta get that lobby music up, yo
#define INIT_ORDER_INPUT 37
#define INIT_ORDER_CHEMISTRY 35

View File

@@ -31,6 +31,11 @@
if (CONFIG_GET(flag/log_admin))
WRITE_LOG(diary, "ADMIN: [text]")
/proc/log_admin_private(text)
admin_log.Add(text)
if (CONFIG_GET(flag/log_admin))
WRITE_LOG(diary, "ADMINPRIVATE: [text]")
/proc/log_adminpm(text, client/source, client/dest)
admin_log.Add(text)
if (CONFIG_GET(flag/log_admin))
@@ -271,6 +276,12 @@
/proc/log_misc(text)
WRITE_LOG(diary, "MISC: [text]")
/proc/log_sql(text)
WRITE_LOG(sql_error_log, "SQL: [text]")
/proc/log_query_debug(text)
WRITE_LOG(query_debug_log, "SQL: [text]")
/proc/log_topic(text)
if(Debug2)
WRITE_LOG(diary, "TOPIC: [text]")

View File

@@ -15,12 +15,10 @@
// Run all strings to be used in an SQL query through this proc first to properly escape out injection attempts.
/proc/sanitizeSQL(var/t as text)
//var/sqltext = dbcon.Quote(t); //CHOMPEdit Begin
//var/sqltext = dbcon.Quote(t);
//return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that
return t
//CHOMPEdit End
// CHOMPEdit - Adds format_table_name
/proc/format_table_name(table as text)
//return CONFIG_GET(string/feedback_tableprefix) + table
return table // We don't implement tableprefix

View File

@@ -497,7 +497,6 @@ Ignore_errors instructes mysql to continue inserting rows if some of them have e
return ..()
/datum/db_query/CanProcCall(proc_name)
//fuck off kevinz
return FALSE
/datum/db_query/proc/Activity(activity)
@@ -579,7 +578,6 @@ Ignore_errors instructes mysql to continue inserting rows if some of them have e
status = DB_QUERY_BROKEN
return
/datum/db_query/proc/slow_query_check()
message_admins("HEY! A database query timed out. Did the server just hang? <a href='byond://?_src_=holder;[HrefToken()];slowquery=yes'>\[YES\]</a>|<a href='byond://?_src_=holder;[HrefToken()];slowquery=no'>\[NO\]</a>")

View File

@@ -10,7 +10,7 @@ SUBSYSTEM_DEF(persist)
flags = SS_BACKGROUND|SS_NO_INIT|SS_KEEP_TIMING
runlevels = RUNLEVEL_GAME|RUNLEVEL_POSTGAME
var/list/currentrun = list()
var/list/query_stack = list() //CHOMPAdd TGSQL
var/list/query_stack = list()
/datum/controller/subsystem/persist/fire(var/resumed = FALSE)
update_department_hours(resumed)
@@ -21,7 +21,7 @@ SUBSYSTEM_DEF(persist)
return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
src.currentrun.Cut()
return
if(!resumed)
@@ -30,7 +30,7 @@ SUBSYSTEM_DEF(persist)
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
var/list/query_stack = src.query_stack //CHOMPAdd TGSQL
var/list/query_stack = src.query_stack
while (currentrun.len)
var/mob/M = currentrun[currentrun.len]
currentrun.len--
@@ -92,15 +92,15 @@ SUBSYSTEM_DEF(persist)
"department" = sql_dpt,
"hours" = sql_bal,
"total_hours" = sql_total
)
query_stack += list(entry) //CHOMPEdit TGSQL
)
query_stack += list(entry)
if (MC_TICK_CHECK)
return
//CHOMPAdd Start TGSQL
if(query_stack.len)
SSdbcore.MassInsert(format_table_name("vr_player_hours"), query_stack, duplicate_key = "ON DUPLICATE KEY UPDATE hours = VALUES(hours), total_hours = VALUES(total_hours)")
query_stack.Cut()
//CHOMPAdd End TGSQL
// This proc tries to find the job datum of an arbitrary mob.
/datum/controller/subsystem/persist/proc/detect_job(var/mob/M)

View File

@@ -31,7 +31,7 @@ SUBSYSTEM_DEF(statpanels)
"Map: [using_map.name]",
//cached ? "Next Map: [cached.map_name]" : null,
//"Next Map: -- Not Available --",
"Round ID: [GLOB.round_id ? GLOB.round_id : "NULL"]", // CHOMPEdit
"Round ID: [GLOB.round_id ? GLOB.round_id : "NULL"]",
"Server Time: [time2text(world.timeofday, "YYYY-MM-DD hh:mm:ss")]",
"Round Time: [roundduration2text()]",
"Station Date: [stationdate2text()], [capitalize(GLOB.world_time_season)]", // CHOMPEdit

View File

@@ -546,7 +546,7 @@ var/global/datum/controller/subsystem/ticker/ticker
for(var/i in total_antagonists)
log_game("[i]s[total_antagonists[i]].")
SSdbcore.SetRoundEnd() // CHOMPEdit
SSdbcore.SetRoundEnd()
return 1

View File

@@ -7,15 +7,15 @@
if(M.client)
playercount += 1
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
log_game("SQL ERROR during population polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO `population` (`playercount`, `admincount`, `time`) VALUES ([playercount], [admincount], '[sqltime]')") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO population ('playercount', 'admincount', 'time') VALUES ([playercount], [admincount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during population polling. Error : \[[err]\]\n")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
/proc/sql_report_round_start()
// TODO
@@ -51,14 +51,14 @@
var/coord = "[H.x], [H.y], [H.z]"
//to_world("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.bruteloss], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()])")
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES (:t_name, :t_byondkey, :t_job, :t_special, :t_pod, '[sqltime]', :t_laname, :t_lakey, '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')", list("t_name" = sqlname,"t_byondkey" = sqlkey, "t_job" = sqljob, "t_special" = sqlspecial, "t_pod" = sqlpod, "t_laname" = laname, "t_lakey" = lakey)) //CHOMPEdit TGSQL
var/datum/db_query/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]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
/proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
@@ -86,14 +86,14 @@
var/coord = "[H.x], [H.y], [H.z]"
//to_world("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.bruteloss], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()])")
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES (:t_name, :t_byondkey, :t_job, :t_special, :t_pod, '[sqltime]', :t_laname, :t_lakey, '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')", list("t_name" = sqlname,"t_byondkey" = sqlkey, "t_job" = sqljob, "t_special" = sqlspecial, "t_pod" = sqlpod, "t_laname" = laname, "t_lakey" = lakey)) //CHOMPEdit TGSQL
var/datum/db_query/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]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
/proc/statistic_cycle()
@@ -118,18 +118,18 @@
return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
log_game("SQL ERROR during feedback reporting. Failed to connect.")
else
var/datum/db_query/max_query = SSdbcore.NewQuery("SELECT MAX(roundid) AS max_round_id FROM erro_feedback") //CHOMPEdit TGSQL
var/datum/db_query/max_query = SSdbcore.NewQuery("SELECT MAX(roundid) AS max_round_id FROM erro_feedback")
max_query.Execute()
var/newroundid
while(max_query.NextRow())
newroundid = max_query.item[1]
qdel(max_query) //CHOMPEdit TGSQL
qdel(max_query)
if(!(isnum(newroundid)))
newroundid = text2num(newroundid)
@@ -142,8 +142,8 @@
var/variable = item.get_variable()
var/value = item.get_value()
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, [newroundid], Now(), '[variable]', '[value]')") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, [newroundid], Now(), '[variable]', '[value]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
qdel(query) //CHOMPEdit TGSQL
qdel(query)

View File

@@ -218,7 +218,7 @@ var/global/list/additional_antag_types = list()
emergency_shuttle.auto_recall = 1
feedback_set_details("round_start","[time2text(world.realtime)]")
INVOKE_ASYNC(SSdbcore, TYPE_PROC_REF(/datum/controller/subsystem/dbcore,SetRoundStart)) // CHOMPEdit
INVOKE_ASYNC(SSdbcore, TYPE_PROC_REF(/datum/controller/subsystem/dbcore, SetRoundStart))
if(ticker && ticker.mode)
feedback_set_details("game_mode","[ticker.mode]")
feedback_set_details("server_ip","[world.internet_address]:[world.port]")

View File

@@ -51,7 +51,7 @@
var/age = user.age
var/gender = user.gender
/* no dbstuff yet
var/datum/db_query/cquery = dbcon.NewQuery("SELECT * from jobban WHERE ckey='[user.ckey]'")
var/datum/db_query/cquery = SSdbcore.NewQuery("SELECT * from jobban WHERE ckey='[user.ckey]'")
if(!cquery.Execute()) return
else
while(cquery.NextRow())

View File

@@ -53,16 +53,13 @@ var/global/datum/book_manager/book_mgr = new()
dat += "<h3>ADMINISTRATIVE MANAGEMENT</h3>"
establish_old_db_connection()
if(!SSdbcore.IsConnected()) //CHOMP Edit Start
if(!SSdbcore.IsConnected())
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font>"
else
var/datum/db_query/query = SSdbcore.NewQuery("DELETE FROM library WHERE id=[isbn]")
if(!query.Execute())
to_chat(usr,query.ErrorMsg())
qdel(query) //CHOMPEdit End TGSQL
else
book_mgr.remove(isbn)
log_admin("[usr.key] has deleted the book [isbn]")
dat += {"<A href='byond://?our_comp=\ref[our_comp];[HrefToken()];orderbyid=1'>(Order book by SS<sup>13</sup>BN)</A><BR><BR>
<table>
<tr><td><A href='byond://?our_comp=\ref[our_comp];[HrefToken()];sort=author>AUTHOR</A></td><td><A href='byond://?our_comp=\ref[our_comp];[HrefToken()];sort=title>TITLE</A></td><td><A href='byond://?our_comp=\ref[our_comp];[HrefToken()];sort=category>CATEGORY</A></td><td></td></tr>"}
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category FROM library ORDER BY [sortby]")
query.Execute()
var/show_admin_options = check_rights(R_ADMIN, show_msg = FALSE)
@@ -77,6 +74,7 @@ var/global/datum/book_manager/book_mgr = new()
dat += "<A href='byond://?our_comp=\ref[our_comp];[HrefToken()];delid=[id]'>\[Del\]</A>"
dat += "</td></tr>"
dat += "</table>"
qdel(query)
usr << browse("<html>[dat]</html>", "window=library")
onclose(usr, "library")

View File

@@ -9,6 +9,8 @@
diary = start_log("[log_path].log")
href_logfile = start_log("[log_path]-hrefs.htm")
error_log = start_log("[log_path]-error.log")
sql_error_log = start_log("[log_path]-sql-error.log")
query_debug_log = start_log("[log_path]-query-debug.log")
debug_log = start_log("[log_path]-debug.log")
//VOREStation Edit End
@@ -106,7 +108,7 @@
// (i.e. basically nothing should be added before load_admins() in here)
// Try to set round ID
SSdbcore.InitializeRound() // CHOMPEdit
SSdbcore.InitializeRound()
//apply a default value to config.python_path, if needed
if (!CONFIG_GET(string/python_path))
@@ -552,14 +554,14 @@ var/world_topic_spam_protect_time = world.timeofday
var/ckey = copytext(line, 1, length(line)+1)
var/datum/mentor/M = new /datum/mentor(ckey)
M.associate(GLOB.directory[ckey])
else // CHOMPedit Start - Implementing loading mentors from database
else
establish_db_connection()
if(!SSdbcore.IsConnected())
error("Failed to connect to database in load_mentors().")
log_misc("Failed to connect to database in load_mentors().")
return
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, mentor FROM erro_mentor") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, mentor FROM erro_mentor")
query.Execute()
while(query.NextRow())
var/ckey = query.item[1]
@@ -569,7 +571,6 @@ var/world_topic_spam_protect_time = world.timeofday
var/datum/mentor/M = new /datum/mentor(ckey)
M.associate(GLOB.directory[ckey])
qdel(query)
// COMPedit End
/world/proc/update_status()
var/s = ""
@@ -636,37 +637,20 @@ var/failed_old_db_connections = 0
/hook/startup/proc/connectDB()
if(!CONFIG_GET(flag/sql_enabled))
to_world_log("SQL connection disabled in config.")
else if(establish_db_connection())//CHOMPEdit Begin
to_world_log("Feedback database connection established.")
var/datum/db_query/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")
qdel(query_truncate)
var/datum/db_query/query_truncate2 = SSdbcore.NewQuery("TRUNCATE erro_attacklog")
num_tries = 0
while(!query_truncate2.Execute() && num_tries<5)
num_tries++
if(num_tries==5)
log_admin("ERROR TRYING TO CLEAR erro_attacklog")
qdel(query_truncate2)
else if(!setup_database_connection())
to_world_log("Your server failed to establish a connection with the feedback database.")
else
to_world_log("Feedback database connection failed.")
//CHOMPEdit End
to_world_log("Feedback database connection established.")
return 1
/*/proc/setup_database_connection() CHOMPEdit TGSQL
/proc/setup_database_connection()
if(!CONFIG_GET(flag/sql_enabled))
return 0
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
if(!dbcon)
dbcon = new()
if(!SSdbcore)
SSdbcore = new()
var/user = CONFIG_GET(string/feedback_login)
var/pass = CONFIG_GET(string/feedback_password)
@@ -674,43 +658,36 @@ var/failed_old_db_connections = 0
var/address = CONFIG_GET(string/address)
var/port = CONFIG_GET(number/port)
dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
. = dbcon.IsConnected()
SSdbcore.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
. = SSdbcore.IsConnected()
if ( . )
failed_db_connections = 0 //If this connection succeeded, reset the failed connections counter.
//CHOMPEdit Begin
var/datum/db_query/query_truncate = dbcon.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")
//CHOMPEdit End
else
failed_db_connections++ //If it failed, increase the failed connections counter.
to_world_log(dbcon.ErrorMsg())
to_world_log(SSdbcore.ErrorMsg())
return .*/
return .
//This proc ensures that the connection to the feedback database (global variable dbcon) is established
/proc/establish_db_connection() //CHOMPEdit TGSQL
return SSdbcore.Connect()
/proc/establish_db_connection()
if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF)
return 0
if(!SSdbcore || !SSdbcore.IsConnected())
return setup_database_connection()
else
return 1
/* CHOMPedit
// Cleans up DB connections and recreates them
/proc/reset_database_connections()
var/list/results = list("-- Resetting DB connections --")
failed_db_connections = 0
if(dbcon?.IsConnected())
dbcon.Disconnect()
results += "dbcon was connected and asked to disconnect"
if(SSdbcore?.IsConnected())
SSdbcore.Disconnect()
results += "SSdbcore was connected and asked to disconnect"
else
results += "dbcon was not connected"
if(dbcon_old?.IsConnected())
results += "WARNING: dbcon_old is connected, not touching it, but is this intentional?"
results += "SSdbcore was not connected"
if(!CONFIG_GET(flag/sql_enabled))
results += "stopping because config.sql_enabled = false"
@@ -723,7 +700,6 @@ var/failed_old_db_connections = 0
results += "-- DB Reset End --"
to_world_log(results.Join("\n"))
*/
// Things to do when a new z-level was just made.
/world/proc/max_z_changed()

View File

@@ -17,6 +17,8 @@ var/list/hit_appends = list("-OOF", "-ACK", "-UGH", "-HRNK", "-HURGH", "-GLORF")
var/log_path = "data/logs/" //See world.dm for the full calculated path
var/diary = null
var/error_log = null
var/sql_error_log = null
var/query_debug_log = null
var/debug_log = null
var/href_logfile = null
//CHOMPStation Removal Start TFF 24/12/19 - Blep. Remove extra stuff. Where do these even come in?
@@ -121,11 +123,6 @@ var/forum_authenticated_group = "10"
var/fileaccess_timer = 0
var/custom_event_msg = null
// Database connections. A connection is established on world creation.
// Ideally, the connection dies when the server restarts (After feedback logging.).
//var/DBConnection/dbcon = new() // Feedback database (New database) //CHOMPEdit Switching to TG SQL
//var/DBConnection/dbcon_old = new() // /tg/station database (Old database) -- see the files in the SQL folder for information on what goes where. //CHOMPEdit Switching to TG SQL
// Added for Xenoarchaeology, might be useful for other stuff.
var/global/list/alphabet_uppercase = list("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")

View File

@@ -5,7 +5,7 @@
if(!check_rights(R_MOD,0) && !check_rights(R_BAN)) return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/serverip = "[world.internet_address]:[world.port]"
@@ -44,12 +44,12 @@
computerid = bancid
ip = banip
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id FROM erro_player WHERE ckey = :t_ckey", list("t_ckey",ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id FROM erro_player WHERE ckey = '[ckey]'")
query.Execute()
var/validckey = 0
if(query.NextRow())
validckey = 1
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(!validckey)
if(!banned_mob || (banned_mob && !IsGuestKey(banned_mob.key))) //VOREStation Edit Start.
var/confirm = tgui_alert(usr, "This ckey hasn't been seen, are you sure?", "Confirm Badmin", list("Yes", "No"))
@@ -80,14 +80,13 @@
adminwho += ", [C]"
reason = sql_sanitize_text(reason)
var/list/sqlargs = list("t_bantype" = bantype_str, "t_reason" = reason, "t_job" = job, "t_ckey" = ckey, "t_a_ckey" = a_ckey, "t_who" = who, "t_adminwho" = adminwho) //CHOMPEdit TGSQL
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]', :t_bantype, :t_reason, :t_job, [(duration)?"[duration]":"0"], [(rounds)?"[rounds]":"0"], Now() + INTERVAL [(duration>0) ? duration : 0] MINUTE, :t_ckey, '[computerid]', '[ip]', :t_a_ckey, '[a_computerid]', '[a_ip]', :t_who, :t_adminwho, '', null, null, null, null, null)" //CHOMPEdit TGSQL
var/datum/db_query/query_insert = SSdbcore.NewQuery(sql,sqlargs) //CHOMPEdit TGSQL
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/datum/db_query/query_insert = SSdbcore.NewQuery(sql)
query_insert.Execute()
to_chat(usr, span_filter_adminlog("[span_blue("Ban saved to database.")]"))
message_admins("[key_name_admin(usr)] has added a [bantype_str] for [ckey] [(job)?"([job])":""] [(duration > 0)?"([duration] minutes)":""] with the reason: \"[reason]\" to the ban database.",1)
qdel(query_insert) //CHOMPEdit TGSQL
qdel(query_insert)
/datum/admins/proc/DB_ban_unban(var/ckey, var/bantype, var/job = "")
@@ -121,23 +120,23 @@
else
bantype_sql = "bantype = '[bantype_str]'"
var/sql = "SELECT id FROM erro_ban WHERE ckey = :t_ckey AND [bantype_sql] AND (unbanned is null OR unbanned = false)" //CHOMPEdit TGSQL
var/sql = "SELECT id FROM erro_ban WHERE ckey = '[ckey]' AND [bantype_sql] AND (unbanned is null OR unbanned = false)"
if(job)
sql += " AND job = '[job]'"
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/ban_id
var/ban_number = 0 //failsafe
var/datum/db_query/query = SSdbcore.NewQuery(sql, list("t_ckey" = ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery(sql)
query.Execute()
while(query.NextRow())
ban_id = query.item[1]
ban_number++;
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(ban_number == 0)
to_chat(usr, span_filter_adminlog("[span_red("Database update failed due to no bans fitting the search criteria. If this is not a legacy ban you should contact the database admin.")]"))
return
@@ -162,7 +161,7 @@
to_chat(usr, "Cancelled")
return
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, duration, reason FROM erro_ban WHERE id = [banid]") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, duration, reason FROM erro_ban WHERE id = [banid]")
query.Execute()
var/eckey = usr.ckey //Editing admin ckey
@@ -176,9 +175,10 @@
reason = query.item[3]
else
to_chat(usr, span_filter_adminlog("Invalid ban id. Contact the database admin"))
qdel(query) //CHOMPEdit TGSQL
qdel(query)
return
qdel(query) //CHOMPEdit TGSQL
qdel(query)
reason = sql_sanitize_text(reason)
var/value
@@ -190,22 +190,22 @@
if(!value)
to_chat(usr, "Cancelled")
return
var/list/sqlargs = list("t_reason" = value, "t_edits" = "- [eckey] changed ban reason from <cite><b>\\\"[reason]\\\"</b></cite> to <cite><b>\\\"[value]\\\"</b></cite><BR>") //CHOMPEdit TGSQL
var/datum/db_query/update_query = SSdbcore.NewQuery("UPDATE erro_ban SET reason = '[value]', edits = CONCAT(edits,:t_edits) WHERE id = [banid]", sqlargs) //CHOMPEdit TGSQL
var/datum/db_query/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]")
update_query.Execute()
message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s reason from [reason] to [value]",1)
qdel(update_query) //CHOMPEdit TGSQL
qdel(update_query)
if("duration")
if(!value)
value = tgui_input_number(usr, "Insert the new duration (in minutes) for [pckey]'s ban", "New Duration", "[duration]", null)
if(!isnum(value) || !value)
to_chat(usr, "Cancelled")
return
var/list/sqlargs = list("t_edits" = "- [eckey] changed ban duration from [duration] to [value]<br>") //CHOMPEdit TGSQL
var/datum/db_query/update_query = SSdbcore.NewQuery("UPDATE erro_ban SET duration = [value], edits = CONCAT(edits,:t_edits), expiration_time = DATE_ADD(bantime, INTERVAL [value] MINUTE) WHERE id = [banid]",sqlargs) //CHOMPEdit TGSQL
var/datum/db_query/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]")
message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s duration from [duration] to [value]",1)
update_query.Execute()
qdel(update_query) //CHOMPEdit TGSQL
qdel(update_query)
if("unban")
if(tgui_alert(usr, "Unban [pckey]?", "Unban?", list("Yes", "No")) == "Yes")
DB_ban_unban_by_id(banid)
@@ -220,18 +220,18 @@
var/sql = "SELECT ckey FROM erro_ban WHERE id = [id]"
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/ban_number = 0 //failsafe
var/pckey
var/datum/db_query/query = SSdbcore.NewQuery(sql) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery(sql)
query.Execute()
while(query.NextRow())
pckey = query.item[1]
ban_number++;
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(ban_number == 0)
to_chat(usr, span_filter_adminlog("[span_red("Database update failed due to a ban id not being present in the database.")]"))
return
@@ -246,13 +246,12 @@
var/unban_ckey = src.owner:ckey
var/unban_computerid = src.owner:computer_id
var/unban_ip = src.owner:address
var/list/sqlargs = list("t_ckey" = unban_ckey) //CHOMPEdit TGSQL
var/sql_update = "UPDATE erro_ban SET unbanned = 1, unbanned_datetime = Now(), unbanned_ckey = :t_ckey, unbanned_computerid = '[unban_computerid]', unbanned_ip = '[unban_ip]' WHERE id = [id]" //CHOMPEdit TGSQL
var/sql_update = "UPDATE erro_ban SET unbanned = 1, unbanned_datetime = Now(), unbanned_ckey = '[unban_ckey]', unbanned_computerid = '[unban_computerid]', unbanned_ip = '[unban_ip]' WHERE id = [id]"
message_admins("[key_name_admin(usr)] has lifted [pckey]'s ban.",1)
var/datum/db_query/query_update = SSdbcore.NewQuery(sql_update,sqlargs) //CHOMPEdit TGSQL
var/datum/db_query/query_update = SSdbcore.NewQuery(sql_update)
query_update.Execute()
qdel(query_update) //CHOMPEdit TGSQL
qdel(query_update)
/client/proc/DB_ban_panel()
set category = "Admin.Moderation"
@@ -272,7 +271,7 @@
if(!check_rights(R_BAN)) return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
to_chat(usr, span_filter_adminlog("[span_red("Failed to establish database connection")]"))
return
@@ -370,26 +369,21 @@
var/ipsearch = ""
var/cidsearch = ""
var/bantypesearch = ""
//CHOMPEdit Begin
var/list/sqlargs = list()
if(!match)
if(adminckey)
adminsearch = "AND a_ckey = :t_adminckey "
sqlargs["t_adminckey"] = adminckey
adminsearch = "AND a_ckey = '[adminckey]' "
if(playerckey)
playersearch = "AND ckey = :t_playerckey "
sqlargs["t_playerckey"] = playerckey //CHOMPEdit End
playersearch = "AND ckey = '[playerckey]' "
if(playerip)
ipsearch = "AND ip = '[playerip]' "
if(playercid)
cidsearch = "AND computerid = '[playercid]' "
else
if(adminckey && length(adminckey) >= 3) //CHOMPEdit Begin
adminsearch = "AND a_ckey LIKE CONCAT(:t_adminckey,'%') "
sqlargs["t_adminckey"] = adminckey
if(adminckey && length(adminckey) >= 3)
adminsearch = "AND a_ckey LIKE '[adminckey]%' "
if(playerckey && length(playerckey) >= 3)
playersearch = "AND ckey LIKE CONCAT(:t_playerckey,'%') "
sqlargs["t_playerckey"] = playerckey //CHOMPEdit End
playersearch = "AND ckey LIKE '[playerckey]%' "
if(playerip && length(playerip) >= 3)
ipsearch = "AND ip LIKE '[playerip]%' "
if(playercid && length(playercid) >= 7)
@@ -408,7 +402,7 @@
else
bantypesearch += "'PERMABAN' "
var/datum/db_query/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", sqlargs) //CHOMPEdit TGSQL
var/datum/db_query/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")
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)
@@ -487,6 +481,6 @@
output += "</tr>"
output += "</table></div>"
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
usr << browse("<html>[output]</html>","window=lookupbans;size=900x700")

View File

@@ -56,7 +56,7 @@
log_misc("Key [ckeytext] cid not checked. Non-Numeric: [computer_id]")
failedcid = 1
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, ip, computerid, a_ckey, reason, expiration_time, duration, bantime, bantype FROM erro_ban WHERE (ckey = :t_ckey [ipquery] [cidquery]) AND (bantype = 'PERMABAN' OR (bantype = 'TEMPBAN' AND expiration_time > Now())) AND isnull(unbanned)", list("t_ckey" = ckeytext)) //CHOMPEdit TGSQL
var/datum/db_query/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)")
query.Execute()
@@ -76,9 +76,9 @@
expires = " The ban is for [duration] minutes and expires on [expiration] (server time)."
var/desc = "\nReason: You, or another user of this computer or connection ([pckey]) is banned from playing here. The ban reason is:\n[reason]\nThis ban was applied by [ackey] on [bantime], [expires]"
qdel(query) //CHOMPEdit TGSQL
qdel(query)
return list("reason"="[bantype]", "desc"="[desc]")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if (failedcid)
message_admins("[key] has logged in with a blank computer id in the ban check.")
if (failedip)

View File

@@ -112,14 +112,14 @@ var/list/admin_ranks = list() //list of all ranks with associated rights
//The current admin system uses SQL
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
error("Failed to connect to database in load_admins(). Reverting to legacy system.")
log_misc("Failed to connect to database in load_admins(). Reverting to legacy system.")
CONFIG_SET(flag/admin_legacy_system, TRUE)
load_admins()
return
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, rank, level, flags FROM erro_admin") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, rank, level, flags FROM erro_admin")
query.Execute()
while(query.NextRow())
var/ckey = query.item[1]
@@ -135,7 +135,7 @@ var/list/admin_ranks = list() //list of all ranks with associated rights
//find the client for a ckey if they are connected and associate them with the new admin datum
D.associate(GLOB.directory[ckey])
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(!admin_datums)
error("The database query in load_admins() resulted in no admins being added to the list. Reverting to legacy system.")
log_misc("The database query in load_admins() resulted in no admins being added to the list. Reverting to legacy system.")

View File

@@ -119,7 +119,7 @@
dat += "</td></tr>"
dat += "</table>"
qdel(query) // CHOMPEdit
qdel(query)
usr << browse("<html>[dat]</html>", "window=library")
onclose(usr, "library")

View File

@@ -77,7 +77,7 @@ DEBUG
return
//Job permabans
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_PERMABAN' AND isnull(unbanned)") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_PERMABAN' AND isnull(unbanned)")
query.Execute()
while(query.NextRow())
@@ -85,9 +85,9 @@ DEBUG
var/job = query.item[2]
jobban_keylist.Add("[ckey] - [job]")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
//Job tempbans
var/datum/db_query/query1 = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_TEMPBAN' AND isnull(unbanned) AND expiration_time > Now()") //CHOMPEdit TGSQL
var/datum/db_query/query1 = SSdbcore.NewQuery("SELECT ckey, job FROM erro_ban WHERE bantype = 'JOB_TEMPBAN' AND isnull(unbanned) AND expiration_time > Now()")
query1.Execute()
while(query1.NextRow())
@@ -95,7 +95,7 @@ DEBUG
var/job = query1.item[2]
jobban_keylist.Add("[ckey] - [job]")
qdel(query1) //CHOMPEdit TGSQL
qdel(query1)
/proc/jobban_savebanfile()
var/savefile/S=new("data/job_full.ban")

View File

@@ -56,7 +56,7 @@
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
to_chat(usr, span_filter_adminlog("[span_red("Failed to establish database connection")]"))
return
@@ -71,7 +71,7 @@
if(!istext(adm_ckey) || !istext(new_rank))
return
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id FROM erro_admin WHERE ckey = '[adm_ckey]'") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id FROM erro_admin WHERE ckey = '[adm_ckey]'")
select_query.Execute()
var/new_admin = 1
@@ -79,23 +79,24 @@
while(select_query.NextRow())
new_admin = 0
admin_id = text2num(select_query.item[1])
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(new_admin)
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO `erro_admin` (`id`, `ckey`, `rank`, `level`, `flags`) VALUES (null, '[adm_ckey]', '[new_rank]', -1, 0)") //CHOMPEdit TGSQL
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO `erro_admin` (`id`, `ckey`, `rank`, `level`, `flags`) VALUES (null, '[adm_ckey]', '[new_rank]', -1, 0)")
insert_query.Execute()
qdel(insert_query) //CHOMPEdit TGSQL
var/datum/db_query/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
qdel(insert_query)
var/datum/db_query/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]');")
log_query.Execute()
qdel(log_query) //CHOMPEdit TGSQL
qdel(log_query)
to_chat(usr, span_filter_adminlog("[span_blue("New admin added.")]"))
else
if(!isnull(admin_id) && isnum(admin_id))
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET rank = '[new_rank]' WHERE id = [admin_id]") //CHOMPEdit TGSQL
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET rank = '[new_rank]' WHERE id = [admin_id]")
insert_query.Execute()
qdel(insert_query) //CHOMPEdit TGSQL
var/datum/db_query/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
qdel(insert_query)
var/datum/db_query/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]');")
log_query.Execute()
qdel(log_query) //CHOMPEdit TGSQL
qdel(log_query)
to_chat(usr, span_filter_adminlog("[span_blue("Admin rank changed.")]"))
/datum/admins/proc/log_admin_permission_modification(var/adm_ckey, var/new_permission)
@@ -109,7 +110,7 @@
return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
to_chat(usr, span_filter_adminlog("[span_red("Failed to establish database connection!")]"))
return
@@ -127,7 +128,7 @@
if(!istext(adm_ckey) || !isnum(new_permission))
return
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id, flags FROM erro_admin WHERE ckey = '[adm_ckey]'") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id, flags FROM erro_admin WHERE ckey = '[adm_ckey]'")
select_query.Execute()
var/admin_id
@@ -135,23 +136,23 @@
while(select_query.NextRow())
admin_id = text2num(select_query.item[1])
admin_rights = text2num(select_query.item[2])
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(!admin_id)
return
if(admin_rights & new_permission) //This admin already has this permission, so we are removing it.
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = [admin_rights & ~new_permission] WHERE id = [admin_id]") //CHOMPEdit TGSQL
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = [admin_rights & ~new_permission] WHERE id = [admin_id]")
insert_query.Execute()
qdel(insert_query) //CHOMPEdit TGSQL
var/datum/db_query/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
qdel(insert_query)
var/datum/db_query/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]');")
log_query.Execute()
qdel(log_query) //CHOMPEdit TGSQL
qdel(log_query)
to_chat(usr, span_filter_adminlog("[span_blue("Permission removed.")]"))
else //This admin doesn't have this permission, so we are adding it.
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = '[admin_rights | new_permission]' WHERE id = [admin_id]") //CHOMPEdit TGSQL
var/datum/db_query/insert_query = SSdbcore.NewQuery("UPDATE `erro_admin` SET flags = '[admin_rights | new_permission]' WHERE id = [admin_id]")
insert_query.Execute()
qdel(insert_query) //CHOMPEdit TGSQL
var/datum/db_query/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
qdel(insert_query)
var/datum/db_query/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]')")
log_query.Execute()
qdel(log_query) //CHOMPEdit TGSQL
qdel(log_query)
to_chat(usr, span_filter_adminlog("[span_blue("Permission added.")]"))

View File

@@ -30,7 +30,7 @@ var/inactive_keys = "None<br>"
return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
//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
var/list/inactive_ckeys = list()
if(ckeys_with_customitems.len)
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60") //CHOMPEdit TGSQL
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey, lastseen FROM erro_player WHERE datediff(Now(), lastseen) > 60")
query_inactive.Execute()
while(query_inactive.NextRow())
var/cur_ckey = query_inactive.item[1]
@@ -63,16 +63,16 @@ var/inactive_keys = "None<br>"
if(ckeys_with_customitems.Find(cur_ckey))
ckeys_with_customitems.Remove(cur_ckey)
inactive_ckeys[cur_ckey] = "last seen on [query_inactive.item[2]]"
qdel(query_inactive) //CHOMPEdit TGSQL
qdel(query_inactive)
//if there are ckeys left over, check whether they have a database entry at all
if(ckeys_with_customitems.len)
for(var/cur_ckey in ckeys_with_customitems)
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ckey = :t_ckey", list("t_ckey" = cur_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query_inactive = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ckey = '[cur_ckey]'")
query_inactive.Execute()
if(!length(query_inactive.rows)) //CHOMPEdit TGSQL
if(!query_inactive.rows)
inactive_ckeys += cur_ckey
qdel(query_inactive) //CHOMPEdit TGSQL
qdel(query_inactive)
if(inactive_ckeys.len)
inactive_keys = ""
for(var/cur_key in inactive_ckeys)

View File

@@ -0,0 +1,39 @@
// Will hoepfully fix the database when it breaks
// Use case: if the server is left in the lobby for long enough, players that join will see player_age = 0, restricting them from all age-locked jobs.
/client/proc/dbcon_fix()
set name = "Fix Database Connection"
set category = "Server"
set desc = "Experimental: Will hopefully perform a one-button fix for a database connection that has timed out."
if(!check_rights(R_ADMIN|R_DEBUG|R_FUN))
to_chat(src, "You must be an admin to do this.")
return FALSE
log_admin("Attempting to fix database connection")
if(SSdbcore.IsConnected())
SSdbcore.Disconnect()
else
log_admin("Database already disconnected")
establish_db_connection()
var/errno = SSdbcore.ErrorMsg()
if(errno)
log_admin("Database connection returned error message `[errno]`. Aborting.")
return FALSE
if(!SSdbcore.IsConnected())
log_admin("Database could not be reconnected! Aborting.")
return FALSE
log_admin("Database reconnected. Fixing player ages...")
var/num = 0
for(var/client/C in GLOB.clients)
C.log_client_to_db()
errno = SSdbcore.ErrorMsg()
if(errno)
log_admin("Database connection returned error message `[errno]` after adjusting player ages for [num] players. [C] was being updated when the error struck. Aborting.")
return FALSE
if(C.player_age)
num++
log_admin("Successfully updated non-0 player age for [num] clients.")
return FALSE

View File

@@ -12,7 +12,7 @@
CONFIG_SET(flag/panic_bunker, !CONFIG_GET(flag/panic_bunker))
log_and_message_admins("has toggled the Panic Bunker, it is now [(CONFIG_GET(flag/panic_bunker) ? "on":"off")].", src)
if (CONFIG_GET(flag/panic_bunker) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
if (CONFIG_GET(flag/panic_bunker) && (!SSdbcore || !SSdbcore.IsConnected()))
message_admins("The database is not connected! Panic bunker will not work until the connection is reestablished.")
feedback_add_details("admin_verb","PANIC") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -26,7 +26,7 @@
CONFIG_SET(flag/paranoia_logging, !CONFIG_GET(flag/paranoia_logging))
log_and_message_admins("has toggled Paranoia Logging, it is now [(CONFIG_GET(flag/paranoia_logging) ? "on":"off")].", src)
if (CONFIG_GET(flag/paranoia_logging) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
if (CONFIG_GET(flag/paranoia_logging) && (!SSdbcore || !SSdbcore.IsConnected()))
message_admins("The database is not connected! Paranoia logging will not be able to give 'player age' (time since first connection) warnings, only Byond account warnings.")
feedback_add_details("admin_verb","PARLOG") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -40,6 +40,6 @@
CONFIG_SET(flag/ip_reputation, !CONFIG_GET(flag/ip_reputation))
log_and_message_admins("has toggled IP reputation checks, it is now [(CONFIG_GET(flag/ip_reputation) ? "on":"off")].", src)
if (CONFIG_GET(flag/ip_reputation) && (!SSdbcore.IsConnected())) //CHOMPEdit TGSQL
if (CONFIG_GET(flag/ip_reputation) && (!SSdbcore || !SSdbcore.IsConnected()))
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!

View File

@@ -145,18 +145,17 @@
var/sql_discord = sql_sanitize_text(their_id)
var/sql_ckey = sql_sanitize_text(ckey)
var/datum/db_query/query = SSdbcore.NewQuery("UPDATE erro_player SET discord_id = :t_discord_id WHERE ckey = :t_ckey", list("t_discord_id" = sql_discord, "t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("UPDATE erro_player SET discord_id = '[sql_discord]' WHERE ckey = '[sql_ckey]'")
if(query.Execute())
to_chat(src, span_notice("Registration complete! Thank you for taking the time to register your Discord ID."))
log_and_message_admins("[ckey] has registered their Discord ID. Their Discord snowflake ID is: [their_id]", src) //YW EDIT
admin_chat_message(message = "[ckey] has registered their Discord ID. Their Discord is: <@[their_id]>", color = "#4eff22") //YW EDIT
notes_add(ckey, "Discord ID: [their_id]")
world.VgsAddMemberRole(their_id)
qdel(query) //CHOMPEdit TGSQL
else
to_chat(src, span_warning("There was an error registering your Discord ID in the database. Contact an administrator."))
log_and_message_admins("[ckey] failed to register their Discord ID. Their Discord snowflake ID is: [their_id]. Is the database connected?", src)
qdel(query) //CHOMPEdit TGSQL
qdel(query)
return
//VOREStation Add End
if(href_list["reload_statbrowser"])
@@ -401,12 +400,12 @@
/proc/get_player_age(key)
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return null
var/sql_ckey = sql_sanitize_text(ckey(key))
var/datum/db_query/query = SSdbcore.NewQuery("SELECT datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = :t_ckey", list("t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'")
query.Execute()
//CHOMPEdit Begin
if(query.NextRow())
@@ -425,12 +424,12 @@
return
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/sql_ckey = sql_sanitize_text(src.ckey)
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = :t_ckey", list("t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'")
query.Execute()
var/sql_id = 0
player_age = 0 // New players won't have an entry so knowing we have a connection we set this to zero to be updated if their is a record.
@@ -438,28 +437,31 @@
sql_id = query.item[1]
player_age = text2num(query.item[2])
break
qdel(query) //CHOMPEdit TGSQL
qdel(query)
account_join_date = sanitizeSQL(findJoinDate())
if(account_join_date && SSdbcore.IsConnected()) //CHOMPEdit TGSQL
var/datum/db_query/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')") //CHOMPEdit TGSQL
if(account_join_date && SSdbcore.IsConnected())
var/datum/db_query/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),'[account_join_date]')")
if(query_datediff.Execute() && query_datediff.NextRow())
account_age = text2num(query_datediff.item[1])
qdel(query_datediff) //CHOMPEdit TGSQL
qdel(query_datediff)
var/datum/db_query/query_ip = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ip = '[address]'") //CHOMPEdit TGSQL
var/datum/db_query/query_ip = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE ip = '[address]'")
query_ip.Execute()
related_accounts_ip = ""
while(query_ip.NextRow())
related_accounts_ip += "[query_ip.item[1]], "
break
qdel(query_ip) //CHOMPEdit TGSQL
var/datum/db_query/query_cid = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE computerid = '[computer_id]'") //CHOMPEdit TGSQL
qdel(query_ip)
var/datum/db_query/query_cid = SSdbcore.NewQuery("SELECT ckey FROM erro_player WHERE computerid = '[computer_id]'")
query_cid.Execute()
related_accounts_cid = ""
while(query_cid.NextRow())
related_accounts_cid += "[query_cid.item[1]], "
break
qdel(query_cid) //CHOMPEdit TGSQL
qdel(query_cid)
//Just the standard check to see if it's actually a number
if(sql_id)
if(istext(sql_id))
@@ -509,7 +511,7 @@
log_admin("Couldn't perform IP check on [key] with [address]")
// VOREStation Edit Start - Department Hours
var/datum/db_query/query_hours = SSdbcore.NewQuery("SELECT department, hours, total_hours FROM vr_player_hours WHERE ckey = :t_ckey", list("t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query_hours = SSdbcore.NewQuery("SELECT department, hours, total_hours FROM vr_player_hours WHERE ckey = '[sql_ckey]'")
if(query_hours.Execute())
while(query_hours.NextRow())
department_hours[query_hours.item[1]] = text2num(query_hours.item[2])
@@ -519,23 +521,23 @@
log_debug("Error loading play hours for [ckey]: [error_message]")
tgui_alert_async(src, "The query to load your existing playtime failed. Screenshot this, give the screenshot to a developer, and reconnect, otherwise you may lose any recorded play hours (which may limit access to jobs). ERROR: [error_message]", "PROBLEMS!!")
// VOREStation Edit End - Department Hours
qdel(query_hours) //CHOMPEdit TGSQL
qdel(query_hours)
if(sql_id)
//Player already identified previously, we need to just update the 'lastseen', 'ip' and 'computer_id' variables
var/datum/db_query/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
var/datum/db_query/query_update = SSdbcore.NewQuery("UPDATE erro_player SET lastseen = Now(), ip = '[sql_ip]', computerid = '[sql_computerid]', lastadminrank = '[sql_admin_rank]' WHERE id = [sql_id]")
query_update.Execute()
qdel(query_update) //CHOMPEdit TGSQL
qdel(query_update)
else
//New player!! Need to insert all the stuff
var/datum/db_query/query_insert = SSdbcore.NewQuery("INSERT INTO erro_player (id, ckey, firstseen, lastseen, ip, computerid, lastadminrank) VALUES (null, :t_ckey, Now(), Now(), '[sql_ip]', '[sql_computerid]', '[sql_admin_rank]')", list("t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/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]')")
query_insert.Execute()
qdel(query_insert) //CHOMPEdit TGSQL
qdel(query_insert)
//Logging player access
var/serverip = "[world.internet_address]:[world.port]"
var/datum/db_query/query_accesslog = SSdbcore.NewQuery("INSERT INTO `erro_connection_log`(`id`,`datetime`,`serverip`,`ckey`,`ip`,`computerid`) VALUES(null,Now(),'[serverip]',:t_ckey,'[sql_ip]','[sql_computerid]');", list("t_ckey" = sql_ckey)) //CHOMPEdit TGSQL
var/datum/db_query/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]');")
query_accesslog.Execute()
qdel(query_accesslog) //CHOMPEdit TGSQL
qdel(query_accesslog)
#undef UPLOAD_LIMIT
#undef MIN_CLIENT_VERSION

View File

@@ -31,7 +31,6 @@
var/category = "Any"
var/author
var/SQLquery
var/list/SQLargs //CHOMPEdit TGSQL
/obj/machinery/librarypubliccomp/attack_hand(var/mob/user as mob)
usr.set_machine(src)
@@ -45,7 +44,7 @@
<A href='byond://?src=\ref[src];search=1'>\[Start Search\]</A><BR>"}
if(1)
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
dat += span_red(span_bold("ERROR") + ": Unable to contact External Archive. Please contact your system administrator for assistance.") + "<BR>"
else if(!SQLquery)
dat += span_red(span_bold("ERROR") + ": Malformed search request. Please contact your system administrator for assistance.") + "<BR>"
@@ -53,7 +52,7 @@
dat += {"<table>
<tr><td>AUTHOR</td><td>TITLE</td><td>CATEGORY</td><td>SS<sup>13</sup>BN</td></tr>"}
var/datum/db_query/query = SSdbcore.NewQuery(SQLquery, SQLargs) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery(SQLquery)
query.Execute()
while(query.NextRow())
@@ -97,16 +96,10 @@
author = sanitizeSQL(author)
if(href_list["search"])
SQLquery = "SELECT author, title, category, id FROM library WHERE "
SQLargs = list() //CHOMPEdit begin
if(category == "Any")
SQLquery += "author LIKE '%:t_author%' AND title LIKE '%:t_title%'"
SQLargs["t_author"] = author
SQLargs["t_title"] = title
SQLquery += "author LIKE '%[author]%' AND title LIKE '%[title]%'"
else
SQLquery += "author LIKE CONCAT('%',:t_author,'%') AND title LIKE CONCAT('%',:t_title,'%') AND category=:t_category"
SQLargs["t_author"] = author
SQLargs["t_title"] = title
SQLargs["t_category"] = category //CHOMPEdit End
SQLquery += "author LIKE '%[author]%' AND title LIKE '%[title]%' AND category='[category]'"
screenstate = 1
if(href_list["back"])
@@ -285,13 +278,13 @@
//dat += "<h3>" + span_red("arning: System Administrator has slated this archive for removal. Personal uploads should be taken to the NT board of internal literature.") + "</h3>" //VOREStation Removal
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
dat += span_red(span_bold("ERROR") + ": Unable to contact External Archive. Please contact your system administrator for assistance.")
else
dat += {"<A href='byond://?src=\ref[src];orderbyid=1'>(Order book by SS<sup>13</sup>BN)</A><BR><BR>
<table>
<tr><td><A href='byond://?src=\ref[src];sort=author>AUTHOR</A></td><td><A href='byond://?src=\ref[src];sort=title>TITLE</A></td><td><A href='byond://?src=\ref[src];sort=category>CATEGORY</A></td><td></td></tr>"}
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category FROM library ORDER BY :t_sortby", list("t_sortby" = sortby)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category FROM library ORDER BY [sortby]")
query.Execute()
while(query.NextRow())
@@ -300,7 +293,7 @@
var/title = query.item[3]
var/category = query.item[4]
dat += "<tr><td>[author]</td><td>[title]</td><td>[category]</td><td><A href='byond://?src=\ref[src];targetid=[id]'>\[Order\]</A></td></tr>"
qdel(query) //CHOMPEdit TGSQL
qdel(query)
dat += "</table>"
dat += "<BR><A href='byond://?src=\ref[src];switchscreen=0'>(Return to main menu)</A><BR>"
@@ -339,7 +332,7 @@
dat += "<tr><td>[author]</td><td>[title]</td><td>[category]</td><td><A href='byond://?src=\ref[src];delid=[id]'>\[Del\]</A>"
dat += "</td></tr>"
dat += "</table>"
qdel(query) // CHOMPEdit
qdel(query)
dat += "<BR><A href='byond://?src=\ref[src];switchscreen=0'>(Return to main menu)</A><BR>"
user << browse("<html>[dat]</html>", "window=library")
@@ -442,33 +435,32 @@
tgui_alert_async(usr, "This book has been rejected from the database. Aborting!")
else
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
tgui_alert_async(usr, "Connection to Archive has been severed. Aborting.")
else
/*
var/sqltitle = dbcon.Quote(scanner.cache.name)
var/sqlauthor = dbcon.Quote(scanner.cache.author)
var/sqlcontent = dbcon.Quote(scanner.cache.dat)
var/sqlcategory = dbcon.Quote(upload_category)
var/sqltitle = SSdbcore.Quote(scanner.cache.name)
var/sqlauthor = SSdbcore.Quote(scanner.cache.author)
var/sqlcontent = SSdbcore.Quote(scanner.cache.dat)
var/sqlcategory = SSdbcore.Quote(upload_category)
*/
var/list/sql_args = list("t_title" = scanner.cache.name, "t_author" = scanner.cache.author, "t_content" = scanner.cache.dat, "t_category" = upload_category) //CHOMPEdit TGSQL
/*var/sqltitle = sanitizeSQL(scanner.cache.name) CHOMPEdit TGSQL
var/sqltitle = sanitizeSQL(scanner.cache.name)
var/sqlauthor = sanitizeSQL(scanner.cache.author)
var/sqlcontent = sanitizeSQL(scanner.cache.dat)
var/sqlcategory = sanitizeSQL(upload_category)*/
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO library (author, title, content, category) VALUES (:t_author, :t_title, :t_content, :t_category)", sql_args) //CHOMPEdit TGSQL
var/sqlcategory = sanitizeSQL(upload_category)
var/datum/db_query/query = SSdbcore.NewQuery("INSERT INTO library (author, title, content, category) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]')")
if(!query.Execute())
to_chat(usr,query.ErrorMsg())
else
log_game("[usr.name]/[usr.key] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] signs")
tgui_alert_async(usr, "Upload Complete.")
qdel(query) //CHOMPEdit TGSQL
qdel(query)
//VOREStation Edit End
if(href_list["targetid"])
var/sqlid = sanitizeSQL(href_list["targetid"])
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
tgui_alert_async(usr, "Connection to Archive has been severed. Aborting.")
if(bibledelay)
for (var/mob/V in hearers(src))
@@ -477,7 +469,7 @@
bibledelay = 1
spawn(6)
bibledelay = 0
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM library WHERE id=[sqlid]") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM library WHERE id=[sqlid]")
query.Execute()
while(query.NextRow())
@@ -493,7 +485,20 @@
B.item_state = B.icon_state
src.visible_message("[src]'s printer hums as it produces a completely bound book. How did it do that?")
break
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(href_list["delid"])
if(!check_rights(R_ADMIN))
return
var/sqlid = sanitizeSQL(href_list["delid"])
establish_db_connection()
if(!SSdbcore.IsConnected())
tgui_alert_async(usr, "Connection to Archive has been severed. Aborting.")
else
var/datum/db_query/query = SSdbcore.NewQuery("DELETE FROM library WHERE id=[sqlid]")
query.Execute()
log_admin("[usr.key] has deleted the book [sqlid]") //VOREStation Addition
qdel(query)
if(href_list["orderbyid"])
var/orderid = tgui_input_number(usr, "Enter your order:")

View File

@@ -81,17 +81,17 @@
if(!IsGuestKey(src.key))
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/isadmin = 0
if(src.client && src.client.holder)
isadmin = 1
var/datum/db_query/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 = :t_ckey) AND id NOT IN (SELECT pollid FROM erro_poll_textreply WHERE ckey = :t_ckey)",list("t_ckey" = ckey)) //CHOMPEdit TGSQL
var/datum/db_query/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]\")")
query.Execute()
var/newpoll = 0
while(query.NextRow())
newpoll = 1
break
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(newpoll)
output += "<p><b><a href='byond://?src=\ref[src];showpoll=1'>Show Player Polls</A><br>(NEW!)</b></p>" //ChompEDIT - fixed height
else
@@ -251,17 +251,17 @@
if(href_list["privacy_poll"])
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/voted = 0
//First check if the person has not voted yet.
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey=:t_ckey", list("t_ckey" = src.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'")
query.Execute()
while(query.NextRow())
voted = 1
break
qdel(query) //CHOMPEdit TGSQL
qdel(query)
//This is a safety switch, so only valid options pass through
var/option = "UNKNOWN"
switch(href_list["privacy_poll"])
@@ -281,9 +281,8 @@
return
if(!voted)
var/list/sqlargs = list("t_ckey" = src.ckey, "t_option" = "[option]") //CHOMPEdit TGSQL
var/sql = "INSERT INTO erro_privacy VALUES (null, Now(), :t_ckey, :t_option)" //CHOMPEdit TGSQL
var/datum/db_query/query_insert = SSdbcore.NewQuery(sql,sqlargs) //CHOMPEdit TGSQL
var/sql = "INSERT INTO erro_privacy VALUES (null, Now(), '[src.ckey]', '[option]')"
var/datum/db_query/query_insert = SSdbcore.NewQuery(sql)
query_insert.Execute()
to_chat(usr, span_bold("Thank you for your vote!"))
qdel(query_insert)

View File

@@ -1,16 +1,16 @@
/mob/new_player/proc/handle_privacy_poll()
establish_db_connection()
if(!SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected())
return
var/voted = 0
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey=:t_ckey", list("t_ckey" = src.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT * FROM erro_privacy WHERE ckey='[src.ckey]'")
query.Execute()
while(query.NextRow())
voted = 1
break
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(!voted)
privacy_poll()
@@ -48,12 +48,12 @@
/mob/new_player/proc/handle_player_polling()
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/isadmin = 0
if(src.client && src.client.holder)
isadmin = 1
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id, question FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT id, question FROM erro_poll_question WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/output = "<div align='center'><B>Player polls</B>"
@@ -72,7 +72,7 @@
pollquestion = select_query.item[2]
output += "<tr bgcolor='[ (i % 2 == 1) ? color1 : color2 ]'><td><a href=\"byond://?src=\ref[src];pollid=[pollid]\"><b>[pollquestion]</b></a></td></tr>"
i++
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
output += "</table>"
src << browse("<html>[output]</html>","window=playerpolllist;size=500x300")
@@ -82,9 +82,9 @@
/mob/new_player/proc/poll_player(var/pollid = -1)
if(pollid == -1) return
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid]")
select_query.Execute()
var/pollstarttime = ""
@@ -101,7 +101,7 @@
polltype = select_query.item[4]
found = 1
break
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(!found)
to_chat(usr, span_red("Poll question details not found."))
return
@@ -109,7 +109,7 @@
switch(polltype)
//Polls that have enumerated options
if("OPTION")
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
var/voted = 0
@@ -118,17 +118,17 @@
votedoptionid = text2num(voted_query.item[1])
voted = 1
break
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
var/list/datum/polloption/options = list()
var/datum/db_query/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]")
options_query.Execute()
while(options_query.NextRow())
var/datum/polloption/PO = new()
PO.optionid = text2num(options_query.item[1])
PO.optiontext = options_query.item[2]
options += PO
qdel(options_query) //CHOMPEdit TGSQL
qdel(options_query)
var/output = "<div align='center'><B>Player poll</B>"
output +="<hr>"
output += span_bold("Question: [pollquestion]") + "<br>"
@@ -162,7 +162,7 @@
//Polls with a text input
if("TEXT")
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT replytext FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT replytext FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
var/voted = 0
@@ -171,7 +171,7 @@
vote_text = voted_query.item[1]
voted = 1
break
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
var/output = "<div align='center'><B>Player poll</B>"
output +="<hr>"
@@ -204,7 +204,7 @@
//Polls with a text input
if("NUMVAL")
var/datum/db_query/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 = :t_ckey AND o.id = v.optionid", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/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")
voted_query.Execute()
var/output = "<div align='center'><B>Player poll</B>"
@@ -220,7 +220,7 @@
var/rating = voted_query.item[2]
output += "<br><b>[optiontext] - [rating]</b>"
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
if(!voted) //Only make this a form if we have not voted yet
output += "<form name='cardcomp' action='?src=\ref[src]' method='get'>"
output += "<input type='hidden' name='src' value='\ref[src]'>"
@@ -230,7 +230,7 @@
var/minid = 999999
var/maxid = 0
var/datum/db_query/option_query = SSdbcore.NewQuery("SELECT id, text, minval, maxval, descmin, descmid, descmax FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/option_query = SSdbcore.NewQuery("SELECT id, text, minval, maxval, descmin, descmid, descmax FROM erro_poll_option WHERE pollid = [pollid]")
option_query.Execute()
while(option_query.NextRow())
var/optionid = text2num(option_query.item[1])
@@ -264,7 +264,7 @@
output += "<option value='[j]'>[j]</option>"
output += "</select>"
qdel(option_query) //CHOMPEdit TGSQL
qdel(option_query)
output += "<input type='hidden' name='minid' value='[minid]'>"
output += "<input type='hidden' name='maxid' value='[maxid]'>"
@@ -273,7 +273,7 @@
src << browse("<html>[output]</html>","window=playerpoll;size=500x500")
if("MULTICHOICE")
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
var/list/votedfor = list()
@@ -281,12 +281,12 @@
while(voted_query.NextRow())
votedfor.Add(text2num(voted_query.item[1]))
voted = 1
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
var/list/datum/polloption/options = list()
var/maxoptionid = 0
var/minoptionid = 0
var/datum/db_query/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]")
options_query.Execute()
while(options_query.NextRow())
var/datum/polloption/PO = new()
@@ -297,7 +297,7 @@
if(PO.optionid < minoptionid || !minoptionid)
minoptionid = PO.optionid
options += PO
qdel(options_query) //CHOMPEdit TGSQL
qdel(options_query)
if(select_query.item[5])
multiplechoiceoptions = text2num(select_query.item[5])
@@ -343,9 +343,9 @@
if(!isnum(pollid) || !isnum(optionid))
return
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/datum/db_query/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
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
@@ -358,12 +358,12 @@
if(select_query.item[5])
multiplechoiceoptions = text2num(select_query.item[5])
break
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]")
select_query2.Execute()
var/validoption = 0
@@ -372,21 +372,21 @@
validoption = 1
break
qdel(select_query2) //CHOMPEdit TGSQL
qdel(select_query2)
if(!validoption)
to_chat(usr, span_red("Poll option is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted += 1
if(!multichoice)
break
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
if(!multichoice && alreadyvoted)
to_chat(usr, span_red("You already voted in this poll."))
return
@@ -400,11 +400,11 @@
adminrank = usr.client.holder.rank
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank) VALUES (null, Now(), [pollid], [optionid], :t_ckey, '[usr.client.address]', '[adminrank]')", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/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]')")
insert_query.Execute()
to_chat(usr, span_blue("Vote successful."))
qdel(insert_query) //CHOMPEdit TGSQL
qdel(insert_query)
usr << browse(null,"window=playerpoll")
@@ -415,9 +415,9 @@
if(!isnum(pollid) || !istext(replytext))
return
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
@@ -427,20 +427,20 @@
return
validpoll = 1
break
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
if(alreadyvoted)
to_chat(usr, span_red("You already sent your feedback for this poll."))
return
@@ -459,11 +459,11 @@
to_chat(usr, "The text you entered was blank, contained illegal characters or was too long. Please correct the text and submit again.")
return
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_textreply (id ,datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (null, Now(), [pollid], :t_ckey, '[usr.client.address]', :t_reply, '[adminrank]')", list("t_ckey" = usr.ckey, "t_reply" = replytext)) //CHOMPEdit TGSQL
var/datum/db_query/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]')")
insert_query.Execute()
to_chat(usr, span_blue("Feedback logging successful."))
qdel(insert_query) //CHOMPEdit TGSQL
qdel(insert_query)
usr << browse(null,"window=playerpoll")
@@ -474,9 +474,9 @@
if(!isnum(pollid) || !isnum(optionid))
return
establish_db_connection()
if(SSdbcore.IsConnected()) //CHOMPEdit TGSQL
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime") //CHOMPEdit TGSQL
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
@@ -486,12 +486,12 @@
return
validpoll = 1
break
qdel(select_query) //CHOMPEdit TGSQL
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]") //CHOMPEdit TGSQL
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]")
select_query2.Execute()
var/validoption = 0
@@ -499,20 +499,20 @@
while(select_query2.NextRow())
validoption = 1
break
qdel(select_query2) //CHOMPEdit TGSQL
qdel(select_query2)
if(!validoption)
to_chat(usr, span_red("Poll option is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = :t_ckey", list("t_ckey" = usr.ckey)) //CHOMPEdit TGSQL
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
qdel(voted_query) //CHOMPEdit TGSQL
qdel(voted_query)
if(alreadyvoted)
to_chat(usr, span_red("You already voted in this poll."))
return
@@ -522,9 +522,9 @@
adminrank = usr.client.holder.rank
var/datum/db_query/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]', :t_rating)", list("t_ckey" = usr.ckey, "t_rating" = rating)) //CHOMPEdit TGSQL
var/datum/db_query/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])")
insert_query.Execute()
to_chat(usr, span_blue("Vote successful."))
qdel(insert_query) //CHOMPEdit TGSQL
qdel(insert_query)
usr << browse(null,"window=playerpoll")

View File

@@ -371,24 +371,23 @@ var/obj/machinery/blackbox_recorder/blackbox
round_end_data_gathering() //round_end time logging and some other data processing
establish_db_connection()
if(!SSdbcore.IsConnected()) return //CHOMPEdit TGSQL
if(!SSdbcore.IsConnected()) return
var/round_id
var/datum/db_query/query = SSdbcore.NewQuery("SELECT MAX(round_id) AS round_id FROM erro_feedback") //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT MAX(round_id) AS round_id FROM erro_feedback")
query.Execute()
while(query.NextRow())
round_id = query.item[1]
qdel(query) //CHOMPEdit TGSQL
qdel(query)
if(!isnum(round_id))
round_id = text2num(round_id)
round_id++
for(var/datum/feedback_variable/FV in feedback)
var/list/sqlargs = list("t_roundid" = round_id, "t_variable" = "[FV.get_variable()]", "t_value" = "[FV.get_value()]", "t_details" = "[FV.get_details()]") //CHOMPEdit TGSQL
var/sql = "INSERT INTO erro_feedback VALUES (null, Now(), :t_roundid, :t_variable, :t_value, :t_details)" //CHOMPEdit TGSQL
var/datum/db_query/query_insert = SSdbcore.NewQuery(sql, sqlargs) //CHOMPEdit TGSQL
var/sql = "INSERT INTO erro_feedback VALUES (null, Now(), [round_id], \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")"
var/datum/db_query/query_insert = SSdbcore.NewQuery(sql)
query_insert.Execute()
qdel(query_insert) //CHOMPEdit TGSQL
qdel(query_insert)
// Sanitize inputs to avoid SQL injection attacks //CHOMPEdit NOTE: This is not secure. Basic filters like this are pretty easy to bypass. Use the format for arguments used in the above.
/proc/sql_sanitize_text(var/text)

View File

@@ -91,13 +91,13 @@ GLOBAL_LIST_EMPTY(pending_discord_registrations)
/datum/tgs_chat_command/register/Run(datum/tgs_chat_user/sender, params)
// Try to find if that ID is registered to someone already
//var/sql_discord = sql_sanitize_text(sender.id) //CHOMPEdit TGSQL
var/datum/db_query/query = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE discord_id = :t_discord", list("t_discord"=sender.id)) //CHOMPEdit TGSQL
var/sql_discord = sql_sanitize_text(sender.id)
var/datum/db_query/query = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE discord_id = '[sql_discord]'")
query.Execute()
if(query.NextRow())
qdel(query) //CHOMPEdit TGSQL
qdel(query)
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."
qdel(query) //CHOMPEdit TGSQL
qdel(query)
var/key_to_find = "[ckey(params)]"
// They didn't provide anything worth looking up.
@@ -115,20 +115,20 @@ GLOBAL_LIST_EMPTY(pending_discord_registrations)
if(!user)
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) //CHOMPEdit TGSQL
var/datum/db_query/query2 = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE ckey = :t_ckey",list("t_ckey" = key_to_find)) //CHOMPEdit TGSQL
query2.Execute() //CHOMPEdit TGSQL
var/sql_ckey = sql_sanitize_text(key_to_find)
query = SSdbcore.NewQuery("SELECT discord_id FROM erro_player WHERE ckey = '[sql_ckey]'")
query.Execute()
// We somehow found their client, BUT they don't exist in the database
if(!query2.NextRow()) //CHOMPEdit TGSQL
qdel(query2) //CHOMPEdit TGSQL
if(!query.NextRow())
qdel(query)
return "[sender.friendly_name], the server's database is either not responding or there's no evidence you've ever logged in. Please contact an administrator."
// We found them in the database, AND they already have a discord ID assigned
if(query2.item[1]) //CHOMPEdit TGSQL
qdel(query2) //CHOMPEdit TGSQL
if(query.item[1])
qdel(query)
return "[sender.friendly_name], it appears you've already registered your chat and game IDs. If you've changed game or chat usernames, please contact an administrator for help."
qdel(query2) //CHOMPEdit TGSQL
qdel(query)
// Okay. We found them, they're in the DB, and they have no discord ID set.
var/message = span_notice("A request has been sent from Discord to validate your Byond username, by '[sender.friendly_name]' in '[sender.channel.friendly_name]'") + "\
<br>" + span_warning("If you did not send this request, do not click the link below, and do notify an administrator in-game or on Discord ASAP.") + "\

View File

@@ -81,7 +81,6 @@
"address" = client.address,
"computer_id" = client.computer_id,
),
// CHOMPEdit - "server" section
"server" = list(
"round_id" = GLOB.round_id,
),

View File

@@ -80,7 +80,7 @@ if number_of_defines == 0:
print(red("No defines found! This is likely an error."))
sys.exit(1)
if number_of_defines <= 900:
if number_of_defines <= 850:
print(red(f"Only found {number_of_defines} defines in {number_of_files} files! Something has likely gone wrong as the number of local defines should not be this low."))
sys.exit(1)

View File

@@ -195,7 +195,7 @@
#include "code\_global_vars\_regexes.dm"
#include "code\_global_vars\bitfields.dm"
#include "code\_global_vars\configuration.dm"
#include "code\_global_vars\logging_ch.dm"
#include "code\_global_vars\logging.dm"
#include "code\_global_vars\misc.dm"
#include "code\_global_vars\mobs.dm"
#include "code\_global_vars\time_vars.dm"