From 815c3955dbd9ff7e1a427cf4bc66da38b581b178 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 21 May 2025 18:01:42 +0800 Subject: feat: join and leave message internal: refactored messaging management, use instnace pointer for verification of session --- src/session.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/session.cpp') 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; -- cgit v1.2.3