Change: [Console] Show help when passing invalid company number

pull/332/head
rubidium42 3 years ago committed by rubidium42
parent 376f2509ad
commit 3bd416bfdb

@ -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);
}
/*********************************

@ -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()

@ -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);

@ -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);

Loading…
Cancel
Save