From 3acfd38a49f906b818e932ba2de89b7c31c3c932 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 22 Mar 2025 13:08:55 +0800 Subject: fix(nameExists): kill dead thread/session fixes a bug where if you quit then rejoin with the same name, it still says name exists --- src/sessionManager.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/sessionManager.cpp') 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 { -- cgit v1.2.3