From 2373e2e48547de9e1f96e65e08c48315d192c15c Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Sat, 15 Apr 2017 14:45:29 -0500 Subject: [PATCH] Afk fixup (#412) --- code/__HELPERS/game.dm | 4 ++-- code/_compile_options.dm | 2 -- code/controllers/configuration.dm | 12 ++++++++---- code/controllers/subsystem/server_maint.dm | 9 +++++---- code/modules/client/client_procs.dm | 4 ++-- config/config.txt | 8 +++++++- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index a727d85dff..6fd41f7ea1 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -313,10 +313,10 @@ // Will return a list of active candidates. It increases the buffer 5 times until it finds a candidate which is active within the buffer. -/proc/get_candidates(be_special_type, afk_bracket=3000, var/jobbanType) +/proc/get_candidates(be_special_type, afk_bracket = config.inactivity_period, jobbanType) var/list/candidates = list() // Keep looping until we find a non-afk candidate within the time bracket (we limit the bracket to 10 minutes (6000)) - while(!candidates.len && afk_bracket < 6000) + while(!candidates.len && afk_bracket < config.afk_period) for(var/mob/dead/observer/G in GLOB.player_list) if(G.client != null) if(!(G.mind && G.mind.current && G.mind.current.stat != DEAD)) diff --git a/code/_compile_options.dm b/code/_compile_options.dm index ec06a6221c..ba5cce3afb 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -20,8 +20,6 @@ #define BACKGROUND_ENABLED 0 // The default value for all uses of set background. Set background can cause gradual lag and is recommended you only turn this on if necessary. // 1 will enable set background. 0 will disable set background. -#define INACTIVITY_KICK 6000 //10 minutes in ticks (approx.) - //ADMIN STUFF #define ROUNDSTART_LOGOUT_REPORT_TIME 6000 //Amount of time (in deciseconds) after the rounds starts, that the player disconnect report is issued. diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 1aa1f3d4fa..fe9d7c5bc5 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -66,7 +66,9 @@ var/respawn = 1 var/guest_jobban = 1 var/usewhitelist = 0 - var/kick_inactive = 0 //force disconnect for inactive players + var/inactivity_period = 3000 //time in ds until a player is considered inactive + var/afk_period = 6000 //time in ds until a player is considered afk and kickable + var/kick_inactive = FALSE //force disconnect for inactive players var/load_jobs_from_txt = 0 var/automute_on = 0 //enables automuting/spam prevention var/minimal_access_threshold = 0 //If the number of players is larger than this threshold, minimal access will be turned on. @@ -408,10 +410,12 @@ usewhitelist = TRUE if("allow_metadata") allow_Metadata = 1 + if("inactivity_period") + inactivity_period = text2num(value) * 10 //documented as seconds in config.txt + if("afk_period") + afk_period = text2num(value) * 10 // ^^^ if("kick_inactive") - if(value < 1) - value = INACTIVITY_KICK - kick_inactive = value + kick_inactive = TRUE if("load_jobs_from_txt") load_jobs_from_txt = 1 if("forbid_singulo_possession") diff --git a/code/controllers/subsystem/server_maint.dm b/code/controllers/subsystem/server_maint.dm index 84d0d333e4..3ef088b328 100644 --- a/code/controllers/subsystem/server_maint.dm +++ b/code/controllers/subsystem/server_maint.dm @@ -10,12 +10,13 @@ SUBSYSTEM_DEF(server_maint) /datum/controller/subsystem/server_maint/fire() //handle kicking inactive players - if(config.kick_inactive > 0) + if(config.kick_inactive) for(var/client/C in GLOB.clients) - if(C.is_afk(INACTIVITY_KICK)) - if(!istype(C.mob, /mob/dead)) + if(C.is_afk(config.afk_period)) + var/cmob = C.mob + if(!(istype(cmob, /mob/dead/observer) || (istype(cmob, /mob/dead) && C.holder))) log_access("AFK: [key_name(C)]") - to_chat(C, "You have been inactive for more than 10 minutes and have been disconnected.") + to_chat(C, "You have been inactive for more than [config.afk_period / 600] minutes and have been disconnected.") qdel(C) if(config.sql_enabled) diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index b78d4d5ff4..0969e53e0d 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -549,10 +549,10 @@ GLOBAL_LIST(external_rsc_urls) //checks if a client is afk //3000 frames = 5 minutes -/client/proc/is_afk(duration=3000) +/client/proc/is_afk(duration = config.inactivity_period) if(inactivity > duration) return inactivity - return 0 + return FALSE // Byond seemingly calls stat, each tick. // Calling things each tick can get expensive real quick. diff --git a/config/config.txt b/config/config.txt index 9b1eb06518..2de9427df3 100644 --- a/config/config.txt +++ b/config/config.txt @@ -90,7 +90,13 @@ LOG_LAW ## As an example of how this could be """useful""" look towards Poly (https://twitter.com/Poly_the_Parrot) # LOG_TWITTER -## disconnect players who did nothing during 10 minutes +## period of time in seconds for players to be considered inactive +# INACTIVITY_PERIOD 300 + +## period of time in seconds for players to be considered afk and kickable +# AFK_PERIOD 600 + +## disconnect players who are considered afk # KICK_INACTIVE ## Comment this out to stop admins being able to choose their personal ooccolor