From f9251ff92c8ffb0a923a004515161e090a2a5dc3 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 28 Oct 2022 17:51:02 +0200 Subject: [PATCH] add more warning prints on unexpected cases --- src/TNetwork.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index bfc9302..68e2e27 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -526,7 +526,7 @@ void TNetwork::OnDisconnect(const std::weak_ptr& ClientPtr) { try { LockedClientPtr = ClientPtr.lock(); } catch (const std::exception&) { - // do nothing ig + beammp_warn("Client expired in OnDisconnect, this is unexpected"); return; } beammp_assert(LockedClientPtr != nullptr); @@ -866,12 +866,13 @@ void TNetwork::SendToAll(TClient* c, const std::vector& Data, bool Self bool ret = true; mServer.ForEachClient([&](std::weak_ptr ClientPtr) -> bool { std::shared_ptr Client; - { + try { ReadLock Lock(mServer.GetClientMutex()); - if (!ClientPtr.expired()) { - Client = ClientPtr.lock(); - } else - return true; + Client = ClientPtr.lock(); + } catch (const std::exception&) { + // continue + beammp_warn("Client expired, shouldn't happen - if a client disconnected recently, you can ignore this"); + return true; } if (Self || Client.get() != c) { if (Client->IsSynced() || Client->IsSyncing()) {