mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: crash to desktop when attempting to join a company while not joined (yet)
This commit is contained in:
parent
515303b8be
commit
0f25eaa271
|
@ -921,13 +921,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) {
|
||||||
|
IConsolePrint(CC_ERROR, "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) {
|
||||||
IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
|
IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
|
||||||
return true;
|
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!");
|
IConsolePrint(CC_ERROR, "You are already there!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -798,6 +798,7 @@ public:
|
||||||
Debug(net, 9, "Client::OnConnect(): connection_string={}", this->connection_string);
|
Debug(net, 9, "Client::OnConnect(): connection_string={}", this->connection_string);
|
||||||
|
|
||||||
_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();
|
||||||
|
|
Loading…
Reference in New Issue