mirror of https://github.com/OpenTTD/OpenTTD
Fix: lobby window doesn't close if no connection could be established (#9223)
parent
e162d0a55c
commit
583011bca0
|
@ -619,35 +619,69 @@ static void NetworkInitialize(bool close_admins = true)
|
||||||
_network_reconnect = 0;
|
_network_reconnect = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Non blocking connection create to query servers */
|
/** Non blocking connection to query servers for their game info. */
|
||||||
class TCPQueryConnecter : TCPConnecter {
|
class TCPQueryConnecter : TCPConnecter {
|
||||||
private:
|
private:
|
||||||
bool request_company_info;
|
|
||||||
std::string connection_string;
|
std::string connection_string;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TCPQueryConnecter(const std::string &connection_string, bool request_company_info) : TCPConnecter(connection_string, NETWORK_DEFAULT_PORT), request_company_info(request_company_info), connection_string(connection_string) {}
|
TCPQueryConnecter(const std::string &connection_string) : TCPConnecter(connection_string, NETWORK_DEFAULT_PORT), connection_string(connection_string) {}
|
||||||
|
|
||||||
void OnConnect(SOCKET s) override
|
void OnConnect(SOCKET s) override
|
||||||
{
|
{
|
||||||
_networking = true;
|
_networking = true;
|
||||||
new ClientNetworkGameSocketHandler(s, this->connection_string);
|
new ClientNetworkGameSocketHandler(s, this->connection_string);
|
||||||
MyClient::SendInformationQuery(request_company_info);
|
MyClient::SendInformationQuery(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query a server to fetch his game-info.
|
* Query a server to fetch the game-info.
|
||||||
* @param connection_string the address to query.
|
* @param connection_string the address to query.
|
||||||
* @param request_company_info Whether to request company info too.
|
|
||||||
*/
|
*/
|
||||||
void NetworkTCPQueryServer(const std::string &connection_string, bool request_company_info)
|
void NetworkQueryServer(const std::string &connection_string)
|
||||||
{
|
{
|
||||||
if (!_network_available) return;
|
if (!_network_available) return;
|
||||||
|
|
||||||
NetworkInitialize();
|
NetworkInitialize();
|
||||||
|
|
||||||
new TCPQueryConnecter(connection_string, request_company_info);
|
new TCPQueryConnecter(connection_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Non blocking connection to query servers for their game and company info. */
|
||||||
|
class TCPLobbyQueryConnecter : TCPConnecter {
|
||||||
|
private:
|
||||||
|
std::string connection_string;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TCPLobbyQueryConnecter(const std::string &connection_string) : TCPConnecter(connection_string, NETWORK_DEFAULT_PORT), connection_string(connection_string) {}
|
||||||
|
|
||||||
|
void OnFailure() override
|
||||||
|
{
|
||||||
|
DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY);
|
||||||
|
|
||||||
|
ShowErrorMessage(STR_NETWORK_ERROR_NOCONNECTION, INVALID_STRING_ID, WL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnConnect(SOCKET s) override
|
||||||
|
{
|
||||||
|
_networking = true;
|
||||||
|
new ClientNetworkGameSocketHandler(s, this->connection_string);
|
||||||
|
MyClient::SendInformationQuery(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query a server to fetch his game-info for the lobby.
|
||||||
|
* @param connection_string the address to query.
|
||||||
|
*/
|
||||||
|
void NetworkQueryLobbyServer(const std::string &connection_string)
|
||||||
|
{
|
||||||
|
if (!_network_available) return;
|
||||||
|
|
||||||
|
NetworkInitialize();
|
||||||
|
|
||||||
|
new TCPLobbyQueryConnecter(connection_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -670,7 +704,7 @@ NetworkGameList *NetworkAddServer(const std::string &connection_string, bool man
|
||||||
NetworkRebuildHostList();
|
NetworkRebuildHostList();
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
|
|
||||||
NetworkTCPQueryServer(connection_string);
|
NetworkQueryServer(connection_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manually) item->manually = true;
|
if (manually) item->manually = true;
|
||||||
|
|
|
@ -752,7 +752,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NG_REFRESH: // Refresh
|
case WID_NG_REFRESH: // Refresh
|
||||||
if (this->server != nullptr) NetworkTCPQueryServer(this->server->connection_string);
|
if (this->server != nullptr) NetworkQueryServer(this->server->connection_string);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NG_NEWGRF: // NewGRF Settings
|
case WID_NG_NEWGRF: // NewGRF Settings
|
||||||
|
@ -1487,7 +1487,7 @@ struct NetworkLobbyWindow : public Window {
|
||||||
/* Clear the information so removed companies don't remain */
|
/* Clear the information so removed companies don't remain */
|
||||||
for (auto &company : this->company_info) company = {};
|
for (auto &company : this->company_info) company = {};
|
||||||
|
|
||||||
NetworkTCPQueryServer(this->server->connection_string, true);
|
NetworkQueryLobbyServer(this->server->connection_string);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1557,7 +1557,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
|
||||||
|
|
||||||
strecpy(_settings_client.network.last_joined, ngl->connection_string.c_str(), lastof(_settings_client.network.last_joined));
|
strecpy(_settings_client.network.last_joined, ngl->connection_string.c_str(), lastof(_settings_client.network.last_joined));
|
||||||
|
|
||||||
NetworkTCPQueryServer(ngl->connection_string, true);
|
NetworkQueryLobbyServer(ngl->connection_string);
|
||||||
|
|
||||||
new NetworkLobbyWindow(&_network_lobby_window_desc, ngl);
|
new NetworkLobbyWindow(&_network_lobby_window_desc, ngl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,8 @@ extern uint8 _network_reconnect;
|
||||||
|
|
||||||
extern CompanyMask _network_company_passworded;
|
extern CompanyMask _network_company_passworded;
|
||||||
|
|
||||||
void NetworkTCPQueryServer(const std::string &connection_string, bool request_company_info = false);
|
void NetworkQueryServer(const std::string &connection_string);
|
||||||
|
void NetworkQueryLobbyServer(const std::string &connection_string);
|
||||||
|
|
||||||
void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
|
void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
|
||||||
struct NetworkGameList *NetworkAddServer(const std::string &connection_string, bool manually = true);
|
struct NetworkGameList *NetworkAddServer(const std::string &connection_string, bool manually = true);
|
||||||
|
|
Loading…
Reference in New Issue