Changeset - r25423:cff94a4ccd78
[Not reviewed]
master
0 3 0
Patric Stout - 3 years ago 2021-05-09 16:48:21
truebrain@openttd.org
Fix: lobby window doesn't close if no connection could be established (#9223)
3 files changed with 48 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -619,35 +619,69 @@ static void NetworkInitialize(bool close
 
	_network_reconnect = 0;
 
}
 

	
 
/** Non blocking connection create to query servers */
 
/** Non blocking connection to query servers for their game info. */
 
class TCPQueryConnecter : TCPConnecter {
 
private:
 
	bool request_company_info;
 
	std::string connection_string;
 

	
 
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
 
	{
 
		_networking = true;
 
		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 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;
 

	
 
	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 
 
		NetworkRebuildHostList();
 
		UpdateNetworkGameWindow();
 

	
 
		NetworkTCPQueryServer(connection_string);
 
		NetworkQueryServer(connection_string);
 
	}
 

	
 
	if (manually) item->manually = true;
src/network/network_gui.cpp
Show inline comments
 
@@ -752,7 +752,7 @@ public:
 
				break;
 

	
 
			case WID_NG_REFRESH: // Refresh
 
				if (this->server != nullptr) NetworkTCPQueryServer(this->server->connection_string);
 
				if (this->server != nullptr) NetworkQueryServer(this->server->connection_string);
 
				break;
 

	
 
			case WID_NG_NEWGRF: // NewGRF Settings
 
@@ -1487,7 +1487,7 @@ struct NetworkLobbyWindow : public Windo
 
				/* Clear the information so removed companies don't remain */
 
				for (auto &company : this->company_info) company = {};
 

	
 
				NetworkTCPQueryServer(this->server->connection_string, true);
 
				NetworkQueryLobbyServer(this->server->connection_string);
 
				break;
 
		}
 
	}
 
@@ -1557,7 +1557,7 @@ static void ShowNetworkLobbyWindow(Netwo
 

	
 
	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);
 
}
src/network/network_internal.h
Show inline comments
 
@@ -87,7 +87,8 @@ extern uint8 _network_reconnect;
 

	
 
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);
 
struct NetworkGameList *NetworkAddServer(const std::string &connection_string, bool manually = true);
0 comments (0 inline, 0 general)