MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / NetworkServerNewCompany

Function NetworkServerNewCompany

src/network/network_server.cpp:2150–2172  ·  view source on GitHub ↗

* Perform all the server specific administration of a new company. * @param c The newly created company; can't be nullptr. * @param ci The client information of the client that made the company; can be nullptr. */

Source from the content-addressed store, hash-verified

2148 * @param ci The client information of the client that made the company; can be nullptr.
2149 */
2150void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
2151{
2152 assert(c != nullptr);
2153
2154 if (!_network_server) return;
2155
2156 if (ci != nullptr) {
2157 /* ci is nullptr when replaying, or for AIs. In neither case there is a client. */
2158 ci->client_playas = c->index;
2159 NetworkUpdateClientInfo(ci->client_id);
2160
2161 /*
2162 * This function is called from a command, but is only called for the server.
2163 * The client information is managed out-of-band from the commands, so to not have a
2164 * different state/president/company name in the different clients, we need to
2165 * circumvent the normal ::Post logic and go directly to sending the command.
2166 */
2167 Command<CMD_COMPANY_ALLOW_LIST_CTRL>::SendNet(STR_NULL, c->index, CALCA_ADD, ci->public_key);
2168 Command<CMD_RENAME_PRESIDENT>::SendNet(STR_NULL, c->index, ci->client_name);
2169
2170 NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);
2171 }
2172}

Callers 2

CmdCompanyCtrlFunction · 0.85
NetworkOnGameStartFunction · 0.85

Calls 2

NetworkUpdateClientInfoFunction · 0.85
NetworkServerSendChatFunction · 0.85

Tested by

no test coverage detected