mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user