From 50edf5dafb991d650630bc52c200200f2f4928aa Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 21 May 2025 23:41:50 +0800 Subject: fixup! feat: join and leave message fix! unstable segfault when user leave without register --- src/sessionManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 @@ -108,7 +109,11 @@ void CSessionManager::kick(CSession *session, const bool kill, const std::string void CSessionManager::kick(std::pair> *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()) { -- cgit v1.2.3