KickRequestSystem - jimdroberts/FishMMO GitHub Wiki

Description

System for processing kick requests from the database and disconnecting accounts as needed. Periodically polls the database for new kick requests and processes them, ensuring that accounts flagged for removal are promptly disconnected from the FishMMO server.


API Access

Fields

  • private LocalConnectionState serverState

    Current connection state of the server.

  • private DateTime lastFetchTime

    Timestamp of the last successful fetch from the database.

  • private long lastPosition

    Last processed position (ID) in the kick request table.

  • private float nextPump

    Time remaining until the next database poll for kick requests.

  • public float UpdatePumpRate

    The server kick request update pump rate limit in seconds.

  • public int UpdateFetchCount

    Maximum number of kick requests to fetch per poll.

Methods

  • public override void InitializeOnce()

    Initializes the system and subscribes to server connection state events.

  • public override void Destroying()

    Unsubscribes from server connection state events when the system is destroyed.

  • private void ServerManager_OnServerConnectionState(ServerConnectionStateArgs args)

    Handles changes in the server's connection state. args: ServerConnectionStateArgs - Connection state arguments.

  • private void ServerManager_OnRemoteConnectionState(NetworkConnection conn, RemoteConnectionStateArgs args)

    Handles remote connection state changes. Deletes kick requests for accounts that disconnect. conn: NetworkConnection - The network connection. args: RemoteConnectionStateArgs - Remote connection state arguments.

  • void LateUpdate()

    Unity LateUpdate callback. Polls the database for kick requests at the specified rate and processes them.

  • private List FetchKickRequests()

    Fetches new kick requests from the database since the last fetch. Updates lastFetchTime and lastPosition for incremental polling. Returns: List - List of new kick request entities.

  • private void ProcessKickRequests(List requests)

    Processes a list of kick requests, setting accounts offline and kicking connections as needed. requests: List - List of kick request entities to process.


Basic Usage

Setup

  1. Requires FishNet networking, FishMMO server infrastructure, and a configured database connection.
  2. Attach the KickRequestSystem to a server GameObject. Configure UpdatePumpRate and UpdateFetchCount as needed.
  3. The system initializes itself on startup, subscribing to server connection state events.
  4. No manual polling is required; the system automatically processes kick requests at the specified interval.

Example

// Example 1: Setting up KickRequestSystem
// Attach KickRequestSystem to a server GameObject and configure UpdatePumpRate and UpdateFetchCount.

kickRequestSystem.UpdatePumpRate = 10.0f;
kickRequestSystem.UpdateFetchCount = 50;

// Example 2: Automatic processing of kick requests
// The system automatically polls the database and processes kick requests; no manual invocation is required.

Best Practices

  • Set UpdatePumpRate and UpdateFetchCount according to expected server load and database performance.
  • Ensure database connectivity and integrity before starting the server.
  • Handle account disconnections and kick requests promptly to maintain server security and stability.
  • Clean up all event subscriptions on shutdown to prevent resource leaks.
⚠️ **GitHub.com Fallback** ⚠️