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

This commit is contained in:
Rubidium 2024-03-22 19:50:27 +01:00 committed by rubidium42
parent 515303b8be
commit 0f25eaa271
2 changed files with 8 additions and 1 deletions

View File

@ -921,13 +921,19 @@ DEF_CONSOLE_CMD(ConJoinCompany)
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) {
IConsolePrint(CC_ERROR, "You have not joined the game yet!");
return true;
}
/* Check we have a valid company id! */
if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
return true;
}
if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
if (info->client_playas == company_id) {
IConsolePrint(CC_ERROR, "You are already there!");
return true;
}

View File

@ -798,6 +798,7 @@ public:
Debug(net, 9, "Client::OnConnect(): connection_string={}", this->connection_string);
_networking = true;
_network_own_client_id = ClientID{};
new ClientNetworkGameSocketHandler(s, this->connection_string);
IConsoleCmdExec("exec scripts/on_client.scr 0");
NetworkClient_Connected();