Moves some stuff that belongs in dbcore to dbcore (#24145)

* Moves some stuff that belongs in dbcore to dbcore

* Wew garbage

* Ree

* Fixed
This commit is contained in:
Cyberboss
2017-02-18 20:21:53 -05:00
committed by oranges
parent 9fbd95320a
commit 2d424cf6be
15 changed files with 64 additions and 105 deletions

View File

@@ -351,7 +351,6 @@ var/datum/subsystem/garbage_collector/SSgarbage
//if find_references isn't working for some datum
//update this list using tools/DMTreeToGlobalsList
/datum/proc/find_references_in_globals()
SearchVar(failed_db_connections)
SearchVar(nextmap)
SearchVar(mapchanging)
SearchVar(rebootingpendingmapchange)

View File

@@ -6,8 +6,7 @@
if(!check_rights(R_BAN))
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return
@@ -183,8 +182,7 @@
if(job)
sql += " AND job = '[job]'"
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
return
var/ban_id
@@ -280,8 +278,7 @@
var/sql = "SELECT ckey FROM [format_table_name("ban")] WHERE id = [id]"
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
return
var/ban_number = 0 //failsafe
@@ -333,8 +330,7 @@
if(!check_rights(R_BAN))
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return

View File

@@ -61,7 +61,7 @@
var/ckeytext = ckey(key)
if(!establish_db_connection())
if(!dbcon.Connect())
log_world("Ban database connection failure. Key [ckeytext] not checked")
diary << "Ban database connection failure. Key [ckeytext] not checked"
return

View File

@@ -127,8 +127,7 @@ var/list/admin_ranks = list() //list of all admin_rank datums
previous_rights = R.rights
else
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_world("Failed to connect to database in load_admin_ranks(). Reverting to legacy system.")
diary << "Failed to connect to database in load_admin_ranks(). Reverting to legacy system."
config.admin_legacy_system = 1
@@ -202,8 +201,7 @@ var/list/admin_ranks = list() //list of all admin_rank datums
world.SetConfig("APP/admin", ckey, "role=admin")
D.associate(directory[ckey]) //find the client for a ckey if they are connected and associate them with the new admin datum
else
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_world("Failed to connect to database in load_admins(). Reverting to legacy system.")
diary << "Failed to connect to database in load_admins(). Reverting to legacy system."
config.admin_legacy_system = 1
@@ -375,8 +373,7 @@ var/list/admin_ranks = list() //list of all admin_rank datums
edit_admin_permissions()
/datum/admins/proc/updateranktodb(ckey,newrank)
establish_db_connection()
if (!dbcon.IsConnected())
if(!dbcon.Connect())
return
var/sql_ckey = sanitizeSQL(ckey)
var/sql_admin_rank = sanitizeSQL(newrank)

View File

@@ -33,7 +33,7 @@
cachedintel.cache = TRUE
return cachedintel
if (establish_db_connection())
if(dbcon.Connect())
var/DBQuery/query = dbcon.NewQuery({"
SELECT date, intel, TIMESTAMPDIFF(MINUTE,date,NOW())
FROM [format_table_name("ipintel")]
@@ -61,7 +61,7 @@
res.intel = ip_intel_query(ip)
if (updatecache && res.intel >= 0)
SSipintel.cache[ip] = res
if (establish_db_connection())
if(dbcon.Connect())
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [format_table_name("ipintel")] (ip, intel) VALUES (INET_ATON('[ip]'), [res.intel]) ON DUPLICATE KEY UPDATE intel = VALUES(intel), date = NOW()")
query.Execute()
return

View File

@@ -60,9 +60,7 @@
if (!check_rights(R_PERMISSIONS))
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return
@@ -109,8 +107,7 @@
if(check_rights(R_PERMISSIONS))
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return

View File

@@ -15,7 +15,6 @@
return
dbcon.Disconnect()
failed_db_connections = 0
log_admin("[key_name(usr)] has forced the database to disconnect")
message_admins("[key_name_admin(usr)] has <b>forced</b> the database to disconnect!")
feedback_add_details("admin_verb","FRDB") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
@@ -24,8 +23,8 @@
message_admins("[key_name_admin(usr)] is attempting to re-established the DB Connection")
feedback_add_details("admin_verb","RDB") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
failed_db_connections = 0
if (!establish_db_connection())
dbcon.failed_connections = 0
if(!dbcon.Connect())
message_admins("Database connection failed: " + dbcon.ErrorMsg())
else
message_admins("Database connection re-established")

View File

@@ -325,8 +325,7 @@ var/next_external_rsc = 0
if (IsGuestKey(src.key))
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
return
var/sql_ckey = sanitizeSQL(src.ckey)
@@ -347,8 +346,7 @@ var/next_external_rsc = 0
if (IsGuestKey(src.key))
return
establish_db_connection()
if (!dbcon.IsConnected())
if (!dbcon.Connect())
return
var/sql_ckey = sanitizeSQL(ckey)

View File

@@ -43,8 +43,7 @@
dat += "<A href='?src=\ref[src];setauthor=1'>Filter by Author: [author]</A><BR>"
dat += "<A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"
if(1)
establish_db_connection()
if(!dbcon.IsConnected())
if (!dbcon.Connect())
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>"
@@ -135,8 +134,7 @@ var/global/list/datum/cachedbook/cachedbooks // List of our cached book datums
/proc/load_library_db_to_cache()
if(cachedbooks)
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
return
cachedbooks = list()
var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM [format_table_name("library")] WHERE isnull(deleted)")
@@ -408,8 +406,7 @@ var/global/list/datum/cachedbook/cachedbooks // List of our cached book datums
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_db_connection()
if(!dbcon.IsConnected())
if (!dbcon.Connect())
alert("Connection to Archive has been severed. Aborting.")
else
@@ -446,8 +443,7 @@ var/global/list/datum/cachedbook/cachedbooks // List of our cached book datums
if(href_list["targetid"])
var/sqlid = sanitizeSQL(href_list["targetid"])
establish_db_connection()
if(!dbcon.IsConnected())
if (!dbcon.Connect())
alert("Connection to Archive has been severed. Aborting.")
if(cooldown > world.time)
say("Printer unavailable. Please allow a short time before attempting to print.")

View File

@@ -34,7 +34,7 @@
. = list()
if(!isnum(amount) || amount<1)
return
if(!establish_db_connection())
if (!dbcon.Connect())
if(fail_loud || prob(5))
var/obj/item/weapon/paper/P = new(location)
P.info = "There once was a book from Nantucket<br>But the database failed us, so f*$! it.<br>I tried to be good to you<br>Now this is an I.O.U<br>If you're feeling entitled, well, stuff it!<br><br><font color='gray'>~</font>"

View File

@@ -40,9 +40,7 @@
output += "<p><a href='byond://?src=\ref[src];observe=1'>Observe</A></p>"
if(!IsGuestKey(src.key))
establish_db_connection()
if(dbcon.IsConnected())
if (dbcon.Connect())
var/isadmin = 0
if(src.client && src.client.holder)
isadmin = 1

View File

@@ -24,7 +24,7 @@
/mob/new_player/proc/poll_player(pollid)
if(!pollid)
return
if(!establish_db_connection())
if (!dbcon.Connect())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM [format_table_name("poll_question")] WHERE id = [pollid]")
@@ -349,7 +349,7 @@
var/table = "poll_vote"
if (text)
table = "poll_textreply"
if (!establish_db_connection())
if (!dbcon.Connect())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return
var/DBQuery/query_hasvoted = dbcon.NewQuery("SELECT id FROM `[format_table_name(table)]` WHERE pollid = [pollid] AND ckey = '[ckey]'")
@@ -379,7 +379,7 @@
return 1
/mob/new_player/proc/vote_valid_check(pollid, holder, type)
if (!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
pollid = text2num(pollid)
@@ -406,7 +406,7 @@
return 1
/mob/new_player/proc/vote_on_irv_poll(pollid, list/votelist)
if (!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
if (!vote_rig_check())
@@ -482,7 +482,7 @@
/mob/new_player/proc/vote_on_poll(pollid, optionid)
if(!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
if (!vote_rig_check())
@@ -504,7 +504,7 @@
return 1
/mob/new_player/proc/log_text_poll_reply(pollid, replytext)
if(!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
if (!vote_rig_check())
@@ -533,7 +533,7 @@
return 1
/mob/new_player/proc/vote_on_numval_poll(pollid, optionid, rating)
if(!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
if (!vote_rig_check())
@@ -563,7 +563,7 @@
return 1
/mob/new_player/proc/vote_on_multi_poll(pollid, optionid)
if(!establish_db_connection())
if (!dbcon.Connect())
src << "<span class='danger'>Failed to establish database connection.</span>"
return 0
if (!vote_rig_check())

View File

@@ -1,4 +1,4 @@
#define FAILED_DB_CONNECTION_CUTOFF 5
//cursors
#define Default_Cursor 0
@@ -47,6 +47,7 @@ DBConnection
//
var/server = ""
var/port = 3306
var/failed_connections = 0
DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
src.dbi = dbi_handler
@@ -55,7 +56,26 @@ DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
src.default_cursor = 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)
DBConnection/proc/Connect()
if(IsConnected())
return TRUE
if(failed_connections > FAILED_DB_CONNECTION_CUTOFF) //If it failed to establish a connection more than 5 times in a row, don't bother attempting to connect anymore.
return FALSE
var/user = sqlfdbklogin
var/pass = sqlfdbkpass
var/db = sqlfdbkdb
var/address = sqladdress
var/port = sqlport
doConnect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
. = IsConnected()
if (!. && config.sql_enabled)
log_world("SQL error: " + ErrorMsg())
++failed_connections
DBConnection/proc/doConnect(dbi_handler=src.dbi,user_handler=src.user,password_handler=src.password,cursor_handler)
if(!config.sql_enabled)
return 0
if(!src) return 0
@@ -63,7 +83,9 @@ DBConnection/proc/Connect(dbi_handler=src.dbi,user_handler=src.user,password_han
if(!cursor_handler) cursor_handler = Default_Cursor
return _dm_db_connect(_db_con,dbi_handler,user_handler,password_handler,cursor_handler,null)
DBConnection/proc/Disconnect() return _dm_db_close(_db_con)
DBConnection/proc/Disconnect()
failed_connections = 0
return _dm_db_close(_db_con)
DBConnection/proc/IsConnected()
if(!config.sql_enabled) return 0
@@ -206,3 +228,6 @@ DBColumn/proc/SqlTypeName(type_handler=src.sql_type)
#undef TIME
#undef STRING
#undef BLOB
#undef FAILED_DB_CONNECTION_CUTOFF

View File

@@ -62,8 +62,7 @@ var/datum/feedback/blackbox = new()
if (!feedback) return
round_end_data_gathering() //round_end time logging and some other data processing
establish_db_connection()
if (!dbcon.IsConnected()) return
if (!dbcon.Connect()) return
var/round_id
var/DBQuery/query = dbcon.NewQuery("SELECT MAX(round_id) AS round_id FROM [format_table_name("feedback")]")
@@ -213,8 +212,7 @@ var/datum/feedback/blackbox = new()
for(var/mob/M in player_list)
if(M.client)
playercount += 1
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_game("SQL ERROR during player polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
@@ -227,8 +225,7 @@ var/datum/feedback/blackbox = new()
if(!config.sql_enabled)
return
var/admincount = admins.len
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_game("SQL ERROR during admin polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
@@ -273,8 +270,7 @@ var/datum/feedback/blackbox = new()
var/coord = "[L.x], [L.y], [L.z]"
var/map = MAP_NAME
var/server = "[world.internet_address]:[world.port]"
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_game("SQL ERROR during death reporting. Failed to connect.")
else
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, mapname, server) VALUES ('[sqlname]', '[sqlkey]', '[sqljob]', '[sqlspecial]', '[sqlpod]', '[sqltime]', '[laname]', '[lakey]', '[L.gender]', [L.getBruteLoss()], [L.getFireLoss()], [L.brainloss], [L.getOxyLoss()], '[coord]', '[map]', '[server]')")
@@ -295,8 +291,7 @@ var/datum/feedback/blackbox = new()
log_game("Round ended without any feedback being generated. No feedback was sent to the database.")
return
establish_db_connection()
if(!dbcon.IsConnected())
if(!dbcon.Connect())
log_game("SQL ERROR during feedback reporting. Failed to connect.")
else

View File

@@ -51,7 +51,7 @@ var/list/map_transition_config = MAP_TRANSITION_CONFIG
timezoneOffset = text2num(time2text(0,"hh")) * 36000
if(config.sql_enabled)
if(!setup_database_connection())
if(!dbcon.Connect())
log_world("Your server failed to establish a connection with the database.")
else
log_world("Database connection established.")
@@ -353,47 +353,6 @@ var/list/map_transition_config = MAP_TRANSITION_CONFIG
status = s
#define FAILED_DB_CONNECTION_CUTOFF 5
var/failed_db_connections = 0
/proc/setup_database_connection()
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 connect anymore.
return 0
if(!dbcon)
dbcon = new()
var/user = sqlfdbklogin
var/pass = sqlfdbkpass
var/db = sqlfdbkdb
var/address = sqladdress
var/port = sqlport
dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
. = dbcon.IsConnected()
if ( . )
failed_db_connections = 0 //If this connection succeeded, reset the failed connections counter.
else
failed_db_connections++ //If it failed, increase the failed connections counter.
if(config.sql_enabled)
log_world("SQL error: " + dbcon.ErrorMsg())
return .
//This proc ensures that the connection to the feedback database (global variable dbcon) is established
/proc/establish_db_connection()
if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF)
return 0
if(!dbcon || !dbcon.IsConnected())
return setup_database_connection()
else
return 1
#undef FAILED_DB_CONNECTION_CUTOFF
/proc/maprotate()
if (!SERVERTOOLS)
return