summaryrefslogtreecommitdiff
path: root/src/sessionManager.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-22 13:08:55 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-22 15:02:46 +0800
commit3acfd38a49f906b818e932ba2de89b7c31c3c932 (patch)
treef7dd26f4624e6f04587c7e24a1c27019101fbb5d /src/sessionManager.cpp
parentbc77c515c7c22159fcbaf0fe6fda5e653b946fa0 (diff)
fix(nameExists): kill dead thread/session
fixes a bug where if you quit then rejoin with the same name, it still says name exists
Diffstat (limited to 'src/sessionManager.cpp')
-rw-r--r--src/sessionManager.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp
index cb8a2d4..3d60db2 100644
--- a/src/sessionManager.cpp
+++ b/src/sessionManager.cpp
@@ -55,7 +55,16 @@ void CSessionManager::broadcastChat(const CChatManager::SMessage &msg) const {
}
bool CSessionManager::nameExists(const std::string &name) {
- return std::ranges::any_of(m_vSessions, [&name](const auto &s) { return s.second->getName() == name; });
+ auto it = std::ranges::find_if(m_vSessions, [&name](const auto &s) { return s.second->getName() == name; });
+
+ if (it != m_vSessions.end()) {
+ if (!it->second->isValid()) {
+ kick(it->second.get(), true, "Connection lost");
+ return false;
+ }
+ return true;
+ }
+ return false;
}
CSession *CSessionManager::getByName(const std::string &name) const {