diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 18:13:30 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-05-21 22:49:45 +0800 |
| commit | fb256d473ed33410d11be56244c565884c2f14bb (patch) | |
| tree | 728dfaf4f6d29638b638a931cf8afca4e699b98b | |
| parent | 815c3955dbd9ff7e1a427cf4bc66da38b581b178 (diff) | |
internal: prefer direct pointers instead of (uintptr_t) converted ones
| -rw-r--r-- | src/chatManager.hpp | 2 | ||||
| -rw-r--r-- | src/session.cpp | 2 | ||||
| -rw-r--r-- | src/sessionManager.cpp | 6 | ||||
| -rw-r--r-- | src/sessionManager.hpp | 2 |
4 files changed, 6 insertions, 6 deletions
diff --git a/src/chatManager.hpp b/src/chatManager.hpp index 0681017..b48dcdb 100644 --- a/src/chatManager.hpp +++ b/src/chatManager.hpp @@ -12,7 +12,7 @@ class CChatManager { struct SMessage { std::string msg; std::string username; - std::optional<uintptr_t> sender = std::nullopt; + std::optional<uintptr_t> sender = std::nullopt; // cant include session to use CSession* cause circular dependency bool admin = false; }; void newMessage(const SMessage &msg); diff --git a/src/session.cpp b/src/session.cpp index 07b89f3..d88af2f 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -196,7 +196,7 @@ 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); + g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has joined the chat", m_name), this); setDeaf(false); return true; diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp index a5dc713..4f68e2e 100644 --- a/src/sessionManager.cpp +++ b/src/sessionManager.cpp @@ -48,9 +48,9 @@ void CSessionManager::run() { newSession(); } -void CSessionManager::broadcast(const std::string &msg, std::optional<uintptr_t> self) const { +void CSessionManager::broadcast(const std::string &msg, std::optional<const CSession* const> self) const { for (const auto &[thread, session] : m_vSessions) - if (!self || (self && (uintptr_t)session.get() != *self)) + if (!self || (self && session.get() != *self)) session->write(msg); g_pIOManager->addCustom({"", msg}); @@ -108,7 +108,7 @@ 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), (uintptr_t)session->second.get()); + 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()) { diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp index 6e946d6..6d3750e 100644 --- a/src/sessionManager.hpp +++ b/src/sessionManager.hpp @@ -15,7 +15,7 @@ class CSessionManager { std::pair<std::jthread, std::shared_ptr<CSession>> *newSession(); void run(); - void broadcast(const std::string &msg, std::optional<uintptr_t> self = std::nullopt) const; // second param only specified when we want to exclude the sender + void broadcast(const std::string &msg, std::optional<const CSession* const> self = std::nullopt) const; // second param only specified when we want to exclude the sender void kick(CSession *session, const bool kill = false, const std::string &reason = ""); void kick(std::pair<std::jthread, std::shared_ptr<CSession>> *session, const bool kill = false, const std::string &reason = ""); void addSession(const CSession &session); |
