From dcbfea018ba37c117412c04fb17dccd4b1b17fdc Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 4 Jun 2024 14:12:16 +0000 Subject: [PATCH] Fix crash on disconnecting from the game --- server/CVCMIServer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 4744e1cfe..4800fa5ab 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -165,6 +165,9 @@ void CVCMIServer::onNewConnection(const std::shared_ptr & co void CVCMIServer::onPacketReceived(const std::shared_ptr & connection, const std::vector & message) { std::shared_ptr c = findConnection(connection); + if (c == nullptr) + throw std::out_of_range("Unknown connection received in CVCMIServer::findConnection"); + auto pack = c->retrievePack(message); pack->c = c; CVCMIServerPackVisitor visitor(*this, this->gh); @@ -197,7 +200,7 @@ std::shared_ptr CVCMIServer::findConnection(const std::shared_ptr & con logNetwork->error("Network error receiving a pack. Connection has been closed"); std::shared_ptr c = findConnection(connection); + if (!c) + return; // player have already disconnected via clientDisconnected call + vstd::erase(activeConnections, c); if(activeConnections.empty() || hostClientId == c->connectionID)