@@ -295,12 +295,17 @@ int UpdateCompanyRatingAndValue(Company
return score;
}
/* use INVALID_OWNER as new_owner to delete the company. */
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;
CompanyID old = _current_company;
assert(old_owner != new_owner);
@@ -469,27 +474,12 @@ void ChangeOwnershipOfCompanyItems(Owner
_current_company = old;
MarkWholeScreenDirty();
static void ChangeNetworkOwner(Owner current_owner, Owner new_owner)
if (!_networking) return;
if (current_owner == _local_company) {
SetLocalCompany(new_owner);
if (!_network_server) return;
NetworkServerChangeOwner(current_owner, new_owner);
static void CompanyCheckBankrupt(Company *c)
/* If the company has money again, it does not go bankrupt */
if (c->money >= 0) {
c->quarters_of_bankruptcy = 0;
c->bankrupt_asked = 0;
@@ -545,14 +535,12 @@ static void CompanyCheckBankrupt(Company
/* Show bankrupt news */
SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
SetDParamStr(2, cni->company_name);
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_BANKRUPT, cni);
/* Remove the company */
ChangeNetworkOwner(c->index, COMPANY_SPECTATOR);
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
if (c->is_ai) AI::Stop(c->index);
CompanyID c_index = c->index;
delete c;
@@ -1458,14 +1446,12 @@ static void DoAcquireCompany(Company *c)
SetDParamStr(3, cni->other_company_name);
SetDParam(4, c->bankrupt_value);
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni);
AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company));
/* original code does this a little bit differently */
ChangeNetworkOwner(ci, _current_company);
ChangeOwnershipOfCompanyItems(ci, _current_company);
if (c->bankrupt_value == 0) {
owner = Company::Get(_current_company);
owner->current_loan += c->current_loan;
@@ -1026,12 +1026,25 @@ void NetworkClientSendRcon(const char *p
*/
void NetworkClientRequestMove(CompanyID company_id, const char *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()
NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
if (ci == NULL) return;
@@ -44,12 +44,13 @@ void NetworkUDPGameLoop();
void NetworkUDPCloseAll();
void ParseConnectionString(const char **company, const char **port, char *connection_string);
void NetworkStartDebugLog(NetworkAddress address);
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
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 NetworkClientRequestMove(CompanyID company, const char *pass = "");
void NetworkClientSendRcon(const char *password, const char *command);
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
bool NetworkCompanyIsPassworded(CompanyID company_id);
@@ -58,13 +59,12 @@ bool NetworkMaxSpectatorsReached();
void NetworkPrintClients();
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
/*** Commands ran by the server ***/
void NetworkServerMonthlyLoop();
void NetworkServerYearlyLoop();
void NetworkServerChangeOwner(Owner current_owner, Owner new_owner);
void NetworkServerSendConfigUpdate();
void NetworkServerShowStatusToConsole();
bool NetworkServerStart();
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
@@ -1096,15 +1096,15 @@ void NetworkServerSendChat(NetworkAction
break;
case DESTTYPE_TEAM: {
bool show_local = true; // If this is false, the message is already displayed
/* on the client who did sent it.
* Find all clients that belong to this company */
/* If this is false, the message is already displayed on the client who sent it. */
bool show_local = true;
/* Find all clients that belong to this company */
ci_to = NULL;
FOR_ALL_CLIENT_SOCKETS(cs) {
ci = cs->GetInfo();
if (ci->client_playas == (CompanyID)dest) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg, data);
if (cs->client_id == from_id) show_local = false;
@@ -1691,33 +1691,12 @@ void NetworkServerYearlyLoop()
void NetworkServerMonthlyLoop()
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 */
NetworkUpdateClientInfo(ci->client_id);
const char *GetClientIP(NetworkClientInfo *ci)
return ci->client_address.GetHostname();
void NetworkServerShowStatusToConsole()
Status change: