summaryrefslogtreecommitdiff
path: root/src/sessionManager.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-21 18:09:05 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-22 15:02:46 +0800
commit3e19bf603af0ac01f6690afe7cf59702a4a5cc02 (patch)
treeb8ee33d721aa200364617239aab557639b5003c5 /src/sessionManager.cpp
parent97d82139d2011a790c0d3d254add5d800de2742f (diff)
feat(commands): client execute commands (#8)
refactor(session): writeChat, unify written chat internal: removed `CChatManager::broadcastMessage`, just use `g_pSessionManager->broadcastChat(msg)`
Diffstat (limited to 'src/sessionManager.cpp')
-rw-r--r--src/sessionManager.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp
index 51bede4..0e27367 100644
--- a/src/sessionManager.cpp
+++ b/src/sessionManager.cpp
@@ -45,13 +45,12 @@ void CSessionManager::broadcast(const std::string &msg) const {
session->write(msg);
}
-void CSessionManager::broadcastChat(const std::string &msg, const std::string &username) const {
+void CSessionManager::broadcastChat(const CChatManager::SMessage &msg) const {
for (const auto &[thread, session] : m_vSessions) {
if (!session)
continue;
- auto name = session->getName();
- if (name != username)
- session->write(msg);
+
+ session->writeChat(msg);
}
}
@@ -83,8 +82,8 @@ void CSessionManager::kick(std::pair<std::jthread, std::shared_ptr<CSession>> *s
auto it = std::ranges::find_if(m_vSessions, [session](const auto &s) { return s.second.get() == session->second.get(); });
if (it != m_vSessions.end()) {
- if (!reason.empty())
- it->second->write(reason);
+ if (!reason.empty())
+ it->second->write(reason);
const auto native_handle = it->first.native_handle();
if (it->first.joinable())
it->first.detach(); // .detach the thread since it's removing itself