From f42d4dc75836acca81e5572f6cbd3beadead778a Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 22 Feb 2025 14:18:45 +0000 Subject: [PATCH] Fix crash on attempting to connect newly created lobby room --- server/CVCMIServer.cpp | 22 ++++++++++------------ server/GlobalLobbyProcessor.cpp | 1 - 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index b64850332..8781d3609 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -80,27 +80,25 @@ CVCMIServer::CVCMIServer(uint16_t port, bool runByClient) CVCMIServer::~CVCMIServer() = default; -uint16_t CVCMIServer::prepare(bool connectToLobby, bool listenForConnections) { - if(connectToLobby) { +uint16_t CVCMIServer::prepare(bool connectToLobby, bool listenForConnections) +{ + if(connectToLobby) lobbyProcessor = std::make_unique(*this); - return 0; - } else { - return startAcceptingIncomingConnections(listenForConnections); - } + + return startAcceptingIncomingConnections(listenForConnections); } uint16_t CVCMIServer::startAcceptingIncomingConnections(bool listenForConnections) { networkServer = networkHandler->createServerTCP(*this); - port - ? logNetwork->info("Port %d will be used", port) - : logNetwork->info("Randomly assigned port will be used"); - - // config port may be 0 => srvport will contain the OS-assigned port value - if (listenForConnections) { + // config port may be 0 => srvport will contain the OS-assigned port value + port + ? logNetwork->info("Port %d will be used", port) + : logNetwork->info("Randomly assigned port will be used"); + auto srvport = networkServer->start(port); logNetwork->info("Listening for connections at port %d", srvport); return srvport; diff --git a/server/GlobalLobbyProcessor.cpp b/server/GlobalLobbyProcessor.cpp index 11b162dd4..2a594a914 100644 --- a/server/GlobalLobbyProcessor.cpp +++ b/server/GlobalLobbyProcessor.cpp @@ -99,7 +99,6 @@ void GlobalLobbyProcessor::receiveServerLoginSuccess(const JsonNode & json) { // no-op, wait just for any new commands from lobby logGlobal->info("Lobby: Successfully connected to lobby server"); - owner.startAcceptingIncomingConnections(true); } void GlobalLobbyProcessor::receiveAccountJoinsRoom(const JsonNode & json)