summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-01 13:54:30 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-01 18:30:08 +0200
commit3bd416bfdba351d9d76a753a0c5b4abdd84fea39 (patch)
treecebdb57e2d8420eb2b17638f7f48e6f082ec2f46 /src
parent376f2509ad5b35910ce2cb949f7ba84d86aed739 (diff)
downloadopenttd-3bd416bfdba351d9d76a753a0c5b4abdd84fea39.tar.xz
Change: [Console] Show help when passing invalid company number
Diffstat (limited to 'src')
-rw-r--r--src/console_cmds.cpp6
-rw-r--r--src/network/network.cpp41
-rw-r--r--src/network/network_func.h2
-rw-r--r--src/network/network_internal.h2
4 files changed, 38 insertions, 13 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 401a52b1f..71f2d4b7b 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -901,8 +901,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect)
/* Don't resolve the address first, just print it directly as it comes from the config file. */
IConsolePrintF(CC_DEFAULT, "Reconnecting to %s ...", _settings_client.network.last_joined);
- NetworkClientConnectGame(_settings_client.network.last_joined, playas);
- return true;
+ return NetworkClientConnectGame(_settings_client.network.last_joined, playas);
}
DEF_CONSOLE_CMD(ConNetworkConnect)
@@ -917,8 +916,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
if (argc < 2) return false;
if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
- NetworkClientConnectGame(argv[1], COMPANY_NEW_COMPANY);
- return true;
+ return NetworkClientConnectGame(argv[1], COMPANY_NEW_COMPANY);
}
/*********************************
diff --git a/src/network/network.cpp b/src/network/network.cpp
index c31a67487..22ac5dc74 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -713,7 +713,24 @@ public:
}
};
-void NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password, const char *join_company_password)
+/**
+ * Join a client to the server at with the given connection string.
+ * The default for the passwords is \c nullptr. When the server or company needs a
+ * password and none is given, the user is asked to enter the password in the GUI.
+ * This function will return false whenever some information required to join is not
+ * correct such as the company number or the client's name, or when there is not
+ * networking avalabile at all. If the function returns false the connection with
+ * the existing server is not disconnected.
+ * It will return true when it starts the actual join process, i.e. when it
+ * actually shows the join status window.
+ *
+ * @param connection_string The IP address, port and company number to join as.
+ * @param default_company The company number to join as when none is given.
+ * @param join_server_password The password for the server.
+ * @param join_company_password The password for the company.
+ * @return Whether the join has started.
+ */
+bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password, const char *join_company_password)
{
CompanyID join_as = default_company;
NetworkAddress address = ParseGameConnectionString(&join_as, connection_string, NETWORK_DEFAULT_PORT);
@@ -721,18 +738,27 @@ void NetworkClientConnectGame(const std::string &connection_string, CompanyID de
if (join_as != COMPANY_NEW_COMPANY && join_as != COMPANY_SPECTATOR) {
join_as--;
if (join_as >= MAX_COMPANIES) {
- return;
+ return false;
}
}
- NetworkClientConnectGame(address, join_as, join_server_password, join_company_password);
+ return NetworkClientConnectGame(address, join_as, join_server_password, join_company_password);
}
-/* Used by clients, to connect to a server */
-void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password, const char *join_company_password)
+/**
+ * Join a client to the server at the given address.
+ * See the overloaded NetworkClientConnectGame for more details.
+ *
+ * @param address The network address of the server to join to.
+ * @param join_as The company number to join as.
+ * @param join_server_password The password for the server.
+ * @param join_company_password The password for the company.
+ * @return Whether the join has started.
+ */
+bool NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password, const char *join_company_password)
{
- if (!_network_available) return;
- if (!NetworkValidateClientName()) return;
+ if (!_network_available) return false;
+ if (!NetworkValidateClientName()) return false;
strecpy(_settings_client.network.last_joined, address.GetAddressAsString(false).c_str(), lastof(_settings_client.network.last_joined));
@@ -747,6 +773,7 @@ void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const
ShowJoinStatusWindow();
new TCPClientConnecter(address);
+ return true;
}
static void NetworkInitGameInfo()
diff --git a/src/network/network_func.h b/src/network/network_func.h
index cd2b291bc..252d207db 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -51,7 +51,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
void NetworkUpdateClientInfo(ClientID client_id);
void NetworkClientsToSpectators(CompanyID cid);
-void NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
+bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
void NetworkClientSendRcon(const char *password, const char *command);
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index 683c954e8..be5b74a0f 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -119,7 +119,7 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkFindName(char *new_name, const char *last);
const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed);
-void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
+bool NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
NetworkAddress ParseConnectionString(const std::string &connection_string, int default_port);
NetworkAddress ParseGameConnectionString(CompanyID *company, const std::string &connection_string, int default_port);