From 3ad8cca9f6fecfb4c1f70f0a8c9d4b860f4c2df3 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 12 Jun 2025 21:03:17 +0800 Subject: internal!: refactored to smart pointer --- src/core/sessionManager.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/core/sessionManager.hpp (limited to 'src/core/sessionManager.hpp') diff --git a/src/core/sessionManager.hpp b/src/core/sessionManager.hpp new file mode 100644 index 0000000..e84226c --- /dev/null +++ b/src/core/sessionManager.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "../debug/format.hpp" +#include "../misc/memory.hpp" +#include "chatManager.hpp" +#include "session.hpp" +#include +#include + +class CSessionManager { + public: + CSessionManager(); + ~CSessionManager(); + + void newSession(); + + void run(); + void broadcast(const std::string &msg, std::optional> self = std::nullopt) const; // second param only specified when we want to exclude the sender + void kick(WP session, const bool kill = false, const std::string &reason = ""); + void addSession(const CSession &session); + + bool nameExists(const std::string &name); + void shutdownSessions(); + + SP getByName(const std::string &name) const; + SP getByIp(const std::string &ip) const; + std::vector> getSessions() const; + + private: + void broadcast(const CChatManager::SMessage &msg) const; + + std::vector>> m_vSessions; + + friend class CChatManager; +}; +inline SP g_pSessionManager; -- cgit v1.2.3