Procházet zdrojové kódy

Better fix for lobby room crash

Always use TCP connection when connecting to self-hosted lobby room.
Effectively reverts 1.6.6 change for lobby connections. Single-player
connections still use intra-process pseudo connection

Main problem is various side effects caused by changing order of
operations. For example, client may inform lobby about joining the room
before server finishes startup, which was not possible before.
Ivan Savenko před 7 měsíci
rodič
revize
42878af3a6
3 změnil soubory, kde provedl 15 přidání a 2 odebrání
  1. 0 1
      client/CServerHandler.cpp
  2. 14 1
      client/ServerRunner.cpp
  3. 1 0
      client/ServerRunner.h

+ 0 - 1
client/CServerHandler.cpp

@@ -194,7 +194,6 @@ void CServerHandler::startLocalServerAndConnect(bool connectToLobby)
 
 void CServerHandler::connectToServer(const std::string & addr, const ui16 port)
 {
-	logNetwork->info("Establishing connection to %s:%d...", addr, port);
 	setState(EClientState::CONNECTING);
 	serverHostname = addr;
 	serverPort = port;

+ 14 - 1
client/ServerRunner.cpp

@@ -40,6 +40,7 @@ void ServerThreadRunner::start(bool listenForConnections, bool connectToLobby, s
 	// cfgport may be 0 -- the real port is returned after calling prepare()
 	uint16_t port = settings["server"]["localPort"].Integer();
 	server = std::make_unique<CVCMIServer>(port, true);
+	lobbyMode = connectToLobby;
 
 	if (startingInfo)
 	{
@@ -77,7 +78,18 @@ int ServerThreadRunner::exitCode()
 
 void ServerThreadRunner::connect(INetworkHandler & network, INetworkClientListener & listener)
 {
-	network.createInternalConnection(listener, server->getNetworkServer());
+	if (lobbyMode)
+	{
+		std::string host = settings["server"]["localHostname"].String();
+		uint16_t port = settings["server"]["localPort"].Integer();
+		logNetwork->info("Establishing connection to %s:%d...", host, port);
+
+		network.connectToRemote(listener, host, port);
+	}
+	else
+	{
+		network.createInternalConnection(listener, server->getNetworkServer());
+	}
 }
 
 #ifdef ENABLE_SERVER_PROCESS
@@ -122,6 +134,7 @@ void ServerProcessRunner::connect(INetworkHandler & network, INetworkClientListe
 {
 	std::string host = settings["server"]["localHostname"].String();
 	uint16_t port = settings["server"]["localPort"].Integer();
+	logNetwork->info("Establishing connection to %s:%d...", host, port);
 
 	network.connectToRemote(listener, host, port);
 }

+ 1 - 0
client/ServerRunner.h

@@ -38,6 +38,7 @@ class ServerThreadRunner final : public IServerRunner, boost::noncopyable
 	std::unique_ptr<CVCMIServer> server;
 	boost::thread threadRunLocalServer;
 	uint16_t serverPort = 0;
+	bool lobbyMode = false;
 
 public:
 	void start(bool listenForConnections, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) override;