summaryrefslogtreecommitdiff
path: root/src/core/sessionManager.hpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-06-12 21:03:17 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-06-13 20:22:13 +0800
commit3ad8cca9f6fecfb4c1f70f0a8c9d4b860f4c2df3 (patch)
tree0e8dc3ed30eac7188714726e188a92ccfe2aa715 /src/core/sessionManager.hpp
parente9f9065e4347ed5e99092612dd90fd85b622ad1c (diff)
internal!: refactored to smart pointer
Diffstat (limited to 'src/core/sessionManager.hpp')
-rw-r--r--src/core/sessionManager.hpp36
1 files changed, 36 insertions, 0 deletions
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 <thread>
+#include <vector>
+
+class CSessionManager {
+ public:
+ CSessionManager();
+ ~CSessionManager();
+
+ void newSession();
+
+ void run();
+ void broadcast(const std::string &msg, std::optional<WP<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender
+ void kick(WP<CSession> session, const bool kill = false, const std::string &reason = "");
+ void addSession(const CSession &session);
+
+ bool nameExists(const std::string &name);
+ void shutdownSessions();
+
+ SP<CSession> getByName(const std::string &name) const;
+ SP<CSession> getByIp(const std::string &ip) const;
+ std::vector<SP<CSession>> getSessions() const;
+
+ private:
+ void broadcast(const CChatManager::SMessage &msg) const;
+
+ std::vector<std::pair<std::jthread, SP<CSession>>> m_vSessions;
+
+ friend class CChatManager;
+};
+inline SP<CSessionManager> g_pSessionManager;