Skip to main content

AfkTimer

A class in Root.Township, the global namespace.

Server: kicks players who don't move or hit anything for a while, when the server's AFK timer setting is on.

Constructors​

MemberWhat it is
AfkTimer()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private float gracePeriodSeconds between the warning and the kick. Defaults to 30.
private bool isEnabledWhether the timer is on, from the server's HasAFKTimer setting.
private static Logger loggerClass logger.
private Dictionary<Player, Coroutine> timeoutsRunning timeout coroutines by player.
private float timerInSecondsIdle seconds before the warning. Defaults to 600.

Methods​

14 private and internal methods
MemberWhat it is
private void CheckUpdateSettings(ServerSettings settings)Turns the timer on or off when the server's HasAFKTimer setting changes.
private void OnDisable()Unhooks the server start and end events.
private void PlayerControllerSet(Player player, PlayerController playerController)Listens to the new controller's movement and tool hits and restarts the timer; stops it if the controller is gone.
private void PlayerJoined(Player player)Listens for the player's controller being set.
private void PlayerLeft(Player player)Stops the player's timer.
private void PositionChanged(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Restarts the player's timer when they move.
private void ResetTimeout(Player player)Stops and restarts the player's timeout coroutine.
private void ResetWithHit(ImpactHitWithTool hit, ImpactTool tool)Restarts the wielder's timer when they hit something with a tool.
private void ServerEnded()Stops every player's timer.
private void ServerStarted()Reads the AFK setting, listens for setting changes and applies it.
private void Start()Hooks the server start and end events.
private void StopTimeout(Player player)Stops and removes the player's timeout coroutine.
private void UpdateSettings()When on, hooks joins and leaves and sets up current players; when off, unhooks and stops every timer.
private IEnumerator WaitForTimeout(Player player) (iterator)Waits timerInSeconds, warns the player, waits gracePeriod, says they're disconnected, then kicks after 5 seconds. The warning wrongly quotes timerInSeconds.