Index: src/economy.cpp
===================================================================
--- src/economy.cpp (revision 27964)
+++ src/economy.cpp (working copy)
@@ -294,7 +294,15 @@
Backup<CompanyByte> cur_company(_current_company, old_owner, FILE_LINE);
#ifdef ENABLE_NETWORK
/* In all cases, make spectators of clients connected to that company */
- if (_networking) NetworkClientsToSpectators(old_owner);
+ if (_networking) {
+ if (Company::IsValidHumanID(new_owner)) {
+ /* Move clients to the new company */
+ NetworkClientsToCompany(old_owner, new_owner);
+ } else {
+ /* Make spectators of clients connected to that company */
+ NetworkClientsToSpectators(old_owner);
+ }
+ }
#endif /* ENABLE_NETWORK */
if (old_owner == _local_company) {
/* Single player cheated to AI company.
Index: src/network/network_client.cpp
===================================================================
--- src/network/network_client.cpp (revision 27964)
+++ src/network/network_client.cpp (working copy)
@@ -1219,6 +1219,26 @@
}
/**
+ * Move the clients of a company to another company.
+ * @param cid_from The company to move the clients from.
+ * @param cid_to The company to move the clients to.
+ */
+void NetworkClientsToCompany(CompanyID cid_from, CompanyID cid_to)
+{
+ if (!_network_server) return;
+
+ Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
+
+ NetworkClientInfo *ci;
+ FOR_ALL_CLIENT_INFOS(ci) {
+ if (ci->client_playas != cid_from) continue;
+ NetworkServerDoMove(ci->client_id, cid_to);
+ }
+
+ cur_company.Restore();
+}
+
+/**
* Send the server our name.
*/
void NetworkUpdateClientName()
Index: src/network/network_func.h
===================================================================
--- src/network/network_func.h (revision 27964)
+++ src/network/network_func.h (working copy)
@@ -53,6 +53,7 @@
void NetworkUpdateClientInfo(ClientID client_id);
void NetworkClientsToSpectators(CompanyID cid);
+void NetworkClientsToCompany(CompanyID cid_from, CompanyID cid_to);
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);