mirror of https://github.com/OpenTTD/OpenTTD
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
parent
96a2cbb58e
commit
cd20724d20
|
@ -298,6 +298,11 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
|
||||||
/* use INVALID_OWNER as new_owner to delete the company. */
|
/* use INVALID_OWNER as new_owner to delete the company. */
|
||||||
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||||
{
|
{
|
||||||
|
#ifdef ENABLE_NETWORK
|
||||||
|
/* In all cases, make spectators of clients connected to that company */
|
||||||
|
if (_networking) NetworkClientsToSpectators(old_owner);
|
||||||
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
||||||
Town *t;
|
Town *t;
|
||||||
CompanyID old = _current_company;
|
CompanyID old = _current_company;
|
||||||
|
|
||||||
|
@ -472,21 +477,6 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ChangeNetworkOwner(Owner current_owner, Owner new_owner)
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_NETWORK
|
|
||||||
if (!_networking) return;
|
|
||||||
|
|
||||||
if (current_owner == _local_company) {
|
|
||||||
SetLocalCompany(new_owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_network_server) return;
|
|
||||||
|
|
||||||
NetworkServerChangeOwner(current_owner, new_owner);
|
|
||||||
#endif /* ENABLE_NETWORK */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CompanyCheckBankrupt(Company *c)
|
static void CompanyCheckBankrupt(Company *c)
|
||||||
{
|
{
|
||||||
/* If the company has money again, it does not go bankrupt */
|
/* If the company has money again, it does not go bankrupt */
|
||||||
|
@ -548,8 +538,6 @@ static void CompanyCheckBankrupt(Company *c)
|
||||||
SetDParamStr(2, cni->company_name);
|
SetDParamStr(2, cni->company_name);
|
||||||
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_BANKRUPT, cni);
|
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_BANKRUPT, cni);
|
||||||
|
|
||||||
/* Remove the company */
|
|
||||||
ChangeNetworkOwner(c->index, COMPANY_SPECTATOR);
|
|
||||||
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
||||||
|
|
||||||
if (c->is_ai) AI::Stop(c->index);
|
if (c->is_ai) AI::Stop(c->index);
|
||||||
|
@ -1461,8 +1449,6 @@ static void DoAcquireCompany(Company *c)
|
||||||
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni);
|
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni);
|
||||||
AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company));
|
AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company));
|
||||||
|
|
||||||
/* original code does this a little bit differently */
|
|
||||||
ChangeNetworkOwner(ci, _current_company);
|
|
||||||
ChangeOwnershipOfCompanyItems(ci, _current_company);
|
ChangeOwnershipOfCompanyItems(ci, _current_company);
|
||||||
|
|
||||||
if (c->bankrupt_value == 0) {
|
if (c->bankrupt_value == 0) {
|
||||||
|
|
|
@ -1029,6 +1029,19 @@ void NetworkClientRequestMove(CompanyID company_id, const char *pass)
|
||||||
SEND_COMMAND(PACKET_CLIENT_MOVE)(company_id, pass);
|
SEND_COMMAND(PACKET_CLIENT_MOVE)(company_id, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkClientsToSpectators(CompanyID cid)
|
||||||
|
{
|
||||||
|
/* If our company is changing owner, go to spectators */
|
||||||
|
if (cid == _local_company) SetLocalCompany(COMPANY_SPECTATOR);
|
||||||
|
|
||||||
|
NetworkClientInfo *ci;
|
||||||
|
FOR_ALL_CLIENT_INFOS(ci) {
|
||||||
|
if (ci->client_playas != cid) continue;
|
||||||
|
NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR, CC_DEFAULT, false, ci->client_name);
|
||||||
|
ci->client_playas = COMPANY_SPECTATOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkUpdateClientName()
|
void NetworkUpdateClientName()
|
||||||
{
|
{
|
||||||
NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
|
NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
|
||||||
|
|
|
@ -47,6 +47,7 @@ void NetworkStartDebugLog(NetworkAddress address);
|
||||||
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
|
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
|
||||||
|
|
||||||
void NetworkUpdateClientInfo(ClientID client_id);
|
void NetworkUpdateClientInfo(ClientID client_id);
|
||||||
|
void NetworkClientsToSpectators(CompanyID cid);
|
||||||
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL);
|
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL);
|
||||||
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
||||||
void NetworkClientSendRcon(const char *password, const char *command);
|
void NetworkClientSendRcon(const char *password, const char *command);
|
||||||
|
@ -61,7 +62,6 @@ void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
|
||||||
/*** Commands ran by the server ***/
|
/*** Commands ran by the server ***/
|
||||||
void NetworkServerMonthlyLoop();
|
void NetworkServerMonthlyLoop();
|
||||||
void NetworkServerYearlyLoop();
|
void NetworkServerYearlyLoop();
|
||||||
void NetworkServerChangeOwner(Owner current_owner, Owner new_owner);
|
|
||||||
void NetworkServerSendConfigUpdate();
|
void NetworkServerSendConfigUpdate();
|
||||||
void NetworkServerShowStatusToConsole();
|
void NetworkServerShowStatusToConsole();
|
||||||
bool NetworkServerStart();
|
bool NetworkServerStart();
|
||||||
|
|
|
@ -1099,9 +1099,9 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DESTTYPE_TEAM: {
|
case DESTTYPE_TEAM: {
|
||||||
bool show_local = true; // If this is false, the message is already displayed
|
/* If this is false, the message is already displayed on the client who sent it. */
|
||||||
/* on the client who did sent it.
|
bool show_local = true;
|
||||||
* Find all clients that belong to this company */
|
/* Find all clients that belong to this company */
|
||||||
ci_to = NULL;
|
ci_to = NULL;
|
||||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||||
ci = cs->GetInfo();
|
ci = cs->GetInfo();
|
||||||
|
@ -1694,27 +1694,6 @@ void NetworkServerMonthlyLoop()
|
||||||
NetworkAutoCleanCompanies();
|
NetworkAutoCleanCompanies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkServerChangeOwner(Owner current_owner, Owner new_owner)
|
|
||||||
{
|
|
||||||
/* The server has to handle all administrative issues, for example
|
|
||||||
* updating and notifying all clients of what has happened */
|
|
||||||
NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
|
|
||||||
|
|
||||||
/* The server has just changed from owner */
|
|
||||||
if (current_owner == ci->client_playas) {
|
|
||||||
ci->client_playas = new_owner;
|
|
||||||
NetworkUpdateClientInfo(CLIENT_ID_SERVER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find all clients that were in control of this company, and mark them as new_owner */
|
|
||||||
FOR_ALL_CLIENT_INFOS(ci) {
|
|
||||||
if (current_owner == ci->client_playas) {
|
|
||||||
ci->client_playas = new_owner;
|
|
||||||
NetworkUpdateClientInfo(ci->client_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *GetClientIP(NetworkClientInfo *ci)
|
const char *GetClientIP(NetworkClientInfo *ci)
|
||||||
{
|
{
|
||||||
return ci->client_address.GetHostname();
|
return ci->client_address.GetHostname();
|
||||||
|
|
Loading…
Reference in New Issue