59 const std::string& username,
const std::vector<std::string>& permissions);
66 bool hasPermission(
const std::string& sessionKey,
const std::string& permission)
const;
70 std::string
getUsername(
const std::string& sessionKey)
const;
95 void assignRole(
const std::string& sessionKey,
const std::string& roleName);
99 void unassignRole(
const std::string& sessionKey,
const std::string& roleName);
103 void clearRoles(
const std::string& sessionKey);
110 std::vector<std::string>
assignedRoles(
const std::string& sessionKey)
const;
161 const std::string& sessionKey,
162 const std::string& clientName,
163 const std::string& wsUserName,
164 const std::string& hostname);
175 const std::string& sessionKey,
176 uint64_t messagesSent,
177 uint64_t messagesReceived,
179 uint64_t bytesReceived,
180 double updateFrequencyHz,
181 size_t knownObjectCount);
194 uint64_t rolesGeneration = 0;
void clearRoles(const std::string &sessionKey)
Removes all roles from the session identified by sessionKey. Does nothing if the session does not exi...
An ephemeral session created for an unauthenticated WebSocket connection.
std::string lastActivityAt
ISO 8601 UTC timestamp of the most recent API/WS activity.
Definition: sessionManager.h:137
std::vector< std::string > permissions
Definition: sessionManager.h:190
Default — used by status/configure clients.
int myNextSessionId
Definition: sessionManager.h:201
A player session assigned a Role in the simulation.
bool hasWebSocket
True if a WebSocket connection is currently attached.
Definition: sessionManager.h:141
std::mutex myMutex
Definition: sessionManager.h:200
Definition: sessionManager.h:186
size_t knownObjectCount
Definition: sessionManager.h:39
std::string sessionKeyForId(int sessionId) const
Returns the session key for the given integer session ID. Returns an empty string if no session with ...
void clearAllRoles()
Removes all roles from every currently active session.
void setSessionType(const std::string &sessionKey, DtSessionType type)
Sets the session type for the given session key. Does nothing if the session does not exist...
double updateFrequencyHz
Definition: sessionManager.h:38
DtSessionManager — process-wide singleton that creates and tracks login sessions. ...
Definition: sessionManager.h:48
std::chrono::system_clock::time_point lastActivityAt
Definition: sessionManager.h:191
int sessionId
Definition: sessionManager.h:135
void detachWebSocket(const std::string &sessionKey)
Detaches the WebSocket connection from the session and clears WS statistics. If the session is Anonym...
bool validateSession(const std::string &sessionKey) const
Returns true if a session with the given key exists.
std::vector< DtSessionInfo > getActiveSessions() const
Returns a snapshot of all currently active sessions. Session keys are intentionally omitted from the ...
bool 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 ...
uint64_t rolesGeneration(const std::string &sessionKey) const
Returns the roles-change generation counter for the session. The counter is incremented whenever assi...
std::string sessionType
"None", "Player", "Instructor", or "Anonymous".
Definition: sessionManager.h:138
std::string getUsername(const std::string &sessionKey) const
Returns the username associated with the session key. Returns an empty string if the session does not...
std::string connectedAt
ISO 8601 UTC timestamp of the WebSocket Connect handshake.
Definition: sessionManager.h:31
void 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.
int sessionId
Definition: sessionManager.h:188
bool wsAttached
True when a WebSocket connection is currently active.
Definition: sessionManager.h:196
std::vector< std::string > assignedRoles
Definition: sessionManager.h:139
std::atomic< uint64_t > myGlobalRolesGeneration
Definition: sessionManager.h:203
DtSessionType
DtSessionType — classification of what role a session plays in the system.
Definition: sessionManager.h:16
std::string wsUserName
From the WebLVC Connect message userName field (informational only).
Definition: sessionManager.h:29
An instructor session; can configure role assignments.
std::string createSession(const std::string &username, const std::vector< std::string > &permissions)
Creates a new session for the given username and returns the session key.
void 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 r...
bool 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.
bool isWebSocketAttached(const std::string &sessionKey) const
Returns true if the session currently has a WebSocket connection attached.
std::string createAnonymousSession()
Creates an ephemeral Anonymous session for an unauthenticated WebSocket connection. The session is automatically removed by detachWebSocket() when the connection closes.
std::vector< std::string > assignedRoles(const std::string &sessionKey) const
Returns the list of role names assigned to the session. Returns an empty vector if the session does n...
DtWsConnectionInfo — snapshot of the WebSocket connection attached to a session. Populated by DtSessi...
Definition: sessionManager.h:26
int sessionIdForKey(const std::string &sessionKey) const
Returns the integer session ID for the given session key. Returns -1 if no session with that key exis...
DtSessionType sessionType(const std::string &sessionKey) const
Returns the type of the session identified by sessionKey. Returns DtSessionType::None if the session ...
Snapshot of a single active session returned by getActiveSessions().
Definition: sessionManager.h:133
void touchSession(const std::string &sessionKey)
Updates the last-activity timestamp for the given session to the current time. Does nothing if the se...
std::vector< std::string > assignedRoles
Definition: sessionManager.h:193
bool 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.
std::string username
Definition: sessionManager.h:136
DtWsConnectionInfo wsInfo
Valid only when hasWebSocket is true.
Definition: sessionManager.h:142
uint64_t messagesSent
Definition: sessionManager.h:33
uint64_t bytesReceived
Definition: sessionManager.h:36
std::string clientName
From the WebLVC Connect message ClientName field.
Definition: sessionManager.h:28
std::string username
Definition: sessionManager.h:189
uint64_t messagesReceived
Definition: sessionManager.h:34
void 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 ...
std::map< std::string, DtSessionData > mySessions
Definition: sessionManager.h:202
std::string hostname
From the WebLVC Connect message hostname field.
Definition: sessionManager.h:30
DtWsConnectionInfo wsInfo
Valid only when wsAttached is true.
Definition: sessionManager.h:197
bool removeSessionById(int sessionId)
Removes the session identified by its integer session ID. Returns true if the session was found and r...
static DtSessionManager & getInstance()
Returns the process-wide singleton instance.
uint64_t bytesSent
Definition: sessionManager.h:35
uint64_t globalRolesGeneration() const
Returns the process-wide roles-change generation counter. Incremented whenever any session's role ass...