Maintenance Mode Architecture Technical

The Maintenance Mode addon is a distributed state management system designed to lock/unlock game access remotely. It uses a lightweight polling mechanism to synchronize the client state with the server configuration.

System Components

  • Global Manager (Singleton): MaintenanceManager persists across scenes (`DontDestroyOnLoad`) and handles the polling loop.
  • Configuration: MaintenanceSettings (ScriptableObject) defines whitelists, blacklists, and redirect targets.
  • Backend: bl_MaintananceMode.php interfaces with the MySQL database to store the system state.
  • Integration: Automatically hooks into ULSP (Login Pro) to resolve server URLs.

Data Flow

  1. Initialization: MaintenanceManager initializes on game start. It attempts to resolve the PHP URL from `bl_LoginProDataBase`.
  2. Polling: The client sends a `GET` request to `bl_MaintananceMode.php` at defined intervals (default: 30s).
  3. State Change: If the server returns `1` (True), `MaintenanceManager.IsMaintenanceMode` becomes true.
  4. Enforcement: When a scene loads, `MaintenanceManager` checks if the scene is restricted. If yes, it redirects the player to the "Safe Scene" (e.g., Login).

Installation & Setup

1. Server-Side Setup

Upload the PHP files to your web server.

/YourServerRoot/
├── bl_Common.php (Required dependency)
├── bl_MaintananceMode.php
└── ...
Database: The system creates the `AdminPanelSettings` table automatically on the first API call if it doesn't exist.

2. Unity Setup

  1. Add the MaintenanceManager prefab to your initial scene (e.g., Login or Splash).
  2. Ensure MaintenanceSettings is located in `Resources/MaintenanceSettings.asset`.
  3. Configure your Redirect Scene and Excluded Scenes in the settings file.

Configuration

Controlled via the MaintenanceSettings ScriptableObject.

General Settings

Setting Type Description
Is Maintenance Enabled Bool Manual local override. Useful for testing without server connection.
Use Admin Panel Maintenance Bool If true, fetches title/description from the Admin Panel table instead of local strings.
Check Interval Float Polling frequency in seconds (Default: 30s).

Scene Management

Setting Description
Target Scenes Specific scenes to block. If empty, blocks ALL scenes except excluded ones.
Excluded Scenes Scenes that are ALWAYS accessible (e.g., "MainMenu", "Credits", "Login").
Redirect Scene Name of the scene to load when kicked (e.g., "Login").

UI & Behavior

Setting Description
Maintenance Message Text displayed to the user (overridden if Admin Panel mode is on).
Show Notice Before Redirect If true, shows a warning UI for `Redirect Delay` seconds before switching scenes.
Block User Input If true, prevents interaction with other UI elements while the maintenance window is up.

Server API Reference

The `bl_MaintananceMode.php` script handles state persistence.

Database Schema (AdminPanelSettings)

id (INT, PK) MaintenanceMode (INT) - 0 = Off, 1 = On

API Actions

  • ?action=get: Returns raw integer status (`0` or `1`).
  • ?action=set&value=1: Enables maintenance mode.
  • ?action=set&value=0: Disables maintenance mode.

Admin Panel Integration

When source=admin is passed, the API returns a JSON object containing richer data from `bl_admin_settings`.

GET ?action=get&source=admin // Response: { "maintenance_on": 1, "m_title": "Scheduled Maintenance", "m_discription": "We are upgrading our servers..." }

Scripting API

MaintenanceManager (Singleton)

public static MaintenanceManager Instance

Global access point. Persists between scenes via `DontDestroyOnLoad`.

public bool IsMaintenanceMode { get; }

Returns `true` if maintenance is currently active.

public void SetMaintenanceMode(bool mode)

Manually sets the maintenance state. If `phpScriptURL` is configured, it sends a POST request to update the server. Otherwise, it updates the local state only.

public void GetMaintenanceMode()

Forces an immediate check of the maintenance status from the server.

MaintenanceSettings

public bool ShouldApplyToCurrentScene(string currentSceneName)

Evaluates whether the current scene is blacklisted or whitelisted based on the configuration arrays.

Scene Management Logic

The system prevents players from entering specific scenes during maintenance.

// Internal Logic Check bool isExcluded = settings.excludedScenes.Contains(currentScene); bool isTarget = settings.targetScenes.Contains(currentScene); if (IsMaintenanceMode && !isExcluded) { if (targetScenes.Length == 0 || isTarget) { RedirectTo(settings.redirectScene); } }
Critical Warning: Ensure your Redirect Scene (e.g., "Login") is added to the Excluded Scenes list.

Why? If the Login scene is not excluded, the system will detect it as "under maintenance," try to redirect to "Login" again, and create an infinite loop that crashes the game or freezes the editor.

Troubleshooting

Maintenance Mode Won't Turn On

  • Check URL: Ensure `bl_LoginProDataBase` is in the scene and configured correctly. The manager needs the base PHP path.
  • Database Connection: Verify `bl_Common.php` has the correct DB credentials.
  • Console Errors: Check Unity Console for "Error fetching Maintenance Mode" messages.

Redirect Loop

  • Check Exclusions: As mentioned above, the scene you are redirecting TO must be in the `Excluded Scenes` list.

Admin Panel Text Not Showing

  • Toggle Setting: Ensure `Use Admin Panel Maintenance` is checked in the `MaintenanceSettings` asset.
  • Table Exists: Ensure `bl_admin_settings` table exists in your database if you are using that mode.