summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-05-21 23:41:50 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-05-21 23:42:08 +0800
commit50edf5dafb991d650630bc52c200200f2f4928aa (patch)
tree226ea8879e0c8e19c559fe26172f9b033a36c410 /src
parenta7a142dba18146efb92726bfebdadb3cf16fae5b (diff)
fixup! feat: join and leave message
fix! unstable segfault when user leave without register
Diffstat (limited to 'src')
-rw-r--r--src/sessionManager.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp
index a7cbaf6..add9015 100644
--- a/src/sessionManager.cpp
+++ b/src/sessionManager.cpp
@@ -1,6 +1,7 @@
#include "sessionManager.hpp"
#include "IOManager.hpp"
#include "chatServer.hpp"
+#include "format.hpp"
#include "log.hpp"
#include "session.hpp"
#include <algorithm>
@@ -108,7 +109,11 @@ void CSessionManager::kick(CSession *session, const bool kill, const std::string
void CSessionManager::kick(std::pair<std::jthread, std::shared_ptr<CSession>> *session, const bool kill, const std::string &reason) {
auto it = std::ranges::find_if(m_vSessions, [session](const auto &s) { return s.second.get() == session->second.get(); });
- g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has left the chat", session->second->m_name), session->second.get());
+ if (session->second)
+ // this only exist when the session is registered
+ // not sure why the second is null, but m_name definately is since it's setted during register
+ // but we don't need to notify people if the session didn't even "join"/register anyways
+ g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has left the chat", session->second->m_name), session->second.get());
if (it != m_vSessions.end()) {
if (!reason.empty()) {