From 092965b583bd0c377ed5d9f2af0e0f4bb0548354 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 20 May 2025 18:33:14 +0800 Subject: internal: use uintptr_t of session instance for identification --- TODO.md | 2 +- src/chatManager.cpp | 1 + src/chatManager.hpp | 2 ++ src/session.cpp | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 2669e16..f3ca69a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ - [ ] ci unit testing - [ ] multiline buffer input/output - [ ] file upload/download -- [ ] user identifier, UUID or something, IP can duplicate, username can be .empty() +- [x] user identifier, ~UUID or something~uintptr_t of instance, IP can duplicate, username can be .empty() ## FTXUI diff --git a/src/chatManager.cpp b/src/chatManager.cpp index 96c1b0c..07dfce4 100644 --- a/src/chatManager.cpp +++ b/src/chatManager.cpp @@ -20,6 +20,7 @@ void CChatManager::newMessage(const SMessage &msg) { return; } g_pSessionManager->broadcastChat(msg); + g_pIOManager->m_vIO.push_back({.msg = msg, .log = std::nullopt}); g_pInputManager->updateIO(); } diff --git a/src/chatManager.hpp b/src/chatManager.hpp index 0f423f7..46b02de 100644 --- a/src/chatManager.hpp +++ b/src/chatManager.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -11,6 +12,7 @@ class CChatManager { struct SMessage { std::string msg; std::string username; + std::optional sender = std::nullopt; bool admin = false; }; void newMessage(const SMessage &msg); diff --git a/src/session.cpp b/src/session.cpp index 8a311bf..8167a91 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -249,7 +249,7 @@ bool CSession::write(const std::string &msg) { } bool CSession::writeChat(const CChatManager::SMessage &msg) { - if (m_name != msg.username) { + if ((uintptr_t)this != *msg.sender) { if (msg.admin && !m_isAdmin) return false; -- cgit v1.2.3