00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifdef ENABLE_NETWORK
00013
00014 #include "../stdafx.h"
00015 #include "../strings_func.h"
00016 #include "../date_func.h"
00017 #include "network_admin.h"
00018 #include "network_server.h"
00019 #include "network_udp.h"
00020 #include "network_base.h"
00021 #include "../console_func.h"
00022 #include "../company_base.h"
00023 #include "../command_func.h"
00024 #include "../saveload/saveload.h"
00025 #include "../saveload/saveload_filter.h"
00026 #include "../station_base.h"
00027 #include "../genworld.h"
00028 #include "../company_func.h"
00029 #include "../company_gui.h"
00030 #include "../window_func.h"
00031 #include "../roadveh.h"
00032 #include "../order_backup.h"
00033 #include "../core/pool_func.hpp"
00034 #include "../core/random_func.hpp"
00035 #include "../rev.h"
00036
00037
00038
00039
00040 DECLARE_POSTFIX_INCREMENT(ClientID)
00042 static ClientID _network_client_id = CLIENT_ID_FIRST;
00043
00045 assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
00046 assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
00047
00048 NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
00049 INSTANTIATE_POOL_METHODS(NetworkClientSocket)
00050
00052 template SocketList TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED>::sockets;
00053
00055 struct PacketWriter : SaveFilter {
00056 ServerNetworkGameSocketHandler *cs;
00057 Packet *current;
00058 size_t total_size;
00059
00064 PacketWriter(ServerNetworkGameSocketHandler *cs) : SaveFilter(NULL), cs(cs), current(NULL), total_size(0)
00065 {
00066 this->cs->savegame_mutex = ThreadMutex::New();
00067 }
00068
00070 ~PacketWriter()
00071 {
00072
00073 if (this->cs != NULL) {
00074 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
00075 this->cs->savegame = NULL;
00076 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->EndCritical();
00077
00078 delete this->cs->savegame_mutex;
00079 this->cs->savegame_mutex = NULL;
00080 }
00081
00082 delete this->current;
00083 }
00084
00086 void AppendQueue()
00087 {
00088 if (this->current == NULL) return;
00089
00090 Packet **p = &this->cs->savegame_packets;
00091 while (*p != NULL) {
00092 p = &(*p)->next;
00093 }
00094 *p = this->current;
00095
00096 this->current = NULL;
00097 }
00098
00099 void Write(byte *buf, size_t size)
00100 {
00101
00102 if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
00103
00104 if (this->current == NULL) this->current = new Packet(PACKET_SERVER_MAP_DATA);
00105
00106 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
00107
00108 byte *bufe = buf + size;
00109 while (buf != bufe) {
00110 size_t to_write = min(SEND_MTU - this->current->size, bufe - buf);
00111 memcpy(this->current->buffer + this->current->size, buf, to_write);
00112 this->current->size += (PacketSize)to_write;
00113 buf += to_write;
00114
00115 if (this->current->size == SEND_MTU) {
00116 this->AppendQueue();
00117 if (buf != bufe) this->current = new Packet(PACKET_SERVER_MAP_DATA);
00118 }
00119 }
00120
00121 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->EndCritical();
00122
00123 this->total_size += size;
00124 }
00125
00126 void Finish()
00127 {
00128
00129 if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
00130
00131 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
00132
00133
00134 this->AppendQueue();
00135
00136
00137 this->current = new Packet(PACKET_SERVER_MAP_DONE);
00138 this->AppendQueue();
00139
00140
00141 Packet *p = new Packet(PACKET_SERVER_MAP_SIZE);
00142 p->Send_uint32((uint32)this->total_size);
00143 this->cs->NetworkTCPSocketHandler::SendPacket(p);
00144
00145 if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->EndCritical();
00146 }
00147 };
00148
00149
00154 ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s)
00155 {
00156 this->status = STATUS_INACTIVE;
00157 this->client_id = _network_client_id++;
00158 this->receive_limit = _settings_client.network.bytes_per_frame_burst;
00159
00160
00161
00162
00163 assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
00164 }
00165
00169 ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
00170 {
00171 if (_redirect_console_to_client == this->client_id) _redirect_console_to_client = INVALID_CLIENT_ID;
00172 OrderBackup::ResetUser(this->client_id);
00173
00174 if (this->savegame_mutex != NULL) this->savegame_mutex->BeginCritical();
00175 if (this->savegame != NULL) this->savegame->cs = NULL;
00176 if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
00177
00178
00179
00180
00181
00182 WaitTillSaved();
00183 ProcessAsyncSaveFinish();
00184
00185 while (this->savegame_packets != NULL) {
00186 Packet *p = this->savegame_packets->next;
00187 delete this->savegame_packets;
00188 this->savegame_packets = p;
00189 }
00190
00191 delete this->savegame_mutex;
00192 }
00193
00194 Packet *ServerNetworkGameSocketHandler::ReceivePacket()
00195 {
00196
00197
00198 if (this->receive_limit <= 0) return NULL;
00199
00200
00201
00202 Packet *p = this->NetworkTCPSocketHandler::ReceivePacket();
00203 if (p != NULL) this->receive_limit -= p->size;
00204 return p;
00205 }
00206
00207 void ServerNetworkGameSocketHandler::SendPacket(Packet *packet)
00208 {
00209 if (this->savegame_mutex != NULL) this->savegame_mutex->BeginCritical();
00210 this->NetworkTCPSocketHandler::SendPacket(packet);
00211 if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
00212 }
00213
00214 NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
00215 {
00216 assert(status != NETWORK_RECV_STATUS_OKAY);
00217
00218
00219
00220
00221
00222
00223
00224 if (this->sock == INVALID_SOCKET) return status;
00225
00226 if (status != NETWORK_RECV_STATUS_CONN_LOST && !this->HasClientQuit() && this->status >= STATUS_AUTHORIZED) {
00227
00228 char client_name[NETWORK_CLIENT_NAME_LENGTH];
00229 NetworkClientSocket *new_cs;
00230
00231 this->GetClientName(client_name, sizeof(client_name));
00232
00233 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
00234
00235
00236 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00237 if (new_cs->status > STATUS_AUTHORIZED && this != new_cs) {
00238 new_cs->SendErrorQuit(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
00239 }
00240 }
00241 }
00242
00243 NetworkAdminClientError(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
00244 DEBUG(net, 1, "Closed client connection %d", this->client_id);
00245
00246
00247 if (this->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
00248 extern byte _network_clients_connected;
00249 _network_clients_connected--;
00250
00251 DeleteWindowById(WC_CLIENT_LIST_POPUP, this->client_id);
00252 SetWindowDirty(WC_CLIENT_LIST, 0);
00253
00254 this->SendPackets(true);
00255
00256 delete this->GetInfo();
00257 delete this;
00258
00259 return status;
00260 }
00261
00266 bool ServerNetworkGameSocketHandler::AllowConnection()
00267 {
00268 extern byte _network_clients_connected;
00269 bool accept = _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients;
00270
00271
00272
00273 assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
00274 assert(ServerNetworkGameSocketHandler::CanAllocateItem());
00275 return accept;
00276 }
00277
00279 void ServerNetworkGameSocketHandler::Send()
00280 {
00281 NetworkClientSocket *cs;
00282 FOR_ALL_CLIENT_SOCKETS(cs) {
00283 if (cs->writable) {
00284 if (cs->SendPackets() != SPS_CLOSED && cs->status == STATUS_MAP) {
00285
00286 cs->SendMap();
00287 }
00288 }
00289 }
00290 }
00291
00292 static void NetworkHandleCommandQueue(NetworkClientSocket *cs);
00293
00294
00295
00296
00297
00298
00299 NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientInfo *ci)
00300 {
00301 if (ci->client_id != INVALID_CLIENT_ID) {
00302 Packet *p = new Packet(PACKET_SERVER_CLIENT_INFO);
00303 p->Send_uint32(ci->client_id);
00304 p->Send_uint8 (ci->client_playas);
00305 p->Send_string(ci->client_name);
00306
00307 this->SendPacket(p);
00308 }
00309 return NETWORK_RECV_STATUS_OKAY;
00310 }
00311
00312 NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
00313 {
00314
00315 NetworkCompanyStats company_stats[MAX_COMPANIES];
00316 NetworkPopulateCompanyStats(company_stats);
00317
00318
00319 char clients[MAX_COMPANIES][NETWORK_CLIENTS_LENGTH];
00320 NetworkClientSocket *csi;
00321 memset(clients, 0, sizeof(clients));
00322
00323
00324 const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
00325 if (ci != NULL && Company::IsValidID(ci->client_playas)) {
00326 strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
00327 }
00328
00329 FOR_ALL_CLIENT_SOCKETS(csi) {
00330 char client_name[NETWORK_CLIENT_NAME_LENGTH];
00331
00332 ((ServerNetworkGameSocketHandler*)csi)->GetClientName(client_name, sizeof(client_name));
00333
00334 ci = csi->GetInfo();
00335 if (ci != NULL && Company::IsValidID(ci->client_playas)) {
00336 if (!StrEmpty(clients[ci->client_playas])) {
00337 strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas]));
00338 }
00339
00340 strecat(clients[ci->client_playas], client_name, lastof(clients[ci->client_playas]));
00341 }
00342 }
00343
00344
00345
00346 Company *company;
00347 Packet *p;
00348
00349 FOR_ALL_COMPANIES(company) {
00350 p = new Packet(PACKET_SERVER_COMPANY_INFO);
00351
00352 p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
00353 p->Send_bool (true);
00354 this->SendCompanyInformation(p, company, &company_stats[company->index]);
00355
00356 if (StrEmpty(clients[company->index])) {
00357 p->Send_string("<none>");
00358 } else {
00359 p->Send_string(clients[company->index]);
00360 }
00361
00362 this->SendPacket(p);
00363 }
00364
00365 p = new Packet(PACKET_SERVER_COMPANY_INFO);
00366
00367 p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
00368 p->Send_bool (false);
00369
00370 this->SendPacket(p);
00371 return NETWORK_RECV_STATUS_OKAY;
00372 }
00373
00374 NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error)
00375 {
00376 char str[100];
00377 Packet *p = new Packet(PACKET_SERVER_ERROR);
00378
00379 p->Send_uint8(error);
00380 this->SendPacket(p);
00381
00382 StringID strid = GetNetworkErrorMsg(error);
00383 GetString(str, strid, lastof(str));
00384
00385
00386 if (this->status > STATUS_AUTHORIZED) {
00387 NetworkClientSocket *new_cs;
00388 char client_name[NETWORK_CLIENT_NAME_LENGTH];
00389
00390 this->GetClientName(client_name, sizeof(client_name));
00391
00392 DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
00393
00394 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
00395
00396 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00397 if (new_cs->status > STATUS_AUTHORIZED && new_cs != this) {
00398
00399
00400 if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || error == NETWORK_ERROR_WRONG_REVISION) {
00401 error = NETWORK_ERROR_ILLEGAL_PACKET;
00402 }
00403 new_cs->SendErrorQuit(this->client_id, error);
00404 }
00405 }
00406
00407 NetworkAdminClientError(this->client_id, error);
00408 } else {
00409 DEBUG(net, 1, "Client %d made an error and has been disconnected. Reason: '%s'", this->client_id, str);
00410 }
00411
00412
00413 return this->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
00414 }
00415
00416 NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
00417 {
00418 Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS);
00419 const GRFConfig *c;
00420 uint grf_count = 0;
00421
00422 for (c = _grfconfig; c != NULL; c = c->next) {
00423 if (!HasBit(c->flags, GCF_STATIC)) grf_count++;
00424 }
00425
00426 p->Send_uint8 (grf_count);
00427 for (c = _grfconfig; c != NULL; c = c->next) {
00428 if (!HasBit(c->flags, GCF_STATIC)) this->SendGRFIdentifier(p, &c->ident);
00429 }
00430
00431 this->SendPacket(p);
00432 return NETWORK_RECV_STATUS_OKAY;
00433 }
00434
00435 NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
00436 {
00437
00438 if (this->status >= STATUS_AUTH_GAME) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
00439
00440 this->status = STATUS_AUTH_GAME;
00441
00442 Packet *p = new Packet(PACKET_SERVER_NEED_GAME_PASSWORD);
00443 this->SendPacket(p);
00444 return NETWORK_RECV_STATUS_OKAY;
00445 }
00446
00447 NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
00448 {
00449
00450 if (this->status >= STATUS_AUTH_COMPANY) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
00451
00452 this->status = STATUS_AUTH_COMPANY;
00453
00454 Packet *p = new Packet(PACKET_SERVER_NEED_COMPANY_PASSWORD);
00455 p->Send_uint32(_settings_game.game_creation.generation_seed);
00456 p->Send_string(_settings_client.network.network_id);
00457 this->SendPacket(p);
00458 return NETWORK_RECV_STATUS_OKAY;
00459 }
00460
00461 NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome()
00462 {
00463 Packet *p;
00464 NetworkClientSocket *new_cs;
00465
00466
00467 if (this->status >= STATUS_AUTHORIZED) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
00468
00469 this->status = STATUS_AUTHORIZED;
00470 _network_game_info.clients_on++;
00471
00472 p = new Packet(PACKET_SERVER_WELCOME);
00473 p->Send_uint32(this->client_id);
00474 p->Send_uint32(_settings_game.game_creation.generation_seed);
00475 p->Send_string(_settings_client.network.network_id);
00476 this->SendPacket(p);
00477
00478
00479 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00480 if (new_cs != this && new_cs->status > STATUS_AUTHORIZED) {
00481 this->SendClientInfo(new_cs->GetInfo());
00482 }
00483 }
00484
00485 return this->SendClientInfo(NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
00486 }
00487
00488 NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait()
00489 {
00490 int waiting = 0;
00491 NetworkClientSocket *new_cs;
00492 Packet *p;
00493
00494
00495 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00496 if (new_cs->status != STATUS_MAP_WAIT) continue;
00497 if (new_cs->GetInfo()->join_date < this->GetInfo()->join_date || (new_cs->GetInfo()->join_date == this->GetInfo()->join_date && new_cs->client_id < this->client_id)) waiting++;
00498 }
00499
00500 p = new Packet(PACKET_SERVER_WAIT);
00501 p->Send_uint8(waiting);
00502 this->SendPacket(p);
00503 return NETWORK_RECV_STATUS_OKAY;
00504 }
00505
00506
00507 NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
00508 {
00509 static uint sent_packets;
00510
00511 if (this->status < STATUS_AUTHORIZED) {
00512
00513 return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
00514 }
00515
00516 if (this->status == STATUS_AUTHORIZED) {
00517 this->savegame = new PacketWriter(this);
00518
00519
00520 Packet *p = new Packet(PACKET_SERVER_MAP_BEGIN);
00521 p->Send_uint32(_frame_counter);
00522 this->SendPacket(p);
00523
00524 NetworkSyncCommandQueue(this);
00525 this->status = STATUS_MAP;
00526
00527 this->last_frame = _frame_counter;
00528 this->last_frame_server = _frame_counter;
00529
00530 sent_packets = 4;
00531
00532
00533 if (SaveWithFilter(this->savegame, true) != SL_OK) usererror("network savedump failed");
00534 }
00535
00536 if (this->status == STATUS_MAP) {
00537 if (this->savegame_mutex != NULL) this->savegame_mutex->BeginCritical();
00538
00539 bool last_packet = false;
00540
00541 for (uint i = 0; i < sent_packets && this->savegame_packets != NULL; i++) {
00542 Packet *p = this->savegame_packets;
00543 last_packet = p->buffer[2] == PACKET_SERVER_MAP_DONE;
00544
00545
00546 this->savegame_packets = p->next;
00547 p->next = NULL;
00548 this->NetworkTCPSocketHandler::SendPacket(p);
00549
00550 if (last_packet) {
00551
00552 break;
00553 }
00554 }
00555
00556 if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
00557
00558 if (last_packet) {
00559
00560 WaitTillSaved();
00561
00562
00563
00564 this->status = STATUS_DONE_MAP;
00565
00566
00567 NetworkClientSocket *new_cs;
00568 NetworkClientSocket *best = NULL;
00569 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00570 if (new_cs->status == STATUS_MAP_WAIT) {
00571 if (best == NULL || best->GetInfo()->join_date > new_cs->GetInfo()->join_date || (best->GetInfo()->join_date == new_cs->GetInfo()->join_date && best->client_id > new_cs->client_id)) {
00572 best = new_cs;
00573 }
00574 }
00575 }
00576
00577
00578 if (best != NULL) {
00579
00580 best->status = STATUS_AUTHORIZED;
00581 best->SendMap();
00582
00583
00584 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00585 if (new_cs->status == STATUS_MAP_WAIT) new_cs->SendWait();
00586 }
00587 }
00588 }
00589
00590 switch (this->SendPackets()) {
00591 case SPS_CLOSED:
00592 return NETWORK_RECV_STATUS_CONN_LOST;
00593
00594 case SPS_ALL_SENT:
00595
00596 if (this->savegame_packets != NULL) sent_packets *= 2;
00597 break;
00598
00599 case SPS_PARTLY_SENT:
00600
00601 break;
00602
00603 case SPS_NONE_SENT:
00604
00605 if (sent_packets > 1) sent_packets /= 2;
00606 break;
00607 }
00608 }
00609 return NETWORK_RECV_STATUS_OKAY;
00610 }
00611
00612 NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin(ClientID client_id)
00613 {
00614 Packet *p = new Packet(PACKET_SERVER_JOIN);
00615
00616 p->Send_uint32(client_id);
00617
00618 this->SendPacket(p);
00619 return NETWORK_RECV_STATUS_OKAY;
00620 }
00621
00622
00623 NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame()
00624 {
00625 Packet *p = new Packet(PACKET_SERVER_FRAME);
00626 p->Send_uint32(_frame_counter);
00627 p->Send_uint32(_frame_counter_max);
00628 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
00629 p->Send_uint32(_sync_seed_1);
00630 #ifdef NETWORK_SEND_DOUBLE_SEED
00631 p->Send_uint32(_sync_seed_2);
00632 #endif
00633 #endif
00634
00635
00636 if (this->last_token == 0) {
00637 this->last_token = InteractiveRandomRange(UINT8_MAX - 1) + 1;
00638 p->Send_uint8(this->last_token);
00639 }
00640
00641 this->SendPacket(p);
00642 return NETWORK_RECV_STATUS_OKAY;
00643 }
00644
00645 NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync()
00646 {
00647 Packet *p = new Packet(PACKET_SERVER_SYNC);
00648 p->Send_uint32(_frame_counter);
00649 p->Send_uint32(_sync_seed_1);
00650
00651 #ifdef NETWORK_SEND_DOUBLE_SEED
00652 p->Send_uint32(_sync_seed_2);
00653 #endif
00654 this->SendPacket(p);
00655 return NETWORK_RECV_STATUS_OKAY;
00656 }
00657
00658 NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacket *cp)
00659 {
00660 Packet *p = new Packet(PACKET_SERVER_COMMAND);
00661
00662 this->NetworkGameSocketHandler::SendCommand(p, cp);
00663 p->Send_uint32(cp->frame);
00664 p->Send_bool (cp->my_cmd);
00665
00666 this->SendPacket(p);
00667 return NETWORK_RECV_STATUS_OKAY;
00668 }
00669
00670 NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
00671 {
00672 Packet *p = new Packet(PACKET_SERVER_CHAT);
00673
00674 p->Send_uint8 (action);
00675 p->Send_uint32(client_id);
00676 p->Send_bool (self_send);
00677 p->Send_string(msg);
00678 p->Send_uint64(data);
00679
00680 this->SendPacket(p);
00681 return NETWORK_RECV_STATUS_OKAY;
00682 }
00683
00684 NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit(ClientID client_id, NetworkErrorCode errorno)
00685 {
00686 Packet *p = new Packet(PACKET_SERVER_ERROR_QUIT);
00687
00688 p->Send_uint32(client_id);
00689 p->Send_uint8 (errorno);
00690
00691 this->SendPacket(p);
00692 return NETWORK_RECV_STATUS_OKAY;
00693 }
00694
00695 NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit(ClientID client_id)
00696 {
00697 Packet *p = new Packet(PACKET_SERVER_QUIT);
00698
00699 p->Send_uint32(client_id);
00700
00701 this->SendPacket(p);
00702 return NETWORK_RECV_STATUS_OKAY;
00703 }
00704
00705 NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown()
00706 {
00707 Packet *p = new Packet(PACKET_SERVER_SHUTDOWN);
00708 this->SendPacket(p);
00709 return NETWORK_RECV_STATUS_OKAY;
00710 }
00711
00712 NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
00713 {
00714 Packet *p = new Packet(PACKET_SERVER_NEWGAME);
00715 this->SendPacket(p);
00716 return NETWORK_RECV_STATUS_OKAY;
00717 }
00718
00719 NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const char *command)
00720 {
00721 Packet *p = new Packet(PACKET_SERVER_RCON);
00722
00723 p->Send_uint16(colour);
00724 p->Send_string(command);
00725 this->SendPacket(p);
00726 return NETWORK_RECV_STATUS_OKAY;
00727 }
00728
00729 NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove(ClientID client_id, CompanyID company_id)
00730 {
00731 Packet *p = new Packet(PACKET_SERVER_MOVE);
00732
00733 p->Send_uint32(client_id);
00734 p->Send_uint8(company_id);
00735 this->SendPacket(p);
00736 return NETWORK_RECV_STATUS_OKAY;
00737 }
00738
00739 NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate()
00740 {
00741 Packet *p = new Packet(PACKET_SERVER_COMPANY_UPDATE);
00742
00743 p->Send_uint16(_network_company_passworded);
00744 this->SendPacket(p);
00745 return NETWORK_RECV_STATUS_OKAY;
00746 }
00747
00748 NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate()
00749 {
00750 Packet *p = new Packet(PACKET_SERVER_CONFIG_UPDATE);
00751
00752 p->Send_uint8(_settings_client.network.max_companies);
00753 p->Send_uint8(_settings_client.network.max_spectators);
00754 this->SendPacket(p);
00755 return NETWORK_RECV_STATUS_OKAY;
00756 }
00757
00758
00759
00760
00761
00762
00763 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMPANY_INFO)
00764 {
00765 return this->SendCompanyInfo();
00766 }
00767
00768 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_NEWGRFS_CHECKED)
00769 {
00770 if (this->status != STATUS_NEWGRFS_CHECK) {
00771
00772 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00773 }
00774
00775 NetworkClientInfo *ci = this->GetInfo();
00776
00777
00778 if (!StrEmpty(_settings_client.network.server_password)) {
00779 return this->SendNeedGamePassword();
00780 }
00781
00782 if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
00783 return this->SendNeedCompanyPassword();
00784 }
00785
00786 return this->SendWelcome();
00787 }
00788
00789 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_JOIN)
00790 {
00791 if (this->status != STATUS_INACTIVE) {
00792
00793 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00794 }
00795
00796 char name[NETWORK_CLIENT_NAME_LENGTH];
00797 CompanyID playas;
00798 NetworkLanguage client_lang;
00799 char client_revision[NETWORK_REVISION_LENGTH];
00800
00801 p->Recv_string(client_revision, sizeof(client_revision));
00802
00803
00804 if (!IsNetworkCompatibleVersion(client_revision)) {
00805
00806 return this->SendError(NETWORK_ERROR_WRONG_REVISION);
00807 }
00808
00809 p->Recv_string(name, sizeof(name));
00810 playas = (Owner)p->Recv_uint8();
00811 client_lang = (NetworkLanguage)p->Recv_uint8();
00812
00813 if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
00814
00815
00816 switch (playas) {
00817 case COMPANY_NEW_COMPANY:
00818 if (Company::GetNumItems() >= _settings_client.network.max_companies) {
00819 return this->SendError(NETWORK_ERROR_FULL);
00820 }
00821 break;
00822 case COMPANY_SPECTATOR:
00823 if (NetworkSpectatorCount() >= _settings_client.network.max_spectators) {
00824 return this->SendError(NETWORK_ERROR_FULL);
00825 }
00826 break;
00827 default:
00828 if (!Company::IsValidHumanID(playas)) {
00829 return this->SendError(NETWORK_ERROR_COMPANY_MISMATCH);
00830 }
00831 break;
00832 }
00833
00834
00835 if (StrEmpty(name)) strecpy(name, "Player", lastof(name));
00836
00837 if (!NetworkFindName(name)) {
00838
00839 return this->SendError(NETWORK_ERROR_NAME_IN_USE);
00840 }
00841
00842 assert(NetworkClientInfo::CanAllocateItem());
00843 NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
00844 this->SetInfo(ci);
00845 ci->join_date = _date;
00846 strecpy(ci->client_name, name, lastof(ci->client_name));
00847 ci->client_playas = playas;
00848 ci->client_lang = client_lang;
00849 DEBUG(desync, 1, "client: %08x; %02x; %02x; %04x", _date, _date_fract, (int)ci->client_playas, ci->index);
00850
00851
00852 if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
00853
00854 this->status = STATUS_NEWGRFS_CHECK;
00855
00856 if (_grfconfig == NULL) {
00857
00858 return this->NetworkPacketReceive_PACKET_CLIENT_NEWGRFS_CHECKED_command(NULL);
00859 }
00860
00861 return this->SendNewGRFCheck();
00862 }
00863
00864 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GAME_PASSWORD)
00865 {
00866 if (this->status != STATUS_AUTH_GAME) {
00867 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00868 }
00869
00870 char password[NETWORK_PASSWORD_LENGTH];
00871 p->Recv_string(password, sizeof(password));
00872
00873
00874 if (!StrEmpty(_settings_client.network.server_password) &&
00875 strcmp(password, _settings_client.network.server_password) != 0) {
00876
00877 return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
00878 }
00879
00880 const NetworkClientInfo *ci = this->GetInfo();
00881 if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
00882 return this->SendNeedCompanyPassword();
00883 }
00884
00885
00886 return this->SendWelcome();
00887 }
00888
00889 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMPANY_PASSWORD)
00890 {
00891 if (this->status != STATUS_AUTH_COMPANY) {
00892 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00893 }
00894
00895 char password[NETWORK_PASSWORD_LENGTH];
00896 p->Recv_string(password, sizeof(password));
00897
00898
00899
00900
00901 CompanyID playas = this->GetInfo()->client_playas;
00902 if (Company::IsValidID(playas) && !StrEmpty(_network_company_states[playas].password) &&
00903 strcmp(password, _network_company_states[playas].password) != 0) {
00904
00905 return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
00906 }
00907
00908 return this->SendWelcome();
00909 }
00910
00911 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GETMAP)
00912 {
00913 NetworkClientSocket *new_cs;
00914
00915
00916
00917
00918
00919
00920
00921
00922 if (HasBit(_openttd_newgrf_version, 19)) {
00923 if (_openttd_newgrf_version != p->Recv_uint32()) {
00924
00925
00926 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00927 }
00928 } else if (p->size != 3) {
00929
00930
00931 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00932 }
00933
00934
00935
00936 if (this->status < STATUS_AUTHORIZED || this->HasClientQuit()) {
00937 return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
00938 }
00939
00940
00941 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00942 if (new_cs->status == STATUS_MAP) {
00943
00944 this->status = STATUS_MAP_WAIT;
00945 return this->SendWait();
00946 }
00947 }
00948
00949
00950 return this->SendMap();
00951 }
00952
00953 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MAP_OK)
00954 {
00955
00956 if (this->status == STATUS_DONE_MAP && !this->HasClientQuit()) {
00957 char client_name[NETWORK_CLIENT_NAME_LENGTH];
00958 NetworkClientSocket *new_cs;
00959
00960 this->GetClientName(client_name, sizeof(client_name));
00961
00962 NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, NULL, this->client_id);
00963
00964
00965
00966 this->status = STATUS_PRE_ACTIVE;
00967 NetworkHandleCommandQueue(this);
00968 this->SendFrame();
00969 this->SendSync();
00970
00971
00972
00973 this->last_frame = _frame_counter;
00974 this->last_frame_server = _frame_counter;
00975
00976 FOR_ALL_CLIENT_SOCKETS(new_cs) {
00977 if (new_cs->status > STATUS_AUTHORIZED) {
00978 new_cs->SendClientInfo(this->GetInfo());
00979 new_cs->SendJoin(this->client_id);
00980 }
00981 }
00982
00983 NetworkAdminClientInfo(this, true);
00984
00985
00986 this->SendConfigUpdate();
00987
00988
00989 return this->SendCompanyUpdate();
00990 }
00991
00992
00993 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
00994 }
00995
01000 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMMAND)
01001 {
01002
01003
01004 if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
01005 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01006 }
01007
01008 if (this->incoming_queue.Count() >= _settings_client.network.max_commands_in_queue) {
01009 return this->SendError(NETWORK_ERROR_TOO_MANY_COMMANDS);
01010 }
01011
01012 CommandPacket cp;
01013 const char *err = this->ReceiveCommand(p, &cp);
01014
01015 if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
01016
01017 NetworkClientInfo *ci = this->GetInfo();
01018
01019 if (err != NULL) {
01020 IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, this->GetClientIP());
01021 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01022 }
01023
01024
01025 if ((GetCommandFlags(cp.cmd) & CMD_SERVER) && ci->client_id != CLIENT_ID_SERVER) {
01026 IConsolePrintF(CC_ERROR, "WARNING: server only command from: client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
01027 return this->SendError(NETWORK_ERROR_KICKED);
01028 }
01029
01030 if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
01031 IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
01032 return this->SendError(NETWORK_ERROR_KICKED);
01033 }
01034
01040 if (!(cp.cmd == CMD_COMPANY_CTRL && cp.p1 == 0 && ci->client_playas == COMPANY_NEW_COMPANY) && ci->client_playas != cp.company) {
01041 IConsolePrintF(CC_ERROR, "WARNING: client %d (IP: %s) tried to execute a command as company %d, kicking...",
01042 ci->client_playas + 1, this->GetClientIP(), cp.company + 1);
01043 return this->SendError(NETWORK_ERROR_COMPANY_MISMATCH);
01044 }
01045
01046 if (cp.cmd == CMD_COMPANY_CTRL) {
01047 if (cp.p1 != 0 || cp.company != COMPANY_SPECTATOR) {
01048 return this->SendError(NETWORK_ERROR_CHEATER);
01049 }
01050
01051
01052 if (Company::GetNumItems() >= _settings_client.network.max_companies) {
01053 NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_CLIENT, ci->client_id, "cannot create new company, server full", CLIENT_ID_SERVER);
01054 return NETWORK_RECV_STATUS_OKAY;
01055 }
01056 }
01057
01058 if (GetCommandFlags(cp.cmd) & CMD_CLIENT_ID) cp.p2 = this->client_id;
01059
01060 this->incoming_queue.Append(&cp);
01061 return NETWORK_RECV_STATUS_OKAY;
01062 }
01063
01064 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ERROR)
01065 {
01066
01067
01068 NetworkClientSocket *new_cs;
01069 char str[100];
01070 char client_name[NETWORK_CLIENT_NAME_LENGTH];
01071 NetworkErrorCode errorno = (NetworkErrorCode)p->Recv_uint8();
01072
01073
01074 if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
01075 return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
01076 }
01077
01078 this->GetClientName(client_name, sizeof(client_name));
01079
01080 StringID strid = GetNetworkErrorMsg(errorno);
01081 GetString(str, strid, lastof(str));
01082
01083 DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
01084
01085 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
01086
01087 FOR_ALL_CLIENT_SOCKETS(new_cs) {
01088 if (new_cs->status > STATUS_AUTHORIZED) {
01089 new_cs->SendErrorQuit(this->client_id, errorno);
01090 }
01091 }
01092
01093 NetworkAdminClientError(this->client_id, errorno);
01094
01095 return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
01096 }
01097
01098 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_QUIT)
01099 {
01100
01101
01102 NetworkClientSocket *new_cs;
01103 char client_name[NETWORK_CLIENT_NAME_LENGTH];
01104
01105
01106 if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
01107 return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
01108 }
01109
01110 this->GetClientName(client_name, sizeof(client_name));
01111
01112 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
01113
01114 FOR_ALL_CLIENT_SOCKETS(new_cs) {
01115 if (new_cs->status > STATUS_AUTHORIZED && new_cs != this) {
01116 new_cs->SendQuit(this->client_id);
01117 }
01118 }
01119
01120 NetworkAdminClientQuit(this->client_id);
01121
01122 return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
01123 }
01124
01125 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ACK)
01126 {
01127 if (this->status < STATUS_AUTHORIZED) {
01128
01129 return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
01130 }
01131
01132 uint32 frame = p->Recv_uint32();
01133
01134
01135 if (this->status == STATUS_PRE_ACTIVE) {
01136
01137 if (frame + DAY_TICKS < _frame_counter) return NETWORK_RECV_STATUS_OKAY;
01138
01139
01140 this->status = STATUS_ACTIVE;
01141 this->last_token_frame = _frame_counter;
01142
01143
01144 IConsoleCmdExec("exec scripts/on_server_connect.scr 0");
01145 }
01146
01147
01148 uint8 token = p->Recv_uint8();
01149 if (token == this->last_token) {
01150
01151
01152
01153
01154
01155
01156
01157
01158 this->last_token_frame = _frame_counter;
01159
01160 this->last_token = 0;
01161 }
01162
01163
01164 this->last_frame = frame;
01165
01166 this->last_frame_server = _frame_counter;
01167 return NETWORK_RECV_STATUS_OKAY;
01168 }
01169
01170
01171
01172 void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin)
01173 {
01174 NetworkClientSocket *cs;
01175 const NetworkClientInfo *ci, *ci_own, *ci_to;
01176
01177 switch (desttype) {
01178 case DESTTYPE_CLIENT:
01179
01180 if ((ClientID)dest == CLIENT_ID_SERVER) {
01181 ci = NetworkClientInfo::GetByClientID(from_id);
01182
01183 if (ci != NULL) {
01184 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
01185
01186 if (_settings_client.network.server_admin_chat) {
01187 NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
01188 }
01189 }
01190 } else {
01191
01192 FOR_ALL_CLIENT_SOCKETS(cs) {
01193 if (cs->client_id == (ClientID)dest) {
01194 cs->SendChat(action, from_id, false, msg, data);
01195 break;
01196 }
01197 }
01198 }
01199
01200
01201 if (from_id != (ClientID)dest) {
01202 if (from_id == CLIENT_ID_SERVER) {
01203 ci = NetworkClientInfo::GetByClientID(from_id);
01204 ci_to = NetworkClientInfo::GetByClientID((ClientID)dest);
01205 if (ci != NULL && ci_to != NULL) {
01206 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), true, ci_to->client_name, msg, data);
01207 }
01208 } else {
01209 FOR_ALL_CLIENT_SOCKETS(cs) {
01210 if (cs->client_id == from_id) {
01211 cs->SendChat(action, (ClientID)dest, true, msg, data);
01212 break;
01213 }
01214 }
01215 }
01216 }
01217 break;
01218 case DESTTYPE_TEAM: {
01219
01220 bool show_local = true;
01221
01222 ci_to = NULL;
01223 FOR_ALL_CLIENT_SOCKETS(cs) {
01224 ci = cs->GetInfo();
01225 if (ci != NULL && ci->client_playas == (CompanyID)dest) {
01226 cs->SendChat(action, from_id, false, msg, data);
01227 if (cs->client_id == from_id) show_local = false;
01228 ci_to = ci;
01229 }
01230 }
01231
01232
01233 if (_local_company == (CompanyID)dest && _settings_client.network.server_admin_chat) {
01234 NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
01235 }
01236
01237 ci = NetworkClientInfo::GetByClientID(from_id);
01238 ci_own = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
01239 if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
01240 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
01241 if (from_id == CLIENT_ID_SERVER) show_local = false;
01242 ci_to = ci_own;
01243 }
01244
01245
01246 if (ci_to == NULL) break;
01247
01248
01249 if (ci != NULL && show_local) {
01250 if (from_id == CLIENT_ID_SERVER) {
01251 char name[NETWORK_NAME_LENGTH];
01252 StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
01253 SetDParam(0, ci_to->client_playas);
01254 GetString(name, str, lastof(name));
01255 NetworkTextMessage(action, GetDrawStringCompanyColour(ci_own->client_playas), true, name, msg, data);
01256 } else {
01257 FOR_ALL_CLIENT_SOCKETS(cs) {
01258 if (cs->client_id == from_id) {
01259 cs->SendChat(action, ci_to->client_id, true, msg, data);
01260 }
01261 }
01262 }
01263 }
01264 break;
01265 }
01266 default:
01267 DEBUG(net, 0, "[server] received unknown chat destination type %d. Doing broadcast instead", desttype);
01268
01269 case DESTTYPE_BROADCAST:
01270 FOR_ALL_CLIENT_SOCKETS(cs) {
01271 cs->SendChat(action, from_id, false, msg, data);
01272 }
01273
01274 NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
01275
01276 ci = NetworkClientInfo::GetByClientID(from_id);
01277 if (ci != NULL) {
01278 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
01279 }
01280 break;
01281 }
01282 }
01283
01284 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_CHAT)
01285 {
01286 if (this->status < STATUS_AUTHORIZED) {
01287
01288 return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
01289 }
01290
01291 NetworkAction action = (NetworkAction)p->Recv_uint8();
01292 DestType desttype = (DestType)p->Recv_uint8();
01293 int dest = p->Recv_uint32();
01294 char msg[NETWORK_CHAT_LENGTH];
01295
01296 p->Recv_string(msg, NETWORK_CHAT_LENGTH);
01297 int64 data = p->Recv_uint64();
01298
01299 NetworkClientInfo *ci = this->GetInfo();
01300 switch (action) {
01301 case NETWORK_ACTION_GIVE_MONEY:
01302 if (!Company::IsValidID(ci->client_playas)) break;
01303
01304 case NETWORK_ACTION_CHAT:
01305 case NETWORK_ACTION_CHAT_CLIENT:
01306 case NETWORK_ACTION_CHAT_COMPANY:
01307 NetworkServerSendChat(action, desttype, dest, msg, this->client_id, data);
01308 break;
01309 default:
01310 IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_id, this->GetClientIP());
01311 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01312 }
01313 return NETWORK_RECV_STATUS_OKAY;
01314 }
01315
01316 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_PASSWORD)
01317 {
01318 if (this->status != STATUS_ACTIVE) {
01319
01320 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01321 }
01322
01323 char password[NETWORK_PASSWORD_LENGTH];
01324 const NetworkClientInfo *ci;
01325
01326 p->Recv_string(password, sizeof(password));
01327 ci = this->GetInfo();
01328
01329 NetworkServerSetCompanyPassword(ci->client_playas, password);
01330 return NETWORK_RECV_STATUS_OKAY;
01331 }
01332
01333 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_NAME)
01334 {
01335 if (this->status != STATUS_ACTIVE) {
01336
01337 return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01338 }
01339
01340 char client_name[NETWORK_CLIENT_NAME_LENGTH];
01341 NetworkClientInfo *ci;
01342
01343 p->Recv_string(client_name, sizeof(client_name));
01344 ci = this->GetInfo();
01345
01346 if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
01347
01348 if (ci != NULL) {
01349
01350 if (NetworkFindName(client_name)) {
01351 NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name);
01352 strecpy(ci->client_name, client_name, lastof(ci->client_name));
01353 NetworkUpdateClientInfo(ci->client_id);
01354 }
01355 }
01356 return NETWORK_RECV_STATUS_OKAY;
01357 }
01358
01359 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_RCON)
01360 {
01361 if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01362
01363 char pass[NETWORK_PASSWORD_LENGTH];
01364 char command[NETWORK_RCONCOMMAND_LENGTH];
01365
01366 if (StrEmpty(_settings_client.network.rcon_password)) return NETWORK_RECV_STATUS_OKAY;
01367
01368 p->Recv_string(pass, sizeof(pass));
01369 p->Recv_string(command, sizeof(command));
01370
01371 if (strcmp(pass, _settings_client.network.rcon_password) != 0) {
01372 DEBUG(net, 0, "[rcon] wrong password from client-id %d", this->client_id);
01373 return NETWORK_RECV_STATUS_OKAY;
01374 }
01375
01376 DEBUG(net, 0, "[rcon] client-id %d executed: '%s'", this->client_id, command);
01377
01378 _redirect_console_to_client = this->client_id;
01379 IConsoleCmdExec(command);
01380 _redirect_console_to_client = INVALID_CLIENT_ID;
01381 return NETWORK_RECV_STATUS_OKAY;
01382 }
01383
01384 DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MOVE)
01385 {
01386 if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
01387
01388 CompanyID company_id = (Owner)p->Recv_uint8();
01389
01390
01391 if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return NETWORK_RECV_STATUS_OKAY;
01392
01393
01394 if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
01395
01396 char password[NETWORK_PASSWORD_LENGTH];
01397 p->Recv_string(password, sizeof(password));
01398
01399
01400 if (strcmp(password, _network_company_states[company_id].password) != 0) {
01401 DEBUG(net, 2, "[move] wrong password from client-id #%d for company #%d", this->client_id, company_id + 1);
01402 return NETWORK_RECV_STATUS_OKAY;
01403 }
01404 }
01405
01406
01407 NetworkServerDoMove(this->client_id, company_id);
01408 return NETWORK_RECV_STATUS_OKAY;
01409 }
01410
01418 void NetworkSocketHandler::SendCompanyInformation(Packet *p, const Company *c, const NetworkCompanyStats *stats, uint max_len)
01419 {
01420
01421 char company_name[NETWORK_COMPANY_NAME_LENGTH];
01422 SetDParam(0, c->index);
01423
01424 assert(max_len <= lengthof(company_name));
01425 GetString(company_name, STR_COMPANY_NAME, company_name + max_len - 1);
01426
01427
01428 Money income = 0;
01429 if (_cur_year - 1 == c->inaugurated_year) {
01430
01431 for (uint i = 0; i < lengthof(c->yearly_expenses[2]); i++) {
01432 income -= c->yearly_expenses[2][i];
01433 }
01434 } else {
01435 for (uint i = 0; i < lengthof(c->yearly_expenses[1]); i++) {
01436 income -= c->yearly_expenses[1][i];
01437 }
01438 }
01439
01440
01441 p->Send_uint8 (c->index);
01442 p->Send_string(company_name);
01443 p->Send_uint32(c->inaugurated_year);
01444 p->Send_uint64(c->old_economy[0].company_value);
01445 p->Send_uint64(c->money);
01446 p->Send_uint64(income);
01447 p->Send_uint16(c->old_economy[0].performance_history);
01448
01449
01450 p->Send_bool (!StrEmpty(_network_company_states[c->index].password));
01451
01452 for (uint i = 0; i < NETWORK_VEH_END; i++) {
01453 p->Send_uint16(stats->num_vehicle[i]);
01454 }
01455
01456 for (uint i = 0; i < NETWORK_VEH_END; i++) {
01457 p->Send_uint16(stats->num_station[i]);
01458 }
01459
01460 p->Send_bool(c->is_ai);
01461 }
01462
01467 void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
01468 {
01469 const Vehicle *v;
01470 const Station *s;
01471
01472 memset(stats, 0, sizeof(*stats) * MAX_COMPANIES);
01473
01474
01475 FOR_ALL_VEHICLES(v) {
01476 if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
01477 byte type = 0;
01478 switch (v->type) {
01479 case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
01480 case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break;
01481 case VEH_AIRCRAFT: type = NETWORK_VEH_PLANE; break;
01482 case VEH_SHIP: type = NETWORK_VEH_SHIP; break;
01483 default: continue;
01484 }
01485 stats[v->owner].num_vehicle[type]++;
01486 }
01487
01488
01489 FOR_ALL_STATIONS(s) {
01490 if (Company::IsValidID(s->owner)) {
01491 NetworkCompanyStats *npi = &stats[s->owner];
01492
01493 if (s->facilities & FACIL_TRAIN) npi->num_station[NETWORK_VEH_TRAIN]++;
01494 if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[NETWORK_VEH_LORRY]++;
01495 if (s->facilities & FACIL_BUS_STOP) npi->num_station[NETWORK_VEH_BUS]++;
01496 if (s->facilities & FACIL_AIRPORT) npi->num_station[NETWORK_VEH_PLANE]++;
01497 if (s->facilities & FACIL_DOCK) npi->num_station[NETWORK_VEH_SHIP]++;
01498 }
01499 }
01500 }
01501
01502
01503 void NetworkUpdateClientInfo(ClientID client_id)
01504 {
01505 NetworkClientSocket *cs;
01506 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
01507
01508 if (ci == NULL) return;
01509
01510 DEBUG(desync, 1, "client: %08x; %02x; %02x; %04x", _date, _date_fract, (int)ci->client_playas, client_id);
01511
01512 FOR_ALL_CLIENT_SOCKETS(cs) {
01513 cs->SendClientInfo(ci);
01514 }
01515
01516 NetworkAdminClientUpdate(ci);
01517 }
01518
01519
01520 static void NetworkCheckRestartMap()
01521 {
01522 if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) {
01523 DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year);
01524
01525 StartNewGameWithoutGUI(GENERATE_NEW_SEED);
01526 }
01527 }
01528
01529
01530
01531
01532
01533
01534 static void NetworkAutoCleanCompanies()
01535 {
01536 const NetworkClientInfo *ci;
01537 const Company *c;
01538 bool clients_in_company[MAX_COMPANIES];
01539 int vehicles_in_company[MAX_COMPANIES];
01540
01541 if (!_settings_client.network.autoclean_companies) return;
01542
01543 memset(clients_in_company, 0, sizeof(clients_in_company));
01544
01545
01546 FOR_ALL_CLIENT_INFOS(ci) {
01547 if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
01548 }
01549
01550 if (!_network_dedicated) {
01551 ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
01552 if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
01553 }
01554
01555 if (_settings_client.network.autoclean_novehicles != 0) {
01556 memset(vehicles_in_company, 0, sizeof(vehicles_in_company));
01557
01558 const Vehicle *v;
01559 FOR_ALL_VEHICLES(v) {
01560 if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
01561 vehicles_in_company[v->owner]++;
01562 }
01563 }
01564
01565
01566 FOR_ALL_COMPANIES(c) {
01567
01568 if (c->is_ai) continue;
01569
01570 if (!clients_in_company[c->index]) {
01571
01572 _network_company_states[c->index].months_empty++;
01573
01574
01575 if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
01576
01577 DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
01578 IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
01579 }
01580
01581 if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
01582
01583 _network_company_states[c->index].password[0] = '\0';
01584 IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
01585 _network_company_states[c->index].months_empty = 0;
01586 NetworkServerUpdateCompanyPassworded(c->index, false);
01587 }
01588
01589 if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
01590
01591 DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
01592 IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
01593 }
01594 } else {
01595
01596 _network_company_states[c->index].months_empty = 0;
01597 }
01598 }
01599 }
01600
01601
01602
01603 bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH])
01604 {
01605 bool found_name = false;
01606 uint number = 0;
01607 char original_name[NETWORK_CLIENT_NAME_LENGTH];
01608
01609
01610 ttd_strlcpy(original_name, new_name, NETWORK_CLIENT_NAME_LENGTH);
01611
01612 while (!found_name) {
01613 const NetworkClientInfo *ci;
01614
01615 found_name = true;
01616 FOR_ALL_CLIENT_INFOS(ci) {
01617 if (strcmp(ci->client_name, new_name) == 0) {
01618
01619 found_name = false;
01620 break;
01621 }
01622 }
01623
01624 ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
01625 if (ci != NULL) {
01626 if (strcmp(ci->client_name, new_name) == 0) found_name = false;
01627 }
01628
01629 if (!found_name) {
01630
01631
01632
01633 if (number++ > MAX_CLIENTS) break;
01634 snprintf(new_name, NETWORK_CLIENT_NAME_LENGTH, "%s #%d", original_name, number);
01635 }
01636 }
01637
01638 return found_name;
01639 }
01640
01647 bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
01648 {
01649 NetworkClientInfo *ci;
01650
01651 FOR_ALL_CLIENT_INFOS(ci) {
01652 if (strcmp(ci->client_name, new_name) == 0) return false;
01653 }
01654
01655 ci = NetworkClientInfo::GetByClientID(client_id);
01656 if (ci == NULL) return false;
01657
01658 NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name);
01659
01660 strecpy(ci->client_name, new_name, lastof(ci->client_name));
01661
01662 NetworkUpdateClientInfo(client_id);
01663 return true;
01664 }
01665
01672 void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed)
01673 {
01674 if (!Company::IsValidHumanID(company_id)) return;
01675
01676 if (!already_hashed) {
01677 password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id, _settings_game.game_creation.generation_seed);
01678 }
01679
01680 strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
01681 NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
01682 }
01683
01684
01685 static void NetworkHandleCommandQueue(NetworkClientSocket *cs)
01686 {
01687 CommandPacket *cp;
01688 while ((cp = cs->outgoing_queue.Pop()) != NULL) {
01689 cs->SendCommand(cp);
01690 free(cp);
01691 }
01692 }
01693
01694
01695 void NetworkServer_Tick(bool send_frame)
01696 {
01697 NetworkClientSocket *cs;
01698 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
01699 bool send_sync = false;
01700 #endif
01701
01702 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
01703 if (_frame_counter >= _last_sync_frame + _settings_client.network.sync_freq) {
01704 _last_sync_frame = _frame_counter;
01705 send_sync = true;
01706 }
01707 #endif
01708
01709
01710
01711 FOR_ALL_CLIENT_SOCKETS(cs) {
01712
01713
01714 cs->receive_limit = min(cs->receive_limit + _settings_client.network.bytes_per_frame,
01715 _settings_client.network.bytes_per_frame_burst);
01716
01717
01718 if (cs->status == NetworkClientSocket::STATUS_ACTIVE) {
01719
01720 uint lag = NetworkCalculateLag(cs) / DAY_TICKS;
01721 if (lag > 0) {
01722 if (lag > 3) {
01723
01724
01725 IConsolePrintF(CC_ERROR, cs->last_packet + 3 * DAY_TICKS * MILLISECONDS_PER_TICK > _realtime_tick ?
01726
01727 "Client #%d is dropped because the client's game state is more than 4 game-days behind" :
01728
01729 "Client #%d is dropped because the client did not respond for more than 4 game-days",
01730 cs->client_id);
01731 cs->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
01732 continue;
01733 }
01734
01735
01736
01737
01738
01739
01740 if (cs->lag_test == 0 && cs->last_packet + DAY_TICKS * MILLISECONDS_PER_TICK > _realtime_tick) {
01741 IConsolePrintF(CC_WARNING,"[%d] Client #%d is slow, try increasing [network.]frame_freq to a higher value!", _frame_counter, cs->client_id);
01742 cs->lag_test = 1;
01743 }
01744 } else {
01745 cs->lag_test = 0;
01746 }
01747 if (cs->last_frame_server - cs->last_token_frame >= 5 * DAY_TICKS) {
01748
01749 IConsolePrintF(CC_ERROR, "Client #%d is dropped because it fails to send valid acks", cs->client_id);
01750 cs->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
01751 continue;
01752 }
01753 } else if (cs->status == NetworkClientSocket::STATUS_PRE_ACTIVE) {
01754 uint lag = NetworkCalculateLag(cs);
01755 if (lag > _settings_client.network.max_join_time) {
01756 IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->client_id, _settings_client.network.max_join_time);
01757 cs->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
01758 continue;
01759 }
01760 } else if (cs->status == NetworkClientSocket::STATUS_INACTIVE) {
01761 uint lag = NetworkCalculateLag(cs);
01762 if (lag > 4 * DAY_TICKS) {
01763 IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->client_id, 4 * DAY_TICKS);
01764 cs->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
01765 continue;
01766 }
01767 }
01768
01769 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) {
01770
01771 NetworkHandleCommandQueue(cs);
01772
01773
01774 if (send_frame) cs->SendFrame();
01775
01776 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
01777
01778 if (send_sync) cs->SendSync();
01779 #endif
01780 }
01781 }
01782
01783
01784 NetworkUDPAdvertise();
01785 }
01786
01788 void NetworkServerYearlyLoop()
01789 {
01790 NetworkCheckRestartMap();
01791 NetworkAdminUpdate(ADMIN_FREQUENCY_ANUALLY);
01792 }
01793
01795 void NetworkServerMonthlyLoop()
01796 {
01797 NetworkAutoCleanCompanies();
01798 NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY);
01799 if ((_cur_month % 3) == 0) NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);
01800 }
01801
01803 void NetworkServerDailyLoop()
01804 {
01805 NetworkAdminUpdate(ADMIN_FREQUENCY_DAILY);
01806 if ((_date % 7) == 3) NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);
01807 }
01808
01813 const char *ServerNetworkGameSocketHandler::GetClientIP()
01814 {
01815 return this->client_address.GetHostname();
01816 }
01817
01818 void NetworkServerShowStatusToConsole()
01819 {
01820 static const char * const stat_str[] = {
01821 "inactive",
01822 "checking NewGRFs",
01823 "authorizing (server password)",
01824 "authorizing (company password)",
01825 "authorized",
01826 "waiting",
01827 "loading map",
01828 "map done",
01829 "ready",
01830 "active"
01831 };
01832 assert_compile(lengthof(stat_str) == NetworkClientSocket::STATUS_END);
01833
01834 NetworkClientSocket *cs;
01835 FOR_ALL_CLIENT_SOCKETS(cs) {
01836 NetworkClientInfo *ci = cs->GetInfo();
01837 if (ci == NULL) continue;
01838 uint lag = NetworkCalculateLag(cs);
01839 const char *status;
01840
01841 status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
01842 IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s",
01843 cs->client_id, ci->client_name, status, lag,
01844 ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
01845 cs->GetClientIP());
01846 }
01847 }
01848
01852 void NetworkServerSendConfigUpdate()
01853 {
01854 NetworkClientSocket *cs;
01855
01856 FOR_ALL_CLIENT_SOCKETS(cs) {
01857 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) cs->SendConfigUpdate();
01858 }
01859 }
01860
01861 void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded)
01862 {
01863 if (NetworkCompanyIsPassworded(company_id) == passworded) return;
01864
01865 SB(_network_company_passworded, company_id, 1, !!passworded);
01866 SetWindowClassesDirty(WC_COMPANY);
01867
01868 NetworkClientSocket *cs;
01869 FOR_ALL_CLIENT_SOCKETS(cs) {
01870 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) cs->SendCompanyUpdate();
01871 }
01872
01873 NetworkAdminCompanyUpdate(Company::GetIfValid(company_id));
01874 }
01875
01882 void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
01883 {
01884
01885 if (client_id == CLIENT_ID_SERVER && _network_dedicated) return;
01886
01887 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
01888
01889
01890 if (ci->client_playas == company_id) return;
01891
01892 ci->client_playas = company_id;
01893
01894 if (client_id == CLIENT_ID_SERVER) {
01895 SetLocalCompany(company_id);
01896 } else {
01897 NetworkClientSocket *cs = NetworkClientSocket::GetByClientID(client_id);
01898
01899 if (cs->status < NetworkClientSocket::STATUS_AUTHORIZED) return;
01900 cs->SendMove(client_id, company_id);
01901 }
01902
01903
01904 NetworkUpdateClientInfo(client_id);
01905
01906 NetworkAction action = (company_id == COMPANY_SPECTATOR) ? NETWORK_ACTION_COMPANY_SPECTATOR : NETWORK_ACTION_COMPANY_JOIN;
01907 NetworkServerSendChat(action, DESTTYPE_BROADCAST, 0, "", client_id, company_id + 1);
01908 }
01909
01910 void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string)
01911 {
01912 NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string);
01913 }
01914
01915 static void NetworkServerSendError(ClientID client_id, NetworkErrorCode error)
01916 {
01917 NetworkClientSocket::GetByClientID(client_id)->SendError(error);
01918 }
01919
01920 void NetworkServerKickClient(ClientID client_id)
01921 {
01922 if (client_id == CLIENT_ID_SERVER) return;
01923 NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
01924 }
01925
01926 uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
01927 {
01928 return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban);
01929 }
01930
01931 uint NetworkServerKickOrBanIP(const char *ip, bool ban)
01932 {
01933
01934 if (ban) *_network_ban_list.Append() = strdup(ip);
01935
01936 uint n = 0;
01937
01938
01939 NetworkClientSocket *cs;
01940 FOR_ALL_CLIENT_SOCKETS(cs) {
01941 if (cs->client_id == CLIENT_ID_SERVER) continue;
01942 if (cs->client_address.IsInNetmask(const_cast<char *>(ip))) {
01943 NetworkServerKickClient(cs->client_id);
01944 n++;
01945 }
01946 }
01947
01948 return n;
01949 }
01950
01951 bool NetworkCompanyHasClients(CompanyID company)
01952 {
01953 const NetworkClientInfo *ci;
01954 FOR_ALL_CLIENT_INFOS(ci) {
01955 if (ci->client_playas == company) return true;
01956 }
01957 return false;
01958 }
01959
01960
01966 void ServerNetworkGameSocketHandler::GetClientName(char *client_name, size_t size) const
01967 {
01968 const NetworkClientInfo *ci = this->GetInfo();
01969
01970 if (ci == NULL || StrEmpty(ci->client_name)) {
01971 snprintf(client_name, size, "Client #%4d", this->client_id);
01972 } else {
01973 ttd_strlcpy(client_name, ci->client_name, size);
01974 }
01975 }
01976
01980 void NetworkPrintClients()
01981 {
01982 NetworkClientInfo *ci;
01983 FOR_ALL_CLIENT_INFOS(ci) {
01984 IConsolePrintF(CC_INFO, _network_server ? "Client #%1d name: '%s' company: %1d IP: %s" : "Client #%1d name: '%s' company: %1d",
01985 ci->client_id,
01986 ci->client_name,
01987 ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
01988 _network_server ? (ci->client_id == CLIENT_ID_SERVER ? "server" : NetworkClientSocket::GetByClientID(ci->client_id)->GetClientIP()) : "");
01989 }
01990 }
01991
01992 #endif