diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-12 21:03:17 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-13 20:22:13 +0800 |
| commit | 3ad8cca9f6fecfb4c1f70f0a8c9d4b860f4c2df3 (patch) | |
| tree | 0e8dc3ed30eac7188714726e188a92ccfe2aa715 /src/sessionManager.hpp | |
| parent | e9f9065e4347ed5e99092612dd90fd85b622ad1c (diff) | |
internal!: refactored to smart pointer
Diffstat (limited to 'src/sessionManager.hpp')
| -rw-r--r-- | src/sessionManager.hpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp index eb3705e..179d7d8 100644 --- a/src/sessionManager.hpp +++ b/src/sessionManager.hpp @@ -12,21 +12,24 @@ class CSessionManager { CSessionManager(); ~CSessionManager(); - std::pair<std::jthread, std::shared_ptr<CSession>> *newSession(); + void newSession(); void run(); - void broadcast(const std::string &msg, std::optional<const CSession *const> self = std::nullopt) const; // second param only specified when we want to exclude the sender - void kick(CSession *session, const bool kill = false, const std::string &reason = ""); - void kick(std::pair<std::jthread, std::shared_ptr<CSession>> *session, const bool kill = false, const std::string &reason = ""); + void broadcast(const std::string &msg, std::optional<std::weak_ptr<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender + void kick(std::weak_ptr<CSession> session, const bool kill = false, const std::string &reason = ""); void addSession(const CSession &session); bool nameExists(const std::string &name); void shutdownSessions(); - CSession *getByName(const std::string &name) const; - CSession *getByIp(const std::string &ip) const; + std::shared_ptr<CSession> getByName(const std::string &name) const; + std::shared_ptr<CSession> getByIp(const std::string &ip) const; std::vector<std::shared_ptr<CSession>> getSessions() const; + // Safer weak_ptr versions - recommended for most use cases to avoid accidental lifetime extension + std::weak_ptr<CSession> getByNameWeak(const std::string &name) const; + std::weak_ptr<CSession> getByIpWeak(const std::string &ip) const; + private: void broadcast(const CChatManager::SMessage &msg) const; |
