diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 18:01:42 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 22:49:45 +0800 |
| commit | 815c3955dbd9ff7e1a427cf4bc66da38b581b178 (patch) | |
| tree | 37b7b20175aeadf789e990fac7bd364792dd7e49 /src/session.cpp | |
| parent | a7cd7d8eb37c50554ae7c75f2ba94db74d293a1b (diff) | |
feat: join and leave message
internal: refactored messaging management, use instnace pointer for
verification of session
Diffstat (limited to 'src/session.cpp')
| -rw-r--r-- | src/session.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/session.cpp b/src/session.cpp index 2814c41..07b89f3 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,6 +1,7 @@ #include "session.hpp" #include "chatManager.hpp" #include "commandHandler.hpp" +#include "format.hpp" #include "log.hpp" #include "server.hpp" #include "sessionManager.hpp" @@ -21,6 +22,7 @@ CSession::CSession() { m_ip.resize(strlen(m_ip.c_str())); m_port = ntohs(m_addr.sin_port); m_isAdmin = std::ranges::any_of(m_adminIps, [this](const char *ip) { return m_ip == ip; }); + log(LOG, "Client {} connected on port {}", m_ip, m_port); log(TRACE, "session: initialized"); @@ -194,6 +196,8 @@ bool CSession::registerSession() { log(LOG, "Client {} registered as: {}", m_ip, m_name); + g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has joined the chat", m_name), (uintptr_t)this); + setDeaf(false); return true; } @@ -249,7 +253,7 @@ bool CSession::write(const std::string &msg) { } bool CSession::writeChat(const CChatManager::SMessage &msg) { - if ((uintptr_t)this != *msg.sender) { + if (msg.sender ? (uintptr_t)this != *msg.sender : msg.msg != m_name) { if (msg.admin && !m_isAdmin) return false; |
