Skip to content

Commit

Permalink
Fix OpenTTD#9492: show for what server a relay session is being creat…
Browse files Browse the repository at this point in the history
…ed (OpenTTD#9494)

Currently it says "the server" which is a bit ambigious. Be more
specific.
  • Loading branch information
TrueBrain committed Aug 18, 2021
1 parent 996ae28 commit c4b700f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ STR_NETWORK_CLIENT_LIST_ASK_COMPANY_RESET :{YELLOW}Are you
STR_NETWORK_CLIENT_LIST_ASK_COMPANY_UNLOCK :{YELLOW}Are you sure you want to reset the password of company '{COMPANY}'?

STR_NETWORK_ASK_RELAY_CAPTION :{WHITE}Use relay?
STR_NETWORK_ASK_RELAY_TEXT :{YELLOW}Failed to establish a connection between you and the server.{}Would you like to relay this session via '{RAW_STRING}'?
STR_NETWORK_ASK_RELAY_TEXT :{YELLOW}Failed to establish a connection between you and server '{RAW_STRING}'.{}Would you like to relay this session via '{RAW_STRING}'?
STR_NETWORK_ASK_RELAY_NO :{BLACK}No
STR_NETWORK_ASK_RELAY_YES_ONCE :{BLACK}Yes, this once
STR_NETWORK_ASK_RELAY_YES_ALWAYS :{BLACK}Yes, don't ask again
Expand Down
18 changes: 13 additions & 5 deletions src/network/network_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet *p)
}

/* Now store it based on the token. */
this->connecter[token] = connecter_pre_it->second;
this->connecter[token] = {invite_code, connecter_pre_it->second};
this->connecter_pre.erase(connecter_pre_it);

return true;
Expand Down Expand Up @@ -378,16 +378,24 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet *p)
this->game_connecter = nullptr;
}

Debug(misc, 0, "{}", ticket);
this->turn_handlers[token] = ClientNetworkTurnSocketHandler::Turn(token, tracking_number, ticket, connection_string);

if (!_network_server) {
auto connecter_it = this->connecter.find(token);
if (connecter_it == this->connecter.end()) {
/* Make sure we are still interested in connecting to this server. */
this->ConnectFailure(token, 0);
return true;
}

switch (_settings_client.network.use_relay_service) {
case URS_NEVER:
this->ConnectFailure(token, 0);
break;

case URS_ASK:
ShowNetworkAskRelay(connection_string, token);
ShowNetworkAskRelay(connecter_it->second.first, connection_string, token);
break;

case URS_ALLOW:
Expand Down Expand Up @@ -579,7 +587,7 @@ void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &to
* processes of connecting us. */
auto connecter_it = this->connecter.find(token);
if (connecter_it != this->connecter.end()) {
connecter_it->second->SetConnected(sock);
connecter_it->second.second->SetConnected(sock);
this->connecter.erase(connecter_it);
}
}
Expand Down Expand Up @@ -665,7 +673,7 @@ void ClientNetworkCoordinatorSocketHandler::CloseToken(const std::string &token)
/* Close the caller of the connection attempt. */
auto connecter_it = this->connecter.find(token);
if (connecter_it != this->connecter.end()) {
connecter_it->second->SetFailure();
connecter_it->second.second->SetFailure();
this->connecter.erase(connecter_it);
}
}
Expand All @@ -685,7 +693,7 @@ void ClientNetworkCoordinatorSocketHandler::CloseAllConnections()
for (auto &[token, it] : this->connecter) {
this->CloseStunHandler(token);
this->CloseTurnHandler(token);
it->SetFailure();
it.second->SetFailure();

/* Inform the Game Coordinator he can stop trying to connect us to the server. */
this->ConnectFailure(token, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/network/network_coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
class ClientNetworkCoordinatorSocketHandler : public NetworkCoordinatorSocketHandler {
private:
std::chrono::steady_clock::time_point next_update; ///< When to send the next update (if server and public).
std::map<std::string, TCPServerConnecter *> connecter; ///< Based on tokens, the current connecters that are pending.
std::map<std::string, std::pair<std::string, TCPServerConnecter *>> connecter; ///< Based on tokens, the current (invite-code, connecter) that are pending.
std::map<std::string, TCPServerConnecter *> connecter_pre; ///< Based on invite codes, the current connecters that are pending.
std::map<std::string, std::map<int, std::unique_ptr<ClientNetworkStunSocketHandler>>> stun_handlers; ///< All pending STUN handlers, stored by token:family.
std::map<std::string, std::unique_ptr<ClientNetworkTurnSocketHandler>> turn_handlers; ///< Pending TURN handler (if any), stored by token.
Expand Down
23 changes: 15 additions & 8 deletions src/network/network_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,13 +2361,18 @@ void ShowNetworkCompanyPasswordWindow(Window *parent)
}

/**
* Window used for asking the user if he is okay using a TURN server.
* Window used for asking the user if he is okay using a relay server.
*/
struct NetworkAskRelayWindow : public Window {
std::string connection_string; ///< The TURN server we want to connect to.
std::string token; ///< The token for this connection.
std::string server_connection_string; ///< The game server we want to connect to.
std::string relay_connection_string; ///< The relay server we want to connect to.
std::string token; ///< The token for this connection.

NetworkAskRelayWindow(WindowDesc *desc, Window *parent, const std::string &connection_string, const std::string &token) : Window(desc), connection_string(connection_string), token(token)
NetworkAskRelayWindow(WindowDesc *desc, Window *parent, const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token) :
Window(desc),
server_connection_string(server_connection_string),
relay_connection_string(relay_connection_string),
token(token)
{
this->parent = parent;
this->InitNested(0);
Expand Down Expand Up @@ -2400,7 +2405,8 @@ struct NetworkAskRelayWindow : public Window {
{
switch (widget) {
case WID_NAR_TEXT:
SetDParamStr(0, this->connection_string);
SetDParamStr(0, this->server_connection_string);
SetDParamStr(1, this->relay_connection_string);
break;
}
}
Expand Down Expand Up @@ -2451,13 +2457,14 @@ static WindowDesc _network_ask_relay_desc(

/**
* Show a modal confirmation window with "no" / "yes, once" / "yes, always" buttons.
* @param connection_string The relay server we want to connect to.
* @param server_connection_string The game server we want to connect to.
* @param relay_connection_string The relay server we want to connect to.
* @param token The token for this connection.
*/
void ShowNetworkAskRelay(const std::string &connection_string, const std::string &token)
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
{
CloseWindowByClass(WC_NETWORK_ASK_RELAY);

Window *parent = FindWindowById(WC_MAIN_WINDOW, 0);
new NetworkAskRelayWindow(&_network_ask_relay_desc, parent, connection_string, token);
new NetworkAskRelayWindow(&_network_ask_relay_desc, parent, server_connection_string, relay_connection_string, token);
}
2 changes: 1 addition & 1 deletion src/network/network_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void ShowJoinStatusWindow();
void ShowNetworkGameWindow();
void ShowClientList();
void ShowNetworkCompanyPasswordWindow(Window *parent);
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token);


/** Company information stored at the client side */
Expand All @@ -37,6 +38,5 @@ struct NetworkCompanyInfo : NetworkCompanyStats {
std::string clients; ///< The clients that control this company (Name1, name2, ..)
};

void ShowNetworkAskRelay(const std::string &connection_string, const std::string &token);

#endif /* NETWORK_GUI_H */

0 comments on commit c4b700f

Please sign in to comment.