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):
MaintenanceManagerpersists across scenes (`DontDestroyOnLoad`) and handles the polling loop. - Configuration:
MaintenanceSettings(ScriptableObject) defines whitelists, blacklists, and redirect targets. - Backend:
bl_MaintananceMode.phpinterfaces with the MySQL database to store the system state. - Integration: Automatically hooks into ULSP (Login Pro) to resolve server URLs.
Data Flow
- Initialization:
MaintenanceManagerinitializes on game start. It attempts to resolve the PHP URL from `bl_LoginProDataBase`. - Polling: The client sends a `GET` request to `bl_MaintananceMode.php` at defined intervals (default: 30s).
- State Change: If the server returns `1` (True), `MaintenanceManager.IsMaintenanceMode` becomes true.
- 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.
├── bl_Common.php (Required dependency)
├── bl_MaintananceMode.php
└── ...
2. Unity Setup
- Add the MaintenanceManager prefab to your initial scene (e.g., Login or Splash).
- Ensure MaintenanceSettings is located in `Resources/MaintenanceSettings.asset`.
- 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)
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`.
Scripting API
MaintenanceManager (Singleton)
Global access point. Persists between scenes via `DontDestroyOnLoad`.
Returns `true` if maintenance is currently active.
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.
Forces an immediate check of the maintenance status from the server.
MaintenanceSettings
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.
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.