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)