Repository navigation
Module System
Алексей . edited this page Apr 12, 2026
·
4 revisions
The module system provides a structured runtime for building features as isolated, manageable units. Each module has metadata, lifecycle management, telemetry, and a management UI via /sfs.
A module is a class that:
- Inherits
SFModuleBase - Has an
[SFModule]attribute with metadata - Is registered in
Program.csviacontainer.RegisterModule<T>()
| Model | Description |
|---|---|
MainThread |
Runs on the game's main thread via SFSynchronizationContext. Use for anything touching game state. |
BackgroundWorker |
Runs on a Task.Run thread pool thread. Use for I/O-heavy or network work. |
Hybrid |
Starts inline, can switch threads via Context.SwitchToMainThreadAsync(). |
| Policy | Behavior |
|---|---|
Manual |
Module stays stopped after fault or completion. User must /sfs start manually. |
OnFault |
Auto-restarts on unhandled exception. A circuit breaker disables auto-restart after 5 faults within 60 seconds. |
Created → Starting → Running → Stopping → Stopped
↓
Faulted
// 1. Container calls module.RunAsync(context)
// 2. SFModuleBase sets Context and Log, then:
OnStartingAsync() // Setup, allocate resources
↓
ExecuteAsync(token) // Main loop - runs until cancelled or throws
↓ (success)
OnCompletedAsync() // Clean completion
↓ (exception)
OnFaultedAsync(ex) // Handle fault, log, notify
↓ (always)
OnStoppingAsync() // Teardown
↓
OnStoppedAsync() // Final cleanup
↓
context.Dispose() // All registered disposables releasedModules are registered in Program.cs:
var container = new SFModuleContainer();
container.RegisterModule<DialogScraper>();
container.RegisterModule<BrightBinder>();
container.RegisterModule<NodShaker>();
// ...
await container.Run();Modules are sorted by Order (ascending), then DisplayName (alphabetical).
| Command | Description |
|---|---|
/sfs |
Interactive dashboard dialog - shows all modules with state, uptime, load, and action buttons |
/sfs status [page] |
Quick status in chat (paginated, 6 per page) |
/sfs info <id> |
Detailed info dialog for a specific module |
/sfs start <id> |
Start a stopped module |
/sfs stop <id> |
Stop a running module |
/sfs restart <id> |
Restart a module |
Module can be resolved by id, display name, or partial match.
Each module automatically tracks:
- State - current lifecycle state
- Uptime - time since last start
- Load - duty cycle percentage (sync work / iteration period)
- Loop metrics - count, avg/max iteration time
-
Counters - custom named counters (e.g.,
commands.invoked) -
Details - custom key-value pairs (e.g.,
status=idle) - Heartbeat - last activity timestamp
- Faults - fault count, last exception info
- Memory - process memory snapshot (polled every 2s)
- Threads - start and last thread IDs
- Главная / Home
- Установка
- Архитектура и совместимость
- SA-MP R1, R3-1, R5-1
- Написание модулей
- Плагины и зависимости
- Жизненный цикл
- API модулей
- Потоки и время жизни
- Ранняя загрузка
- Конфигурация и ассеты