mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-09 16:14:13 +00:00
-Almost every instance of 'for(mob in world)' has been killed. Because GODDAMN was it being run a bunch. Instead, a series of global lists have been made, and they are all handled auto-magically through New()'s, Del()'s, Login()'s, death()'s, etc... Lists are as follows: -mob_list : Contains all atom/mobs by ref -player_list : Like mob_list, but only contains mobs with clients attached -admin_list : Like player_list, but holds all mobs with clients attached and admin status -living_mob_list : Contains all mobs that ARE alive, regardless of client status -dead_mob_list : Contains all mobs that are dead, which comes down to corpses and ghosts -cable_list : A list containing every obj/structure/cable in existence Note: There is an object (/obj/item/debuglist) that you can use to check the contents of each of the lists except for cables (Since getting a message saying "a cable," x9001 isn't very helpful) These lists have been tested as much as I could on my own, and have been mostly implemented. There are still places where they could be used, but for now it's important that the core is working. If this all checks out I would really like to implement it into the MC as well, simply so it doesn't check call Life() on every mob by checking for all the ones in world every damn tick. Just testing locally I was able to notice improvements with certain aspects, like admin verbs being MUCH more responsive (They checked for every mob in the world every time they were clicked), many sources of needless lag were cut out (Like Adminwho and Who checking every single mob when clicked), and due to the cable_list powernet rebuilding is MUCH more efficient, because instead of checking for every cable in the world every time a powernet was broken (read: A cable was deleted), it runs though the pre-made list, and even with a singulo tearing all the way across the station, the powernet load was VERY small compared to pretty much everything else. If you want to know how any of this works, check global_lists.dm, there I have it rigorously commented, and it should provide an understanding of what's going on. Mob related in worlds before this commit: 1262 After: 4 I'm helping git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4179 316c924e-a436-60f5-8080-3fe189b3f50e
198 lines
7.4 KiB
Plaintext
198 lines
7.4 KiB
Plaintext
proc/sql_poll_players()
|
|
if(!sqllogging)
|
|
return
|
|
var/playercount = 0
|
|
for(var/mob/M in player_list)
|
|
if(M.client)
|
|
playercount += 1
|
|
var/DBConnection/dbcon = new()
|
|
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
|
|
if(!dbcon.IsConnected())
|
|
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.NewQuery("INSERT INTO population (playercount, time) VALUES ([playercount], '[sqltime]')")
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during player polling. Error : \[[err]\]\n")
|
|
dbcon.Disconnect()
|
|
|
|
|
|
proc/sql_poll_admins()
|
|
if(!sqllogging)
|
|
return
|
|
var/admincount = 0
|
|
for (var/mob/M in admin_list)
|
|
if(M && M.client)
|
|
admincount += 1
|
|
var/DBConnection/dbcon = new()
|
|
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
|
|
if(!dbcon.IsConnected())
|
|
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.NewQuery("INSERT INTO population (admincount, time) VALUES ([admincount], '[sqltime]')")
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during admin polling. Error : \[[err]\]\n")
|
|
dbcon.Disconnect()
|
|
|
|
proc/sql_report_round_start()
|
|
// TODO
|
|
if(!sqllogging)
|
|
return
|
|
proc/sql_report_round_end()
|
|
// TODO
|
|
if(!sqllogging)
|
|
return
|
|
|
|
proc/sql_report_death(var/mob/living/carbon/human/H)
|
|
if(!sqllogging)
|
|
return
|
|
if(!H)
|
|
return
|
|
if(!H.key || !H.mind)
|
|
return
|
|
|
|
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)
|
|
var/sqlpod = sanitizeSQL(podname)
|
|
var/sqlspecial = sanitizeSQL(H.mind.special_role)
|
|
var/sqljob = sanitizeSQL(H.mind.assigned_role)
|
|
var/laname
|
|
var/lakey
|
|
if(H.lastattacker)
|
|
laname = sanitizeSQL(H.lastattacker:real_name)
|
|
lakey = sanitizeSQL(H.lastattacker:key)
|
|
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
|
var/coord = "[H.x], [H.y], [H.z]"
|
|
//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()])"
|
|
var/DBConnection/dbcon = new()
|
|
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
|
|
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]')")
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
|
|
dbcon.Disconnect()
|
|
|
|
|
|
proc/sql_report_cyborg_death(var/mob/living/silicon/robot/H)
|
|
if(!sqllogging)
|
|
return
|
|
if(!H)
|
|
return
|
|
if(!H.key || !H.mind)
|
|
return
|
|
|
|
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)
|
|
var/sqlpod = sanitizeSQL(podname)
|
|
var/sqlspecial = sanitizeSQL(H.mind.special_role)
|
|
var/sqljob = sanitizeSQL(H.mind.assigned_role)
|
|
var/laname
|
|
var/lakey
|
|
if(H.lastattacker)
|
|
laname = sanitizeSQL(H.lastattacker:real_name)
|
|
lakey = sanitizeSQL(H.lastattacker:key)
|
|
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
|
|
var/coord = "[H.x], [H.y], [H.z]"
|
|
//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()])"
|
|
var/DBConnection/dbcon = new()
|
|
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
|
|
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]')")
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
|
|
dbcon.Disconnect()
|
|
|
|
|
|
proc/statistic_cycle()
|
|
if(!sqllogging)
|
|
return
|
|
while(1)
|
|
sql_poll_players()
|
|
sleep(600)
|
|
sql_poll_admins()
|
|
sleep(6000) // Poll every ten minutes
|
|
|
|
//This proc is used for feedback. It is executed at round end.
|
|
proc/sql_commit_feedback()
|
|
if(!blackbox)
|
|
log_game("Round ended without a blackbox recorder. No feedback was sent to the database.")
|
|
return
|
|
|
|
//content is a list of lists. Each item in the list is a list with two fields, a variable name and a value. Items MUST only have these two values.
|
|
var/list/datum/feedback_variable/content = blackbox.get_round_feedback()
|
|
|
|
if(!content)
|
|
log_game("Round ended without any feedback being generated. No feedback was sent to the database.")
|
|
return
|
|
|
|
var/DBConnection/dbcon = new()
|
|
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
|
|
if(!dbcon.IsConnected())
|
|
log_game("SQL ERROR during feedback reporting. Failed to connect.")
|
|
else
|
|
|
|
var/DBQuery/max_query = dbcon.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]
|
|
|
|
if(!(isnum(newroundid)))
|
|
newroundid = text2num(newroundid)
|
|
|
|
if(isnum(newroundid))
|
|
newroundid++
|
|
else
|
|
newroundid = 1
|
|
|
|
for(var/datum/feedback_variable/item in content)
|
|
var/variable = item.get_variable()
|
|
var/value = item.get_value()
|
|
|
|
var/DBQuery/query = dbcon.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")
|
|
|
|
dbcon.Disconnect()
|
|
|
|
|
|
proc/debug_sql_commit_feedback()
|
|
if(!blackbox)
|
|
world << "Round ended without a blackbox recorder. No feedback was sent to the database."
|
|
return
|
|
|
|
//content is a list of lists. Each item in the list is a list with two fields, a variable name and a value. Items MUST only have these two values.
|
|
var/list/datum/feedback_variable/content = blackbox.get_round_feedback()
|
|
|
|
if(!content)
|
|
world << "Round ended without any feedback being generated. No feedback was sent to the database."
|
|
return
|
|
|
|
for(var/datum/feedback_variable/item in content)
|
|
var/variable = item.get_variable()
|
|
var/value = item.get_value()
|
|
|
|
world << "INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, ABC, Now(), '[variable]', '[value]')"
|
|
|
|
|
|
world << "end" |