* Handle the tid-bits of moving a client from one company to another. * @param client_id id of the client we want to move. * @param company_id id of the company we want to move the client to. * @return void */
| 1974 | * @return void |
| 1975 | */ |
| 1976 | void NetworkServerDoMove(ClientID client_id, CompanyID company_id) |
| 1977 | { |
| 1978 | /* Only allow non-dedicated servers and normal clients to be moved */ |
| 1979 | if (client_id == CLIENT_ID_SERVER && _network_dedicated) return; |
| 1980 | |
| 1981 | NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); |
| 1982 | assert(ci != nullptr); |
| 1983 | |
| 1984 | /* No need to waste network resources if the client is in the company already! */ |
| 1985 | if (ci->client_playas == company_id) return; |
| 1986 | |
| 1987 | ci->client_playas = company_id; |
| 1988 | |
| 1989 | if (client_id == CLIENT_ID_SERVER) { |
| 1990 | SetLocalCompany(company_id); |
| 1991 | } else { |
| 1992 | NetworkClientSocket *cs = NetworkClientSocket::GetByClientID(client_id); |
| 1993 | /* When the company isn't authorized we can't move them yet. */ |
| 1994 | if (cs->status < NetworkClientSocket::STATUS_AUTHORIZED) return; |
| 1995 | cs->SendMove(client_id, company_id); |
| 1996 | } |
| 1997 | |
| 1998 | /* Announce the client's move. */ |
| 1999 | NetworkUpdateClientInfo(client_id); |
| 2000 | |
| 2001 | if (company_id == COMPANY_SPECTATOR) { |
| 2002 | /* The client has joined spectators. */ |
| 2003 | NetworkServerSendChat(NETWORK_ACTION_COMPANY_SPECTATOR, DESTTYPE_BROADCAST, 0, "", client_id); |
| 2004 | } else { |
| 2005 | /* The client has joined another company. */ |
| 2006 | std::string company_name = GetString(STR_COMPANY_NAME, company_id); |
| 2007 | NetworkServerSendChat(NETWORK_ACTION_COMPANY_JOIN, DESTTYPE_BROADCAST, 0, company_name, client_id); |
| 2008 | } |
| 2009 | |
| 2010 | InvalidateWindowData(WC_CLIENT_LIST, 0); |
| 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * Send an rcon reply to the client. |
no test coverage detected