VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
DtSessionManager Class Reference

DtSessionManager — process-wide singleton that creates and tracks login sessions.

Each session is identified by a cryptographically random 64-character hex key. Sessions persist for the lifetime of the server process (no expiry).

Thread safety: all public methods are safe to call from concurrent threads.

Classes

struct  DtSessionData
 
struct  DtSessionInfo
 

Public Member Functions

std::string createSession (const std::string &username, const std::vector< std::string > &permissions)
 
bool validateSession (const std::string &sessionKey) const
 
bool hasPermission (const std::string &sessionKey, const std::string &permission) const
 
std::string getUsername (const std::string &sessionKey) const
 
bool removeSession (const std::string &sessionKey)
 
void touchSession (const std::string &sessionKey)
 
bool removeSessionById (int sessionId)
 
void setSessionType (const std::string &sessionKey, DtSessionType type)
 
DtSessionType sessionType (const std::string &sessionKey) const
 
void assignRole (const std::string &sessionKey, const std::string &roleName)
 
void unassignRole (const std::string &sessionKey, const std::string &roleName)
 
void clearRoles (const std::string &sessionKey)
 
void clearAllRoles ()
 
std::vector< std::string > assignedRoles (const std::string &sessionKey) const
 
uint64_t rolesGeneration (const std::string &sessionKey) const
 
uint64_t globalRolesGeneration () const
 
std::string sessionKeyForId (int sessionId) const
 
int sessionIdForKey (const std::string &sessionKey) const
 
std::vector< DtSessionInfo > getActiveSessions () const
 
std::string createAnonymousSession ()
 
bool isWebSocketAttached (const std::string &sessionKey) const
 
bool attachWebSocket (const std::string &sessionKey, const std::string &clientName, const std::string &wsUserName, const std::string &hostname)
 
void detachWebSocket (const std::string &sessionKey)
 
void updateWsStats (const std::string &sessionKey, uint64_t messagesSent, uint64_t messagesReceived, uint64_t bytesSent, uint64_t bytesReceived, double updateFrequencyHz, size_t knownObjectCount)
 

Static Public Member Functions

static DtSessionManager & getInstance ()
 

Private Member Functions

 DtSessionManager ()
 

Private Attributes

std::mutex myMutex
 
int myNextSessionId {1}
 
std::map< std::string,
DtSessionData > 
mySessions
 
std::atomic< uint64_t > myGlobalRolesGeneration {0}
 

Constructor & Destructor Documentation

DtSessionManager::DtSessionManager ( )
private

Member Function Documentation

static DtSessionManager& DtSessionManager::getInstance ( )
static

Returns the process-wide singleton instance.

Referenced by DtAuthHelpers::requirePermission(), and DtAuthHelpers::requireValidSession().

std::string DtSessionManager::createSession ( const std::string &  username,
const std::vector< std::string > &  permissions 
)

Creates a new session for the given username and returns the session key.

Parameters
usernameThe authenticated username.
permissionsThe permission strings for this user.
Returns
A 64-character hex session key.
bool DtSessionManager::validateSession ( const std::string &  sessionKey) const

Returns true if a session with the given key exists.

Referenced by DtAuthHelpers::requireValidSession().

bool DtSessionManager::hasPermission ( const std::string &  sessionKey,
const std::string &  permission 
) const

Returns true if the session has the given permission. Returns false if the session does not exist or does not have the permission.

std::string DtSessionManager::getUsername ( const std::string &  sessionKey) const

Returns the username associated with the session key. Returns an empty string if the session does not exist.

bool DtSessionManager::removeSession ( const std::string &  sessionKey)

Removes the session identified by sessionKey. Does nothing if the key does not exist. Returns true if the session was found and removed, false otherwise.

void DtSessionManager::touchSession ( const std::string &  sessionKey)

Updates the last-activity timestamp for the given session to the current time. Does nothing if the session does not exist or the key is empty.

Referenced by DtAuthHelpers::requirePermission(), and DtAuthHelpers::requireValidSession().

bool DtSessionManager::removeSessionById ( int  sessionId)

Removes the session identified by its integer session ID. Returns true if the session was found and removed, false if no such ID exists.

void DtSessionManager::setSessionType ( const std::string &  sessionKey,
DtSessionType  type 
)

Sets the session type for the given session key. Does nothing if the session does not exist.

DtSessionType DtSessionManager::sessionType ( const std::string &  sessionKey) const

Returns the type of the session identified by sessionKey. Returns DtSessionType::None if the session does not exist.

void DtSessionManager::assignRole ( const std::string &  sessionKey,
const std::string &  roleName 
)

Adds a role name to the session's assigned roles. Does nothing if the session does not exist or the role is already assigned.

void DtSessionManager::unassignRole ( const std::string &  sessionKey,
const std::string &  roleName 
)

Removes a role name from the session's assigned roles. Does nothing if the session does not exist or the role is not assigned.

void DtSessionManager::clearRoles ( const std::string &  sessionKey)

Removes all roles from the session identified by sessionKey. Does nothing if the session does not exist.

void DtSessionManager::clearAllRoles ( )

Removes all roles from every currently active session.

std::vector<std::string> DtSessionManager::assignedRoles ( const std::string &  sessionKey) const

Returns the list of role names assigned to the session. Returns an empty vector if the session does not exist.

uint64_t DtSessionManager::rolesGeneration ( const std::string &  sessionKey) const

Returns the roles-change generation counter for the session. The counter is incremented whenever assignedRoles changes. Returns 0 if the session does not exist.

uint64_t DtSessionManager::globalRolesGeneration ( ) const

Returns the process-wide roles-change generation counter. Incremented whenever any session's role assignments change, or when the membership of the active Player session set changes (a session transitions to or from DtSessionType::Player, or a Player session is removed). Used by runTimerLoop() to detect when ScenarioRolesStatus should be re-pushed.

std::string DtSessionManager::sessionKeyForId ( int  sessionId) const

Returns the session key for the given integer session ID. Returns an empty string if no session with that ID exists.

int DtSessionManager::sessionIdForKey ( const std::string &  sessionKey) const

Returns the integer session ID for the given session key. Returns -1 if no session with that key exists.

std::vector<DtSessionInfo> DtSessionManager::getActiveSessions ( ) const

Returns a snapshot of all currently active sessions. Session keys are intentionally omitted from the returned data.

std::string DtSessionManager::createAnonymousSession ( )

Creates an ephemeral Anonymous session for an unauthenticated WebSocket connection. The session is automatically removed by detachWebSocket() when the connection closes.

Returns
A 64-character hex session key for the new anonymous session.
bool DtSessionManager::isWebSocketAttached ( const std::string &  sessionKey) const

Returns true if the session currently has a WebSocket connection attached.

bool DtSessionManager::attachWebSocket ( const std::string &  sessionKey,
const std::string &  clientName,
const std::string &  wsUserName,
const std::string &  hostname 
)

Attaches a WebSocket connection to the session, recording initial connection metadata. Returns false (and does nothing) if the session already has a WebSocket attached, or if the session does not exist.

void DtSessionManager::detachWebSocket ( const std::string &  sessionKey)

Detaches the WebSocket connection from the session and clears WS statistics. If the session is Anonymous, the session is also removed automatically. Does nothing if the session does not exist or has no WebSocket attached.

void DtSessionManager::updateWsStats ( const std::string &  sessionKey,
uint64_t  messagesSent,
uint64_t  messagesReceived,
uint64_t  bytesSent,
uint64_t  bytesReceived,
double  updateFrequencyHz,
size_t  knownObjectCount 
)

Updates WebSocket statistics for the session and touches its last-activity timestamp. Replaces the direct touchSession() call in the WebSocket read path. Does nothing if the session does not exist or the key is empty.

Member Data Documentation

std::mutex DtSessionManager::myMutex
mutableprivate
int DtSessionManager::myNextSessionId {1}
private
std::map<std::string, DtSessionData> DtSessionManager::mySessions
private
std::atomic<uint64_t> DtSessionManager::myGlobalRolesGeneration {0}
private

The documentation for this class was generated from the following file:

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)