Files
Aurora.3/code/controllers/subsystems/statistics.dm
Matt Atlas 659752e2ea Removes goonchat, adds TGChat and TG Stat Panels (#16514)
* tgui the beginning

* binaries and the like

* Bring in the last of it

* Example radio UI

* delete example

* NTOS Main Menu, start on manifest, tgui states

* tasks.json

* gunnery ui pt 1

* okay

* fix everything

* scss update

* oops

* manifest gigablast

* downloader part 1

* download prt 2

* NTOSDownloader final

* mfw committing to_worlds

* gunnery console pt2

* i cooked

* targeting (finished)

* one vueui down

* voting ui almost done

* MY MIND FEELS LIKE AN ARCH ENEMYYYY

* voting ui down

* photocopier

* ntos config + download fixes

* photocopier 2

* refactor define

* NTOS client manager + fixes

* fax machine final (it also uses toner now)

* marching forwards... left behind...

* ntnrc part 1

* canister

* add quotes

* portable pumps pt1 + more backgrounds

* oops

* finish the portable pump

* freezers

so I'll keep on pushing forward... you haven't seen the last of me... oooooooh...

* doors ui pt1

* finish doors UI (forgive me wildkins it's a bit of shitcode)

* vitals monitor, make things use labeled lists, new backgrounds

* mais j'envoyé aucun mayday...

* maglock pt1

* pour ça je me suis perdu...

* infrared

* fix that

* prox sensor pt1

* prox sensor

* signaler (this was actually pretty hard)

* atmos control pt1

* atmos control pt1.1

* atmos pt 2

* fuel injector

* multitool UI

* jammer

* list viewer

* APC

* portgen

* targeting console updates + SMES ui

* new themes, shield generator

* supermatter

* Add ore detector and (shitty) NTNet Relay

* orderterminal pt1

* orderterminal pt2

* smartfridge

* Add (air-)tank GUI update ore detector size

* Adds Transfer Valves

* Add AtmoScrubber

* analyzer pt1

* weapons analyzer pt2

* bodyscanner pt1

* bodyscanner pt2

* fix this shitcode

* seed storage

* appearance changer

* appearance changer final

* sleeper pt1

* sleeper

* gps

* vehicles

* chem dispenser

* lily request

* holopad

* tgui modules pt1

* ppanel

* damage menu

* fixes

* im here too now

* follow menu, search bars

* quikpay

* quikpay fixes

* circuit printer

* ppanel

* ppanel updates

* pai

* turret controls (i want to kill myself)

* tweak

* remove the boardgame

* guntracker

* implant tracker

* penal mechs

come close to me, come close to me

* chem codex

* pai radio

* doorjack

* pai directives

* signaler removal, sensors

* ghost spawner

* spawnpoint

* fixes

* teleporter

* one more to the chopping block

* account database

* remove divider

* scanner, atmos

* latejoin ui pt1

* latejoin

* records pt1

* RECORDS UI DONE

* delete interpreter & records

* CHAT FUCKING CLIENT

* data updates

* fix some things

* final UI, log

* basic nanoui fix

* antag panel

* remove vueui

* atm update

* vending update

* warrants, cameras

* ntmonitor

* time comes for all

* preserve this legacy

* bring that back (oops)

* rcon, ui auto update for computer UIs, remove rcon computers

* alarm monitoring (a bit broke and also todo: add custom alarm monitoring programs to a few consoles)

* A LIKE SUPREME

* a

* power monitor

* lights on

* fuck this code, fuck nanoui modules, and fuck nanoui

* LEAVE IT OH SO FAR BEHIND

* fix alarm monitoring for synths

* I SAW IN YOU WHAT LIFE WAS MISSING

* comms console

* idcard and record updates

* turn the light on

* arcade

* pt2

* news browser

* static

* crusher

* f

* COULD I JUST SLEIGH THE GOLD FROM THE BALLS? I'M SO FRUSTRATED OH COULD YOU TELL? IF I HEAR ONE MORE VUEUI OR ONE NANOUI I'M GONNA LOSE IT SO LET ME GOOOOOOOOOOOOOOOOO

* codeowners & suit sensors

* html ui style removal

* make lint happy

* tgchat

* tgpanels pt1

* THE SOUL LONGS FOR OBLIVION!!!!!!!!!!!!!!!!!

* figure out why stat isnt working

* goodbye ping

* shhh

* stat updates

* An oath sworn in scors! Omni vortex lies!

* final almost edits

* fix that

* last skin adjustments

* resist and disorder

* i slowly get up and turn off the noise, already fed up...

* pleaseeeeeeeeeeeeeee

* THE CREDIT LARP IS NECESSARY

* i hold the keys

* RISE UP

* fix that?

* harry's suggestions xoxo

* runtime fix pt2

* You are the only thing that I still care about

* fix runtimes and cl

* whoops

* misc fixes

* fix that too

* adds build workflow

* f

* Update update_tgui.yml

* adds some needed steps

* ATM

* misc fixes and tweaks

* fixes 2

* make newscasters usable and fix use power on freezers

* turret control is clearer

* remove duplicate

* makes some verb tabs work properly

* makes verbs work properly for real

* sans moi

* fixes pt2

* fix the chat unnecessarily reloading

* fixes

* epic

* fixes

* fix missing consoles

---------

Co-authored-by: John Wildkins <john.wildkins@gmail.com>
Co-authored-by: Matt Atlas <liermattia@gmail.com>
Co-authored-by: harryob <55142896+harryob@users.noreply.github.com>
Co-authored-by: Werner <Arrow768@users.noreply.github.com>
Co-authored-by: Geeves <ggrobler447@gmail.com>
Co-authored-by: harryob <me@harryob.live>
2023-06-26 02:00:14 +02:00

294 lines
9.0 KiB
Plaintext

/var/datum/controller/subsystem/statistics/SSfeedback
/datum/controller/subsystem/statistics
name = "Statistics & Inactivity"
wait = 1 MINUTE
flags = SS_NO_TICK_CHECK | SS_BACKGROUND
priority = SS_PRIORITY_STATISTICS
var/kicked_clients = 0
var/list/messages = list() //Stores messages of non-standard frequencies
var/list/messages_admin = list()
var/list/msg_common = list()
var/list/msg_science = list()
var/list/msg_command = list()
var/list/msg_medical = list()
var/list/msg_engineering = list()
var/list/msg_security = list()
var/list/msg_deathsquad = list()
var/list/msg_syndicate = list()
var/list/msg_raider = list()
var/list/msg_burglar = list()
var/list/msg_ninja = list()
var/list/msg_bluespace = list()
var/list/msg_cargo = list()
var/list/msg_service = list()
var/list/msg_ship = list()
var/list/datum/statistic/simple_statistics = list()
var/list/datum/feedback_variable/feedback = list()
var/status_needs_update = FALSE
/datum/controller/subsystem/statistics/New()
NEW_SS_GLOBAL(SSfeedback)
/datum/controller/subsystem/statistics/Initialize(timeofday)
for (var/type in subtypesof(/datum/statistic) - list(/datum/statistic/numeric, /datum/statistic/grouped))
var/datum/statistic/S = new type
if (!S.name)
qdel(S)
continue
simple_statistics[S.key] = S
sortTim(simple_statistics, GLOBAL_PROC_REF(cmp_name_asc), TRUE)
/datum/controller/subsystem/statistics/fire()
// Handle AFK.
if(config.kick_inactive)
var/inactivity_threshold = config.kick_inactive MINUTES
for(var/client/C in clients)
if(!isobserver(C.mob) && !C.holder)
if(C.is_afk(inactivity_threshold))
log_access("AFK: [key_name(C)]")
to_chat_immediate(C, SPAN_WARNING("You have been inactive for more than [config.kick_inactive] minute\s and have been disconnected."))
qdel(C)
kicked_clients++
// Handle population polling.
if (config.sql_enabled && config.sql_stats)
var/admincount = staff.len
var/playercount = 0
for(var/mob/M in player_list)
if(M.client)
playercount += 1
if(!establish_db_connection(dbcon))
log_game("SQL ERROR during population polling. Failed to connect.")
else
var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")
var/DBQuery/query = dbcon.NewQuery("INSERT INTO `ss13_population` (`playercount`, `admincount`, `time`) VALUES ([playercount], [admincount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during population polling. Error : \[[err]\]\n")
if (status_needs_update)
// Update world status.
world.update_status()
status_needs_update = FALSE
/datum/controller/subsystem/statistics/proc/update_status()
status_needs_update = TRUE
/datum/controller/subsystem/statistics/Recover()
src.messages = SSfeedback.messages
src.messages_admin = SSfeedback.messages_admin
src.msg_common = SSfeedback.msg_common
src.msg_science = SSfeedback.msg_science
src.msg_command = SSfeedback.msg_command
src.msg_medical = SSfeedback.msg_medical
src.msg_engineering = SSfeedback.msg_engineering
src.msg_security = SSfeedback.msg_security
src.msg_deathsquad = SSfeedback.msg_deathsquad
src.msg_syndicate = SSfeedback.msg_syndicate
src.msg_cargo = SSfeedback.msg_cargo
src.msg_service = SSfeedback.msg_service
src.feedback = SSfeedback.feedback
/datum/controller/subsystem/statistics/proc/find_feedback_datum(variable)
for (var/datum/feedback_variable/FV in feedback)
if (FV.get_variable() == variable)
return FV
var/datum/feedback_variable/FV = new(variable)
feedback += FV
return FV
/datum/controller/subsystem/statistics/proc/get_round_feedback()
return feedback
/datum/controller/subsystem/statistics/proc/round_end_data_gathering()
var/pda_msg_amt = 0
var/rc_msg_amt = 0
for(var/obj/machinery/telecomms/message_server/MS in SSmachinery.all_telecomms)
if(MS.pda_msgs.len > pda_msg_amt)
pda_msg_amt = MS.pda_msgs.len
if(MS.rc_msgs.len > rc_msg_amt)
rc_msg_amt = MS.rc_msgs.len
feedback_set_details("radio_usage","")
feedback_add_details("radio_usage","COM-[msg_common.len]")
feedback_add_details("radio_usage","SCI-[msg_science.len]")
feedback_add_details("radio_usage","HEA-[msg_command.len]")
feedback_add_details("radio_usage","MED-[msg_medical.len]")
feedback_add_details("radio_usage","ENG-[msg_engineering.len]")
feedback_add_details("radio_usage","SEC-[msg_security.len]")
feedback_add_details("radio_usage","DTH-[msg_deathsquad.len]")
feedback_add_details("radio_usage","SYN-[msg_syndicate.len]")
feedback_add_details("radio_usage","CAR-[msg_cargo.len]")
feedback_add_details("radio_usage","SRV-[msg_service.len]")
feedback_add_details("radio_usage","OTH-[messages.len]")
feedback_add_details("radio_usage","RC-[rc_msg_amt]")
for (var/key in simple_statistics)
var/datum/statistic/S = simple_statistics[key]
if (S.write_to_db && S.key)
S.write_to_database()
feedback_set_details("round_end","[time2text(world.realtime)]") //This one MUST be the last one that gets set.
/datum/controller/subsystem/statistics/proc/print_round_end_message()
var/list/dat = list()
dat += "<h3>Round Statistics</h3>"
for (var/statistic in simple_statistics)
var/datum/statistic/S = simple_statistics[statistic]
if (S.broadcast_at_roundend && S.has_value())
dat += SPAN_NOTICE("<b>[S]:</b> [S.get_roundend_lines()]")
to_chat(world, dat.Join("\n"))
// Called on world reboot.
/datum/controller/subsystem/statistics/Shutdown()
if(!feedback)
return
if (!config.sql_enabled || !config.sql_stats)
return
round_end_data_gathering() //round_end time logging and some other data processing
if(!establish_db_connection(dbcon))
return
for(var/datum/feedback_variable/FV in feedback)
var/sql = "INSERT INTO ss13_feedback VALUES (null, Now(), \"[game_id]\", \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")"
var/DBQuery/query_insert = dbcon.NewQuery(sql)
query_insert.Execute()
// Sanitize inputs to avoid SQL injection attacks
/proc/sql_sanitize_text(var/text)
text = replacetext(text, "'", "''")
text = replacetext(text, ";", "")
text = replacetext(text, "&", "")
return text
/proc/feedback_set(var/variable,var/value)
if(!SSfeedback)
return
variable = sql_sanitize_text(variable)
var/datum/feedback_variable/FV = SSfeedback.find_feedback_datum(variable)
if(!FV) return
FV.set_value(value)
/proc/feedback_inc(var/variable,var/value)
if(!SSfeedback) return
variable = sql_sanitize_text(variable)
var/datum/feedback_variable/FV = SSfeedback.find_feedback_datum(variable)
if(!FV) return
FV.inc(value)
/proc/feedback_dec(var/variable,var/value)
if(!SSfeedback) return
variable = sql_sanitize_text(variable)
var/datum/feedback_variable/FV = SSfeedback.find_feedback_datum(variable)
if(!FV) return
FV.dec(value)
/proc/feedback_set_details(var/variable,var/details)
if(!SSfeedback) return
variable = sql_sanitize_text(variable)
details = sql_sanitize_text(details)
var/datum/feedback_variable/FV = SSfeedback.find_feedback_datum(variable)
if(!FV) return
FV.set_details(details)
/proc/feedback_add_details(var/variable,var/details)
if(!SSfeedback) return
variable = sql_sanitize_text(variable)
details = sql_sanitize_text(details)
var/datum/feedback_variable/FV = SSfeedback.find_feedback_datum(variable)
if(!FV) return
FV.add_details(details)
/proc/sql_report_death(var/mob/living/H)
if(!config.sql_enabled || !config.sql_stats)
return
if(!H)
return
if(!istype(H, /mob/living/carbon/human) && !istype(H, /mob/living/silicon/robot))
return
if(!H.key || !H.mind)
return
var/area/placeofdeath = get_area(H)
var/podname = placeofdeath ? "[placeofdeath]" : "Unknown area"
if(!establish_db_connection(dbcon))
log_game("SQL ERROR during death reporting. Failed to connect.")
else
var/DBQuery/query = dbcon.NewQuery("INSERT INTO ss13_death (name, ckey, char_id, job, special, pod, tod, laname, lackey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES \
(:name:, :ckey:, :char_id:, :job:, :special:, :pod:, :tod:, :laname:, :lackey:, :gender:, :bruteloss:, :fireloss:, :brainloss:, :oxyloss:, :coord:')")
if(!query.Execute(list(
"name"=H.real_name,
"ckey"=H.ckey,
"char_id"=H.character_id,
"job"=H?.mind.assigned_role,
"special"=H?.mind.special_role,
"pod"=podname,
"tod"=time2text(world.realtime, "YYYY-MM-DD hh:mm:ss"),
"laname"=H?.lastattacker?.real_name,
"lackey"=H?.lastattacker?.ckey,
"gender"=H.gender,
"bruteloss"=H.getBruteLoss(),
"fireloss"=H.getFireLoss(),
"brainloss"=H.getBrainLoss(),
"oxyloss"=H.getOxyLoss(),
"coord"="[H.x], [H.y], [H.z]")
))
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
/datum/controller/subsystem/statistics/proc/IncrementSimpleStat(stat)
. = TRUE
var/datum/statistic/numeric/S = simple_statistics[stat]
if (!S)
return FALSE
S.increment_value()
/datum/controller/subsystem/statistics/proc/IncrementGroupedStat(stat, key)
. = TRUE
var/datum/statistic/grouped/S = simple_statistics[stat]
if (!S)
return FALSE
S.increment_value(key)
/datum/controller/subsystem/statistics/stat_entry(msg)
msg = "Kicked: [kicked_clients]"
return ..()