Cleans up some awful code from the ticker

This commit is contained in:
AffectedArc07
2020-05-30 11:07:40 +01:00
parent 73fe71cb79
commit 7927391042
4 changed files with 37 additions and 60 deletions
+28
View File
@@ -0,0 +1,28 @@
SUBSYSTEM_DEF(statistics)
name = "Statistics"
wait = 6000 // 10 minute delay between fires
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME // Only count time actually ingame to avoid logging pre-round dips
offline_implications = "Player count and admin count statistics will no longer be logged to the database. No immediate action is needed."
/datum/controller/subsystem/statistics/Initialize(start_timeofday)
if(!config.sql_enabled)
flags |= SS_NO_FIRE // Disable firing if SQL is disabled
return ..()
/datum/controller/subsystem/statistics/fire(resumed = 0)
sql_poll_players()
/datum/controller/subsystem/statistics/proc/sql_poll_players()
if(!config.sql_enabled)
return
var/playercount = GLOB.clients.len
var/admincount = GLOB.admins.len
if(!GLOB.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 = GLOB.dbcon.NewQuery("INSERT INTO [format_table_name("legacy_population")] (playercount, admincount, time) VALUES ([playercount], [admincount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during playercount polling. Error: \[[err]\]\n")
+8 -19
View File
@@ -29,7 +29,7 @@ SUBSYSTEM_DEF(ticker)
var/pregame_timeleft // This is used for calculations
var/delay_end = 0 //if set to nonzero, the round will not restart on it's own
var/triai = 0//Global holder for Triumvirate
var/initialtpass = 0 //holder for inital autotransfer vote timer
var/next_autotransfer = 0 //holder for inital autotransfer vote timer
var/obj/screen/cinematic = null //used for station explosion cinematic
var/round_end_announced = 0 // Spam Prevention. Announce round end only once.
var/ticker_going = TRUE // This used to be in the unused globals, but it turns out its actually used in a load of places. Its now a ticker var because its related to round stuff, -aa
@@ -90,6 +90,11 @@ SUBSYSTEM_DEF(ticker)
delay_end = 0 // reset this in case round start was delayed
mode.process()
mode.process_job_tasks()
if(world.time > next_autotransfer)
SSvote.autotransfer()
next_autotransfer = world.time + config.vote_autotransfer_interval
var/game_finished = SSshuttle.emergency.mode >= SHUTTLE_ENDGAME || mode.station_was_nuked
if(config.continuous_rounds)
mode.check_finished() // some modes contain var-changing code in here, so call even if we don't uses result
@@ -111,19 +116,6 @@ SUBSYSTEM_DEF(ticker)
else
world.Reboot("Round ended.", "end_proper", "proper completion")
/datum/controller/subsystem/ticker/proc/votetimer()
var/timerbuffer = 0
if(initialtpass == 0)
timerbuffer = config.vote_autotransfer_initial
else
timerbuffer = config.vote_autotransfer_interval
spawn(timerbuffer)
SSvote.autotransfer()
initialtpass = 1
votetimer()
/datum/controller/subsystem/ticker/proc/setup()
cultdat = setupcult()
//Create and announce mode
@@ -281,11 +273,8 @@ SUBSYSTEM_DEF(ticker)
auto_toggle_ooc(0) // Turn it off
round_start_time = world.time
if(config.sql_enabled)
spawn(3000)
statistic_cycle() // Polls population totals regularly and stores them in an SQL DB
votetimer()
// Sets the auto shuttle vote to happen after the config duration
next_autotransfer = world.time + config.vote_autotransfer_initial
for(var/mob/new_player/N in GLOB.mob_list)
if(N.client)
-41
View File
@@ -1,35 +1,3 @@
/proc/sql_poll_players()
if(!config.sql_enabled)
return
var/playercount = 0
for(var/mob/M in GLOB.player_list)
if(M.client)
playercount += 1
establish_db_connection()
if(!GLOB.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 = GLOB.dbcon.NewQuery("INSERT INTO [format_table_name("legacy_population")] (playercount, time) VALUES ([playercount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during player polling. Error : \[[err]\]\n")
/proc/sql_poll_admins()
if(!config.sql_enabled)
return
var/admincount = GLOB.admins.len
establish_db_connection()
if(!GLOB.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 = GLOB.dbcon.NewQuery("INSERT INTO [format_table_name("legacy_population")] (admincount, time) VALUES ([admincount], '[sqltime]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during admin polling. Error : \[[err]\]\n")
/proc/sql_report_round_start()
// TODO
if(!config.sql_enabled)
@@ -110,15 +78,6 @@
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")
/proc/statistic_cycle()
if(!config.sql_enabled)
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(!GLOB.blackbox)
+1
View File
@@ -242,6 +242,7 @@
#include "code\controllers\subsystem\radio.dm"
#include "code\controllers\subsystem\shuttles.dm"
#include "code\controllers\subsystem\spacedrift.dm"
#include "code\controllers\subsystem\statistics.dm"
#include "code\controllers\subsystem\sun.dm"
#include "code\controllers\subsystem\throwing.dm"
#include "code\controllers\subsystem\ticker.dm"