diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-13 16:43:14 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:45:00 +0800 |
| commit | d580a4468a26f6b47b4dfe7c9171e680c788be41 (patch) | |
| tree | 6f1b4a5c86f6d0065c4c066cd6d8ddc83d147d4d /src | |
| parent | 4f2c686a36dc5a091a47c5d8eac9193608242ad3 (diff) | |
NFormatter: no more prefix support for socket write
NFormatter: remove CHAT prefix
Diffstat (limited to 'src')
| -rw-r--r-- | src/format.hpp | 4 | ||||
| -rw-r--r-- | src/session.cpp | 16 | ||||
| -rw-r--r-- | src/session.hpp | 4 | ||||
| -rw-r--r-- | src/sessionManager.cpp | 7 | ||||
| -rw-r--r-- | src/sessionManager.hpp | 2 |
5 files changed, 15 insertions, 18 deletions
diff --git a/src/format.hpp b/src/format.hpp index df1aa40..42a4458 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -9,7 +9,6 @@ enum eFormatType : int8_t { WARN, ERR, SYS, - CHAT, }; namespace NFormatter { @@ -28,9 +27,6 @@ inline std::string fmt(eFormatType type, std::string str) { case SYS: prefix = "[SYSTEM] "; break; - case CHAT: - prefix = "[CHAT] "; - break; case TRACE: prefix = "[DEBUG] "; break; diff --git a/src/session.cpp b/src/session.cpp index a990e08..2a25db2 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -84,7 +84,7 @@ CSession::SRecvData CSession::read() { } CSession::SRecvData CSession::read(const std::string &msg) { - write({}, "{}", msg, false); + write("{}", msg, false); m_isReading = true; return read(); } @@ -102,13 +102,13 @@ bool CSession::registerSession() { return false; if (recvData.data[0] == '\n' || recvData.data[0] == ' ') { - write("Name cannot be empty", ERR); + write("Name cannot be empty"); return registerSession(); } *std::remove(recvData.data, recvData.data + strlen(recvData.data), '\n') = '\0'; if (g_pSessionManager->nameExists(recvData.data)) { - write("Name already exists", ERR); + write("Name already exists"); return registerSession(); } @@ -130,8 +130,8 @@ bool CSession::isValid() { } template <typename... Args> -bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) { - std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...); +bool CSession::write(std::format_string<Args...> fmt, Args &&...args) { + std::string msg = NFormatter::fmt(NONE, fmt, std::forward<Args>(args)...); if (m_isReading) msg.insert(0, "\n"); @@ -143,8 +143,8 @@ bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&. return true; } -bool CSession::write(const std::string &msg, eFormatType type) { - return write(type, "{}", msg); +bool CSession::write(const std::string &msg) { + return write("{}", msg); } std::string CSession::getName() { @@ -156,6 +156,6 @@ void CSession::setSelf(std::pair<std::jthread, std::shared_ptr<CSession>> *self) } void CSession::onShutdown() { - write(SYS, "Shutting down, bye"); + write("Shutting down, bye"); g_pSessionManager->removeSession(self); } diff --git a/src/session.hpp b/src/session.hpp index 48e2dad..4f5adb2 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -23,9 +23,9 @@ class CSession { SRecvData read(); SRecvData read(const std::string &msg); - bool write(const std::string &msg, eFormatType type); + bool write(const std::string &msg); template <typename... Args> - bool write(eFormatType type, std::format_string<Args...> fmt, Args &&...args); + bool write(std::format_string<Args...> fmt, Args &&...args); void run(); diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp index a7490e3..049ec2b 100644 --- a/src/sessionManager.cpp +++ b/src/sessionManager.cpp @@ -38,9 +38,9 @@ void CSessionManager::run() { newSession(); } -void CSessionManager::broadcast(eFormatType type, const std::string &msg) const { +void CSessionManager::broadcast(const std::string &msg) const { for (const auto &[thread, session] : m_vSessions) - session->write(msg, type); + session->write(msg); } void CSessionManager::broadcastChat(const std::string &msg, const std::string &username) const { @@ -49,7 +49,7 @@ void CSessionManager::broadcastChat(const std::string &msg, const std::string &u continue; auto name = session->getName(); if (name != username) - session->write(msg, NONE); + session->write(msg); } } @@ -66,4 +66,5 @@ void CSessionManager::removeSession(std::pair<std::jthread, std::shared_ptr<CSes it->second.reset(); m_vSessions.erase(it); } + } diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp index 0f95dc9..21c47b9 100644 --- a/src/sessionManager.hpp +++ b/src/sessionManager.hpp @@ -14,7 +14,7 @@ class CSessionManager { std::pair<std::jthread, std::shared_ptr<CSession>> *newSession(); void run(); - void broadcast(eFormatType type, const std::string &msg) const; + void broadcast(const std::string &msg) const; void kick(const CSession *session) const; void addSession(const CSession &session); void removeSession(std::pair<std::jthread, std::shared_ptr<CSession>> *session); |
