diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-05-30 20:53:22 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-05-30 20:53:22 +0800 |
| commit | ae8affe9fff64f9119b50cab409c47460d42b6e6 (patch) | |
| tree | 0eee78308e2ad221c9a074958c9143caee1f0ce2 /src/session.cpp | |
| parent | ab27760e7a20ef26790a93174ac5331e6c1b51b8 (diff) | |
perf(session): directly use m_bDeaf
Diffstat (limited to 'src/session.cpp')
| -rw-r--r-- | src/session.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/session.cpp b/src/session.cpp index 4cafd56..c537b25 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,9 +1,9 @@ -#include "session.hpp" #include "chatManager.hpp" #include "commandHandler.hpp" #include "format.hpp" #include "log.hpp" #include "server.hpp" +#include "session.hpp" #include "sessionManager.hpp" #include <algorithm> #include <arpa/inet.h> @@ -134,12 +134,11 @@ std::unique_ptr<CSession::SRecvData> CSession::read() { } std::unique_ptr<CSession::SRecvData> CSession::read(const std::string &msg, bool bypassDeaf) { - const auto deaf = isDeaf(); - if (bypassDeaf && deaf) - setDeaf(false); - write(NONEWLINE, "{}", msg, false); - if (bypassDeaf && deaf) - setDeaf(true); + if (bypassDeaf && m_bDeaf) + m_bDeaf = false; + write(NONEWLINE, "{}", msg); + if (bypassDeaf && m_bDeaf) + m_bDeaf = true; m_szReading = msg; return read(); } @@ -181,16 +180,16 @@ bool CSession::registerSession() { recvData->sanitize(); if (recvData->isEmpty()) { - setDeaf(false); + m_bDeaf = false; write("Name cannot be empty"); - setDeaf(true); + m_bDeaf = true; return registerSession(); } if (g_pSessionManager->nameExists(recvData->data)) { - setDeaf(false); + m_bDeaf = false; write("Name already exists"); - setDeaf(true); + m_bDeaf = true; return registerSession(); } @@ -200,7 +199,7 @@ bool CSession::registerSession() { g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has joined the chat", m_name), this); - setDeaf(false); + m_bDeaf = false; return true; } @@ -215,14 +214,14 @@ bool CSession::isValid() { template <typename... Args> bool CSession::write(std::format_string<Args...> fmt, Args &&...args) { - if (isDeaf()) + if (m_bDeaf) return false; return write(NONE, fmt, std::forward<Args>(args)...); } template <typename... Args> bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) { - if (isDeaf()) + if (m_bDeaf) return false; std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...); |
