![]() |
VR-Forces Developer's Guide
|
DtRoleDefinitionStore — process-wide singleton for role definition files.
At startup, initialize() scans a directory of JSON role definition files and builds an index of available definitions. A specific definition is activated via loadDefinition(); the active definition drives WebSocket entity filtering and command authorization for Player sessions.
No definition is active until loadDefinition() is called. When no definition is active, entityMatchesRoles() returns true (permissive default — all entities are visible).
Role definition JSON format (one file per named definition):
Thread safety: all public methods are safe to call from concurrent threads.
Public Member Functions | |
| void | initialize (const std::string &defsDir, const std::string &defaultDefsDir=std::string(), const std::string &scenarioFilename=std::string()) |
| std::vector< DtRoleDefSummary > | listDefinitions () const |
| bool | loadDefinition (const std::string &name) |
| bool | saveDefinition (const std::string &name, const Json::Value &defJson, std::string &outError) |
| std::string | activeDefinitionName () const |
| std::string | activeDefinitionId () const |
| std::string | activeDefinitionDescription () const |
| bool | addRole (const DtRoleDefinition &role, std::string &outError) |
| bool | removeRole (const std::string &roleName, std::string &outError) |
| bool | updateRolePolicy (const std::string &roleName, const Json::Value &partialPolicies, std::string &outError) |
| bool | updateRoleDescription (const std::string &roleName, const std::string &description, std::string &outError) |
| void | setActiveAllowSelfAssignment (bool allow) |
| void | clearActiveConfiguration () |
| bool | loadDefinitionById (const std::string &definitionId) |
| bool | saveActiveToSourceDefinition (std::string &outError) |
| std::string | saveActiveAsNewDefinition (const std::string &name, const std::string &scenarioName, const std::string &description, std::string &outError) |
| bool | setDefinitionScenario (const std::string &definitionId, const std::string &scenarioName, std::string &outError) |
| bool | setDefinitionDescription (const std::string &definitionId, const std::string &description, std::string &outError) |
| bool | deleteDefinition (const std::string &definitionId, std::string &outError) |
| std::vector< DtRoleDefSummary > | listDefinitionsForScenario (const std::string &scenarioFilename) const |
| bool | getDefinitionById (const std::string &definitionId, Json::Value &outJson, std::string &outError) const |
| std::vector< std::string > | roleNames () const |
| bool | getRole (const std::string &roleName, DtRoleDefinition &outRole) const |
| std::vector< DtRoleDefinition > | activeRoles () const |
| bool | allowSelfAssignment () const |
| uint64_t | definitionGeneration () const |
| bool | entityMatchesRoles (const std::string &objectName, int forceId, const std::vector< std::string > &roleNames) const |
| bool | isEntityCommanded (const std::string &objectName, int forceId, const std::vector< std::string > &roleNames) const |
| bool | isTacticalGraphicViewable (const std::string &overlayName, int forceId, const std::vector< std::string > &roleNames) const |
| bool | isTacticalGraphicEditable (const std::string &overlayName, int forceId, const std::vector< std::string > &roleNames) const |
| std::string | defaultOverlayForRoles (const std::vector< std::string > &roleNames) const |
| void | setSubordinateResolver (const DtSubordinateResolver *resolver, tbb::spin_rw_mutex *vrfDataMutex=nullptr) |
Static Public Member Functions | |
| static DtRoleDefinitionStore & | getInstance () |
| static DtRoleDefinition | parseRoleJson (const Json::Value &roleJson) |
Private Member Functions | |
| DtRoleDefinitionStore ()=default | |
| void | createDefaultDefinition () |
| Json::Value | serializeActiveDefinition () const |
Static Private Member Functions | |
| static std::vector< std::string > | scanDirectory (const std::string &dir) |
| static std::string | generateUuid () |
Private Attributes | |
| tbb::spin_rw_mutex | myMutex |
| std::string | myDefsDir |
| std::map< std::string, std::string > | myNameToFilePath |
| std::map< std::string, DtRoleDefSummary > | myIndex |
| std::map< std::string, std::string > | myIdToName |
| std::string | myActiveDefinitionName |
| std::string | myActiveDefinitionId |
| std::string | myActiveScenarioName |
| std::string | myActiveDefinitionDescription |
| std::map< std::string, DtRoleDefinition > | myActiveRoles |
| bool | myAllowSelfAssignment = true |
| std::atomic< uint64_t > | myDefinitionGeneration {0} |
| const DtSubordinateResolver * | mySubordinateResolver = nullptr |
| tbb::spin_rw_mutex * | myVrfDataMutex = nullptr |
|
privatedefault |
|
static |
Returns the process-wide singleton instance.
| void DtRoleDefinitionStore::initialize | ( | const std::string & | defsDir, |
| const std::string & | defaultDefsDir = std::string(), |
||
| const std::string & | scenarioFilename = std::string() |
||
| ) |
Scans defsDir for *.json role definition files and builds the index. Must be called from main() before any background threads start. The scenario directory contributes all definitions. The default directory contributes only the shared "Default" definition. If neither directory contributes any files, the built-in Blue/Red definition is activated.
Active-definition selection order after indexing: 1) A definition whose scenarioName exactly matches scenarioFilename 2) A definition named "Default" (case-insensitive) 3) The first indexed definition (stable fallback)
| std::vector<DtRoleDefSummary> DtRoleDefinitionStore::listDefinitions | ( | ) | const |
Returns summary information for all available definition files.
| bool DtRoleDefinitionStore::loadDefinition | ( | const std::string & | name | ) |
Loads and activates the named definition. Replaces any previously active definition.
| bool DtRoleDefinitionStore::saveDefinition | ( | const std::string & | name, |
| const Json::Value & | defJson, | ||
| std::string & | outError | ||
| ) |
Saves a new role definition to disk and registers it in the index.
| name | The unique name for this definition (used as file base name). |
| defJson | The complete definition JSON (must contain "name", "roles" fields). |
| outError | Populated with a human-readable error string on failure. Policy: only "Default" may have empty scenarioName. All non-default definitions must include scenarioName. |
| std::string DtRoleDefinitionStore::activeDefinitionName | ( | ) | const |
Returns the name of the currently active definition, or an empty string if none.
| std::string DtRoleDefinitionStore::activeDefinitionId | ( | ) | const |
Returns the definitionId of the currently active definition, or empty string if unsaved.
| std::string DtRoleDefinitionStore::activeDefinitionDescription | ( | ) | const |
Returns the description of the currently active definition, or empty string if none.
| bool DtRoleDefinitionStore::addRole | ( | const DtRoleDefinition & | role, |
| std::string & | outError | ||
| ) |
Adds a role to the active runtime configuration.
| bool DtRoleDefinitionStore::removeRole | ( | const std::string & | roleName, |
| std::string & | outError | ||
| ) |
Removes a role from the active runtime configuration.
| bool DtRoleDefinitionStore::updateRolePolicy | ( | const std::string & | roleName, |
| const Json::Value & | partialPolicies, | ||
| std::string & | outError | ||
| ) |
Deep-merges partial policy fields into an existing role.
| bool DtRoleDefinitionStore::updateRoleDescription | ( | const std::string & | roleName, |
| const std::string & | description, | ||
| std::string & | outError | ||
| ) |
Updates the optional user-facing description for an existing role.
| void DtRoleDefinitionStore::setActiveAllowSelfAssignment | ( | bool | allow | ) |
Changes the allowSelfAssignment setting in the active configuration.
| void DtRoleDefinitionStore::clearActiveConfiguration | ( | ) |
Resets the active configuration to empty (no roles, no source definition).
| bool DtRoleDefinitionStore::loadDefinitionById | ( | const std::string & | definitionId | ) |
Loads a definition by its definitionId (UUID) instead of by name.
| bool DtRoleDefinitionStore::saveActiveToSourceDefinition | ( | std::string & | outError | ) |
Saves the active runtime configuration back to its source definition file.
| std::string DtRoleDefinitionStore::saveActiveAsNewDefinition | ( | const std::string & | name, |
| const std::string & | scenarioName, | ||
| const std::string & | description, | ||
| std::string & | outError | ||
| ) |
Saves the active runtime configuration as a new definition with the given name. Generates a new definitionId. Updates myActiveDefinitionId to the new ID. Policy: scenarioName must be non-empty (scenario must be loaded).
| bool DtRoleDefinitionStore::setDefinitionScenario | ( | const std::string & | definitionId, |
| const std::string & | scenarioName, | ||
| std::string & | outError | ||
| ) |
Updates the scenarioName field for an existing saved definition by definitionId. Policy: "Default" may only be unassigned (empty scenarioName). Non-default definitions must keep a non-empty scenarioName.
| bool DtRoleDefinitionStore::setDefinitionDescription | ( | const std::string & | definitionId, |
| const std::string & | description, | ||
| std::string & | outError | ||
| ) |
Updates the description field for an existing saved definition by definitionId.
| bool DtRoleDefinitionStore::deleteDefinition | ( | const std::string & | definitionId, |
| std::string & | outError | ||
| ) |
Deletes a saved definition file by its definitionId.
| std::vector<DtRoleDefSummary> DtRoleDefinitionStore::listDefinitionsForScenario | ( | const std::string & | scenarioFilename | ) | const |
Lists definitions filtered by scenarioName matching the given filename.
| bool DtRoleDefinitionStore::getDefinitionById | ( | const std::string & | definitionId, |
| Json::Value & | outJson, | ||
| std::string & | outError | ||
| ) | const |
Reads and returns the full JSON content of a saved definition by its definitionId.
| std::vector<std::string> DtRoleDefinitionStore::roleNames | ( | ) | const |
Returns the names of all roles in the active definition. Returns an empty vector if no definition is active.
| bool DtRoleDefinitionStore::getRole | ( | const std::string & | roleName, |
| DtRoleDefinition & | outRole | ||
| ) | const |
Populates outRole with the definition for the named role in the active definition.
| std::vector<DtRoleDefinition> DtRoleDefinitionStore::activeRoles | ( | ) | const |
Returns a snapshot of all role definitions in the active definition set.
| bool DtRoleDefinitionStore::allowSelfAssignment | ( | ) | const |
Returns whether player self-assignment is allowed by the active definition. Returns true when no definition is active.
| uint64_t DtRoleDefinitionStore::definitionGeneration | ( | ) | const |
Monotonically increasing counter incremented each time a new definition is activated. Listeners compare against a cached value to detect changes without polling.
| bool DtRoleDefinitionStore::entityMatchesRoles | ( | const std::string & | objectName, |
| int | forceId, | ||
| const std::vector< std::string > & | roleNames | ||
| ) | const |
Returns true if the entity passes the visibility filter for at least one of the given roles. Returns true when roleNames is empty or no definition is active (permissive default).
Filter union logic: an entity is visible to a role when any of the following hold:
| bool DtRoleDefinitionStore::isEntityCommanded | ( | const std::string & | objectName, |
| int | forceId, | ||
| const std::vector< std::string > & | roleNames | ||
| ) | const |
Returns true if the entity is commanded by at least one of the given roles. A role commands an entity when: commanded.all is true, OR forceId is in commanded.forces, OR objectName is in commanded.uuids.
| bool DtRoleDefinitionStore::isTacticalGraphicViewable | ( | const std::string & | overlayName, |
| int | forceId, | ||
| const std::vector< std::string > & | roleNames | ||
| ) | const |
Returns true if the tactical graphic is viewable by at least one of the given roles. Returns true when roleNames is empty or no definition is active (permissive default).
| bool DtRoleDefinitionStore::isTacticalGraphicEditable | ( | const std::string & | overlayName, |
| int | forceId, | ||
| const std::vector< std::string > & | roleNames | ||
| ) | const |
Returns true if the tactical graphic is editable by at least one of the given roles. Returns true when roleNames is empty (permissive default).
| std::string DtRoleDefinitionStore::defaultOverlayForRoles | ( | const std::vector< std::string > & | roleNames | ) | const |
Returns the default overlay name for the first assigned role that specifies one, or an empty string if none of the roles sets a default.
|
static |
Parses a role definition from a JSON object using the standard role definition file format. Public to allow controllers to reuse the parsing logic without duplicating it.
| void DtRoleDefinitionStore::setSubordinateResolver | ( | const DtSubordinateResolver * | resolver, |
| tbb::spin_rw_mutex * | vrfDataMutex = nullptr |
||
| ) |
Sets the subordinate resolver used to expand includeSubordinates entries.
|
staticprivate |
Returns full file paths for every *.json file found directly in dir.
|
private |
Activates a built-in default definition containing "Blue" (friendly force) and "Red" (opposing force) roles. Called when no definition files are found in the definitions directory.
|
staticprivate |
Generates a random UUID in 8-4-4-4-12 lowercase hex format.
|
private |
Serializes the active configuration to a complete JSON definition object. Caller must hold at least a read lock on myMutex.
|
mutableprivate |
|
private |
|
private |
name -> absolute file path
|
private |
name -> summary
|
private |
definitionId -> name
|
private |
|
private |
UUID of the currently loaded definition, or empty.
|
private |
scenarioName from the loaded file, or empty.
|
private |
Description from the loaded file, or empty.
|
private |
roleName -> DtRoleDefinition
|
private |
|
private |
|
private |
|
private |