OpenTTD Source: src/network/network_admin.cpp Source File

OpenTTD Source 1.11.0-RC1

network_admin.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../date_func.h"
13 #include "network_admin.h"
14 #include "network_base.h"
15 #include "network_server.h"
16 #include "../command_func.h"
17 #include "../company_base.h"
18 #include "../console_func.h"
19 #include "../core/pool_func.hpp"
20 #include "../map_func.h"
21 #include "../rev.h"
22 #include "../game/game.hpp"
23
24 #include "../safeguards.h"
25
26
27 /* This file handles all the admin network commands. */
28
30 AdminIndex _redirect_console_to_admin = INVALID_ADMIN_ID;
31
33 byte _network_admins_connected = 0;
34
36 NetworkAdminSocketPool _networkadminsocket_pool("NetworkAdminSocket");
37 INSTANTIATE_POOL_METHODS(NetworkAdminSocket)
38
39
40 static const std::chrono::seconds ADMIN_AUTHORISATION_TIMEOUT(10);
41
42
44 static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
45 ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_DAILY | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY,
46 ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_AUTOMATIC,
47 ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_AUTOMATIC,
48 ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY,
49 ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY,
50 ADMIN_FREQUENCY_AUTOMATIC,
51 ADMIN_FREQUENCY_AUTOMATIC,
52 ADMIN_FREQUENCY_POLL,
53 ADMIN_FREQUENCY_AUTOMATIC,
54 ADMIN_FREQUENCY_AUTOMATIC,
55 };
57 static_assert(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
58
63 ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler(SOCKET s) : NetworkAdminSocketHandler(s)
64 {
65 _network_admins_connected++;
66 this->status = ADMIN_STATUS_INACTIVE;
67 this->connect_time = std::chrono::steady_clock::now();
68 }
69
73 ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
74 {
75 _network_admins_connected--;
76 DEBUG(net, 1, "[admin] '%s' (%s) has disconnected", this->admin_name, this->admin_version);
77 if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID;
78 }
79
84 /* static */ bool ServerNetworkAdminSocketHandler::AllowConnection()
85 {
86 bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS;
87 /* We can't go over the MAX_ADMINS limit here. However, if we accept
88 * the connection, there has to be space in the pool. */
89 static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
90 assert(!accept || ServerNetworkAdminSocketHandler::CanAllocateItem());
91 return accept;
92 }
93
95 /* static */ void ServerNetworkAdminSocketHandler::Send()
96 {
97 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::Iterate()) {
98 if (as->status == ADMIN_STATUS_INACTIVE && std::chrono::steady_clock::now() > as->connect_time + ADMIN_AUTHORISATION_TIMEOUT) {
99 DEBUG(net, 1, "[admin] Admin did not send its authorisation within %d seconds", (uint32)std::chrono::duration_cast<std::chrono::seconds>(ADMIN_AUTHORISATION_TIMEOUT).count());
100 as->CloseConnection(true);
101 continue;
102 }
103 if (as->writable) {
104 as->SendPackets();
105 }
106 }
107 }
108
114 /* static */ void ServerNetworkAdminSocketHandler::AcceptConnection(SOCKET s, const NetworkAddress &address)
115 {
116 ServerNetworkAdminSocketHandler *as = new ServerNetworkAdminSocketHandler(s);
117 as->address = address; // Save the IP of the client
118 }
119
120 /***********
121 * Sending functions for admin network
122 ************/
123
128 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode error)
129 {
130 Packet *p = new Packet(ADMIN_PACKET_SERVER_ERROR);
131
132 p->Send_uint8(error);
133 this->SendPacket(p);
134
135 char str[100];
136 StringID strid = GetNetworkErrorMsg(error);
137 GetString(str, strid, lastof(str));
138
139 DEBUG(net, 1, "[admin] the admin '%s' (%s) made an error and has been disconnected. Reason: '%s'", this->admin_name, this->admin_version, str);
140
141 return this->CloseConnection(true);
142 }
143
145 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
146 {
147 Packet *p = new Packet(ADMIN_PACKET_SERVER_PROTOCOL);
148
149 /* announce the protocol version */
150 p->Send_uint8(NETWORK_GAME_ADMIN_VERSION);
151
152 for (int i = 0; i < ADMIN_UPDATE_END; i++) {
153 p->Send_bool (true);
154 p->Send_uint16(i);
155 p->Send_uint16(_admin_update_type_frequencies[i]);
156 }
157
158 p->Send_bool(false);
159 this->SendPacket(p);
160
161 return this->SendWelcome();
162 }
163
165 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
166 {
167 Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME);
168
169 p->Send_string(_settings_client.network.server_name);
170 p->Send_string(GetNetworkRevisionString());
171 p->Send_bool (_network_dedicated);
172
173 p->Send_string(_network_game_info.map_name);
174 p->Send_uint32(_settings_game.game_creation.generation_seed);
175 p->Send_uint8 (_settings_game.game_creation.landscape);
176 p->Send_uint32(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
177 p->Send_uint16(MapSizeX());
178 p->Send_uint16(MapSizeY());
179
180 this->SendPacket(p);
181
182 return NETWORK_RECV_STATUS_OKAY;
183 }
184
186 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame()
187 {
188 Packet *p = new Packet(ADMIN_PACKET_SERVER_NEWGAME);
189 this->SendPacket(p);
190 return NETWORK_RECV_STATUS_OKAY;
191 }
192
194 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown()
195 {
196 Packet *p = new Packet(ADMIN_PACKET_SERVER_SHUTDOWN);
197 this->SendPacket(p);
198 return NETWORK_RECV_STATUS_OKAY;
199 }
200
202 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
203 {
204 Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
205
206 p->Send_uint32(_date);
207 this->SendPacket(p);
208
209 return NETWORK_RECV_STATUS_OKAY;
210 }
211
216 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID client_id)
217 {
218 Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_JOIN);
219
220 p->Send_uint32(client_id);
221 this->SendPacket(p);
222
223 return NETWORK_RECV_STATUS_OKAY;
224 }
225
231 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
232 {
233 /* Only send data when we're a proper client, not just someone trying to query the server. */
234 if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY;
235
236 Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO);
237
238 p->Send_uint32(ci->client_id);
239 p->Send_string(cs == nullptr ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
240 p->Send_string(ci->client_name);
241 p->Send_uint8 (ci->client_lang);
242 p->Send_uint32(ci->join_date);
243 p->Send_uint8 (ci->client_playas);
244
245 this->SendPacket(p);
246
247 return NETWORK_RECV_STATUS_OKAY;
248 }
249
250
255 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const NetworkClientInfo *ci)
256 {
257 Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_UPDATE);
258
259 p->Send_uint32(ci->client_id);
260 p->Send_string(ci->client_name);
261 p->Send_uint8 (ci->client_playas);
262
263 this->SendPacket(p);
264
265 return NETWORK_RECV_STATUS_OKAY;
266 }
267
272 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID client_id)
273 {
274 Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_QUIT);
275
276 p->Send_uint32(client_id);
277 this->SendPacket(p);
278
279 return NETWORK_RECV_STATUS_OKAY;
280 }
281
287 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID client_id, NetworkErrorCode error)
288 {
289 Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_ERROR);
290
291 p->Send_uint32(client_id);
292 p->Send_uint8 (error);
293 this->SendPacket(p);
294
295 return NETWORK_RECV_STATUS_OKAY;
296 }
297
302 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID company_id)
303 {
304 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_NEW);
305 p->Send_uint8(company_id);
306
307 this->SendPacket(p);
308
309 return NETWORK_RECV_STATUS_OKAY;
310 }
311
316 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company *c)
317 {
318 char company_name[NETWORK_COMPANY_NAME_LENGTH];
319 char manager_name[NETWORK_COMPANY_NAME_LENGTH];
320
321 SetDParam(0, c->index);
322 GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
323
324 SetDParam(0, c->index);
325 GetString(manager_name, STR_PRESIDENT_NAME, lastof(manager_name));
326
327 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_INFO);
328
329 p->Send_uint8 (c->index);
330 p->Send_string(company_name);
331 p->Send_string(manager_name);
332 p->Send_uint8 (c->colour);
333 p->Send_bool (NetworkCompanyIsPassworded(c->index));
334 p->Send_uint32(c->inaugurated_year);
335 p->Send_bool (c->is_ai);
336 p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
337
338 for (size_t i = 0; i < lengthof(c->share_owners); i++) {
339 p->Send_uint8(c->share_owners[i]);
340 }
341
342 this->SendPacket(p);
343
344 return NETWORK_RECV_STATUS_OKAY;
345 }
346
347
352 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Company *c)
353 {
354 char company_name[NETWORK_COMPANY_NAME_LENGTH];
355 char manager_name[NETWORK_COMPANY_NAME_LENGTH];
356
357 SetDParam(0, c->index);
358 GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
359
360 SetDParam(0, c->index);
361 GetString(manager_name, STR_PRESIDENT_NAME, lastof(manager_name));
362
363 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_UPDATE);
364
365 p->Send_uint8 (c->index);
366 p->Send_string(company_name);
367 p->Send_string(manager_name);
368 p->Send_uint8 (c->colour);
369 p->Send_bool (NetworkCompanyIsPassworded(c->index));
370 p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
371
372 for (size_t i = 0; i < lengthof(c->share_owners); i++) {
373 p->Send_uint8(c->share_owners[i]);
374 }
375
376 this->SendPacket(p);
377
378 return NETWORK_RECV_STATUS_OKAY;
379 }
380
386 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason acrr)
387 {
388 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
389
390 p->Send_uint8(company_id);
391 p->Send_uint8(acrr);
392
393 this->SendPacket(p);
394
395 return NETWORK_RECV_STATUS_OKAY;
396 }
397
399 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
400 {
401 for (const Company *company : Company::Iterate()) {
402 /* Get the income. */
403 Money income = 0;
404 for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
405 income -= company->yearly_expenses[0][i];
406 }
407
408 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
409
410 p->Send_uint8(company->index);
411
412 /* Current information. */
413 p->Send_uint64(company->money);
414 p->Send_uint64(company->current_loan);
415 p->Send_uint64(income);
416 p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>())));
417
418 /* Send stats for the last 2 quarters. */
419 for (uint i = 0; i < 2; i++) {
420 p->Send_uint64(company->old_economy[i].company_value);
421 p->Send_uint16(company->old_economy[i].performance_history);
422 p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>())));
423 }
424
425 this->SendPacket(p);
426 }
427
428
429 return NETWORK_RECV_STATUS_OKAY;
430 }
431
433 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
434 {
435 /* Fetch the latest version of the stats. */
436 NetworkCompanyStats company_stats[MAX_COMPANIES];
437 NetworkPopulateCompanyStats(company_stats);
438
439 /* Go through all the companies. */
440 for (const Company *company : Company::Iterate()) {
441 Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS);
442
443 /* Send the information. */
444 p->Send_uint8(company->index);
445
446 for (uint i = 0; i < NETWORK_VEH_END; i++) {
447 p->Send_uint16(company_stats[company->index].num_vehicle[i]);
448 }
449
450 for (uint i = 0; i < NETWORK_VEH_END; i++) {
451 p->Send_uint16(company_stats[company->index].num_station[i]);
452 }
453
454 this->SendPacket(p);
455 }
456
457 return NETWORK_RECV_STATUS_OKAY;
458 }
459
468 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
469 {
470 Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
471
472 p->Send_uint8 (action);
473 p->Send_uint8 (desttype);
474 p->Send_uint32(client_id);
475 p->Send_string(msg);
476 p->Send_uint64(data);
477
478 this->SendPacket(p);
479 return NETWORK_RECV_STATUS_OKAY;
480 }
481
486 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const char *command)
487 {
488 Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON_END);
489
490 p->Send_string(command);
491 this->SendPacket(p);
492
493 return NETWORK_RECV_STATUS_OKAY;
494 }
495
501 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16 colour, const char *result)
502 {
503 Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON);
504
505 p->Send_uint16(colour);
506 p->Send_string(result);
507 this->SendPacket(p);
508
509 return NETWORK_RECV_STATUS_OKAY;
510 }
511
512 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
513 {
514 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
515
516 char command[NETWORK_RCONCOMMAND_LENGTH];
517
518 p->Recv_string(command, sizeof(command));
519
520 DEBUG(net, 2, "[admin] Rcon command from '%s' (%s): '%s'", this->admin_name, this->admin_version, command);
521
522 _redirect_console_to_admin = this->index;
523 IConsoleCmdExec(command);
524 _redirect_console_to_admin = INVALID_ADMIN_ID;
525 return this->SendRconEnd(command);
526 }
527
528 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *p)
529 {
530 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
531
532 char json[NETWORK_GAMESCRIPT_JSON_LENGTH];
533
534 p->Recv_string(json, sizeof(json));
535
536 DEBUG(net, 2, "[admin] GameScript JSON from '%s' (%s): '%s'", this->admin_name, this->admin_version, json);
537
538 Game::NewEvent(new ScriptEventAdminPort(json));
539 return NETWORK_RECV_STATUS_OKAY;
540 }
541
542 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p)
543 {
544 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
545
546 uint32 d1 = p->Recv_uint32();
547
548 DEBUG(net, 2, "[admin] Ping from '%s' (%s): '%d'", this->admin_name, this->admin_version, d1);
549
550 return this->SendPong(d1);
551 }
552
558 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origin, const char *string)
559 {
560 /* If the length of both strings, plus the 2 '\0' terminations and 3 bytes of the packet
561 * are bigger than the MTU, just ignore the message. Better safe than sorry. It should
562 * never occur though as the longest strings are chat messages, which are still 30%
563 * smaller than SEND_MTU. */
564 if (strlen(origin) + strlen(string) + 2 + 3 >= SEND_MTU) return NETWORK_RECV_STATUS_OKAY;
565
566 Packet *p = new Packet(ADMIN_PACKET_SERVER_CONSOLE);
567
568 p->Send_string(origin);
569 p->Send_string(string);
570 this->SendPacket(p);
571
572 return NETWORK_RECV_STATUS_OKAY;
573 }
574
579 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const char *json)
580 {
581 /* At the moment we cannot transmit anything larger than MTU. So we limit
582 * the maximum amount of json data that can be sent. Account also for
583 * the trailing \0 of the string */
584 if (strlen(json) + 1 >= NETWORK_GAMESCRIPT_JSON_LENGTH) return NETWORK_RECV_STATUS_OKAY;
585
586 Packet *p = new Packet(ADMIN_PACKET_SERVER_GAMESCRIPT);
587
588 p->Send_string(json);
589 this->SendPacket(p);
590
591 return NETWORK_RECV_STATUS_OKAY;
592 }
593
595 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32 d1)
596 {
597 Packet *p = new Packet(ADMIN_PACKET_SERVER_PONG);
598
599 p->Send_uint32(d1);
600 this->SendPacket(p);
601
602 return NETWORK_RECV_STATUS_OKAY;
603 }
604
606 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
607 {
608 Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES);
609
610 for (uint i = 0; i < CMD_END; i++) {
611 const char *cmdname = GetCommandName(i);
612
613 /* Should SEND_MTU be exceeded, start a new packet
614 * (magic 5: 1 bool "more data" and one uint16 "command id", one
615 * byte for string '\0' termination and 1 bool "no more data" */
616 if (p->size + strlen(cmdname) + 5 >= SEND_MTU) {
617 p->Send_bool(false);
618 this->SendPacket(p);
619
620 p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES);
621 }
622
623 p->Send_bool(true);
624 p->Send_uint16(i);
625 p->Send_string(cmdname);
626 }
627
628 /* Marker to notify the end of the packet has been reached. */
629 p->Send_bool(false);
630 this->SendPacket(p);
631
632 return NETWORK_RECV_STATUS_OKAY;
633 }
634
640 NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID client_id, const CommandPacket *cp)
641 {
642 Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_LOGGING);
643
644 p->Send_uint32(client_id);
645 p->Send_uint8 (cp->company);
646 p->Send_uint16(cp->cmd & CMD_ID_MASK);
647 p->Send_uint32(cp->p1);
648 p->Send_uint32(cp->p2);
649 p->Send_uint32(cp->tile);
650 p->Send_string(cp->text);
651 p->Send_uint32(cp->frame);
652
653 this->SendPacket(p);
654
655 return NETWORK_RECV_STATUS_OKAY;
656 }
657
658 /***********
659 * Receiving functions
660 ************/
661
662 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
663 {
664 if (this->status != ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
665
666 char password[NETWORK_PASSWORD_LENGTH];
667 p->Recv_string(password, sizeof(password));
668
669 if (StrEmpty(_settings_client.network.admin_password) ||
670 strcmp(password, _settings_client.network.admin_password) != 0) {
671 /* Password is invalid */
672 return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
673 }
674
675 p->Recv_string(this->admin_name, sizeof(this->admin_name));
676 p->Recv_string(this->admin_version, sizeof(this->admin_version));
677
678 if (StrEmpty(this->admin_name) || StrEmpty(this->admin_version)) {
679 /* no name or version supplied */
680 return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
681 }
682
683 this->status = ADMIN_STATUS_ACTIVE;
684
685 DEBUG(net, 1, "[admin] '%s' (%s) has connected", this->admin_name, this->admin_version);
686
687 return this->SendProtocol();
688 }
689
690 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *p)
691 {
692 /* The admin is leaving nothing else to do */
693 return this->CloseConnection();
694 }
695
696 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet *p)
697 {
698 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
699
700 AdminUpdateType type = (AdminUpdateType)p->Recv_uint16();
701 AdminUpdateFrequency freq = (AdminUpdateFrequency)p->Recv_uint16();
702
703 if (type >= ADMIN_UPDATE_END || (_admin_update_type_frequencies[type] & freq) != freq) {
704 /* The server does not know of this UpdateType. */
705 DEBUG(net, 3, "[admin] Not supported update frequency %d (%d) from '%s' (%s).", type, freq, this->admin_name, this->admin_version);
706 return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
707 }
708
709 this->update_frequency[type] = freq;
710
711 return NETWORK_RECV_STATUS_OKAY;
712 }
713
714 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
715 {
716 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
717
718 AdminUpdateType type = (AdminUpdateType)p->Recv_uint8();
719 uint32 d1 = p->Recv_uint32();
720
721 switch (type) {
722 case ADMIN_UPDATE_DATE:
723 /* The admin is requesting the current date. */
724 this->SendDate();
725 break;
726
727 case ADMIN_UPDATE_CLIENT_INFO:
728 /* The admin is requesting client info. */
729 if (d1 == UINT32_MAX) {
730 this->SendClientInfo(nullptr, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
731 for (const NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
732 this->SendClientInfo(cs, cs->GetInfo());
733 }
734 } else {
735 if (d1 == CLIENT_ID_SERVER) {
736 this->SendClientInfo(nullptr, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
737 } else {
738 const NetworkClientSocket *cs = NetworkClientSocket::GetByClientID((ClientID)d1);
739 if (cs != nullptr) this->SendClientInfo(cs, cs->GetInfo());
740 }
741 }
742 break;
743
744 case ADMIN_UPDATE_COMPANY_INFO:
745 /* The admin is asking for company info. */
746 if (d1 == UINT32_MAX) {
747 for (const Company *company : Company::Iterate()) {
748 this->SendCompanyInfo(company);
749 }
750 } else {
751 const Company *company = Company::GetIfValid(d1);
752 if (company != nullptr) this->SendCompanyInfo(company);
753 }
754 break;
755
756 case ADMIN_UPDATE_COMPANY_ECONOMY:
757 /* The admin is requesting economy info. */
758 this->SendCompanyEconomy();
759 break;
760
761 case ADMIN_UPDATE_COMPANY_STATS:
762 /* the admin is requesting company stats. */
763 this->SendCompanyStats();
764 break;
765
766 case ADMIN_UPDATE_CMD_NAMES:
767 /* The admin is requesting the names of DoCommands. */
768 this->SendCmdNames();
769 break;
770
771 default:
772 /* An unsupported "poll" update type. */
773 DEBUG(net, 3, "[admin] Not supported poll %d (%d) from '%s' (%s).", type, d1, this->admin_name, this->admin_version);
774 return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
775 }
776
777 return NETWORK_RECV_STATUS_OKAY;
778 }
779
780 NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
781 {
782 if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
783
784 NetworkAction action = (NetworkAction)p->Recv_uint8();
785 DestType desttype = (DestType)p->Recv_uint8();
786 int dest = p->Recv_uint32();
787
788 char msg[NETWORK_CHAT_LENGTH];
789 p->Recv_string(msg, NETWORK_CHAT_LENGTH);
790
791 switch (action) {
792 case NETWORK_ACTION_CHAT:
793 case NETWORK_ACTION_CHAT_CLIENT:
794 case NETWORK_ACTION_CHAT_COMPANY:
795 case NETWORK_ACTION_SERVER_MESSAGE:
796 NetworkServerSendChat(action, desttype, dest, msg, _network_own_client_id, 0, true);
797 break;
798
799 default:
800 DEBUG(net, 3, "[admin] Invalid chat action %d from admin '%s' (%s).", action, this->admin_name, this->admin_version);
801 return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
802 }
803
804 return NETWORK_RECV_STATUS_OKAY;
805 }
806
807 /*
808 * Useful wrapper functions
809 */
810
816 void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client)
817 {
818 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
819 if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
820 as->SendClientInfo(cs, cs->GetInfo());
821 if (new_client) {
822 as->SendClientJoin(cs->client_id);
823 }
824 }
825 }
826 }
827
832 void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
833 {
834 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
835 if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
836 as->SendClientUpdate(ci);
837 }
838 }
839 }
840
845 void NetworkAdminClientQuit(ClientID client_id)
846 {
847 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
848 if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
849 as->SendClientQuit(client_id);
850 }
851 }
852 }
853
859 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
860 {
861 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
862 if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
863 as->SendClientError(client_id, error_code);
864 }
865 }
866 }
867
873 void NetworkAdminCompanyInfo(const Company *company, bool new_company)
874 {
875 if (company == nullptr) {
876 DEBUG(net, 1, "[admin] Empty company given for update");
877 return;
878 }
879
880 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
881 if (as->update_frequency[ADMIN_UPDATE_COMPANY_INFO] != ADMIN_FREQUENCY_AUTOMATIC) continue;
882
883 as->SendCompanyInfo(company);
884 if (new_company) {
885 as->SendCompanyNew(company->index);
886 }
887 }
888 }
889
894 void NetworkAdminCompanyUpdate(const Company *company)
895 {
896 if (company == nullptr) return;
897
898 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
899 if (as->update_frequency[ADMIN_UPDATE_COMPANY_INFO] != ADMIN_FREQUENCY_AUTOMATIC) continue;
900
901 as->SendCompanyUpdate(company);
902 }
903 }
904
910 void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
911 {
912 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
913 as->SendCompanyRemove(company_id, bcrr);
914 }
915 }
916
917
921 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data, bool from_admin)
922 {
923 if (from_admin) return;
924
925 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
926 if (as->update_frequency[ADMIN_UPDATE_CHAT] & ADMIN_FREQUENCY_AUTOMATIC) {
927 as->SendChat(action, desttype, client_id, msg, data);
928 }
929 }
930 }
931
938 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string)
939 {
940 ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code, string);
941 }
942
948 void NetworkAdminConsole(const char *origin, const char *string)
949 {
950 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
951 if (as->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) {
952 as->SendConsole(origin, string);
953 }
954 }
955 }
956
961 void NetworkAdminGameScript(const char *json)
962 {
963 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
964 if (as->update_frequency[ADMIN_UPDATE_GAMESCRIPT] & ADMIN_FREQUENCY_AUTOMATIC) {
965 as->SendGameScript(json);
966 }
967 }
968 }
969
975 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
976 {
977 ClientID client_id = owner == nullptr ? _network_own_client_id : owner->client_id;
978
979 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
980 if (as->update_frequency[ADMIN_UPDATE_CMD_LOGGING] & ADMIN_FREQUENCY_AUTOMATIC) {
981 as->SendCmdLogging(client_id, cp);
982 }
983 }
984 }
985
989 void ServerNetworkAdminSocketHandler::WelcomeAll()
990 {
991 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
992 as->SendWelcome();
993 }
994 }
995
1000 void NetworkAdminUpdate(AdminUpdateFrequency freq)
1001 {
1002 for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
1003 for (int i = 0; i < ADMIN_UPDATE_END; i++) {
1004 if (as->update_frequency[i] & freq) {
1005 /* Update the admin for the required details */
1006 switch (i) {
1007 case ADMIN_UPDATE_DATE:
1008 as->SendDate();
1009 break;
1010
1011 case ADMIN_UPDATE_COMPANY_ECONOMY:
1012 as->SendCompanyEconomy();
1013 break;
1014
1015 case ADMIN_UPDATE_COMPANY_STATS:
1016 as->SendCompanyStats();
1017 break;
1018
1019 default: NOT_REACHED();
1020 }
1021 }
1022 }
1023 }
1024 }
NetworkCompanyStats::num_station
uint16 num_station[NETWORK_VEH_END]
How many stations are there of this type?
Definition: network_type.h:59
ADMIN_PACKET_SERVER_GAMESCRIPT
@ ADMIN_PACKET_SERVER_GAMESCRIPT
The server gives the admin information from the GameScript in JSON.
Definition: tcp_admin.h:59
ServerNetworkAdminSocketHandler::SendGameScript
NetworkRecvStatus SendGameScript(const char *json)
Send GameScript JSON output.
Definition: network_admin.cpp:579
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:94
NetworkCompanyStats
Simple calculated statistics of a company.
Definition: network_type.h:57
CommandContainer::cmd
uint32 cmd
command being executed.
Definition: command_type.h:483
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:81
ADMIN_UPDATE_CMD_NAMES
@ ADMIN_UPDATE_CMD_NAMES
The admin would like a list of all DoCommand names.
Definition: tcp_admin.h:82
ADMIN_UPDATE_COMPANY_INFO
@ ADMIN_UPDATE_COMPANY_INFO
Updates about the generic information of companies.
Definition: tcp_admin.h:77
ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY
NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p) override
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16 Upda...
Definition: network_admin.cpp:696
GameCreationSettings::generation_seed
uint32 generation_seed
noise seed for world generation
Definition: settings_type.h:292
ServerNetworkAdminSocketHandler::SendConsole
NetworkRecvStatus SendConsole(const char *origin, const char *command)
Send console output of other clients.
Definition: network_admin.cpp:558
Pool::PoolItem<&_networkadminsocket_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
NetworkAdminUpdate
void NetworkAdminUpdate(AdminUpdateFrequency freq)
Send (push) updates to the admin network as they have registered for these updates.
Definition: network_admin.cpp:1000
Packet::Recv_string
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
Definition: packet.cpp:286
NetworkAdminSocketHandler::status
AdminStatus status
Status of this admin.
Definition: tcp_admin.h:114
_network_game_info
NetworkServerGameInfo _network_game_info
Information about our game.
Definition: network.cpp:57
NetworkAdminSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
Definition: tcp_admin.cpp:41
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:340
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:305
ADMIN_PACKET_SERVER_CLIENT_QUIT
@ ADMIN_PACKET_SERVER_CLIENT_QUIT
The server tells the admin that a client quit.
Definition: tcp_admin.h:46
ServerNetworkAdminSocketHandler::SendError
NetworkRecvStatus SendError(NetworkErrorCode error)
Send an error to the admin.
Definition: network_admin.cpp:128
ADMIN_UPDATE_CLIENT_INFO
@ ADMIN_UPDATE_CLIENT_INFO
Updates about the information of clients.
Definition: tcp_admin.h:76
ADMIN_PACKET_SERVER_COMPANY_INFO
@ ADMIN_PACKET_SERVER_COMPANY_INFO
The server gives the admin information about a company.
Definition: tcp_admin.h:49
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
ServerNetworkAdminSocketHandler::SendCompanyEconomy
NetworkRecvStatus SendCompanyEconomy()
Send economic information of all companies.
Definition: network_admin.cpp:399
CompanyProperties::inaugurated_year
Year inaugurated_year
Year of starting the company.
Definition: company_base.h:79
ServerNetworkAdminSocketHandler::update_frequency
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]
Admin requested update intervals.
Definition: network_admin.h:39
ADMIN_UPDATE_CONSOLE
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
Definition: tcp_admin.h:81
ADMIN_PACKET_SERVER_PONG
@ ADMIN_PACKET_SERVER_PONG
The server replies to a ping request from the admin.
Definition: tcp_admin.h:61
GetCommandName
const char * GetCommandName(uint32 cmd)
Definition: command.cpp:407
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:91
ADMIN_UPDATE_CHAT
@ ADMIN_UPDATE_CHAT
The admin would like to have chat messages.
Definition: tcp_admin.h:80
NetworkClientInfo::client_name
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Definition: network_base.h:25
CommandPacket::frame
uint32 frame
the frame in which this packet is executed
Definition: network_internal.h:154
NetworkAdminChat
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data, bool from_admin)
Send chat to the admin network (if they did opt in for the respective update).
Definition: network_admin.cpp:921
Pool::PoolItem<&_networkadminsocket_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
NetworkPopulateCompanyStats
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
Definition: network_server.cpp:1565
ServerNetworkAdminSocketHandler::WelcomeAll
static void WelcomeAll()
Send a Welcome packet to all connected admins.
Definition: network_admin.cpp:989
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Definition: config.h:50
ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN
NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p) override
Join the admin network: string Password the server is expecting for this network.
Definition: network_admin.cpp:662
ADMIN_PACKET_SERVER_NEWGAME
@ ADMIN_PACKET_SERVER_NEWGAME
The server tells the admin its going to start a new game.
Definition: tcp_admin.h:39
NetworkServerGameInfo::map_name
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
Definition: game.h:25
NetworkClientInfo::join_date
Date join_date
Gamedate the client has joined.
Definition: network_base.h:28
ADMIN_FREQUENCY_DAILY
@ ADMIN_FREQUENCY_DAILY
The admin gets information about this on a daily basis.
Definition: tcp_admin.h:91
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
CommandContainer::p2
uint32 p2
parameter p2.
Definition: command_type.h:482
ServerNetworkAdminSocketHandler::IterateActive
static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > IterateActive(size_t from=0)
Returns an iterable ensemble of all active admin sockets.
Definition: network_admin.h:95
ADMIN_PACKET_SERVER_CHAT
@ ADMIN_PACKET_SERVER_CHAT
The server received a chat message and relays it.
Definition: tcp_admin.h:54
ADMIN_PACKET_SERVER_COMPANY_NEW
@ ADMIN_PACKET_SERVER_COMPANY_NEW
The server tells the admin that a new company has started.
Definition: tcp_admin.h:48
ServerNetworkAdminSocketHandler::SendCompanyUpdate
NetworkRecvStatus SendCompanyUpdate(const Company *c)
Send an update about a company.
Definition: network_admin.cpp:352
ADMIN_PACKET_SERVER_PROTOCOL
@ ADMIN_PACKET_SERVER_PROTOCOL
The server tells the admin its protocol version.
Definition: tcp_admin.h:37
ADMIN_UPDATE_CMD_LOGGING
@ ADMIN_UPDATE_CMD_LOGGING
The admin would like to have DoCommand information.
Definition: tcp_admin.h:83
CommandContainer::text
char text[32 *MAX_CHAR_LENGTH]
possible text sent for name changes etc, in bytes including '\0'.
Definition: command_type.h:485
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
ADMIN_FREQUENCY_MONTHLY
@ ADMIN_FREQUENCY_MONTHLY
The admin gets information about this on a monthly basis.
Definition: tcp_admin.h:93
GetNetworkErrorMsg
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Definition: network.cpp:299
ADMIN_PACKET_SERVER_COMPANY_STATS
@ ADMIN_PACKET_SERVER_COMPANY_STATS
The server gives the admin some statistics about a company.
Definition: tcp_admin.h:53
NetworkAdminGameScript
void NetworkAdminGameScript(const char *json)
Send GameScript JSON to the admin network (if they did opt in for the respective update).
Definition: network_admin.cpp:961
NetworkSettings::admin_password
char admin_password[NETWORK_PASSWORD_LENGTH]
password for the admin network
Definition: settings_type.h:268
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NETWORK_GAME_ADMIN_VERSION
static const byte NETWORK_GAME_ADMIN_VERSION
What version of the admin network do we use?
Definition: config.h:35
Packet::Send_uint8
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Definition: packet.cpp:96
ServerNetworkAdminSocketHandler::SendCompanyInfo
NetworkRecvStatus SendCompanyInfo(const Company *c)
Send the admin some information about a company.
Definition: network_admin.cpp:316
ServerNetworkAdminSocketHandler::address
NetworkAddress address
Address of the admin.
Definition: network_admin.h:41
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
INVALID_ADMIN_ID
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
Definition: network_type.h:54
NetworkAdminClientQuit
void NetworkAdminClientQuit(ClientID client_id)
Notify the admin network that a client quit (if they have opt in for the respective update).
Definition: network_admin.cpp:845
NetworkAdminConsole
void NetworkAdminConsole(const char *origin, const char *string)
Send console to the admin network (if they did opt in for the respective update).
Definition: network_admin.cpp:948
_redirect_console_to_admin
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
Definition: network_admin.cpp:30
_networkadminsocket_pool
NetworkAdminSocketPool _networkadminsocket_pool("NetworkAdminSocket")
The pool with sockets/clients.
ServerNetworkAdminSocketHandler::Send
static void Send()
Send the packets for the server sockets.
Definition: network_admin.cpp:95
network_base.h
NetworkAdminClientInfo
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client)
Notify the admin network of a new client (if they did opt in for the respective update).
Definition: network_admin.cpp:816
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:560
Packet::Send_uint32
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
Definition: packet.cpp:117
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:119
ADMIN_FREQUENCY_QUARTERLY
@ ADMIN_FREQUENCY_QUARTERLY
The admin gets information about this on a quarterly basis.
Definition: tcp_admin.h:94
CommandPacket::company
CompanyID company
company that is executing the command
Definition: network_internal.h:153
NetworkClientInfo::client_lang
byte client_lang
The language of the client.
Definition: network_base.h:26
ADMIN_STATUS_INACTIVE
@ ADMIN_STATUS_INACTIVE
The admin is not connected nor active.
Definition: tcp_admin.h:68
ADMIN_PACKET_SERVER_DATE
@ ADMIN_PACKET_SERVER_DATE
The server tells the admin what the current game date is.
Definition: tcp_admin.h:42
ADMIN_PACKET_SERVER_ERROR
@ ADMIN_PACKET_SERVER_ERROR
The server tells the admin an error has occurred.
Definition: tcp_admin.h:36
CommandContainer::p1
uint32 p1
parameter p1.
Definition: command_type.h:481
ServerNetworkAdminSocketHandler::SendShutdown
NetworkRecvStatus SendShutdown()
Tell the admin we're shutting down.
Definition: network_admin.cpp:194
NetworkCompanyStats::num_vehicle
uint16 num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
Definition: network_type.h:58
Packet::Recv_uint32
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:246
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:70
NetworkAdminSocketHandler::admin_version
char admin_version[NETWORK_REVISION_LENGTH]
Version string of the admin.
Definition: tcp_admin.h:113
ServerNetworkAdminSocketHandler::connect_time
std::chrono::steady_clock::time_point connect_time
Time of connection.
Definition: network_admin.h:40
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:149
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
Pool::MAX_SIZE
static const size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:85
MAX_ADMINS
static const AdminIndex MAX_ADMINS
Maximum number of allowed admins.
Definition: network_type.h:52
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
Packet::Send_string
void Send_string(const char *data)
Sends a string over the network.
Definition: packet.cpp:148
NetworkAddress::GetHostname
const char * GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
Definition: address.cpp:22
CompanyProperties::months_of_bankruptcy
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
Definition: company_base.h:81
ServerNetworkAdminSocketHandler::SendCompanyRemove
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Tell the admin that a company got removed.
Definition: network_admin.cpp:386
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:39
Packet::size
PacketSize size
The size of the whole packet for received packets.
Definition: packet.h:48
NetworkAdminSocketHandler
Main socket handler for admin related connections.
Definition: tcp_admin.h:110
ADMIN_PACKET_SERVER_COMPANY_REMOVE
@ ADMIN_PACKET_SERVER_COMPANY_REMOVE
The server tells the admin that a company was removed.
Definition: tcp_admin.h:51
SEND_MTU
static const uint16 SEND_MTU
Number of bytes we can pack in a single packet.
Definition: config.h:33
ADMIN_FREQUENCY_POLL
@ ADMIN_FREQUENCY_POLL
The admin can poll this.
Definition: tcp_admin.h:90
ADMIN_PACKET_SERVER_CLIENT_ERROR
@ ADMIN_PACKET_SERVER_CLIENT_ERROR
The server tells the admin that a client caused an error.
Definition: tcp_admin.h:47
ADMIN_UPDATE_DATE
@ ADMIN_UPDATE_DATE
Updates about the date of the game.
Definition: tcp_admin.h:75
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
ServerNetworkAdminSocketHandler::AllowConnection
static bool AllowConnection()
Whether a connection is allowed or not at this moment.
Definition: network_admin.cpp:84
ServerNetworkAdminSocketHandler::SendWelcome
NetworkRecvStatus SendWelcome()
Send a welcome message to the admin.
Definition: network_admin.cpp:165
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:141
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
ServerNetworkAdminSocketHandler::SendRcon
NetworkRecvStatus SendRcon(uint16 colour, const char *command)
Send the reply of an rcon command.
Definition: network_admin.cpp:501
ADMIN_UPDATE_COMPANY_STATS
@ ADMIN_UPDATE_COMPANY_STATS
Updates about the statistics of companies.
Definition: tcp_admin.h:79
ADMIN_UPDATE_COMPANY_ECONOMY
@ ADMIN_UPDATE_COMPANY_ECONOMY
Updates about the economy of companies.
Definition: tcp_admin.h:78
Packet::Send_uint16
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
Definition: packet.cpp:106
NetworkTCPSocketHandler::SendPacket
virtual void SendPacket(Packet *packet)
This function puts the packet in the send-queue and it is send as soon as possible.
Definition: tcp.cpp:61
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:41
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler
~ServerNetworkAdminSocketHandler()
Clear everything related to this admin.
Definition: network_admin.cpp:73
ADMIN_PACKET_SERVER_RCON
@ ADMIN_PACKET_SERVER_RCON
The server's reply to a remove console command.
Definition: tcp_admin.h:55
ServerNetworkAdminSocketHandler::SendClientQuit
NetworkRecvStatus SendClientQuit(ClientID client_id)
Tell the admin that a client quit.
Definition: network_admin.cpp:272
AdminCompanyRemoveReason
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition: tcp_admin.h:101
ADMIN_PACKET_SERVER_CONSOLE
@ ADMIN_PACKET_SERVER_CONSOLE
The server gives the admin the data that got printed to its console.
Definition: tcp_admin.h:56
ADMIN_PACKET_SERVER_CLIENT_UPDATE
@ ADMIN_PACKET_SERVER_CLIENT_UPDATE
The server gives the admin an information update on a client.
Definition: tcp_admin.h:45
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
NetworkSettings::server_name
char server_name[NETWORK_NAME_LENGTH]
name of the server
Definition: settings_type.h:265
CompanyProperties::share_owners
Owner share_owners[4]
Owners of the 4 shares of the company. INVALID_OWNER if nobody has bought them yet.
Definition: company_base.h:77
network_server.h
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:55
ADMIN_UPDATE_GAMESCRIPT
@ ADMIN_UPDATE_GAMESCRIPT
The admin would like to have gamescript messages.
Definition: tcp_admin.h:84
Packet
Internal entity of a packet.
Definition: packet.h:40
ADMIN_FREQUENCY_ANUALLY
@ ADMIN_FREQUENCY_ANUALLY
The admin gets information about this on a yearly basis.
Definition: tcp_admin.h:95
ServerNetworkAdminSocketHandler::SendCmdNames
NetworkRecvStatus SendCmdNames()
Send the names of the commands.
Definition: network_admin.cpp:606
NetworkAdminCompanyRemove
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
Definition: network_admin.cpp:910
NetworkCompanyIsPassworded
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:213
AdminUpdateType
AdminUpdateType
Update types an admin can register a frequency for.
Definition: tcp_admin.h:74
NetworkClientInfo::client_id
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition: network_base.h:24
ADMIN_PACKET_SERVER_RCON_END
@ ADMIN_PACKET_SERVER_RCON_END
The server indicates that the remote console command has completed.
Definition: tcp_admin.h:60
NETWORK_PASSWORD_LENGTH
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
Definition: config.h:45
ServerNetworkAdminSocketHandler::SendNewGame
NetworkRecvStatus SendNewGame()
Tell the admin we started a new game.
Definition: network_admin.cpp:186
Packet::Send_bool
void Send_bool(bool data)
Package a boolean in the packet.
Definition: packet.cpp:87
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:59
NetworkAdminCompanyUpdate
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
Definition: network_admin.cpp:894
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
ADMIN_PACKET_SERVER_CLIENT_JOIN
@ ADMIN_PACKET_SERVER_CLIENT_JOIN
The server tells the admin that a client has joined.
Definition: tcp_admin.h:43
NetworkAddress
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Definition: address.h:29
NETWORK_RCONCOMMAND_LENGTH
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
Definition: config.h:48
Pool::PoolItem<&_networkadminsocket_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
ServerNetworkAdminSocketHandler::SendDate
NetworkRecvStatus SendDate()
Tell the admin the date.
Definition: network_admin.cpp:202
ServerNetworkAdminSocketHandler::SendCompanyNew
NetworkRecvStatus SendCompanyNew(CompanyID company_id)
Tell the admin that a new company was founded.
Definition: network_admin.cpp:302
Pool
Base class for all pools.
Definition: pool_type.hpp:81
ADMIN_PACKET_SERVER_CMD_NAMES
@ ADMIN_PACKET_SERVER_CMD_NAMES
The server sends out the names of the DoCommands to the admins.
Definition: tcp_admin.h:57
ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT
NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p) override
Notification to the server that this admin is quitting.
Definition: network_admin.cpp:690
ADMIN_PACKET_SERVER_CLIENT_INFO
@ ADMIN_PACKET_SERVER_CLIENT_INFO
The server gives the admin information about a client.
Definition: tcp_admin.h:44
CMD_ID_MASK
@ CMD_ID_MASK
mask for the command ID
Definition: command_type.h:382
ServerNetworkAdminSocketHandler::SendPong
NetworkRecvStatus SendPong(uint32 d1)
Send ping-reply (pong) to admin.
Definition: network_admin.cpp:595
Packet::Send_uint64
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
Definition: packet.cpp:130
ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler
ServerNetworkAdminSocketHandler(SOCKET s)
Sanity check.
Definition: network_admin.cpp:63
ServerNetworkAdminSocketHandler
Class for handling the server side of the game connection.
Definition: network_admin.h:25
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:22
ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL
NetworkRecvStatus Receive_ADMIN_POLL(Packet *p) override
Poll the server for certain updates, an invalid poll (e.g.
Definition: network_admin.cpp:714
ServerNetworkAdminSocketHandler::SendClientInfo
NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
Send an initial set of data from some client's information.
Definition: network_admin.cpp:231
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
Definition: network_server.cpp:1273
ADMIN_FREQUENCY_AUTOMATIC
@ ADMIN_FREQUENCY_AUTOMATIC
The admin gets information about this when it changes.
Definition: tcp_admin.h:96
ADMIN_STATUS_ACTIVE
@ ADMIN_STATUS_ACTIVE
The admin is active.
Definition: tcp_admin.h:69
ADMIN_PACKET_SERVER_COMPANY_UPDATE
@ ADMIN_PACKET_SERVER_COMPANY_UPDATE
The server gives the admin an information update on a company.
Definition: tcp_admin.h:50
ServerNetworkAdminSocketHandler::SendProtocol
NetworkRecvStatus SendProtocol()
Send the protocol version to the admin.
Definition: network_admin.cpp:145
ServerNetworkAdminSocketHandler::SendRconEnd
NetworkRecvStatus SendRconEnd(const char *command)
Send a notification indicating the rcon command has completed.
Definition: network_admin.cpp:486
ServerNetworkAdminSocketHandler::Receive_ADMIN_PING
NetworkRecvStatus Receive_ADMIN_PING(Packet *p) override
Ping the server, requiring the server to reply with a pong packet.
Definition: network_admin.cpp:542
Pool::PoolItem<&_networkadminsocket_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:299
ADMIN_PACKET_SERVER_WELCOME
@ ADMIN_PACKET_SERVER_WELCOME
The server welcomes the admin to a game.
Definition: tcp_admin.h:38
NetworkAdminSocketHandler::admin_name
char admin_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the admin.
Definition: tcp_admin.h:112
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:293
Packet::Recv_uint8
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:217
ServerNetworkAdminSocketHandler::AcceptConnection
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the acception of a connection.
Definition: network_admin.cpp:114
ServerNetworkAdminSocketHandler::SendClientUpdate
NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci)
Send an update for some client's information.
Definition: network_admin.cpp:255
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:224
ADMIN_PACKET_SERVER_COMPANY_ECONOMY
@ ADMIN_PACKET_SERVER_COMPANY_ECONOMY
The server gives the admin some economy related company information.
Definition: tcp_admin.h:52
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:131
ADMIN_PACKET_SERVER_CMD_LOGGING
@ ADMIN_PACKET_SERVER_CMD_LOGGING
The server gives the admin copies of incoming command packets.
Definition: tcp_admin.h:58
AdminIndex
uint8 AdminIndex
Indices into the admin tables.
Definition: network_type.h:49
NetworkAdminClientUpdate
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
Notify the admin network of a client update (if they did opt in for the respective update).
Definition: network_admin.cpp:832
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:578
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
_network_admins_connected
byte _network_admins_connected
The amount of admins connected.
Definition: network_admin.cpp:33
IConsoleCmdExec
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:407
NETWORK_RECV_STATUS_OKAY
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
Definition: core.h:23
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
ADMIN_FREQUENCY_WEEKLY
@ ADMIN_FREQUENCY_WEEKLY
The admin gets information about this on a weekly basis.
Definition: tcp_admin.h:92
ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON
NetworkRecvStatus Receive_ADMIN_RCON(Packet *p) override
Execute a command on the servers console: string Command to be executed.
Definition: network_admin.cpp:512
_admin_update_type_frequencies
static const AdminUpdateFrequency _admin_update_type_frequencies[]
Frequencies, which may be registered for a certain update type.
Definition: network_admin.cpp:44
CMD_END
@ CMD_END
Must ALWAYS be on the end of this list!! (period)
Definition: command_type.h:338
ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT
NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p) override
Send chat as the server: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
Definition: network_admin.cpp:780
NetworkAdminCmdLogging
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
Definition: network_admin.cpp:975
ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT
NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p) override
Send a JSON string to the current active GameScript.
Definition: network_admin.cpp:528
network_admin.h
CommandContainer::tile
TileIndex tile
tile command being executed on.
Definition: command_type.h:480
ServerNetworkAdminSocketHandler::SendCompanyStats
NetworkRecvStatus SendCompanyStats()
Send statistics about the companies.
Definition: network_admin.cpp:433
NETWORK_GAMESCRIPT_JSON_LENGTH
static const uint NETWORK_GAMESCRIPT_JSON_LENGTH
The maximum length of a gamescript json string, in bytes including '\0'. Must not be longer than SEND...
Definition: config.h:49
ADMIN_AUTHORISATION_TIMEOUT
static const std::chrono::seconds ADMIN_AUTHORISATION_TIMEOUT(10)
The timeout for authorisation of the client.
GetNetworkRevisionString
const char * GetNetworkRevisionString()
Get the network version string used by this build.
Definition: network.cpp:1098
ADMIN_UPDATE_END
@ ADMIN_UPDATE_END
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_admin.h:85
Company
Definition: company_base.h:110
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
AdminUpdateFrequency
AdminUpdateFrequency
Update frequencies an admin can register.
Definition: tcp_admin.h:89
ServerNetworkAdminSocketHandler::SendClientJoin
NetworkRecvStatus SendClientJoin(ClientID client_id)
Tell the admin that a client joined.
Definition: network_admin.cpp:216
ServerNetworkAdminSocketHandler::SendChat
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
Send a chat message.
Definition: network_admin.cpp:468
NetworkAdminCompanyInfo
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
Notify the admin network of company details.
Definition: network_admin.cpp:873
NetworkErrorCode
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:110
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:23
NetworkAdminClientError
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
Notify the admin network of a client error (if they have opt in for the respective update).
Definition: network_admin.cpp:859
Packet::Recv_uint16
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
Definition: packet.cpp:231
NetworkServerSendAdminRcon
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string)
Pass the rcon reply to the admin.
Definition: network_admin.cpp:938
ServerNetworkAdminSocketHandler::SendClientError
NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error)
Tell the admin that a client made an error.
Definition: network_admin.cpp:287
ADMIN_PACKET_SERVER_SHUTDOWN
@ ADMIN_PACKET_SERVER_SHUTDOWN
The server tells the admin its shutting down.
Definition: tcp_admin.h:40
NETWORK_COMPANY_NAME_LENGTH
static const uint NETWORK_COMPANY_NAME_LENGTH
The maximum length of the company name, in bytes including '\0'.
Definition: config.h:41
ServerNetworkAdminSocketHandler::SendCmdLogging
NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp)
Send a command for logging purposes.
Definition: network_admin.cpp:640