Fix: crash to desktop when attempting to join a company while not joined (yet)

(cherry picked from commit 0f25eaa271)

# Conflicts:
#	src/console_cmds.cpp
This commit is contained in:
Rubidium
2024-03-22 19:50:27 +01:00
committed by Jonathan G Rennison
parent d21369b258
commit a12f166815
2 changed files with 8 additions and 1 deletions

View File

@@ -1043,13 +1043,19 @@ DEF_CONSOLE_CMD(ConJoinCompany)
CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1])); CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
const NetworkClientInfo *info = NetworkClientInfo::GetByClientID(_network_own_client_id);
if (info == nullptr) {
IConsoleError("You have not joined the game yet!");
return true;
}
/* Check we have a valid company id! */ /* Check we have a valid company id! */
if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) { if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES); IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true; return true;
} }
if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) { if (info->client_playas == company_id) {
IConsoleError("You are already there!"); IConsoleError("You are already there!");
return true; return true;
} }

View File

@@ -812,6 +812,7 @@ public:
void OnConnect(SOCKET s) override void OnConnect(SOCKET s) override
{ {
_networking = true; _networking = true;
_network_own_client_id = ClientID{};
new ClientNetworkGameSocketHandler(s, this->connection_string); new ClientNetworkGameSocketHandler(s, this->connection_string);
IConsoleCmdExec("exec scripts/on_client.scr 0"); IConsoleCmdExec("exec scripts/on_client.scr 0");
NetworkClient_Connected(); NetworkClient_Connected();