mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-11 11:31:52 +02:00
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.
This commit is contained in:
parent
a6a929eb95
commit
42878af3a6
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user