Skip to content

Inactive Player Management

Latest
Compare
Choose a tag to compare
@jimmybutzen jimmybutzen released this 27 Oct 14:55

AkimboInactivityManager

Overview

AkimboInactivityManager is a sub class to track player inactivity when logged on to the server.

Features

  • Inactivity Tracking: Automatically tracks players' positions and activities. If a player remains inactive for longer than a configurable threshold, they will be disconnected.
  • Configurable Options: The manager reads settings from a configuration file, allowing you to set the inactivity threshold, timer check intervals, and enable or disable the manager.
  • Player Privilege Handling: Players with the correct privileges set in the config file will be exempted from being tracked and disconnected due to inactivity.
  • Activity-Based Behavior: The manager respects player actions, such as using in-game elements, and will not disconnect players while they are actively interacting with these elements.

Configuration

The InactivePlayerManager can be configured through a settings file, which includes the following parameters:

  • enabled: Determines whether the InactivePlayerManager is active. When set to false, all inactivity checks are skipped.
  • inactivityThreshold: The time in seconds that a player can remain inactive before being disconnected (e.g., 600 seconds for 10 minutes).
  • timerCheck: Interval (in milliseconds) at which the manager checks for inactive players (e.g., 60000 milliseconds for 1 minute).
  • autoReset: Determines if the timer should automatically restart after each interval.

How It Works

  1. Initialization: The InactivePlayerManager is initialized, starting a timer that checks for inactive players at regular intervals.
  2. Player Tracking: Players are added to a dictionary (onlinePlayers) when they join the game. Each player is identified by their unique ID (ulong) and is tracked for their last known position and whether they are using an in-game element.
  3. Activity Updates: Player activity is updated through hooks:
    • Position Updates: Uses PlayerPositionUpdate() to track changes in position.
    • Element Interaction: Listens for events indicating when a player starts or stops using in-game elements, updating their activity status.
  4. Inactivity Checks: At each timer interval, the manager checks for players who have been inactive for longer than the specified threshold:
    • If the player’s position has not changed and they are not using any elements, they are considered inactive.
    • A warning message is sent to the player with a countdown before disconnection.
    • If the player remains inactive, they are disconnected.
  5. Privilege Exemption: Players with specific privileges are excluded from inactivity tracking and will not be added to the onlinePlayers list.

Usage

To use InactivePlayerManager, include the settings to the json according to the readme and configure like you want. Here is a basic setup guide:

Example Configuration

{
  "enabled": true,
  "inactivityThreshold": 300,
  "timerCheck": 60000,
  "autoReset": true
}