summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt2
-rw-r--r--src/network/network_coordinator.cpp18
-rw-r--r--src/network/network_coordinator.h2
-rw-r--r--src/network/network_gui.cpp23
-rw-r--r--src/network/network_gui.h2
5 files changed, 31 insertions, 16 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index ce87fa2b3..1c6eca55c 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -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
diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp
index 91ba3ee8b..8f9c73e75 100644
--- a/src/network/network_coordinator.cpp
+++ b/src/network/network_coordinator.cpp
@@ -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;
@@ -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:
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
diff --git a/src/network/network_coordinator.h b/src/network/network_coordinator.h
index 42e16d91d..3977c4e63 100644
--- a/src/network/network_coordinator.h
+++ b/src/network/network_coordinator.h
@@ -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.
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 502b9d725..df2314cd7 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -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);
@@ -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;
}
}
@@ -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);
}
diff --git a/src/network/network_gui.h b/src/network/network_gui.h
index c3194edaf..f1841cbf4 100644
--- a/src/network/network_gui.h
+++ b/src/network/network_gui.h
@@ -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 */
@@ -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 */