How the Anti-AFK System Works in phpDTS: Technical Analysis of antiAFKmng.php

The anti-AFK system in the amarillonmc/phpdts repository combines automatic idle detection through the antiAFK() function with manual administrator controls in include/admin/antiAFKmng.php, automatically removing inactive players when they exceed the $antiAFKertime threshold while allowing admins to force-remove idle users via kill_all_AFKer().

The amarillonmc/phpdts project implements a robust two-tier mechanism to maintain game flow by eliminating inactive participants. This system operates through automatic game-tick detection and manual administrative overrides, ensuring that away-from-keyboard (AFK) players do not stall ongoing matches. At its core, the implementation relies on timing checks against player activity timestamps and configurable idle limits stored in the game's configuration layer.

Automatic AFK Detection During Gameplay

The Core antiAFK() Function Implementation

In include/system.func.php, the system defines the antiAFK($timelimit = 0) function starting at line 913. This routine evaluates the global $antiAFKertime configuration value, which represents the default idle-time limit in minutes. When invoked without parameters, the function uses this global setting to determine which players have exceeded the allowed inactivity window.

Game Tick Execution in common.inc.php

The automatic trigger resides in include/common.inc.php at lines 249-251. The system checks if the current game state is active ($gamestate >= 40) and whether the current timestamp exceeds the sum of the last activity marker and the configured interval:

if (($gamestate >= 40) && ($now > $afktime + $antiAFKertime * 60)) {
    antiAFK();                // automatically removes idle players
}

When this condition evaluates to true, the engine executes antiAFK(), immediately removing players who have not performed actions within the defined $antiAFKertime window.

Manual AFK Management via antiAFKmng.php

Administrator Interface and Form Handling

The file include/admin/antiAFKmng.php provides the administrative interface for manual AFK cleanup. Starting at line 51, the script renders a form allowing administrators to specify a custom idle limit in minutes. When submitted, this form triggers the manual purge routine with the user-defined threshold rather than the global configuration value.

The kill_all_AFKer() Function

Defined at lines 12-13 in include/admin/antiAFKmng.php, the kill_all_AFKer($timelimit) function iterates through all online player records. It compares each player's last activity timestamp against the supplied $timelimit parameter, terminating sessions for those whose idle duration meets or exceeds the specified minutes:

// Admin submits the form with a custom limit (e.g., 10 minutes)
$timelimit = (int)$_POST['timelimit'];
kill_all_AFKer($timelimit);   // removes players idle ≥ $timelimit minutes

Safety Guards Against Accidental Removal

To prevent administrators from inadvertently removing active players, the file implements a hardcoded safety minimum. At line 7, the script sets $antiAFKintv = 3, establishing a three-minute floor for manual operations. Lines 18-19 enforce this constraint, rejecting any submitted threshold below three minutes regardless of administrative intent.

Configuration Variables and File Structure

The anti-AFK system relies on specific configuration values and source files across the phpDTS codebase:

Key Configuration Values

Core Implementation Files

Summary

  • The phpDTS anti-AFK system operates through two complementary mechanisms: automatic game-tick detection and manual administrative cleanup.
  • Automatic removal relies on antiAFK() in include/system.func.php, triggered from include/common.inc.php when $gamestate >= 40 and idle time exceeds $antiAFKertime.
  • Manual management occurs through include/admin/antiAFKmng.php, using kill_all_AFKer() to purge players based on administrator-specified thresholds.
  • A three-minute safety minimum ($antiAFKintv) prevents accidental removal of recently active players during manual operations.
  • Configuration persists through gamecfgmng.php and cached ruleset files, allowing per-game customization of idle limits.

Frequently Asked Questions

What triggers the automatic anti-AFK check in phpDTS?

The automatic check executes during each game tick when the system detects an active match state ($gamestate >= 40) and the current server time exceeds the last activity timestamp plus the configured idle interval ($now > $afktime + $antiAFKertime * 60). This logic resides in include/common.inc.php at lines 249-251.

How does manual AFK cleanup differ from automatic detection?

Automatic detection uses the global $antiAFKertime configuration value and runs unprompted during gameplay, while manual cleanup allows administrators to specify custom thresholds through the antiAFKmng.php interface. The manual process explicitly calls kill_all_AFKer($timelimit) with the form-submitted value rather than relying on the default configuration.

What is the minimum idle time allowed for manual AFK removal?

The system enforces a hard minimum of three minutes through the $antiAFKintv variable defined at line 7 of include/admin/antiAFKmng.php. Lines 18-19 validate that submitted thresholds meet or exceed this floor, preventing administrators from accidentally removing players who have been idle for less than three minutes.

Where is the default AFK time limit configured?

The default idle time limit $antiAFKertime is configured through include/admin/gamecfgmng.php and stored in cached configuration files such as gamedata/cache/gamecfg_1.php. This value controls the automatic detection threshold but does not constrain manual administrative operations beyond the three-minute safety minimum.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →