Skip to content

Commit

Permalink
Fix: crash to desktop when attempting to join a company while not joi…
Browse files Browse the repository at this point in the history
…ned (yet)
  • Loading branch information
rubidium42 committed Mar 23, 2024
1 parent 515303b commit 0f25eaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/console_cmds.cpp
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/network/network.cpp
Expand Up @@ -798,6 +798,7 @@ class TCPClientConnecter : public TCPServerConnecter {
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();
Expand Down

0 comments on commit 0f25eaa

Please sign in to comment.