mirror of
https://github.com/fulpstation/fulpstation.git
synced 2025-12-10 10:01:40 +00:00
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:
@@ -351,7 +351,6 @@ var/datum/subsystem/garbage_collector/SSgarbage
|
|||||||
//if find_references isn't working for some datum
|
//if find_references isn't working for some datum
|
||||||
//update this list using tools/DMTreeToGlobalsList
|
//update this list using tools/DMTreeToGlobalsList
|
||||||
/datum/proc/find_references_in_globals()
|
/datum/proc/find_references_in_globals()
|
||||||
SearchVar(failed_db_connections)
|
|
||||||
SearchVar(nextmap)
|
SearchVar(nextmap)
|
||||||
SearchVar(mapchanging)
|
SearchVar(mapchanging)
|
||||||
SearchVar(rebootingpendingmapchange)
|
SearchVar(rebootingpendingmapchange)
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
if(!check_rights(R_BAN))
|
if(!check_rights(R_BAN))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
src << "<span class='danger'>Failed to establish database connection.</span>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -183,8 +182,7 @@
|
|||||||
if(job)
|
if(job)
|
||||||
sql += " AND job = '[job]'"
|
sql += " AND job = '[job]'"
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var/ban_id
|
var/ban_id
|
||||||
@@ -280,8 +278,7 @@
|
|||||||
|
|
||||||
var/sql = "SELECT ckey FROM [format_table_name("ban")] WHERE id = [id]"
|
var/sql = "SELECT ckey FROM [format_table_name("ban")] WHERE id = [id]"
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var/ban_number = 0 //failsafe
|
var/ban_number = 0 //failsafe
|
||||||
@@ -333,8 +330,7 @@
|
|||||||
if(!check_rights(R_BAN))
|
if(!check_rights(R_BAN))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
var/ckeytext = ckey(key)
|
var/ckeytext = ckey(key)
|
||||||
|
|
||||||
if(!establish_db_connection())
|
if(!dbcon.Connect())
|
||||||
log_world("Ban database connection failure. Key [ckeytext] not checked")
|
log_world("Ban database connection failure. Key [ckeytext] not checked")
|
||||||
diary << "Ban database connection failure. Key [ckeytext] not checked"
|
diary << "Ban database connection failure. Key [ckeytext] not checked"
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -127,8 +127,7 @@ var/list/admin_ranks = list() //list of all admin_rank datums
|
|||||||
|
|
||||||
previous_rights = R.rights
|
previous_rights = R.rights
|
||||||
else
|
else
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_world("Failed to connect to database in load_admin_ranks(). Reverting to legacy system.")
|
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."
|
diary << "Failed to connect to database in load_admin_ranks(). Reverting to legacy system."
|
||||||
config.admin_legacy_system = 1
|
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")
|
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
|
D.associate(directory[ckey]) //find the client for a ckey if they are connected and associate them with the new admin datum
|
||||||
else
|
else
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_world("Failed to connect to database in load_admins(). Reverting to legacy system.")
|
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."
|
diary << "Failed to connect to database in load_admins(). Reverting to legacy system."
|
||||||
config.admin_legacy_system = 1
|
config.admin_legacy_system = 1
|
||||||
@@ -375,8 +373,7 @@ var/list/admin_ranks = list() //list of all admin_rank datums
|
|||||||
edit_admin_permissions()
|
edit_admin_permissions()
|
||||||
|
|
||||||
/datum/admins/proc/updateranktodb(ckey,newrank)
|
/datum/admins/proc/updateranktodb(ckey,newrank)
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if (!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
var/sql_ckey = sanitizeSQL(ckey)
|
var/sql_ckey = sanitizeSQL(ckey)
|
||||||
var/sql_admin_rank = sanitizeSQL(newrank)
|
var/sql_admin_rank = sanitizeSQL(newrank)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
cachedintel.cache = TRUE
|
cachedintel.cache = TRUE
|
||||||
return cachedintel
|
return cachedintel
|
||||||
|
|
||||||
if (establish_db_connection())
|
if(dbcon.Connect())
|
||||||
var/DBQuery/query = dbcon.NewQuery({"
|
var/DBQuery/query = dbcon.NewQuery({"
|
||||||
SELECT date, intel, TIMESTAMPDIFF(MINUTE,date,NOW())
|
SELECT date, intel, TIMESTAMPDIFF(MINUTE,date,NOW())
|
||||||
FROM [format_table_name("ipintel")]
|
FROM [format_table_name("ipintel")]
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
res.intel = ip_intel_query(ip)
|
res.intel = ip_intel_query(ip)
|
||||||
if (updatecache && res.intel >= 0)
|
if (updatecache && res.intel >= 0)
|
||||||
SSipintel.cache[ip] = res
|
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()")
|
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()
|
query.Execute()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -60,9 +60,7 @@
|
|||||||
if (!check_rights(R_PERMISSIONS))
|
if (!check_rights(R_PERMISSIONS))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
|
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -109,8 +107,7 @@
|
|||||||
if(check_rights(R_PERMISSIONS))
|
if(check_rights(R_PERMISSIONS))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
return
|
return
|
||||||
|
|
||||||
dbcon.Disconnect()
|
dbcon.Disconnect()
|
||||||
failed_db_connections = 0
|
|
||||||
log_admin("[key_name(usr)] has forced the database to disconnect")
|
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!")
|
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!
|
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")
|
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!
|
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
|
dbcon.failed_connections = 0
|
||||||
if (!establish_db_connection())
|
if(!dbcon.Connect())
|
||||||
message_admins("Database connection failed: " + dbcon.ErrorMsg())
|
message_admins("Database connection failed: " + dbcon.ErrorMsg())
|
||||||
else
|
else
|
||||||
message_admins("Database connection re-established")
|
message_admins("Database connection re-established")
|
||||||
@@ -325,8 +325,7 @@ var/next_external_rsc = 0
|
|||||||
if (IsGuestKey(src.key))
|
if (IsGuestKey(src.key))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var/sql_ckey = sanitizeSQL(src.ckey)
|
var/sql_ckey = sanitizeSQL(src.ckey)
|
||||||
@@ -347,8 +346,7 @@ var/next_external_rsc = 0
|
|||||||
if (IsGuestKey(src.key))
|
if (IsGuestKey(src.key))
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if (!dbcon.Connect())
|
||||||
if (!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var/sql_ckey = sanitizeSQL(ckey)
|
var/sql_ckey = sanitizeSQL(ckey)
|
||||||
|
|||||||
@@ -43,8 +43,7 @@
|
|||||||
dat += "<A href='?src=\ref[src];setauthor=1'>Filter by Author: [author]</A><BR>"
|
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>"
|
dat += "<A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"
|
||||||
if(1)
|
if(1)
|
||||||
establish_db_connection()
|
if (!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
|
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
|
||||||
else if(!SQLquery)
|
else if(!SQLquery)
|
||||||
dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>"
|
dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>"
|
||||||
@@ -135,8 +134,7 @@ var/global/list/datum/cachedbook/cachedbooks // List of our cached book datums
|
|||||||
/proc/load_library_db_to_cache()
|
/proc/load_library_db_to_cache()
|
||||||
if(cachedbooks)
|
if(cachedbooks)
|
||||||
return
|
return
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
return
|
return
|
||||||
cachedbooks = list()
|
cachedbooks = list()
|
||||||
var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM [format_table_name("library")] WHERE isnull(deleted)")
|
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)
|
if(scanner.cache)
|
||||||
var/choice = input("Are you certain you wish to upload this title to the Archive?") in list("Confirm", "Abort")
|
var/choice = input("Are you certain you wish to upload this title to the Archive?") in list("Confirm", "Abort")
|
||||||
if(choice == "Confirm")
|
if(choice == "Confirm")
|
||||||
establish_db_connection()
|
if (!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
alert("Connection to Archive has been severed. Aborting.")
|
alert("Connection to Archive has been severed. Aborting.")
|
||||||
else
|
else
|
||||||
|
|
||||||
@@ -446,8 +443,7 @@ var/global/list/datum/cachedbook/cachedbooks // List of our cached book datums
|
|||||||
|
|
||||||
if(href_list["targetid"])
|
if(href_list["targetid"])
|
||||||
var/sqlid = sanitizeSQL(href_list["targetid"])
|
var/sqlid = sanitizeSQL(href_list["targetid"])
|
||||||
establish_db_connection()
|
if (!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
alert("Connection to Archive has been severed. Aborting.")
|
alert("Connection to Archive has been severed. Aborting.")
|
||||||
if(cooldown > world.time)
|
if(cooldown > world.time)
|
||||||
say("Printer unavailable. Please allow a short time before attempting to print.")
|
say("Printer unavailable. Please allow a short time before attempting to print.")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
. = list()
|
. = list()
|
||||||
if(!isnum(amount) || amount<1)
|
if(!isnum(amount) || amount<1)
|
||||||
return
|
return
|
||||||
if(!establish_db_connection())
|
if (!dbcon.Connect())
|
||||||
if(fail_loud || prob(5))
|
if(fail_loud || prob(5))
|
||||||
var/obj/item/weapon/paper/P = new(location)
|
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>"
|
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>"
|
||||||
|
|||||||
@@ -40,9 +40,7 @@
|
|||||||
output += "<p><a href='byond://?src=\ref[src];observe=1'>Observe</A></p>"
|
output += "<p><a href='byond://?src=\ref[src];observe=1'>Observe</A></p>"
|
||||||
|
|
||||||
if(!IsGuestKey(src.key))
|
if(!IsGuestKey(src.key))
|
||||||
establish_db_connection()
|
if (dbcon.Connect())
|
||||||
|
|
||||||
if(dbcon.IsConnected())
|
|
||||||
var/isadmin = 0
|
var/isadmin = 0
|
||||||
if(src.client && src.client.holder)
|
if(src.client && src.client.holder)
|
||||||
isadmin = 1
|
isadmin = 1
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
/mob/new_player/proc/poll_player(pollid)
|
/mob/new_player/proc/poll_player(pollid)
|
||||||
if(!pollid)
|
if(!pollid)
|
||||||
return
|
return
|
||||||
if(!establish_db_connection())
|
if (!dbcon.Connect())
|
||||||
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM [format_table_name("poll_question")] WHERE id = [pollid]")
|
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"
|
var/table = "poll_vote"
|
||||||
if (text)
|
if (text)
|
||||||
table = "poll_textreply"
|
table = "poll_textreply"
|
||||||
if (!establish_db_connection())
|
if (!dbcon.Connect())
|
||||||
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
usr << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return
|
return
|
||||||
var/DBQuery/query_hasvoted = dbcon.NewQuery("SELECT id FROM `[format_table_name(table)]` WHERE pollid = [pollid] AND ckey = '[ckey]'")
|
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
|
return 1
|
||||||
|
|
||||||
/mob/new_player/proc/vote_valid_check(pollid, holder, type)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
pollid = text2num(pollid)
|
pollid = text2num(pollid)
|
||||||
@@ -406,7 +406,7 @@
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
/mob/new_player/proc/vote_on_irv_poll(pollid, list/votelist)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
if (!vote_rig_check())
|
if (!vote_rig_check())
|
||||||
@@ -482,7 +482,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/mob/new_player/proc/vote_on_poll(pollid, optionid)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
if (!vote_rig_check())
|
if (!vote_rig_check())
|
||||||
@@ -504,7 +504,7 @@
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
/mob/new_player/proc/log_text_poll_reply(pollid, replytext)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
if (!vote_rig_check())
|
if (!vote_rig_check())
|
||||||
@@ -533,7 +533,7 @@
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
/mob/new_player/proc/vote_on_numval_poll(pollid, optionid, rating)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
if (!vote_rig_check())
|
if (!vote_rig_check())
|
||||||
@@ -563,7 +563,7 @@
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
/mob/new_player/proc/vote_on_multi_poll(pollid, optionid)
|
/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>"
|
src << "<span class='danger'>Failed to establish database connection.</span>"
|
||||||
return 0
|
return 0
|
||||||
if (!vote_rig_check())
|
if (!vote_rig_check())
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
#define FAILED_DB_CONNECTION_CUTOFF 5
|
||||||
|
|
||||||
//cursors
|
//cursors
|
||||||
#define Default_Cursor 0
|
#define Default_Cursor 0
|
||||||
@@ -47,6 +47,7 @@ DBConnection
|
|||||||
//
|
//
|
||||||
var/server = ""
|
var/server = ""
|
||||||
var/port = 3306
|
var/port = 3306
|
||||||
|
var/failed_connections = 0
|
||||||
|
|
||||||
DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
|
DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
|
||||||
src.dbi = dbi_handler
|
src.dbi = dbi_handler
|
||||||
@@ -55,7 +56,26 @@ DBConnection/New(dbi_handler,username,password_handler,cursor_handler)
|
|||||||
src.default_cursor = cursor_handler
|
src.default_cursor = cursor_handler
|
||||||
_db_con = _dm_db_new_con()
|
_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)
|
if(!config.sql_enabled)
|
||||||
return 0
|
return 0
|
||||||
if(!src) 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
|
if(!cursor_handler) cursor_handler = Default_Cursor
|
||||||
return _dm_db_connect(_db_con,dbi_handler,user_handler,password_handler,cursor_handler,null)
|
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()
|
DBConnection/proc/IsConnected()
|
||||||
if(!config.sql_enabled) return 0
|
if(!config.sql_enabled) return 0
|
||||||
@@ -206,3 +228,6 @@ DBColumn/proc/SqlTypeName(type_handler=src.sql_type)
|
|||||||
#undef TIME
|
#undef TIME
|
||||||
#undef STRING
|
#undef STRING
|
||||||
#undef BLOB
|
#undef BLOB
|
||||||
|
|
||||||
|
|
||||||
|
#undef FAILED_DB_CONNECTION_CUTOFF
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ var/datum/feedback/blackbox = new()
|
|||||||
if (!feedback) return
|
if (!feedback) return
|
||||||
|
|
||||||
round_end_data_gathering() //round_end time logging and some other data processing
|
round_end_data_gathering() //round_end time logging and some other data processing
|
||||||
establish_db_connection()
|
if (!dbcon.Connect()) return
|
||||||
if (!dbcon.IsConnected()) return
|
|
||||||
var/round_id
|
var/round_id
|
||||||
|
|
||||||
var/DBQuery/query = dbcon.NewQuery("SELECT MAX(round_id) AS round_id FROM [format_table_name("feedback")]")
|
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)
|
for(var/mob/M in player_list)
|
||||||
if(M.client)
|
if(M.client)
|
||||||
playercount += 1
|
playercount += 1
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_game("SQL ERROR during player polling. Failed to connect.")
|
log_game("SQL ERROR during player polling. Failed to connect.")
|
||||||
else
|
else
|
||||||
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
||||||
@@ -227,8 +225,7 @@ var/datum/feedback/blackbox = new()
|
|||||||
if(!config.sql_enabled)
|
if(!config.sql_enabled)
|
||||||
return
|
return
|
||||||
var/admincount = admins.len
|
var/admincount = admins.len
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_game("SQL ERROR during admin polling. Failed to connect.")
|
log_game("SQL ERROR during admin polling. Failed to connect.")
|
||||||
else
|
else
|
||||||
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
||||||
@@ -273,8 +270,7 @@ var/datum/feedback/blackbox = new()
|
|||||||
var/coord = "[L.x], [L.y], [L.z]"
|
var/coord = "[L.x], [L.y], [L.z]"
|
||||||
var/map = MAP_NAME
|
var/map = MAP_NAME
|
||||||
var/server = "[world.internet_address]:[world.port]"
|
var/server = "[world.internet_address]:[world.port]"
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_game("SQL ERROR during death reporting. Failed to connect.")
|
log_game("SQL ERROR during death reporting. Failed to connect.")
|
||||||
else
|
else
|
||||||
var/DBQuery/query = dbcon.NewQuery("INSERT INTO [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]')")
|
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.")
|
log_game("Round ended without any feedback being generated. No feedback was sent to the database.")
|
||||||
return
|
return
|
||||||
|
|
||||||
establish_db_connection()
|
if(!dbcon.Connect())
|
||||||
if(!dbcon.IsConnected())
|
|
||||||
log_game("SQL ERROR during feedback reporting. Failed to connect.")
|
log_game("SQL ERROR during feedback reporting. Failed to connect.")
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ var/list/map_transition_config = MAP_TRANSITION_CONFIG
|
|||||||
timezoneOffset = text2num(time2text(0,"hh")) * 36000
|
timezoneOffset = text2num(time2text(0,"hh")) * 36000
|
||||||
|
|
||||||
if(config.sql_enabled)
|
if(config.sql_enabled)
|
||||||
if(!setup_database_connection())
|
if(!dbcon.Connect())
|
||||||
log_world("Your server failed to establish a connection with the database.")
|
log_world("Your server failed to establish a connection with the database.")
|
||||||
else
|
else
|
||||||
log_world("Database connection established.")
|
log_world("Database connection established.")
|
||||||
@@ -353,47 +353,6 @@ var/list/map_transition_config = MAP_TRANSITION_CONFIG
|
|||||||
|
|
||||||
status = s
|
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()
|
/proc/maprotate()
|
||||||
if (!SERVERTOOLS)
|
if (!SERVERTOOLS)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user