diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 22:24:23 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-21 11:18:14 +0800 |
| commit | e970b786f9e5b9307c1113373b9c1f96eaafacf4 (patch) | |
| tree | 225ceb78256f76adbb6779b06b52389e415460e3 | |
| parent | d2afc5f872b98e8e8f20307221bf13e7dafaac4e (diff) | |
feat(sessionManager): getSessions
| -rw-r--r-- | src/sessionManager.cpp | 5 | ||||
| -rw-r--r-- | src/sessionManager.hpp | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp index adf3834..801d9a7 100644 --- a/src/sessionManager.cpp +++ b/src/sessionManager.cpp @@ -3,6 +3,7 @@ #include "session.hpp" #include <algorithm> #include <cstring> +#include <ranges> #include <unistd.h> #include <utility> @@ -68,6 +69,10 @@ CSession *CSessionManager::getByIp(const char m_ip[INET_ADDRSTRLEN]) const { return it != m_vSessions.end() ? it->second.get() : nullptr; } +std::vector<std::shared_ptr<CSession>> CSessionManager::getSessions() const { + return m_vSessions | std::views::transform([](const auto &s) { return s.second; }) | std::ranges::to<std::vector>(); +} + void CSessionManager::kick(CSession *session, const bool &kill, const std::string &reason) { for (auto &_session : m_vSessions) if (_session.second.get() == session) diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp index 70faa58..b33a39e 100644 --- a/src/sessionManager.hpp +++ b/src/sessionManager.hpp @@ -24,6 +24,7 @@ class CSessionManager { CSession *getByName(const std::string &name) const; CSession *getByIp(const char m_ip[INET_ADDRSTRLEN]) const; + std::vector<std::shared_ptr<CSession>> getSessions() const; private: void broadcastChat(const std::string &msg, const std::string &username) const; |
