Changeset - r27992:df178e3b95a9
[Not reviewed]
master
0 3 0
Peter Nelson - 14 months ago 2023-10-13 11:59:30
peter1138@openttd.org
Fix: Treat closing network relay window as a choice of "No".

Issue ConnectFailure when closing the window if the relay request is
considered unhandled.
3 files changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/network/network_coordinator.cpp
Show inline comments
 
@@ -648,7 +648,7 @@ void ClientNetworkCoordinatorSocketHandl
 
 */
 
void ClientNetworkCoordinatorSocketHandler::CloseTurnHandler(const std::string &token)
 
{
 
	CloseWindowByClass(WC_NETWORK_ASK_RELAY);
 
	CloseWindowByClass(WC_NETWORK_ASK_RELAY, NRWCD_HANDLED);
 

	
 
	auto turn_it = this->turn_handlers.find(token);
 
	if (turn_it == this->turn_handlers.end()) return;
src/network/network_gui.cpp
Show inline comments
 
@@ -2413,6 +2413,12 @@ struct NetworkAskRelayWindow : public Wi
 
		this->InitNested(0);
 
	}
 

	
 
	void Close(int data = 0) override
 
	{
 
		if (data == NRWCD_UNHANDLED) _network_coordinator_client.ConnectFailure(this->token, 0);
 
		this->Window::Close();
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
 
	{
 
		if (widget == WID_NAR_TEXT) {
 
@@ -2452,18 +2458,18 @@ struct NetworkAskRelayWindow : public Wi
 
		switch (widget) {
 
			case WID_NAR_NO:
 
				_network_coordinator_client.ConnectFailure(this->token, 0);
 
				this->Close();
 
				this->Close(NRWCD_HANDLED);
 
				break;
 

	
 
			case WID_NAR_YES_ONCE:
 
				_network_coordinator_client.StartTurnConnection(this->token);
 
				this->Close();
 
				this->Close(NRWCD_HANDLED);
 
				break;
 

	
 
			case WID_NAR_YES_ALWAYS:
 
				_settings_client.network.use_relay_service = URS_ALLOW;
 
				_network_coordinator_client.StartTurnConnection(this->token);
 
				this->Close();
 
				this->Close(NRWCD_HANDLED);
 
				break;
 
		}
 
	}
 
@@ -2499,7 +2505,7 @@ static WindowDesc _network_ask_relay_des
 
 */
 
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
 
{
 
	CloseWindowByClass(WC_NETWORK_ASK_RELAY);
 
	CloseWindowByClass(WC_NETWORK_ASK_RELAY, NRWCD_HANDLED);
 

	
 
	Window *parent = GetMainWindow();
 
	new NetworkAskRelayWindow(&_network_ask_relay_desc, parent, server_connection_string, relay_connection_string, token);
src/network/network_gui.h
Show inline comments
 
@@ -39,5 +39,9 @@ struct NetworkCompanyInfo : NetworkCompa
 
	std::string clients;      ///< The clients that control this company (Name1, name2, ..)
 
};
 

	
 
enum NetworkRelayWindowCloseData {
 
	NRWCD_UNHANDLED = 0, ///< Relay request is unhandled.
 
	NRWCD_HANDLED = 1, ///< Relay request is handled, either by user or by timeout.
 
};
 

	
 
#endif /* NETWORK_GUI_H */
0 comments (0 inline, 0 general)