Fix: Treat closing network relay window as a choice of "No".

Issue ConnectFailure when closing the window if the relay request is
considered unhandled.
This commit is contained in:
Peter Nelson 2023-10-13 12:59:30 +01:00 committed by Peter Nelson
parent f379b31e28
commit bdcf6b6acd
3 changed files with 15 additions and 5 deletions

View File

@ -648,7 +648,7 @@ void ClientNetworkCoordinatorSocketHandler::CloseStunHandler(const std::string &
*/
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;

View File

@ -2413,6 +2413,12 @@ struct NetworkAskRelayWindow : public Window {
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 Window {
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_desc(
*/
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);

View File

@ -39,5 +39,9 @@ struct NetworkCompanyInfo : NetworkCompanyStats {
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 */