summaryrefslogtreecommitdiff
path: root/src/session.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-23 12:56:38 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-04-03 18:31:41 +0800
commit50de5f9b80f1859b6eaa3b68c10a3f1cfb994737 (patch)
treebd125b0af19af04776e3740f707a0012555d460f /src/session.cpp
parentb02e484013ede3ed8d43ad19c177af2afb0bbfc8 (diff)
feat: deaf
necessary for being deaf during registeration
Diffstat (limited to 'src/session.cpp')
-rw-r--r--src/session.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/session.cpp b/src/session.cpp
index 526e041..5bd41d9 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -119,8 +119,11 @@ std::unique_ptr<CSession::SRecvData> CSession::read() {
return recvData;
}
-std::unique_ptr<CSession::SRecvData> CSession::read(const std::string &msg) {
+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);
m_isReading = true;
return read();
}
@@ -140,26 +143,38 @@ void CSession::run() {
}
bool CSession::isMuted() const {
- return m_isMuted;
+ return m_bMuted;
}
void CSession::setMuted(bool mute) {
- m_isMuted = mute;
+ m_bMuted = mute;
+}
+
+bool CSession::isDeaf() const {
+ return m_bDeaf;
+}
+
+void CSession::setDeaf(bool deaf) {
+ m_bDeaf = deaf;
}
bool CSession::registerSession() {
- auto recvData = read("Name: ");
+ auto recvData = read("Name: ", true);
if (!recvData->good)
return false;
recvData->sanitize();
if (recvData->isEmpty()) {
+ setDeaf(false);
write("Name cannot be empty");
+ setDeaf(true);
return registerSession();
}
if (g_pSessionManager->nameExists(recvData->data)) {
+ setDeaf(false);
write("Name already exists");
+ setDeaf(true);
return registerSession();
}
@@ -167,6 +182,7 @@ bool CSession::registerSession() {
log(LOG, "Client registered as: {}", m_name);
+ setDeaf(false);
return true;
}
@@ -181,6 +197,8 @@ bool CSession::isValid() {
template <typename... Args>
bool CSession::write(std::format_string<Args...> fmt, Args &&...args) {
+ if (isDeaf())
+ return false;
std::string msg = NFormatter::fmt(NONE, fmt, std::forward<Args>(args)...);
if (m_isReading)
msg.insert(0, "\n");
@@ -197,6 +215,9 @@ bool CSession::write(std::format_string<Args...> fmt, Args &&...args) {
template <typename... Args>
bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
+ if (isDeaf())
+ return false;
+
std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...);
if (m_isReading)
msg.insert(0, "\n");