SQL update

This commit is contained in:
Markolie
2015-09-23 06:13:42 +02:00
parent d10b68363f
commit bec9fca533
23 changed files with 677 additions and 455 deletions
+3 -28
View File
@@ -1,36 +1,11 @@
// MySQL configuration
// MySQL configuration
var/sqladdress = "localhost"
var/sqlport = "3306"
var/sqldb = "paradise"
var/sqllogin = "root"
var/sqlpass = "example"
// Feedback gathering sql connection
var/sqlfdbkdb = "paradise"
var/sqlfdbkdb = "test"
var/sqlfdbklogin = "root"
var/sqlfdbkpass = "example"
var/sqlfdbkpass = ""
var/sqlfdbktableprefix = "erro_" //backwords compatibility with downstream server hosts
var/sqllogging = 0 // Should we log deaths, population stats, etc?
// Forum MySQL configuration (for use with forum account/key authentication)
// These are all default values that will load should the forumdbconfig.txt
// file fail to read for whatever reason.
var/forumsqladdress = "localhost"
var/forumsqlport = "3306"
var/forumsqldb = "tgstation"
var/forumsqllogin = "root"
var/forumsqlpass = "bleh"
var/forum_activated_group = "2"
var/forum_authenticated_group = "10"
// For FTP requests. (i.e. downloading runtime logs.)
// However it'd be ok to use for accessing attack logs and such too, which are even laggier.
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)
var/DBConnection/dbcon_old = new() //Tgstation database (Old database) - See the files in the SQL folder for information what goes where.
+3 -1
View File
@@ -2,4 +2,6 @@ var/master_mode = "extended"//"extended"
var/secret_force_mode = "secret" // if this is anything but "secret", the secret rotation will forceably choose this mode
var/wavesecret = 0 // meteor mode, delays wave progression, terrible name
var/datum/station_state/start_state = null // Used in round-end report
var/datum/station_state/start_state = null // Used in round-end report
var/custom_event_msg = null
+5 -1
View File
@@ -66,4 +66,8 @@ var/score_dmgestkey = null
var/TAB = "    "
var/timezoneOffset = 0 // The difference betwen midnight (of the host computer) and 0 world.ticks.
var/timezoneOffset = 0 // The difference betwen midnight (of the host computer) and 0 world.ticks.
// For FTP requests. (i.e. downloading runtime logs.)
// However it'd be ok to use for accessing attack logs and such too, which are even laggier.
var/fileaccess_timer = 0
+6 -58
View File
@@ -21,7 +21,7 @@
var/log_runtimes = 0 // Logs all runtimes.
var/log_hrefs = 0 // logs all links clicked in-game. Could be used for debugging and tracking down exploits
var/log_runtime = 0 // logs world.log to a file
var/sql_enabled = 1 // for sql switching
var/sql_enabled = 0 // for sql switching
var/allow_admin_ooccolor = 0 // Allows admins with relevant permissions to have their own ooc colour
var/allow_vote_restart = 0 // allow votes to restart
var/allow_vote_mode = 0 // allow votes to change mode
@@ -78,10 +78,10 @@
var/server
var/banappeals
var/wikiurl = "http://baystation12.net/wiki"
var/forumurl = "http://baystation12.net/forums/"
var/wikiurl = "http://example.org"
var/forumurl = "http://example.org"
var/media_base_url = "http://nanotrasen.se/media" // http://ss13.nexisonline.net/media
var/media_base_url = "http://example.org"
var/overflow_server_url
var/forbid_singulo_possession = 0
@@ -101,7 +101,6 @@
var/revival_cloning = 1
var/revival_brain_life = -1
var/auto_toggle_ooc_during_round = 0
//Used for modifying movement speed for mobs.
@@ -234,9 +233,6 @@
if ("log_access")
config.log_access = 1
if ("sql_enabled")
config.sql_enabled = text2num(value)
if ("log_say")
config.log_say = 1
@@ -623,16 +619,12 @@
continue
switch (name)
if("sql_enabled")
config.sql_enabled = 1
if ("address")
sqladdress = value
if ("port")
sqlport = value
if ("database")
sqldb = value
if ("login")
sqllogin = value
if ("password")
sqlpass = value
if ("feedback_database")
sqlfdbkdb = value
if ("feedback_login")
@@ -641,50 +633,6 @@
sqlfdbkpass = value
if("feedback_tableprefix")
sqlfdbktableprefix = value
if ("enable_stat_tracking")
sqllogging = 1
else
diary << "Unknown setting in configuration: '[name]'"
/datum/configuration/proc/loadforumsql(filename) // -- TLE
var/list/Lines = file2list(filename)
for(var/t in Lines)
if(!t) continue
t = trim(t)
if (length(t) == 0)
continue
else if (copytext(t, 1, 2) == "#")
continue
var/pos = findtext(t, " ")
var/name = null
var/value = null
if (pos)
name = lowertext(copytext(t, 1, pos))
value = copytext(t, pos + 1)
else
name = lowertext(t)
if (!name)
continue
switch (name)
if ("address")
forumsqladdress = value
if ("port")
forumsqlport = value
if ("database")
forumsqldb = value
if ("login")
forumsqllogin = value
if ("password")
forumsqlpass = value
if ("activatedgroup")
forum_activated_group = value
if ("authenticatedgroup")
forum_authenticated_group = value
else
diary << "Unknown setting in configuration: '[name]'"
+2 -2
View File
@@ -56,7 +56,7 @@ DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
_db_con = _dm_db_new_con()
DBConnection/proc/Connect(dbi_handler=src.dbi,user_handler=src.user,password_handler=src.password,cursor_handler)
if(!sqllogging)
if(!config.sql_enabled)
return 0
if(!src) return 0
cursor_handler = src.default_cursor
@@ -66,7 +66,7 @@ DBConnection/proc/Connect(dbi_handler=src.dbi,user_handler=src.user,password_han
DBConnection/proc/Disconnect() return _dm_db_close(_db_con)
DBConnection/proc/IsConnected()
if(!sqllogging) return 0
if(!config.sql_enabled) return 0
var/success = _dm_db_is_connected(_db_con)
return success
+31 -34
View File
@@ -1,5 +1,5 @@
proc/sql_poll_players()
if(!sqllogging)
/proc/sql_poll_players()
if(!config.sql_enabled)
return
var/playercount = 0
for(var/mob/M in player_list)
@@ -10,14 +10,14 @@ proc/sql_poll_players()
log_game("SQL ERROR during player polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO population (playercount, time) VALUES ([playercount], '[sqltime]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("legacy_population")] (playercount, time) VALUES ([playercount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during player polling. Error : \[[err]\]\n")
proc/sql_poll_admins()
if(!sqllogging)
/proc/sql_poll_admins()
if(!config.sql_enabled)
return
var/admincount = admins.len
establish_db_connection()
@@ -25,33 +25,32 @@ proc/sql_poll_admins()
log_game("SQL ERROR during admin polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO population (admincount, time) VALUES ([admincount], '[sqltime]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("legacy_population")] (admincount, time) VALUES ([admincount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during admin polling. Error : \[[err]\]\n")
proc/sql_report_round_start()
/proc/sql_report_round_start()
// TODO
if(!sqllogging)
return
proc/sql_report_round_end()
// TODO
if(!sqllogging)
if(!config.sql_enabled)
return
proc/sql_report_death(var/mob/living/carbon/human/H)
if(!sqllogging)
/proc/sql_report_round_end()
// TODO
if(!config.sql_enabled)
return
/proc/sql_report_death(mob/living/carbon/human/H)
if(!config.sql_enabled)
return
if(!H)
return
if(!H.key || !H.mind)
return
var/turf/T = get_turf(H)
var/area/placeofdeath = get_area(T)
var/podname = sanitizeSQL("Unknown Area")
if(placeofdeath)
podname = sanitizeSQL(placeofdeath.name)
var/turf/T = H.loc
var/area/placeofdeath = get_area(T.loc)
var/podname = placeofdeath.name
var/sqlname = sanitizeSQL(H.real_name)
var/sqlkey = sanitizeSQL(H.key)
@@ -70,25 +69,23 @@ proc/sql_report_death(var/mob/living/carbon/human/H)
if(!dbcon.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
var/DBQuery/query = dbcon.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("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")
proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
if(!sqllogging)
/proc/sql_report_cyborg_death(mob/living/silicon/robot/H)
if(!config.sql_enabled)
return
if(!H)
return
if(!H.key || !H.mind)
return
var/turf/T = get_turf(H)
var/area/placeofdeath = get_area(T)
var/podname = sanitizeSQL("Unknown Area")
if(placeofdeath)
podname = sanitizeSQL(placeofdeath.name)
var/turf/T = H.loc
var/area/placeofdeath = get_area(T.loc)
var/podname = placeofdeath.name
var/sqlname = sanitizeSQL(H.real_name)
var/sqlkey = sanitizeSQL(H.key)
@@ -107,23 +104,22 @@ proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
if(!dbcon.IsConnected())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
var/DBQuery/query = dbcon.NewQuery("INSERT INTO death (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[H.gender]', [H.getBruteLoss()], [H.getFireLoss()], [H.brainloss], [H.getOxyLoss()], '[coord]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("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")
proc/statistic_cycle()
if(!sqllogging)
/proc/statistic_cycle()
if(!config.sql_enabled)
return
while(1)
sql_poll_players()
sleep(600)
sql_poll_admins()
sleep(6000) // Poll every ten minutes
sleep(6000) //Poll every ten minutes
//This proc is used for feedback. It is executed at round end.
proc/sql_commit_feedback()
/proc/sql_commit_feedback()
if(!blackbox)
log_game("Round ended without a blackbox recorder. No feedback was sent to the database.")
return
@@ -163,4 +159,5 @@ proc/sql_commit_feedback()
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("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")
log_game("SQL ERROR during feedback reporting. Error : \[[err]\]\n")
+4 -4
View File
@@ -214,6 +214,10 @@ var/global/datum/controller/gameticker/ticker
if(admins_number == 0)
send2adminirc("Round has started with no admins online.")
auto_toggle_ooc(0) // Turn it off
if(config.sql_enabled)
spawn(3000)
statistic_cycle() // Polls population totals regularly and stores them in an SQL DB
/* DONE THROUGH PROCESS SCHEDULER
supply_controller.process() //Start the supply shuttle regenerating points -- TLE
@@ -223,10 +227,6 @@ var/global/datum/controller/gameticker/ticker
processScheduler.start()
if(config.sql_enabled)
spawn(3000)
statistic_cycle() // Polls population totals regularly and stores them in an SQL DB -- TLE
votetimer()
for(var/mob/M in mob_list)
+2 -2
View File
@@ -27,7 +27,7 @@ var/list/whitelist = list()
usr << "\red Unable to connect to whitelist database. Please try again later.<br>"
return 0
else
var/DBQuery/query = dbcon.NewQuery("SELECT job FROM whitelist WHERE ckey='[M.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT job FROM [format_table_name("whitelist")] WHERE ckey='[M.key]'")
query.Execute()
@@ -72,7 +72,7 @@ var/list/whitelist = list()
usr << "\red Unable to connect to whitelist database. Please try again later.<br>"
return 0
else
var/DBQuery/query = dbcon.NewQuery("SELECT species FROM whitelist WHERE ckey='[M.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT species FROM [format_table_name("whitelist")] WHERE ckey='[M.key]'")
query.Execute()
while(query.NextRow())
+1 -8
View File
@@ -51,14 +51,7 @@ obj/machinery/scanner/attack_hand(mob/living/carbon/human/user)
var/list/marks = list()
var/age = user.age
var/gender = user.gender
/* no dbstuff yet
var/DBQuery/cquery = dbcon.NewQuery("SELECT * from jobban WHERE ckey='[user.ckey]'")
if(!cquery.Execute()) return
else
while(cquery.NextRow())
var/list/row = cquery.GetRowData()
marks += row["rank"]
*/
var/text = {"
<font size=4><center>Report</center></font><br>
<b><u>Name</u></b>: [mname]
-126
View File
@@ -1,126 +0,0 @@
//This file was auto-corrected by findeclaration.exe on 29/05/2012 15:03:04
#define BOOK_VERSION_MIN 1
#define BOOK_VERSION_MAX 2
#define BOOK_PATH "data/books/"
#define BOOKS_USE_SQL 0 // no guarentee for this branch to work right with sql
var/global/datum/book_manager/book_mgr = new()
datum/book_manager/proc/path(id)
if(isnum(id)) // kill any path exploits
return "[BOOK_PATH][id].sav"
datum/book_manager/proc/getall()
var/list/paths = flist(BOOK_PATH)
var/list/books = new()
for(var/path in paths)
var/datum/archived_book/B = new(BOOK_PATH + path)
books += B
return books
datum/book_manager/proc/freeid()
var/list/paths = flist(BOOK_PATH)
var/id = paths.len + 101
// start at 101+number of books, which will be correct id if none have been deleted, etc
// otherwise, keep moving forward until we find an open id
while(fexists(path(id)))
id++
return id
/client/proc/delbook()
set name = "Delete Book"
set desc = "Permamently deletes a book from the database."
set category = "Admin"
if(!src.holder)
src << "Only administrators may use this command."
return
var/isbn = input("ISBN number?", "Delete Book") as num | null
if(!isbn)
return
if(BOOKS_USE_SQL && config.sql_enabled)
var/DBConnection/dbcon = new()
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
alert("Connection to Archive has been severed. Aborting.")
else
var/DBQuery/query = dbcon.NewQuery("DELETE FROM library WHERE id=[isbn]")
if(!query.Execute())
usr << query.ErrorMsg()
dbcon.Disconnect()
else
book_mgr.remove(isbn)
log_admin("[usr.key] has deleted the book [isbn]")
// delete a book
datum/book_manager/proc/remove(var/id)
fdel(path(id))
datum/archived_book
var/author // Who wrote the thing, can be changed by pen or PC. It is not automatically assigned
var/title // The real name of the book.
var/category // The category/genre of the book
var/id // the id of the book (like an isbn number)
var/dat // Actual page content
var/author_real // author's real_name
var/author_key // author's byond key
var/list/icon/photos // in-game photos used
// loads the book corresponding by the specified id
datum/archived_book/New(var/path)
if(isnull(path))
return
var/savefile/F = new(path)
var/version
F["version"] >> version
if (isnull(version) || version < BOOK_VERSION_MIN || version > BOOK_VERSION_MAX)
fdel(path)
usr << "What book?"
return 0
F["author"] >> author
F["title"] >> title
F["category"] >> category
F["id"] >> id
F["dat"] >> dat
F["author_real"] >> author_real
F["author_key"] >> author_key
F["photos"] >> photos
if(!photos)
photos = new()
// let's sanitize it here too!
for(var/tag in paper_blacklist)
if(findtext(dat,"<"+tag))
dat = ""
return
datum/archived_book/proc/save()
var/savefile/F = new(book_mgr.path(id))
F["version"] << BOOK_VERSION_MAX
F["author"] << author
F["title"] << title
F["category"] << category
F["id"] << id
F["dat"] << dat
F["author_real"] << author_real
F["author_key"] << author_key
F["photos"] << photos
#undef BOOK_VERSION_MIN
#undef BOOK_VERSION_MAX
#undef BOOK_PATH
+17 -12
View File
@@ -783,6 +783,8 @@ var/list/admin_verbs_mentor = list(
/client/proc/playernotes()
set name = "Show Player Info"
set category = "Admin"
if(!check_rights(R_ADMIN))
return
if(holder)
holder.PlayerNotes()
return
@@ -790,18 +792,21 @@ var/list/admin_verbs_mentor = list(
/client/proc/free_slot()
set name = "Free Job Slot"
set category = "Admin"
if(holder)
var/list/jobs = list()
for (var/datum/job/J in job_master.occupations)
if (J.current_positions >= J.total_positions && J.total_positions != -1)
jobs += J.title
if (!jobs.len)
usr << "There are no fully staffed jobs."
return
var/job = input("Please select job slot to free", "Free job slot") as null|anything in jobs
if (job)
job_master.FreeRole(job)
return
if(!check_rights(R_ADMIN))
return
var/list/jobs = list()
for (var/datum/job/J in job_master.occupations)
if (J.current_positions >= J.total_positions && J.total_positions != -1)
jobs += J.title
if (!jobs.len)
usr << "There are no fully staffed jobs."
return
var/job = input("Please select job slot to free", "Free job slot") as null|anything in jobs
if (job)
job_master.FreeRole(job)
log_admin("[key_name(usr)] has freed a job slot for [job].")
message_admins("[key_name_admin(usr) has freed a job slot for [job].")
/client/proc/toggleattacklogs()
set name = "Toggle Attack Log Messages"
+2 -3
View File
@@ -5,17 +5,16 @@
if(Debug2)
Debug2 = 0
message_admins("[key_name(src)] toggled debugging off.")
message_admins("[key_name_admin(src)] toggled debugging off.")
log_admin("[key_name(src)] toggled debugging off.")
else
Debug2 = 1
message_admins("[key_name(src)] toggled debugging on.")
message_admins("[key_name_admin(src)] toggled debugging on.")
log_admin("[key_name(src)] toggled debugging on.")
feedback_add_details("admin_verb","DG2") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/* 21st Sept 2010
Updated by Skie -- Still not perfect but better!
Stuff you can't do:
+1 -1
View File
@@ -1608,7 +1608,7 @@ datum/preferences
proc/open_load_dialog(mob/user)
var/DBQuery/query = dbcon.NewQuery("SELECT slot,real_name FROM characters WHERE ckey='[user.ckey]' ORDER BY slot")
var/DBQuery/query = dbcon.NewQuery("SELECT slot,real_name FROM [format_table_name("characters")] WHERE ckey='[user.ckey]' ORDER BY slot")
var/dat = "<body>"
dat += "<tt><center>"
+1 -1
View File
@@ -37,7 +37,7 @@
*/
// Grab the info we want.
var/DBQuery/query = dbcon.NewQuery("SELECT cuiPath, cuiPropAdjust, cuiJobMask, cuiDescription, cuiItemName FROM CustomUserItems WHERE cuiCKey='[M.ckey]' AND (cuiRealName='[M.real_name]' OR cuiRealName='*')")
var/DBQuery/query = dbcon.NewQuery("SELECT cuiPath, cuiPropAdjust, cuiJobMask, cuiDescription, cuiItemName FROM [format_table_name("customuseritems")] WHERE cuiCKey='[M.ckey]' AND (cuiRealName='[M.real_name]' OR cuiRealName='*')")
query.Execute()
while(query.NextRow())
+16 -16
View File
@@ -18,13 +18,13 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver)
log_game("SQL ERROR during karma logging. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO karma (spendername, spenderkey, receivername, receiverkey, receiverrole, receiverspecial, spenderip, time) VALUES ('[sqlspendername]', '[sqlspenderkey]', '[sqlreceivername]', '[sqlreceiverkey]', '[sqlreceiverrole]', '[sqlreceiverspecial]', '[sqlspenderip]', '[sqltime]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("karma")] (spendername, spenderkey, receivername, receiverkey, receiverrole, receiverspecial, spenderip, time) VALUES ('[sqlspendername]', '[sqlspenderkey]', '[sqlreceivername]', '[sqlreceiverkey]', '[sqlreceiverrole]', '[sqlreceiverspecial]', '[sqlspenderip]', '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during karma logging. Error : \[[err]\]\n")
query = dbcon.NewQuery("SELECT * FROM karmatotals WHERE byondkey='[receiver.key]'")
query = dbcon.NewQuery("SELECT * FROM [format_table_name("karmatotals")] WHERE byondkey='[receiver.key]'")
query.Execute()
var/karma
@@ -34,13 +34,13 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver)
karma = text2num(query.item[3])
if(karma == null)
karma = 1
query = dbcon.NewQuery("INSERT INTO karmatotals (byondkey, karma) VALUES ('[receiver.key]', [karma])")
query = dbcon.NewQuery("INSERT INTO [format_table_name("karmatotals")] (byondkey, karma) VALUES ('[receiver.key]', [karma])")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during karmatotal logging (adding new key). Error : \[[err]\]\n")
else
karma += 1
query = dbcon.NewQuery("UPDATE karmatotals SET karma=[karma] WHERE id=[id]")
query = dbcon.NewQuery("UPDATE [format_table_name("karmatotals")] SET karma=[karma] WHERE id=[id]")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during karmatotal logging (updating existing entry). Error : \[[err]\]\n")
@@ -149,7 +149,7 @@ var/list/karma_spenders = list()
usr << "\red Unable to connect to karma database. Please try again later.<br>"
return
else
var/DBQuery/query = dbcon.NewQuery("SELECT karma, karmaspent FROM karmatotals WHERE byondkey='[src.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT karma, karmaspent FROM [format_table_name("karmatotals")] WHERE byondkey='[src.key]'")
query.Execute()
var/totalkarma
@@ -249,7 +249,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
return
/client/proc/DB_job_unlock(var/job,var/cost)
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM whitelist WHERE ckey='[usr.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.key]'")
query.Execute()
var/dbjob
@@ -258,7 +258,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
dbckey = query.item[2]
dbjob = query.item[3]
if(!dbckey)
query = dbcon.NewQuery("INSERT INTO whitelist (ckey, job) VALUES ('[usr.key]','[job]')")
query = dbcon.NewQuery("INSERT INTO [format_table_name("whitelist")] (ckey, job) VALUES ('[usr.key]','[job]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during whitelist logging (adding new key). Error: \[[err]\]\n")
@@ -274,7 +274,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
if(!(job in joblist))
joblist += job
var/newjoblist = list2text(joblist,",")
query = dbcon.NewQuery("UPDATE whitelist SET job='[newjoblist]' WHERE ckey='[dbckey]'")
query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET job='[newjoblist]' WHERE ckey='[dbckey]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during whitelist logging (updating existing entry). Error : \[[err]\]\n")
@@ -289,7 +289,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
return
/client/proc/DB_species_unlock(var/species,var/cost)
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM whitelist WHERE ckey='[usr.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.key]'")
query.Execute()
var/dbspecies
@@ -298,7 +298,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
dbckey = query.item[2]
dbspecies = query.item[4]
if(!dbckey)
query = dbcon.NewQuery("INSERT INTO whitelist (ckey, species) VALUES ('[usr.key]','[species]')")
query = dbcon.NewQuery("INSERT INTO [format_table_name("whitelist")] (ckey, species) VALUES ('[usr.key]','[species]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during whitelist logging (adding new key). Error : \[[err]\]\n")
@@ -314,7 +314,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
if(!(species in specieslist))
specieslist += species
var/newspecieslist = list2text(specieslist,",")
query = dbcon.NewQuery("UPDATE whitelist SET species='[newspecieslist]' WHERE ckey='[dbckey]'")
query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET species='[newspecieslist]' WHERE ckey='[dbckey]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n")
@@ -329,7 +329,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
return
/client/proc/karmacharge(var/cost,var/refund = 0)
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM karmatotals WHERE byondkey='[usr.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("karmatotals")] WHERE byondkey='[usr.key]'")
query.Execute()
while(query.NextRow())
@@ -338,7 +338,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
spent -= cost
else
spent += cost
query = dbcon.NewQuery("UPDATE karmatotals SET karmaspent=[spent] WHERE byondkey='[usr.key]'")
query = dbcon.NewQuery("UPDATE [format_table_name("karmatotals")] SET karmaspent=[spent] WHERE byondkey='[usr.key]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during karmaspent updating (updating existing entry). Error: \[[err]\]\n")
@@ -374,7 +374,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
usr << "\red That job is not refundable."
return
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM whitelist WHERE ckey='[usr.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.key]'")
query.Execute()
var/dbjob
@@ -397,7 +397,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
if(name in typelist)
typelist -= name
var/newtypelist = list2text(typelist,",")
query = dbcon.NewQuery("UPDATE whitelist SET [type]='[newtypelist]' WHERE ckey='[dbckey]'")
query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET [type]='[newtypelist]' WHERE ckey='[dbckey]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n")
@@ -414,7 +414,7 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
usr << "\red Your ckey ([dbckey]) was not found."
/client/proc/checkpurchased(var/name = null) // If the first parameter is null, return a full list of purchases
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM whitelist WHERE ckey='[usr.key]'")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.key]'")
query.Execute()
var/dbjob
+25 -26
View File
@@ -43,8 +43,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
<A href='?src=\ref[src];setauthor=1'>Filter by Author: [author]</A><BR>
<A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"}
if(1)
establish_old_db_connection()
if(!dbcon_old.IsConnected())
if(!dbcon.IsConnected())
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
else if(!SQLquery)
dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>"
@@ -52,7 +51,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
dat += "<table>"
dat += "<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 = dbcon.NewQuery(SQLquery)
query.Execute()
while(query.NextRow())
@@ -94,7 +93,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
author = null
author = sanitizeSQL(author)
if(href_list["search"])
SQLquery = "SELECT author, title, category, id FROM library WHERE "
SQLquery = "SELECT author, title, category, id FROM [format_table_name("library")] WHERE "
if(category == "Any")
SQLquery += "author LIKE '%[author]%' AND title LIKE '%[title]%'"
else
@@ -189,16 +188,18 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
<A href='?src=\ref[src];switchscreen=0'>(Return to main menu)</A><BR>"}
if(4)
dat += "<h3>External Archive</h3>"
establish_old_db_connection()
if(!dbcon_old.IsConnected())
if(!dbcon.IsConnected())
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font>"
else
dat += "<A href='?src=\ref[src];orderbyid=1'>(Order book by SS<sup>13</sup>BN)</A><BR><BR>"
dat += "<table>"
dat += "<tr><td>AUTHOR</td><td>TITLE</td><td>CATEGORY</td><td>ID</td><td></td></tr>"
var/DBQuery/query = dbcon_old.NewQuery("SELECT id, author, title, category FROM library")
query.Execute()
var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM [format_table_name("library")]")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR accessing book. Error : \[[err]\]\n")
return
while(query.NextRow())
var/id = query.item[1]
@@ -333,8 +334,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
if(scanner.cache)
var/choice = input("Are you certain you wish to upload this title to the Archive?") in list("Confirm", "Abort")
if(choice == "Confirm")
establish_old_db_connection()
if(!dbcon_old.IsConnected())
if(!dbcon.IsConnected())
alert("Connection to Archive has been severed. Aborting.")
else
/*
@@ -347,9 +347,11 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
var/sqlauthor = sanitizeSQL(scanner.cache.author)
var/sqlcontent = sanitizeSQL(scanner.cache.dat)
var/sqlcategory = sanitizeSQL(upload_category)
var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO library (author, title, content, category, ckey) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', '[usr.key]')")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("library")] (author, title, content, category, ckey) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', '[usr.key]')")
if(!query.Execute())
usr << query.ErrorMsg()
var/err = query.ErrorMsg()
log_game("SQL ERROR adding new book. Error : \[[err]\]\n")
return
else
log_game("[usr.name]/[usr.key] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] signs")
message_admins("[key_name_admin(usr)] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] signs")
@@ -357,8 +359,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
if(href_list["targetid"])
var/sqlid = sanitizeSQL(href_list["targetid"])
establish_old_db_connection()
if(!dbcon_old.IsConnected())
if(!dbcon.IsConnected())
alert("Connection to Archive has been severed. Aborting.")
// reused working printing call from bible code.. needs testing ((Lazureus))
@@ -367,7 +368,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
bibledelay = 1
spawn(60)
bibledelay = 0
var/DBQuery/query = dbcon_old.NewQuery("SELECT * FROM library WHERE id=[sqlid]")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("library")] WHERE id=[sqlid]")
query.Execute()
while(query.NextRow())
@@ -472,6 +473,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
qdel(O)
else
..()
/client/proc/delbook()
set name = "Delete Book"
set desc = "Permamently deletes a book from the database."
@@ -483,15 +485,12 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
var/isbn = input("ISBN number?", "Delete Book") as num | null
if(!isbn)
return
var/DBQuery/query_delbook = dbcon.NewQuery("DELETE FROM [format_table_name("library")] WHERE id=[isbn]")
if(!query_delbook.Execute())
var/err = query_delbook.ErrorMsg()
log_game("SQL ERROR deleting book. Error : \[[err]\]\n")
return
if(dbcon_old.IsConnected())
var/DBConnection/dbcon = new()
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!dbcon.IsConnected())
alert("Connection to Archive has been severed. Aborting.")
else
var/DBQuery/query = dbcon.NewQuery("DELETE FROM library WHERE id=[isbn]")
if(!query.Execute())
usr << query.ErrorMsg()
dbcon.Disconnect()
log_admin("[usr.key] has deleted the book [isbn]")
log_admin("[key_name(usr)] has deleted the book [isbn].")
message_admins("[key_name_admin(usr) has deleted the book [isbn].")
-44
View File
@@ -332,7 +332,6 @@ var/world_topic_spam_protect_time = world.timeofday
config.load("config/config.txt")
config.load("config/game_options.txt","game_options")
config.loadsql("config/dbconfig.txt")
config.loadforumsql("config/forumdbconfig.txt")
config.loadoverflowwhitelist("config/ofwhitelist.txt")
// apply some settings from config..
@@ -469,47 +468,4 @@ proc/establish_db_connection()
else
return 1
/hook/startup/proc/connectOldDB()
if(!setup_old_database_connection())
log_to_dd("Your server failed to establish a connection with the SQL database.")
else
log_to_dd("SQL database connection established.")
return 1
//These two procs are for the old database, while it's being phased out. See the tgstation.sql file in the SQL folder for more information.
proc/setup_old_database_connection()
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
if(!dbcon_old)
dbcon_old = new()
var/user = sqllogin
var/pass = sqlpass
var/db = sqldb
var/address = sqladdress
var/port = sqlport
dbcon_old.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
. = dbcon_old.IsConnected()
if ( . )
failed_old_db_connections = 0 //If this connection succeeded, reset the failed connections counter.
else
failed_old_db_connections++ //If it failed, increase the failed connections counter.
log_to_dd(dbcon.ErrorMsg())
return .
//This proc ensures that the connection to the feedback database (global variable dbcon) is established
proc/establish_old_db_connection()
if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF)
return 0
if(!dbcon_old || !dbcon_old.IsConnected())
return setup_old_database_connection()
else
return 1
#undef FAILED_DB_CONNECTION_CUTOFF