3.1 KiB
Forge Server Common
Overview
The common addon provides shared SQF utilities used by server-side Forge addons. It contains lightweight helpers only; gameplay domain state belongs in the specific domain addons or the Rust extension.
Dependencies
forge_server_main
Main Components
fnc_baseStore.sqfprovides shared hash-map object behavior such as JSON conversion.fnc_eventBus.sqfprovides a framework-wide in-process event bus for cross-addon notifications.fnc_log.sqfstandardizes server log messages.fnc_getPlayer.sqfresolves online players by UID.fnc_formatNumber.sqfformats numeric values for notifications and UI text.fnc_generateHash.sqfandfnc_generateSecureData.sqfprovide hashing and random data helpers.fnc_timeToSeconds.sqfconverts time values into seconds.
Notes
Keep this addon free of domain-specific behavior. If a helper needs actor, bank, org, task, store, or CAD state, it belongs in that addon instead.
Event Bus
The event bus is initialized as forge_server_common_EventBus during store
bootstrap. It is synchronous and in-process: listeners run immediately when an
event is emitted.
Event Naming
Use lower-case dot-separated names:
<domain>.<entity>.<action>for domain events, such ascad.assignment.assigned<domain>.<action>for simple lifecycle events, such astask.started
Prefer past-tense action names for events that report completed state changes:
created, started, assigned, acknowledged, declined, completed,
failed, cleared, updated, closed.
Payloads should be hash maps and should include stable identifiers first:
taskID, requestID, groupID, uid, orgID, or accountID as appropriate.
The event bus adds event, source, and timestamp when the event is emitted.
Current Events
Task lifecycle:
task.createdtask.startedtask.completedtask.failedtask.cleared
Task rewards and notifications:
task.reward.requestedtask.reward.appliedtask.reward.failedtask.rating.appliedtask.rating.failedtask.notification.requestedtask.reward.notification.requested
CAD state:
cad.assignment.assignedcad.assignment.createdcad.assignment.acknowledgedcad.assignment.declinedcad.assignment.closedcad.request.submittedcad.request.closedcad.group.updated
Client sync and notification requests:
notification.requestedbank.account.sync.requestedorg.sync.requestedlocker.sync.requestedlocker.va.sync.requestedgarage.vgarage.sync.requested
Example
Register a listener, emit an event, then remove the listener when it is no longer needed:
private _token = EGVAR(common,EventBus) call ["on", [
"task.completed",
{
params ["_event"];
["INFO", format ["Task completed: %1", _event getOrDefault ["taskID", ""]]] call EFUNC(common,log);
},
"example"
]];
EGVAR(common,EventBus) call ["emit", [
"task.completed",
createHashMapFromArray [["taskID", "task_001"]],
createHashMapFromArray [["source", "task"]]
]];
EGVAR(common,EventBus) call ["off", [_token]];