mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-22 14:37:49 +01:00
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request update time related procs & glob too (i was originally targeting that lmao). also **stop** using byondtime for sql stuff, we have `NOW()`!! <!-- Describe The Pull Request. Please be sure every change is documented or this can delay review and even discourage maintainers from merging your PR! --> ## Why It's Good For The Game <!-- Argue for the merits of your changes and how they benefit the game, especially if they are controversial and/or far reaching. If you can't actually explain WHY what you are doing will improve the game, then it probably isn't good for the game in the first place. --> ## Changelog <!-- If your PR modifies aspects of the game that can be concretely observed by players or admins you should add a changelog. If your change does NOT meet this description, remove this section. Please note that maintainers freely reserve the right to remove and add tags should they deem it appropriate. You can attempt to finagle the system all you want, but it's best to shoot for clear communication right off the bat. --> <!-- Both 🆑's are required for the changelog to work! You can put your name to the right of the first 🆑 if you want to overwrite your GitHub username as author ingame. --> <!-- You can use multiple of the same prefix (they're only used for the icon ingame) and delete the unneeded ones. Despite some of the tags, changelogs should generally represent how a player might be affected by the changes rather than a summary of the PR's contents. -->
178 lines
5.2 KiB
Plaintext
178 lines
5.2 KiB
Plaintext
/proc/sql_poll_population()
|
|
var/admincount = GLOB.admins.len
|
|
var/playercount = 0
|
|
for(var/mob/M in GLOB.player_list)
|
|
if(M.client)
|
|
playercount += 1
|
|
|
|
if(!SSdbcore.Connect())
|
|
log_game("SQL ERROR during population polling. Failed to connect.")
|
|
else
|
|
var/datum/db_query/query = SSdbcore.NewQuery(
|
|
"INSERT INTO [DB_PREFIX_TABLE_NAME("population")] (playercount, admincount, time) VALUES (:pc, :ac, NOW())",
|
|
list(
|
|
"pc" = sanitizeSQL(playercount),
|
|
"ac" = sanitizeSQL(admincount),
|
|
)
|
|
)
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during population polling. Error : \[[err]\]\n")
|
|
qdel(query)
|
|
|
|
/proc/sql_report_death(mob/living/carbon/human/H)
|
|
if(!H)
|
|
return
|
|
if(!H.key || !H.mind)
|
|
return
|
|
|
|
var/area/placeofdeath = get_area(H)
|
|
var/podname = placeofdeath ? placeofdeath.name : "Unknown area"
|
|
|
|
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/coord = "[H.x], [H.y], [H.z]"
|
|
|
|
if(!SSdbcore.Connect())
|
|
log_game("SQL ERROR during death reporting. Failed to connect.")
|
|
else
|
|
var/datum/db_query/query = SSdbcore.NewQuery(
|
|
"INSERT INTO [DB_PREFIX_TABLE_NAME("death")] (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES \
|
|
(:name, :key, :job, :special, :pod, NOW(), :laname, :lakey, :gender, :bruteloss, :fireloss, :brainloss, :oxyloss, :coord)",
|
|
list(
|
|
"name" = sqlname,
|
|
"key" = sqlkey,
|
|
"job" = sqljob,
|
|
"special" = sqlspecial,
|
|
"pod" = sqlpod,
|
|
"laname" = laname,
|
|
"lakey" = lakey,,
|
|
"gender" = H.gender,
|
|
"bruteloss" = H.getBruteLoss(),
|
|
"fireloss" = H.getFireLoss(),
|
|
"brainloss" = H.getBrainLoss(),
|
|
"oxyloss" = H.getOxyLoss(),
|
|
"coord" = coord,
|
|
)
|
|
)
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
|
|
qdel(query)
|
|
|
|
/proc/sql_report_cyborg_death(mob/living/silicon/robot/H)
|
|
if(!H)
|
|
return
|
|
if(!H.key || !H.mind)
|
|
return
|
|
|
|
var/area/placeofdeath = get_area(H)
|
|
var/podname = placeofdeath ? placeofdeath.name : "Unknown area"
|
|
|
|
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/coord = "[H.x], [H.y], [H.z]"
|
|
|
|
if(!SSdbcore.Connect())
|
|
log_game("SQL ERROR during death reporting. Failed to connect.")
|
|
else
|
|
var/datum/db_query/query = SSdbcore.NewQuery(
|
|
"INSERT INTO [DB_PREFIX_TABLE_NAME("death")] (name, byondkey, job, special, pod, tod, laname, lakey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES \
|
|
(:name, :key, :job, :special, :pod, NOW(), :laname, :lakey, :geender, :bruteloss, :fireloss, :brainloss, :oxyloss, :coord)",
|
|
list(
|
|
"name" = sqlname,
|
|
"key" = sqlkey,
|
|
"job" = sqljob,
|
|
"special" = sqlspecial,
|
|
"pod" = sqlpod,
|
|
"laname" = laname,
|
|
"lakey" = lakey,,
|
|
"gender" = H.gender,
|
|
"bruteloss" = H.getBruteLoss(),
|
|
"fireloss" = H.getFireLoss(),
|
|
"brainloss" = H.getBrainLoss(),
|
|
"oxyloss" = H.getOxyLoss(),
|
|
"coord" = coord,
|
|
)
|
|
)
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
|
|
qdel(query)
|
|
|
|
|
|
/proc/statistic_cycle()
|
|
while(1)
|
|
sql_poll_population()
|
|
sleep(6000)
|
|
|
|
// 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
|
|
|
|
if(!SSdbcore.Connect())
|
|
log_game("SQL ERROR during feedback reporting. Failed to connect.")
|
|
else
|
|
|
|
var/datum/db_query/max_query = SSdbcore.RunQuery(
|
|
"SELECT MAX(roundid) AS max_round_id FROM [DB_PREFIX_TABLE_NAME("feedback")]",
|
|
list(),
|
|
)
|
|
|
|
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/datum/db_query/query = SSdbcore.NewQuery(
|
|
"INSERT INTO [DB_PREFIX_TABLE_NAME("feedback")] (id, roundid, time, variable, value) VALUES (null, :rid, Now(), :var, :val)",
|
|
list(
|
|
"rid" = newroundid,
|
|
"var" = sanitizeSQL(variable),
|
|
"val" = sanitizeSQL(value),
|
|
)
|
|
)
|
|
if(!query.Execute())
|
|
var/err = query.ErrorMsg()
|
|
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
|
|
qdel(query)
|