From ee63886625aef473a177ad4728eeb5784ffbe159 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 21 Mar 2025 21:19:31 +0800 Subject: fix: potential crash for weirdly exited clients fixes #9 FIXME: spamming too much will still give ``` terminate called after throwing an instance of 'std::system_error' what(): Resource deadlock avoided ``` --- src/sessionManager.cpp | 4 ++-- src/sessionManager.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sessionManager.cpp b/src/sessionManager.cpp index 0e27367..cb8a2d4 100644 --- a/src/sessionManager.cpp +++ b/src/sessionManager.cpp @@ -72,13 +72,13 @@ std::vector> CSessionManager::getSessions() const { return m_vSessions | std::views::transform([](const auto &s) { return s.second; }) | std::ranges::to(); } -void CSessionManager::kick(CSession *session, const bool &kill, const std::string &reason) { +void CSessionManager::kick(CSession *session, const bool kill, const std::string &reason) { for (auto &_session : m_vSessions) if (_session.second.get() == session) kick(&_session, kill, reason); } -void CSessionManager::kick(std::pair> *session, const bool &kill, const std::string &reason) { +void CSessionManager::kick(std::pair> *session, const bool kill, const std::string &reason) { auto it = std::ranges::find_if(m_vSessions, [session](const auto &s) { return s.second.get() == session->second.get(); }); if (it != m_vSessions.end()) { diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp index 4ca3311..9739918 100644 --- a/src/sessionManager.hpp +++ b/src/sessionManager.hpp @@ -16,8 +16,8 @@ class CSessionManager { void run(); void broadcast(const std::string &msg) const; - void kick(CSession *session, const bool &kill = false, const std::string &reason = ""); - void kick(std::pair> *session, const bool &kill = false, const std::string &reason = ""); + void kick(CSession *session, const bool kill = false, const std::string &reason = ""); + void kick(std::pair> *session, const bool kill = false, const std::string &reason = ""); void addSession(const CSession &session); bool nameExists(const std::string &name); -- cgit v1.2.3