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

OpenTTD Source 14.1

network_client.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 "network_gui.h"
12 #include "../saveload/saveload.h"
13 #include "../saveload/saveload_filter.h"
14 #include "../command_func.h"
15 #include "../console_func.h"
16 #include "../strings_func.h"
17 #include "../window_func.h"
18 #include "../company_func.h"
19 #include "../company_base.h"
20 #include "../company_gui.h"
21 #include "../company_cmd.h"
22 #include "../core/random_func.hpp"
23 #include "../timer/timer_game_tick.h"
24 #include "../timer/timer_game_calendar.h"
25 #include "../gfx_func.h"
26 #include "../error.h"
27 #include "../rev.h"
28 #include "network.h"
29 #include "network_base.h"
30 #include "network_client.h"
31 #include "network_gamelist.h"
32 #include "../core/backup_type.hpp"
33 #include "../thread.h"
34 #include "../social_integration.h"
35
36 #include "table/strings.h"
37
38 #include "../safeguards.h"
39
40 /* This file handles all the client-commands */
41
43 struct PacketReader : LoadFilter {
44 static const size_t CHUNK = 32 * 1024;
45
46 std::vector<byte *> blocks;
47 byte *buf;
48 byte *bufe;
49 byte **block;
50 size_t written_bytes;
51 size_t read_bytes;
52
54 PacketReader() : LoadFilter(nullptr), buf(nullptr), bufe(nullptr), block(nullptr), written_bytes(0), read_bytes(0)
55 {
56 }
57
58 ~PacketReader() override
59 {
60 for (auto p : this->blocks) {
61 free(p);
62 }
63 }
64
72 static inline ssize_t TransferOutMemCopy(PacketReader *destination, const char *source, size_t amount)
73 {
74 memcpy(destination->buf, source, amount);
75 destination->buf += amount;
76 destination->written_bytes += amount;
77 return amount;
78 }
79
84 void AddPacket(Packet &p)
85 {
86 assert(this->read_bytes == 0);
87 p.TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
88
89 /* Did everything fit in the current chunk, then we're done. */
90 if (p.RemainingBytesToTransfer() == 0) return;
91
92 /* Allocate a new chunk and add the remaining data. */
93 this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
94 this->bufe = this->buf + CHUNK;
95
96 p.TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
97 }
98
99 size_t Read(byte *rbuf, size_t size) override
100 {
101 /* Limit the amount to read to whatever we still have. */
102 size_t ret_size = size = std::min(this->written_bytes - this->read_bytes, size);
103 this->read_bytes += ret_size;
104 const byte *rbufe = rbuf + ret_size;
105
106 while (rbuf != rbufe) {
107 if (this->buf == this->bufe) {
108 this->buf = *this->block++;
109 this->bufe = this->buf + CHUNK;
110 }
111
112 size_t to_write = std::min(this->bufe - this->buf, rbufe - rbuf);
113 memcpy(rbuf, this->buf, to_write);
114 rbuf += to_write;
115 this->buf += to_write;
116 }
117
118 return ret_size;
119 }
120
121 void Reset() override
122 {
123 this->read_bytes = 0;
124
125 this->block = this->blocks.data();
126 this->buf = *this->block++;
127 this->bufe = this->buf + CHUNK;
128 }
129 };
130
131
135 void ClientNetworkEmergencySave()
136 {
137 static FiosNumberedSaveName _netsave_ctr("netsave");
138 DoAutoOrNetsave(_netsave_ctr);
139 }
140
141
146 ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s, const std::string &connection_string) : NetworkGameSocketHandler(s), connection_string(connection_string), savegame(nullptr), status(STATUS_INACTIVE)
147 {
148 assert(ClientNetworkGameSocketHandler::my_client == nullptr);
149 ClientNetworkGameSocketHandler::my_client = this;
150 }
151
153 ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
154 {
155 assert(ClientNetworkGameSocketHandler::my_client == this);
156 ClientNetworkGameSocketHandler::my_client = nullptr;
157
158 delete this->GetInfo();
159 }
160
161 NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
162 {
163 assert(status != NETWORK_RECV_STATUS_OKAY);
164 if (this->IsPendingDeletion()) return status;
165
166 assert(this->sock != INVALID_SOCKET);
167
168 if (!this->HasClientQuit()) {
169 Debug(net, 3, "Closed client connection {}", this->client_id);
170
171 this->SendPackets(true);
172
173 /* Wait a number of ticks so our leave message can reach the server.
174 * This is especially needed for Windows servers as they seem to get
175 * the "socket is closed" message before receiving our leave message,
176 * which would trigger the server to close the connection as well. */
177 CSleep(3 * MILLISECONDS_PER_TICK);
178 }
179
180 this->DeferDeletion();
181
182 return status;
183 }
184
189 void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
190 {
191 if (this->IsPendingDeletion()) return;
192
193 /* First, send a CLIENT_ERROR to the server, so it knows we are
194 * disconnected (and why!) */
195 NetworkErrorCode errorno;
196
197 /* We just want to close the connection.. */
198 if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
199 this->NetworkSocketHandler::MarkClosed();
200 this->CloseConnection(res);
201 _networking = false;
202
203 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
204 return;
205 }
206
207 switch (res) {
208 case NETWORK_RECV_STATUS_DESYNC: errorno = NETWORK_ERROR_DESYNC; break;
209 case NETWORK_RECV_STATUS_SAVEGAME: errorno = NETWORK_ERROR_SAVEGAME_FAILED; break;
210 case NETWORK_RECV_STATUS_NEWGRF_MISMATCH: errorno = NETWORK_ERROR_NEWGRF_MISMATCH; break;
211 default: errorno = NETWORK_ERROR_GENERAL; break;
212 }
213
214 if (res == NETWORK_RECV_STATUS_SERVER_ERROR || res == NETWORK_RECV_STATUS_SERVER_FULL ||
215 res == NETWORK_RECV_STATUS_SERVER_BANNED) {
216 /* This means the server closed the connection. Emergency save is
217 * already created if this was appropriate during handling of the
218 * disconnect. */
219 this->CloseConnection(res);
220 } else {
221 /* This means we as client made a boo-boo. */
222 SendError(errorno);
223
224 /* Close connection before we make an emergency save, as the save can
225 * take a bit of time; better that the server doesn't stall while we
226 * are doing the save, and already disconnects us. */
227 this->CloseConnection(res);
228 ClientNetworkEmergencySave();
229 }
230
231 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
232
233 if (_game_mode != GM_MENU) _switch_mode = SM_MENU;
234 _networking = false;
235 }
236
237
243 /* static */ bool ClientNetworkGameSocketHandler::Receive()
244 {
245 if (my_client->CanSendReceive()) {
246 NetworkRecvStatus res = my_client->ReceivePackets();
247 if (res != NETWORK_RECV_STATUS_OKAY) {
248 /* The client made an error of which we can not recover.
249 * Close the connection and drop back to the main menu. */
250 my_client->ClientError(res);
251 return false;
252 }
253 }
254 return _networking;
255 }
256
258 /* static */ void ClientNetworkGameSocketHandler::Send()
259 {
260 my_client->SendPackets();
261 if (my_client != nullptr) my_client->CheckConnection();
262 }
263
268 /* static */ bool ClientNetworkGameSocketHandler::GameLoop()
269 {
270 _frame_counter++;
271
272 NetworkExecuteLocalCommandQueue();
273
274 StateGameLoop();
275
276 /* Check if we are in sync! */
277 if (_sync_frame != 0) {
278 if (_sync_frame == _frame_counter) {
279 #ifdef NETWORK_SEND_DOUBLE_SEED
280 if (_sync_seed_1 != _random.state[0] || _sync_seed_2 != _random.state[1]) {
281 #else
282 if (_sync_seed_1 != _random.state[0]) {
283 #endif
284 ShowNetworkError(STR_NETWORK_ERROR_DESYNC);
285 Debug(desync, 1, "sync_err: {:08x}; {:02x}", TimerGameEconomy::date, TimerGameEconomy::date_fract);
286 Debug(net, 0, "Sync error detected");
287 my_client->ClientError(NETWORK_RECV_STATUS_DESYNC);
288 return false;
289 }
290
291 /* If this is the first time we have a sync-frame, we
292 * need to let the server know that we are ready and at the same
293 * frame as it is.. so we can start playing! */
294 if (_network_first_time) {
295 _network_first_time = false;
296 SendAck();
297 }
298
299 _sync_frame = 0;
300 } else if (_sync_frame < _frame_counter) {
301 Debug(net, 1, "Missed frame for sync-test: {} / {}", _sync_frame, _frame_counter);
302 _sync_frame = 0;
303 }
304 }
305
306 return true;
307 }
308
309
311 ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = nullptr;
312
314 static uint32_t last_ack_frame;
315
317 static uint32_t _password_game_seed;
319 static std::string _password_server_id;
320
322 static uint8_t _network_server_max_companies;
324 std::string _network_server_name;
325
327 NetworkJoinInfo _network_join;
328
330 static_assert(NETWORK_SERVER_ID_LENGTH == MD5_HASH_BYTES * 2 + 1);
331
332 /***********
333 * Sending functions
334 ************/
335
337 NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
338 {
339 Debug(net, 9, "Client::SendJoin()");
340
341 Debug(net, 9, "Client::status = JOIN");
342 my_client->status = STATUS_JOIN;
343 Debug(net, 9, "Client::join_status = AUTHORIZING");
344 _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING;
345 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
346
347 auto p = std::make_unique<Packet>(PACKET_CLIENT_JOIN);
348 p->Send_string(GetNetworkRevisionString());
349 p->Send_uint32(_openttd_newgrf_version);
350 p->Send_string(_settings_client.network.client_name); // Client name
351 p->Send_uint8 (_network_join.company); // PlayAs
352 p->Send_uint8 (0); // Used to be language
353 my_client->SendPacket(std::move(p));
354 return NETWORK_RECV_STATUS_OKAY;
355 }
356
358 NetworkRecvStatus ClientNetworkGameSocketHandler::SendNewGRFsOk()
359 {
360 Debug(net, 9, "Client::SendNewGRFsOk()");
361
362 auto p = std::make_unique<Packet>(PACKET_CLIENT_NEWGRFS_CHECKED);
363 my_client->SendPacket(std::move(p));
364 return NETWORK_RECV_STATUS_OKAY;
365 }
366
371 NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword(const std::string &password)
372 {
373 Debug(net, 9, "Client::SendGamePassword()");
374
375 auto p = std::make_unique<Packet>(PACKET_CLIENT_GAME_PASSWORD);
376 p->Send_string(password);
377 my_client->SendPacket(std::move(p));
378 return NETWORK_RECV_STATUS_OKAY;
379 }
380
385 NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword(const std::string &password)
386 {
387 Debug(net, 9, "Client::SendCompanyPassword()");
388
389 auto p = std::make_unique<Packet>(PACKET_CLIENT_COMPANY_PASSWORD);
390 p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
391 my_client->SendPacket(std::move(p));
392 return NETWORK_RECV_STATUS_OKAY;
393 }
394
396 NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap()
397 {
398 Debug(net, 9, "Client::SendGetMap()");
399
400 Debug(net, 9, "Client::status = MAP_WAIT");
401 my_client->status = STATUS_MAP_WAIT;
402
403 auto p = std::make_unique<Packet>(PACKET_CLIENT_GETMAP);
404 my_client->SendPacket(std::move(p));
405 return NETWORK_RECV_STATUS_OKAY;
406 }
407
409 NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk()
410 {
411 Debug(net, 9, "Client::SendMapOk()");
412
413 Debug(net, 9, "Client::status = ACTIVE");
414 my_client->status = STATUS_ACTIVE;
415
416 auto p = std::make_unique<Packet>(PACKET_CLIENT_MAP_OK);
417 my_client->SendPacket(std::move(p));
418 return NETWORK_RECV_STATUS_OKAY;
419 }
420
422 NetworkRecvStatus ClientNetworkGameSocketHandler::SendAck()
423 {
424 Debug(net, 9, "Client::SendAck()");
425
426 auto p = std::make_unique<Packet>(PACKET_CLIENT_ACK);
427
428 p->Send_uint32(_frame_counter);
429 p->Send_uint8 (my_client->token);
430 my_client->SendPacket(std::move(p));
431 return NETWORK_RECV_STATUS_OKAY;
432 }
433
438 NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacket &cp)
439 {
440 Debug(net, 9, "Client::SendCommand(): cmd={}", cp.cmd);
441
442 auto p = std::make_unique<Packet>(PACKET_CLIENT_COMMAND);
443 my_client->NetworkGameSocketHandler::SendCommand(*p, cp);
444
445 my_client->SendPacket(std::move(p));
446 return NETWORK_RECV_STATUS_OKAY;
447 }
448
450 NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
451 {
452 Debug(net, 9, "Client::SendChat(): action={}, type={}, dest={}", action, type, dest);
453
454 auto p = std::make_unique<Packet>(PACKET_CLIENT_CHAT);
455
456 p->Send_uint8 (action);
457 p->Send_uint8 (type);
458 p->Send_uint32(dest);
459 p->Send_string(msg);
460 p->Send_uint64(data);
461
462 my_client->SendPacket(std::move(p));
463 return NETWORK_RECV_STATUS_OKAY;
464 }
465
467 NetworkRecvStatus ClientNetworkGameSocketHandler::SendError(NetworkErrorCode errorno)
468 {
469 Debug(net, 9, "Client::SendError(): errorno={}", errorno);
470
471 auto p = std::make_unique<Packet>(PACKET_CLIENT_ERROR);
472
473 p->Send_uint8(errorno);
474 my_client->SendPacket(std::move(p));
475 return NETWORK_RECV_STATUS_OKAY;
476 }
477
482 NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword(const std::string &password)
483 {
484 Debug(net, 9, "Client::SendSetPassword()");
485
486 auto p = std::make_unique<Packet>(PACKET_CLIENT_SET_PASSWORD);
487
488 p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
489 my_client->SendPacket(std::move(p));
490 return NETWORK_RECV_STATUS_OKAY;
491 }
492
497 NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName(const std::string &name)
498 {
499 Debug(net, 9, "Client::SendSetName()");
500
501 auto p = std::make_unique<Packet>(PACKET_CLIENT_SET_NAME);
502
503 p->Send_string(name);
504 my_client->SendPacket(std::move(p));
505 return NETWORK_RECV_STATUS_OKAY;
506 }
507
511 NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit()
512 {
513 Debug(net, 9, "Client::SendSetName()");
514
515 auto p = std::make_unique<Packet>(PACKET_CLIENT_QUIT);
516
517 my_client->SendPacket(std::move(p));
518 return NETWORK_RECV_STATUS_OKAY;
519 }
520
526 NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pass, const std::string &command)
527 {
528 Debug(net, 9, "Client::SendRCon()");
529
530 auto p = std::make_unique<Packet>(PACKET_CLIENT_RCON);
531 p->Send_string(pass);
532 p->Send_string(command);
533 my_client->SendPacket(std::move(p));
534 return NETWORK_RECV_STATUS_OKAY;
535 }
536
542 NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, const std::string &password)
543 {
544 Debug(net, 9, "Client::SendMove(): company={}", company);
545
546 auto p = std::make_unique<Packet>(PACKET_CLIENT_MOVE);
547 p->Send_uint8(company);
548 p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
549 my_client->SendPacket(std::move(p));
550 return NETWORK_RECV_STATUS_OKAY;
551 }
552
557 bool ClientNetworkGameSocketHandler::IsConnected()
558 {
559 return my_client != nullptr && my_client->status == STATUS_ACTIVE;
560 }
561
562
563 /***********
564 * Receiving functions
565 ************/
566
567 extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<struct LoadFilter> lf);
568
569 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet &)
570 {
571 Debug(net, 9, "Client::Receive_SERVER_FULL()");
572
573 /* We try to join a server which is full */
574 ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
575
576 return NETWORK_RECV_STATUS_SERVER_FULL;
577 }
578
579 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet &)
580 {
581 Debug(net, 9, "Client::Receive_SERVER_BANNED()");
582
583 /* We try to join a server where we are banned */
584 ShowErrorMessage(STR_NETWORK_ERROR_SERVER_BANNED, INVALID_STRING_ID, WL_CRITICAL);
585
586 return NETWORK_RECV_STATUS_SERVER_BANNED;
587 }
588
589 /* This packet contains info about the client (playas and name)
590 * as client we save this in NetworkClientInfo, linked via 'client_id'
591 * which is always an unique number on a server. */
592 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet &p)
593 {
594 NetworkClientInfo *ci;
595 ClientID client_id = (ClientID)p.Recv_uint32();
596 CompanyID playas = (CompanyID)p.Recv_uint8();
597
598 Debug(net, 9, "Client::Receive_SERVER_CLIENT_INFO(): client_id={}, playas={}", client_id, playas);
599
600 std::string name = p.Recv_string(NETWORK_NAME_LENGTH);
601
602 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
603 if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
604 /* The server validates the name when receiving it from clients, so when it is wrong
605 * here something went really wrong. In the best case the packet got malformed on its
606 * way too us, in the worst case the server is broken or compromised. */
607 if (!NetworkIsValidClientName(name)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
608
609 ci = NetworkClientInfo::GetByClientID(client_id);
610 if (ci != nullptr) {
611 if (playas == ci->client_playas && name.compare(ci->client_name) != 0) {
612 /* Client name changed, display the change */
613 NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, name);
614 } else if (playas != ci->client_playas) {
615 /* The client changed from client-player..
616 * Do not display that for now */
617 }
618
619 /* Make sure we're in the company the server tells us to be in,
620 * for the rare case that we get moved while joining. */
621 if (client_id == _network_own_client_id) SetLocalCompany(!Company::IsValidID(playas) ? COMPANY_SPECTATOR : playas);
622
623 ci->client_playas = playas;
624 ci->client_name = name;
625
626 InvalidateWindowData(WC_CLIENT_LIST, 0);
627
628 return NETWORK_RECV_STATUS_OKAY;
629 }
630
631 /* There are at most as many ClientInfo as ClientSocket objects in a
632 * server. Having more info than a server can have means something
633 * has gone wrong somewhere, i.e. the server has more info than it
634 * has actual clients. That means the server is feeding us an invalid
635 * state. So, bail out! This server is broken. */
636 if (!NetworkClientInfo::CanAllocateItem()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
637
638 /* We don't have this client_id yet, find an empty client_id, and put the data there */
639 ci = new NetworkClientInfo(client_id);
640 ci->client_playas = playas;
641 if (client_id == _network_own_client_id) this->SetInfo(ci);
642
643 ci->client_name = name;
644
645 InvalidateWindowData(WC_CLIENT_LIST, 0);
646
647 return NETWORK_RECV_STATUS_OKAY;
648 }
649
650 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet &p)
651 {
652 static const StringID network_error_strings[] = {
653 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_GENERAL
654 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_DESYNC
655 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_SAVEGAME_FAILED
656 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_CONNECTION_LOST
657 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_ILLEGAL_PACKET
658 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NEWGRF_MISMATCH
659 STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_AUTHORIZED
660 STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_EXPECTED
661 STR_NETWORK_ERROR_WRONG_REVISION, // NETWORK_ERROR_WRONG_REVISION
662 STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NAME_IN_USE
663 STR_NETWORK_ERROR_WRONG_PASSWORD, // NETWORK_ERROR_WRONG_PASSWORD
664 STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_COMPANY_MISMATCH
665 STR_NETWORK_ERROR_KICKED, // NETWORK_ERROR_KICKED
666 STR_NETWORK_ERROR_CHEATER, // NETWORK_ERROR_CHEATER
667 STR_NETWORK_ERROR_SERVER_FULL, // NETWORK_ERROR_FULL
668 STR_NETWORK_ERROR_TOO_MANY_COMMANDS, // NETWORK_ERROR_TOO_MANY_COMMANDS
669 STR_NETWORK_ERROR_TIMEOUT_PASSWORD, // NETWORK_ERROR_TIMEOUT_PASSWORD
670 STR_NETWORK_ERROR_TIMEOUT_COMPUTER, // NETWORK_ERROR_TIMEOUT_COMPUTER
671 STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP
672 STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN
673 STR_NETWORK_ERROR_INVALID_CLIENT_NAME, // NETWORK_ERROR_INVALID_CLIENT_NAME
674 };
675 static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
676
677 NetworkErrorCode error = (NetworkErrorCode)p.Recv_uint8();
678
679 Debug(net, 9, "Client::Receive_SERVER_ERROR(): error={}", error);
680
681 StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
682 if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
683 /* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
684 if (error == NETWORK_ERROR_KICKED && p.CanReadFromPacket(1)) {
685 SetDParamStr(0, p.Recv_string(NETWORK_CHAT_LENGTH));
686 ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
687 } else {
688 ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
689 }
690
691 /* Perform an emergency save if we had already entered the game */
692 if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
693
694 return NETWORK_RECV_STATUS_SERVER_ERROR;
695 }
696
697 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet &p)
698 {
699 if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
700
701 uint grf_count = p.Recv_uint8();
702 NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;
703
704 Debug(net, 9, "Client::Receive_SERVER_CHECK_NEWGRFS(): grf_count={}", grf_count);
705
706 /* Check all GRFs */
707 for (; grf_count > 0; grf_count--) {
708 GRFIdentifier c;
709 DeserializeGRFIdentifier(p, c);
710
711 /* Check whether we know this GRF */
712 const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, &c.md5sum);
713 if (f == nullptr) {
714 /* We do not know this GRF, bail out of initialization */
715 Debug(grf, 0, "NewGRF {:08X} not found; checksum {}", BSWAP32(c.grfid), FormatArrayAsHex(c.md5sum));
716 ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
717 }
718 }
719
720 if (ret == NETWORK_RECV_STATUS_OKAY) {
721 /* Start receiving the map */
722 return SendNewGRFsOk();
723 }
724
725 /* NewGRF mismatch, bail out */
726 ShowErrorMessage(STR_NETWORK_ERROR_NEWGRF_MISMATCH, INVALID_STRING_ID, WL_CRITICAL);
727 return ret;
728 }
729
730 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet &)
731 {
732 if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
733 Debug(net, 9, "Client::status = AUTH_GAME");
734 this->status = STATUS_AUTH_GAME;
735
736 Debug(net, 9, "Client::Receive_SERVER_NEED_GAME_PASSWORD()");
737
738 if (!_network_join.server_password.empty()) {
739 return SendGamePassword(_network_join.server_password);
740 }
741
742 ShowNetworkNeedPassword(NETWORK_GAME_PASSWORD);
743
744 return NETWORK_RECV_STATUS_OKAY;
745 }
746
747 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p)
748 {
749 if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_COMPANY) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
750 Debug(net, 9, "Client::status = AUTH_COMPANY");
751 this->status = STATUS_AUTH_COMPANY;
752
753 Debug(net, 9, "Client::Receive_SERVER_NEED_COMPANY_PASSWORD()");
754
755 _password_game_seed = p.Recv_uint32();
756 _password_server_id = p.Recv_string(NETWORK_SERVER_ID_LENGTH);
757 if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
758
759 if (!_network_join.company_password.empty()) {
760 return SendCompanyPassword(_network_join.company_password);
761 }
762
763 ShowNetworkNeedPassword(NETWORK_COMPANY_PASSWORD);
764
765 return NETWORK_RECV_STATUS_OKAY;
766 }
767
768 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet &p)
769 {
770 if (this->status < STATUS_JOIN || this->status >= STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
771 Debug(net, 9, "Client::status = AUTHORIZED");
772 this->status = STATUS_AUTHORIZED;
773
774 _network_own_client_id = (ClientID)p.Recv_uint32();
775
776 Debug(net, 9, "Client::Receive_SERVER_WELCOME(): client_id={}", _network_own_client_id);
777
778 /* Initialize the password hash salting variables, even if they were previously. */
779 _password_game_seed = p.Recv_uint32();
780 _password_server_id = p.Recv_string(NETWORK_SERVER_ID_LENGTH);
781
782 /* Start receiving the map */
783 return SendGetMap();
784 }
785
786 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet &p)
787 {
788 /* We set the internal wait state when requesting the map. */
789 if (this->status != STATUS_MAP_WAIT) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
790
791 Debug(net, 9, "Client::Receive_SERVER_WAIT()");
792
793 /* But... only now we set the join status to waiting, instead of requesting. */
794 Debug(net, 9, "Client::join_status = WAITING");
795 _network_join_status = NETWORK_JOIN_STATUS_WAITING;
796 _network_join_waiting = p.Recv_uint8();
797 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
798
799 return NETWORK_RECV_STATUS_OKAY;
800 }
801
802 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet &p)
803 {
804 if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
805 Debug(net, 9, "Client::status = MAP");
806 this->status = STATUS_MAP;
807
808 if (this->savegame != nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
809
810 this->savegame = std::make_shared<PacketReader>();
811
812 _frame_counter = _frame_counter_server = _frame_counter_max = p.Recv_uint32();
813
814 Debug(net, 9, "Client::Receive_SERVER_MAP_BEGIN(): frame_counter={}", _frame_counter);
815
816 _network_join_bytes = 0;
817 _network_join_bytes_total = 0;
818
819 Debug(net, 9, "Client::join_status = DOWNLOADING");
820 _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
821 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
822
823 return NETWORK_RECV_STATUS_OKAY;
824 }
825
826 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet &p)
827 {
828 if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
829 if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
830
831 _network_join_bytes_total = p.Recv_uint32();
832 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
833
834 Debug(net, 9, "Client::Receive_SERVER_MAP_SIZE(): bytes_total={}", _network_join_bytes_total);
835
836 return NETWORK_RECV_STATUS_OKAY;
837 }
838
839 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet &p)
840 {
841 if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
842 if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
843
844 /* We are still receiving data, put it to the file */
845 this->savegame->AddPacket(p);
846
847 _network_join_bytes = (uint32_t)this->savegame->written_bytes;
848 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
849
850 return NETWORK_RECV_STATUS_OKAY;
851 }
852
853 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet &)
854 {
855 if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
856 if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
857
858 Debug(net, 9, "Client::Receive_SERVER_MAP_DONE()");
859
860 Debug(net, 9, "Client::join_status = PROCESSING");
861 _network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
862 SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
863
864 this->savegame->Reset();
865
866 /* The map is done downloading, load it */
867 ClearErrorMessages();
868 bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, this->savegame);
869 this->savegame = nullptr;
870
871 /* Long savegame loads shouldn't affect the lag calculation! */
872 this->last_packet = std::chrono::steady_clock::now();
873
874 if (!load_success) {
875 ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, INVALID_STRING_ID, WL_CRITICAL);
876 return NETWORK_RECV_STATUS_SAVEGAME;
877 }
878 /* If the savegame has successfully loaded, ALL windows have been removed,
879 * only toolbar/statusbar and gamefield are visible */
880
881 /* Say we received the map and loaded it correctly! */
882 SendMapOk();
883
884 /* As we skipped switch-mode, update the time we "switched". */
885 _game_session_stats.start_time = std::chrono::steady_clock::now();
886 _game_session_stats.savegame_size = std::nullopt;
887
888 ShowClientList();
889
890 /* New company/spectator (invalid company) or company we want to join is not active
891 * Switch local company to spectator and await the server's judgement */
892 if (_network_join.company == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join.company)) {
893 SetLocalCompany(COMPANY_SPECTATOR);
894
895 if (_network_join.company != COMPANY_SPECTATOR) {
896 /* We have arrived and ready to start playing; send a command to make a new company;
897 * the server will give us a client-id and let us in */
898 Debug(net, 9, "Client::join_status = REGISTERING");
899 _network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
900 ShowJoinStatusWindow();
901 Command<CMD_COMPANY_CTRL>::SendNet(STR_NULL, _local_company, CCA_NEW, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);
902 }
903 } else {
904 /* take control over an existing company */
905 SetLocalCompany(_network_join.company);
906 }
907
908 SocialIntegration::EventEnterMultiplayer(Map::SizeX(), Map::SizeY());
909
910 return NETWORK_RECV_STATUS_OKAY;
911 }
912
913 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet &p)
914 {
915 if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
916
917 _frame_counter_server = p.Recv_uint32();
918 _frame_counter_max = p.Recv_uint32();
919 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
920 /* Test if the server supports this option
921 * and if we are at the frame the server is */
922 #ifdef NETWORK_SEND_DOUBLE_SEED
923 if (p.CanReadFromPacket(sizeof(uint32_t) + sizeof(uint32_t))) {
924 #else
925 if (p.CanReadFromPacket(sizeof(uint32_t))) {
926 #endif
927 _sync_frame = _frame_counter_server;
928 _sync_seed_1 = p.Recv_uint32();
929 #ifdef NETWORK_SEND_DOUBLE_SEED
930 _sync_seed_2 = p.Recv_uint32();
931 #endif
932 }
933 #endif
934 /* Receive the token. */
935 if (p.CanReadFromPacket(sizeof(uint8_t))) this->token = p.Recv_uint8();
936
937 /* Let the server know that we received this frame correctly
938 * We do this only once per day, to save some bandwidth ;) */
939 if (!_network_first_time && last_ack_frame < _frame_counter) {
940 last_ack_frame = _frame_counter + Ticks::DAY_TICKS;
941 Debug(net, 7, "Sent ACK at {}", _frame_counter);
942 SendAck();
943 }
944
945 return NETWORK_RECV_STATUS_OKAY;
946 }
947
948 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC(Packet &p)
949 {
950 if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
951
952 _sync_frame = p.Recv_uint32();
953 _sync_seed_1 = p.Recv_uint32();
954 #ifdef NETWORK_SEND_DOUBLE_SEED
955 _sync_seed_2 = p.Recv_uint32();
956 #endif
957
958 Debug(net, 9, "Client::Receive_SERVER_SYNC(): sync_frame={}, sync_seed_1={}", _sync_frame, _sync_seed_1);
959
960 return NETWORK_RECV_STATUS_OKAY;
961 }
962
963 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet &p)
964 {
965 if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
966
967 CommandPacket cp;
968 const char *err = this->ReceiveCommand(p, cp);
969 cp.frame = p.Recv_uint32();
970 cp.my_cmd = p.Recv_bool();
971
972 Debug(net, 9, "Client::Receive_SERVER_COMMAND(): cmd={}, frame={}", cp.cmd, cp.frame);
973
974 if (err != nullptr) {
975 IConsolePrint(CC_WARNING, "Dropping server connection due to {}.", err);
976 return NETWORK_RECV_STATUS_MALFORMED_PACKET;
977 }
978
979 this->incoming_queue.push_back(cp);
980
981 return NETWORK_RECV_STATUS_OKAY;
982 }
983
984 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet &p)
985 {
986 if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
987
988 std::string name;
989 const NetworkClientInfo *ci = nullptr, *ci_to;
990
991 NetworkAction action = (NetworkAction)p.Recv_uint8();
992 ClientID client_id = (ClientID)p.Recv_uint32();
993 bool self_send = p.Recv_bool();
994 std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
995 int64_t data = p.Recv_uint64();
996
997 Debug(net, 9, "Client::Receive_SERVER_CHAT(): action={}, client_id={}, self_send={}", action, client_id, self_send);
998
999 ci_to = NetworkClientInfo::GetByClientID(client_id);
1000 if (ci_to == nullptr) return NETWORK_RECV_STATUS_OKAY;
1001
1002 /* Did we initiate the action locally? */
1003 if (self_send) {
1004 switch (action) {
1005 case NETWORK_ACTION_CHAT_CLIENT:
1006 /* For speaking to client we need the client-name */
1007 name = ci_to->client_name;
1008 ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
1009 break;
1010
1011 /* For speaking to company, we need the company-name */
1012 case NETWORK_ACTION_CHAT_COMPANY: {
1013 StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
1014 SetDParam(0, ci_to->client_playas);
1015
1016 name = GetString(str);
1017 ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
1018 break;
1019 }
1020
1021 default: return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1022 }
1023 } else {
1024 /* Display message from somebody else */
1025 name = ci_to->client_name;
1026 ci = ci_to;
1027 }
1028
1029 if (ci != nullptr) {
1030 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), self_send, name, msg, data);
1031 }
1032 return NETWORK_RECV_STATUS_OKAY;
1033 }
1034
1035 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet &p)
1036 {
1037 if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1038
1039 std::string source = p.Recv_string(NETWORK_CHAT_LENGTH);
1040 TextColour colour = (TextColour)p.Recv_uint16();
1041 std::string user = p.Recv_string(NETWORK_CHAT_LENGTH);
1042 std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
1043
1044 Debug(net, 9, "Client::Receive_SERVER_EXTERNAL_CHAT(): source={}", source);
1045
1046 if (!IsValidConsoleColour(colour)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1047
1048 NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
1049
1050 return NETWORK_RECV_STATUS_OKAY;
1051 }
1052
1053 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet &p)
1054 {
1055 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1056
1057 ClientID client_id = (ClientID)p.Recv_uint32();
1058
1059 Debug(net, 9, "Client::Receive_SERVER_ERROR_QUIT(): client_id={}", client_id);
1060
1061 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
1062 if (ci != nullptr) {
1063 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", GetNetworkErrorMsg((NetworkErrorCode)p.Recv_uint8()));
1064 delete ci;
1065 }
1066
1067 InvalidateWindowData(WC_CLIENT_LIST, 0);
1068
1069 return NETWORK_RECV_STATUS_OKAY;
1070 }
1071
1072 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet &p)
1073 {
1074 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1075
1076 ClientID client_id = (ClientID)p.Recv_uint32();
1077
1078 Debug(net, 9, "Client::Receive_SERVER_QUIT(): client_id={}", client_id);
1079
1080 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
1081 if (ci != nullptr) {
1082 NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", STR_NETWORK_MESSAGE_CLIENT_LEAVING);
1083 delete ci;
1084 } else {
1085 Debug(net, 1, "Unknown client ({}) is leaving the game", client_id);
1086 }
1087
1088 InvalidateWindowData(WC_CLIENT_LIST, 0);
1089
1090 /* If we come here it means we could not locate the client.. strange :s */
1091 return NETWORK_RECV_STATUS_OKAY;
1092 }
1093
1094 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet &p)
1095 {
1096 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1097
1098 ClientID client_id = (ClientID)p.Recv_uint32();
1099
1100 Debug(net, 9, "Client::Receive_SERVER_JOIN(): client_id={}", client_id);
1101
1102 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
1103 if (ci != nullptr) {
1104 NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name);
1105 }
1106
1107 InvalidateWindowData(WC_CLIENT_LIST, 0);
1108
1109 return NETWORK_RECV_STATUS_OKAY;
1110 }
1111
1112 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet &)
1113 {
1114 Debug(net, 9, "Client::Receive_SERVER_SHUTDOWN()");
1115
1116 /* Only when we're trying to join we really
1117 * care about the server shutting down. */
1118 if (this->status >= STATUS_JOIN) {
1119 ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_SHUTDOWN, INVALID_STRING_ID, WL_CRITICAL);
1120 }
1121
1122 if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
1123
1124 return NETWORK_RECV_STATUS_SERVER_ERROR;
1125 }
1126
1127 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet &)
1128 {
1129 Debug(net, 9, "Client::Receive_SERVER_NEWGAME()");
1130
1131 /* Only when we're trying to join we really
1132 * care about the server shutting down. */
1133 if (this->status >= STATUS_JOIN) {
1134 /* To throttle the reconnects a bit, every clients waits its
1135 * Client ID modulo 16 + 1 (value 0 means no reconnect).
1136 * This way reconnects should be spread out a bit. */
1137 _network_reconnect = _network_own_client_id % 16 + 1;
1138 ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_REBOOT, INVALID_STRING_ID, WL_CRITICAL);
1139 }
1140
1141 if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
1142
1143 return NETWORK_RECV_STATUS_SERVER_ERROR;
1144 }
1145
1146 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON(Packet &p)
1147 {
1148 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1149
1150 Debug(net, 9, "Client::Receive_SERVER_RCON()");
1151
1152 TextColour colour_code = (TextColour)p.Recv_uint16();
1153 if (!IsValidConsoleColour(colour_code)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1154
1155 std::string rcon_out = p.Recv_string(NETWORK_RCONCOMMAND_LENGTH);
1156
1157 IConsolePrint(colour_code, rcon_out);
1158
1159 return NETWORK_RECV_STATUS_OKAY;
1160 }
1161
1162 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet &p)
1163 {
1164 if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1165
1166 /* Nothing more in this packet... */
1167 ClientID client_id = (ClientID)p.Recv_uint32();
1168 CompanyID company_id = (CompanyID)p.Recv_uint8();
1169
1170 Debug(net, 9, "Client::Receive_SERVER_MOVE(): client_id={}, comapny_id={}", client_id, company_id);
1171
1172 if (client_id == 0) {
1173 /* definitely an invalid client id, debug message and do nothing. */
1174 Debug(net, 1, "Received invalid client index = 0");
1175 return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1176 }
1177
1178 const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
1179 /* Just make sure we do not try to use a client_index that does not exist */
1180 if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY;
1181
1182 /* if not valid player, force spectator, else check player exists */
1183 if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
1184
1185 if (client_id == _network_own_client_id) {
1186 SetLocalCompany(company_id);
1187 }
1188
1189 return NETWORK_RECV_STATUS_OKAY;
1190 }
1191
1192 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet &p)
1193 {
1194 if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1195
1196 _network_server_max_companies = p.Recv_uint8();
1197 _network_server_name = p.Recv_string(NETWORK_NAME_LENGTH);
1198 SetWindowClassesDirty(WC_CLIENT_LIST);
1199
1200 Debug(net, 9, "Client::Receive_SERVER_CONFIG_UPDATE(): max_companies={}", _network_server_max_companies);
1201
1202 return NETWORK_RECV_STATUS_OKAY;
1203 }
1204
1205 NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet &p)
1206 {
1207 if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1208
1209 static_assert(sizeof(_network_company_passworded) <= sizeof(uint16_t));
1210 _network_company_passworded = p.Recv_uint16();
1211 SetWindowClassesDirty(WC_COMPANY);
1212
1213 Debug(net, 9, "Client::Receive_SERVER_COMPANY_UPDATE()");
1214
1215 return NETWORK_RECV_STATUS_OKAY;
1216 }
1217
1221 void ClientNetworkGameSocketHandler::CheckConnection()
1222 {
1223 /* Only once we're authorized we can expect a steady stream of packets. */
1224 if (this->status < STATUS_AUTHORIZED) return;
1225
1226 /* 5 seconds are roughly twice the server's "you're slow" threshold (1 game day). */
1227 std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->last_packet;
1228 if (lag < std::chrono::seconds(5)) return;
1229
1230 /* 20 seconds are (way) more than 4 game days after which
1231 * the server will forcefully disconnect you. */
1232 if (lag > std::chrono::seconds(20)) {
1233 this->NetworkGameSocketHandler::CloseConnection();
1234 return;
1235 }
1236
1237 /* Prevent showing the lag message every tick; just update it when needed. */
1238 static std::chrono::steady_clock::duration last_lag = {};
1239 if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag)) return;
1240
1241 last_lag = lag;
1242 SetDParam(0, std::chrono::duration_cast<std::chrono::seconds>(lag).count());
1243 ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO);
1244 }
1245
1246
1248 void NetworkClient_Connected()
1249 {
1250 /* Set the frame-counter to 0 so nothing happens till we are ready */
1251 _frame_counter = 0;
1252 _frame_counter_server = 0;
1253 last_ack_frame = 0;
1254
1255 Debug(net, 9, "Client::NetworkClient_Connected()");
1256
1257 /* Request the game-info */
1258 MyClient::SendJoin();
1259 }
1260
1266 void NetworkClientSendRcon(const std::string &password, const std::string &command)
1267 {
1268 MyClient::SendRCon(password, command);
1269 }
1270
1277 void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
1278 {
1279 MyClient::SendMove(company_id, pass);
1280 }
1281
1286 void NetworkClientsToSpectators(CompanyID cid)
1287 {
1288 Backup<CompanyID> cur_company(_current_company, FILE_LINE);
1289 /* If our company is changing owner, go to spectators */
1290 if (cid == _local_company) SetLocalCompany(COMPANY_SPECTATOR);
1291
1292 for (NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
1293 if (ci->client_playas != cid) continue;
1294 NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR, CC_DEFAULT, false, ci->client_name);
1295 ci->client_playas = COMPANY_SPECTATOR;
1296 }
1297
1298 cur_company.Restore();
1299 }
1300
1308 bool NetworkIsValidClientName(const std::string_view client_name)
1309 {
1310 if (client_name.empty()) return false;
1311 if (client_name[0] == ' ') return false;
1312 return true;
1313 }
1314
1330 bool NetworkValidateClientName(std::string &client_name)
1331 {
1332 StrTrimInPlace(client_name);
1333 if (NetworkIsValidClientName(client_name)) return true;
1334
1335 ShowErrorMessage(STR_NETWORK_ERROR_BAD_PLAYER_NAME, INVALID_STRING_ID, WL_ERROR);
1336 return false;
1337 }
1338
1346 bool NetworkValidateOurClientName()
1347 {
1348 return NetworkValidateClientName(_settings_client.network.client_name);
1349 }
1350
1355 void NetworkUpdateClientName(const std::string &client_name)
1356 {
1357 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
1358 if (ci == nullptr) return;
1359
1360 /* Don't change the name if it is the same as the old name */
1361 if (client_name.compare(ci->client_name) != 0) {
1362 if (!_network_server) {
1363 MyClient::SendSetName(client_name);
1364 } else {
1365 /* Copy to a temporary buffer so no #n gets added after our name in the settings when there are duplicate names. */
1366 std::string temporary_name = client_name;
1367 if (NetworkMakeClientNameUnique(temporary_name)) {
1368 NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, temporary_name);
1369 ci->client_name = temporary_name;
1370 NetworkUpdateClientInfo(CLIENT_ID_SERVER);
1371 }
1372 }
1373 }
1374 }
1375
1384 void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
1385 {
1386 MyClient::SendChat(action, type, dest, msg, data);
1387 }
1388
1393 void NetworkClientSetCompanyPassword(const std::string &password)
1394 {
1395 MyClient::SendSetPassword(password);
1396 }
1397
1403 bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
1404 {
1405 /* Only companies actually playing can speak to team. Eg spectators cannot */
1406 if (!_settings_client.gui.prefer_teamchat || !Company::IsValidID(cio->client_playas)) return false;
1407
1408 for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
1409 if (ci->client_playas == cio->client_playas && ci != cio) return true;
1410 }
1411
1412 return false;
1413 }
1414
1419 uint NetworkMaxCompaniesAllowed()
1420 {
1421 return _network_server ? _settings_client.network.max_companies : _network_server_max_companies;
1422 }
1423
1428 bool NetworkMaxCompaniesReached()
1429 {
1430 return Company::GetNumItems() >= NetworkMaxCompaniesAllowed();
1431 }
Packet::Recv_uint64
uint64_t Recv_uint64()
Read a 64 bits integer from the packet.
Definition: packet.cpp:338
NetworkClientSendRcon
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
Definition: network_client.cpp:1266
NetworkGameSocketHandler::ReceiveCommand
const char * ReceiveCommand(Packet &p, CommandPacket &cp)
Receives a command from the network.
Definition: network_command.cpp:363
ClientNetworkGameSocketHandler::SendNewGRFsOk
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
Definition: network_client.cpp:358
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3204
NETWORK_RECV_STATUS_CLIENT_QUIT
@ NETWORK_RECV_STATUS_CLIENT_QUIT
The connection is lost gracefully. Other clients are already informed of this leaving client.
Definition: core.h:27
ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet &p) override
Sends that all data of the map are sent to the client:
Definition: network_client.cpp:853
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:88
ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT
NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet &p) override
Sends a chat-packet for external source to the client: string Name of the source this message came fr...
Definition: network_client.cpp:1035
ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet &p) override
Indication to the client that the server needs a game password.
Definition: network_client.cpp:730
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3086
NetworkValidateOurClientName
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
Definition: network_client.cpp:1346
NetworkTCPSocketHandler::SendPacket
virtual void SendPacket(std::unique_ptr< Packet > &&packet)
This function puts the packet in the send-queue and it is send as soon as possible.
Definition: tcp.cpp:68
ClientNetworkGameSocketHandler::Receive_SERVER_MOVE
NetworkRecvStatus Receive_SERVER_MOVE(Packet &p) override
Move a client from one company into another: uint32_t ID of the client.
Definition: network_client.cpp:1162
NetworkGameSocketHandler::ReceivePackets
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Definition: tcp_game.cpp:136
CSleep
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
Definition: thread.h:24
NetworkValidateClientName
bool NetworkValidateClientName(std::string &client_name)
Trim the given client name in place, i.e.
Definition: network_client.cpp:1330
NETWORK_RECV_STATUS_DESYNC
@ NETWORK_RECV_STATUS_DESYNC
A desync did occur.
Definition: core.h:24
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
ClientNetworkGameSocketHandler::STATUS_AUTH_COMPANY
@ STATUS_AUTH_COMPANY
Last action was requesting company password.
Definition: network_client.h:28
NetworkClientInfo::client_name
std::string client_name
Name of the client.
Definition: network_base.h:26
NetworkJoinInfo::company_password
std::string company_password
The password of the company to join.
Definition: network_client.h:116
ClientNetworkGameSocketHandler::savegame
std::shared_ptr< struct PacketReader > savegame
Packet reader for reading the savegame.
Definition: network_client.h:19
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
PacketReader::AddPacket
void AddPacket(Packet &p)
Add a packet to this buffer.
Definition: network_client.cpp:84
CommandPacket::frame
uint32_t frame
the frame in which this packet is executed
Definition: network_internal.h:99
NETWORK_NAME_LENGTH
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
Definition: config.h:53
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
ClientNetworkEmergencySave
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
Definition: network_client.cpp:135
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1277
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_network_server
bool _network_server
network-server is active
Definition: network.cpp:66
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler
ClientNetworkGameSocketHandler(SOCKET s, const std::string &connection_string)
Create a new socket for the client side of the game connection.
Definition: network_client.cpp:146
PACKET_CLIENT_COMMAND
@ PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
Definition: tcp_game.h:99
_network_company_passworded
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
Definition: network.cpp:88
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:102
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Definition: network_client.cpp:1403
ClientNetworkGameSocketHandler::Receive_SERVER_QUIT
NetworkRecvStatus Receive_SERVER_QUIT(Packet &p) override
Notification that a client left the game: uint32_t ID of the client.
Definition: network_client.cpp:1072
ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p) override
Send information about a client: uint32_t ID of the client (always unique on a server.
Definition: network_client.cpp:592
NetworkGameSocketHandler::last_packet
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
Definition: tcp_game.h:500
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition: window_type.h:478
ClientNetworkGameSocketHandler::CheckConnection
void CheckConnection()
Check the connection's state, i.e.
Definition: network_client.cpp:1221
NetworkJoinInfo::server_password
std::string server_password
The password of the server to join.
Definition: network_client.h:115
NetworkGameSocketHandler::SetInfo
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
Definition: tcp_game.h:515
ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p) override
Indication to the client that the server needs a company password: uint32_t Generation seed.
Definition: network_client.cpp:747
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition: network_server.cpp:1533
ClientNetworkGameSocketHandler::GameLoop
static bool GameLoop()
Actual game loop for the client.
Definition: network_client.cpp:268
PacketReader::block
byte ** block
The block we're reading from/writing to.
Definition: network_client.cpp:49
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Definition: config.h:63
ClientNetworkGameSocketHandler::SendChat
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat-packet over the network.
Definition: network_client.cpp:450
ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet &p) override
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
Definition: network_client.cpp:839
SetLocalCompany
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
Definition: company_cmd.cpp:115
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition: fileio_type.h:31
NetworkTCPSocketHandler::sock
SOCKET sock
The socket currently connected to.
Definition: tcp.h:38
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
PacketReader::written_bytes
size_t written_bytes
The total number of bytes we've written.
Definition: network_client.cpp:50
PACKET_CLIENT_ERROR
@ PACKET_CLIENT_ERROR
A client reports an error to the server.
Definition: tcp_game.h:124
ClientNetworkGameSocketHandler::SendCommand
static NetworkRecvStatus SendCommand(const CommandPacket &cp)
Send a command to the server.
Definition: network_client.cpp:438
_random
Randomizer _random
Random used in the game state calculations.
Definition: random_func.cpp:37
TimerGameEconomy::date_fract
static DateFract date_fract
Fractional part of the day.
Definition: timer_game_economy.h:38
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
PACKET_CLIENT_QUIT
@ PACKET_CLIENT_QUIT
A client tells the server it is going to quit.
Definition: tcp_game.h:122
network_gui.h
_network_join_status
NetworkJoinStatus _network_join_status
The status of joining.
Definition: network_gui.cpp:2101
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:369
GetNetworkErrorMsg
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Definition: network.cpp:304
_network_server_name
std::string _network_server_name
The current name of the server you are on.
Definition: network_client.cpp:324
ClientNetworkGameSocketHandler::my_client
static ClientNetworkGameSocketHandler * my_client
This is us!
Definition: network_client.h:41
ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet &p) override
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
Definition: network_client.cpp:1192
ClientNetworkGameSocketHandler::Receive_SERVER_SYNC
NetworkRecvStatus Receive_SERVER_SYNC(Packet &p) override
Sends a sync-check to the client: uint32_t Frame counter.
Definition: network_client.cpp:948
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ClientNetworkGameSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
Definition: network_client.cpp:161
NetworkGameSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp_game.h:141
PacketReader::Read
size_t Read(byte *rbuf, size_t size) override
Read a given number of bytes from the savegame.
Definition: network_client.cpp:99
ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet &p) override
Sends the size of the map to the client.
Definition: network_client.cpp:826
ClientNetworkGameSocketHandler::Receive_SERVER_ERROR
NetworkRecvStatus Receive_SERVER_ERROR(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
Definition: network_client.cpp:650
CC_DEFAULT
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
PacketReader
Read some packets, and when do use that data as initial load filter.
Definition: network_client.cpp:43
_network_first_time
bool _network_first_time
Whether we have finished joining or not.
Definition: network.cpp:87
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
network_base.h
PacketReader::read_bytes
size_t read_bytes
The total number of read bytes.
Definition: network_client.cpp:51
PACKET_CLIENT_JOIN
@ PACKET_CLIENT_JOIN
The client telling the server it wants to join.
Definition: tcp_game.h:37
Packet::CanReadFromPacket
bool CanReadFromPacket(size_t bytes_to_read, bool close_connection=false)
Is it safe to read from the packet, i.e.
Definition: packet.cpp:204
Packet::Recv_string
std::string Recv_string(size_t length, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads characters (bytes) from the packet until it finds a '\0', or reaches a maximum of length charac...
Definition: packet.cpp:383
ClientNetworkGameSocketHandler::SendJoin
static NetworkRecvStatus SendJoin()
Make sure the server ID length is the same as a md5 hash.
Definition: network_client.cpp:337
_sync_seed_1
uint32_t _sync_seed_1
Seed to compare during sync checks.
Definition: network.cpp:82
ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p) override
Let the clients know that the server is closing.
Definition: network_client.cpp:1112
ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet &p) override
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of ...
Definition: network_client.cpp:1053
_password_game_seed
static uint32_t _password_game_seed
One bit of 'entropy' used to generate a salt for the company passwords.
Definition: network_client.cpp:317
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:120
NetworkJoinInfo::company
CompanyID company
The company to join.
Definition: network_client.h:114
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
Packet::TransferOutWithLimit
ssize_t TransferOutWithLimit(F transfer_function, size_t limit, D destination, Args &&... args)
Transfer data from the packet to the given function.
Definition: packet.h:106
ClientNetworkGameSocketHandler::SendMove
static NetworkRecvStatus SendMove(CompanyID company, const std::string &password)
Ask the server to move us.
Definition: network_client.cpp:542
ClientNetworkGameSocketHandler::STATUS_MAP
@ STATUS_MAP
The client is downloading the map.
Definition: network_client.h:31
PACKET_CLIENT_RCON
@ PACKET_CLIENT_RCON
Client asks the server to execute some command.
Definition: tcp_game.h:108
ClientNetworkGameSocketHandler::SendCompanyPassword
static NetworkRecvStatus SendCompanyPassword(const std::string &password)
Set the company password as requested.
Definition: network_client.cpp:385
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:328
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:34
GameSessionStats::start_time
std::chrono::steady_clock::time_point start_time
Time when the current game was started.
Definition: openttd.h:56
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition: fileio_type.h:49
ClientNetworkGameSocketHandler::Receive_SERVER_FULL
NetworkRecvStatus Receive_SERVER_FULL(Packet &p) override
Notification that the server is full.
Definition: network_client.cpp:569
PacketReader::CHUNK
static const size_t CHUNK
32 KiB chunks of memory.
Definition: network_client.cpp:44
ClientNetworkGameSocketHandler::SendSetName
static NetworkRecvStatus SendSetName(const std::string &name)
Tell the server that we like to change the name of the client.
Definition: network_client.cpp:497
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:96
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
PacketReader::blocks
std::vector< byte * > blocks
Buffer with blocks of allocated memory.
Definition: network_client.cpp:46
NETWORK_RECV_STATUS_NEWGRF_MISMATCH
@ NETWORK_RECV_STATUS_NEWGRF_MISMATCH
We did not have the required NewGRFs.
Definition: core.h:25
NetworkMaxCompaniesReached
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
Definition: network_client.cpp:1428
NETWORK_RECV_STATUS_SERVER_FULL
@ NETWORK_RECV_STATUS_SERVER_FULL
The server is full.
Definition: core.h:30
Packet::Recv_uint32
uint32_t Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:321
ClientNetworkGameSocketHandler::IsConnected
static bool IsConnected()
Check whether the client is actually connected (and in the game).
Definition: network_client.cpp:557
free
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:382
StrTrimInPlace
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
Definition: string.cpp:288
NETWORK_RECV_STATUS_SERVER_ERROR
@ NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
Definition: core.h:29
GRFIdentifier::md5sum
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
_password_server_id
static std::string _password_server_id
The other bit of 'entropy' used to generate a salt for the company passwords.
Definition: network_client.cpp:319
NETWORK_RECV_STATUS_SERVER_BANNED
@ NETWORK_RECV_STATUS_SERVER_BANNED
The server has banned us.
Definition: core.h:31
last_ack_frame
static uint32_t last_ack_frame
Last frame we performed an ack.
Definition: network_client.cpp:314
NetworkUpdateClientName
void NetworkUpdateClientName(const std::string &client_name)
Send the server our name as callback from the setting.
Definition: network_client.cpp:1355
NetworkClient_Connected
void NetworkClient_Connected()
Is called after a client is connected to the server.
Definition: network_client.cpp:1248
GameSessionStats::savegame_size
std::optional< size_t > savegame_size
Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
Definition: openttd.h:58
PacketReader::Reset
void Reset() override
Reset this filter to read from the beginning of the file.
Definition: network_client.cpp:121
NetworkClientsToSpectators
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
Definition: network_client.cpp:1286
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
ClientNetworkGameSocketHandler::STATUS_JOIN
@ STATUS_JOIN
We are trying to join a server.
Definition: network_client.h:25
NetworkSocketHandler::MarkClosed
void MarkClosed()
Mark the connection as closed.
Definition: core.h:60
NETWORK_COMPANY_PASSWORD
@ NETWORK_COMPANY_PASSWORD
The password of the company.
Definition: network_type.h:84
NetworkSettings::client_name
std::string client_name
name of the player (as client)
Definition: settings_type.h:318
ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p) override
Let the clients know that the server is loading a new map.
Definition: network_client.cpp:1127
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition: console_gui.cpp:488
NETWORK_RECV_STATUS_CLOSE_QUERY
@ NETWORK_RECV_STATUS_CLOSE_QUERY
Done querying the server.
Definition: core.h:32
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
ClientNetworkGameSocketHandler::SendRCon
static NetworkRecvStatus SendRCon(const std::string &password, const std::string &command)
Send a console command.
Definition: network_client.cpp:526
NETWORK_SERVER_ID_LENGTH
static const uint NETWORK_SERVER_ID_LENGTH
The maximum length of the network id of the servers, in bytes including '\0'.
Definition: config.h:57
ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet &p) override
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is re...
Definition: network_client.cpp:697
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:65
PACKET_CLIENT_SET_PASSWORD
@ PACKET_CLIENT_SET_PASSWORD
A client (re)sets its company's password.
Definition: tcp_game.h:116
ClientNetworkGameSocketHandler::STATUS_MAP_WAIT
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
Definition: network_client.h:30
network_client.h
CommandPacket::my_cmd
bool my_cmd
did the command originate from "me"
Definition: network_internal.h:100
DoAutoOrNetsave
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
Definition: saveload.cpp:3143
Packet
Internal entity of a packet.
Definition: packet.h:42
GameMode
GameMode
Mode which defines the state of the game.
Definition: openttd.h:18
PacketReader::buf
byte * buf
Buffer we're going to write to/read from.
Definition: network_client.cpp:47
_game_session_stats
GameSessionStats _game_session_stats
Statistics about the current session.
Definition: gfx.cpp:50
ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p) override
Update the clients knowledge of which company is password protected: uint16_t Bitwise representation ...
Definition: network_client.cpp:1205
SocialIntegration::EventEnterMultiplayer
static void EventEnterMultiplayer(uint map_width, uint map_height)
Event: user entered a multiplayer game.
Definition: social_integration.cpp:234
GUISettings::prefer_teamchat
bool prefer_teamchat
choose the chat message target with <ENTER>, true=all clients, false=your team
Definition: settings_type.h:149
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:71
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
SafeLoad
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr< LoadFilter > lf=nullptr)
Load the specified savegame but on error do different things.
Definition: openttd.cpp:973
ClientNetworkGameSocketHandler::Receive
static bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
Definition: network_client.cpp:243
CCA_NEW
@ CCA_NEW
Create a new company.
Definition: company_type.h:68
NetworkGameSocketHandler::GetInfo
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
Definition: tcp_game.h:525
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:48
NetworkSocketHandler::HasClientQuit
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
Definition: core.h:68
_frame_counter_server
uint32_t _frame_counter_server
The frame_counter of the server, if in network-mode.
Definition: network.cpp:77
NetworkTCPSocketHandler::SendPackets
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
Definition: tcp.cpp:86
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
NETWORK_RCONCOMMAND_LENGTH
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
Definition: config.h:61
NetworkTCPSocketHandler::CanSendReceive
bool CanSendReceive()
Check whether this socket can send or receive something.
Definition: tcp.cpp:200
Pool::PoolItem<&_networkclientinfo_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
FiosNumberedSaveName
A savegame name automatically numbered.
Definition: fios.h:129
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:28
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:49
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:369
PacketReader::TransferOutMemCopy
static ssize_t TransferOutMemCopy(PacketReader *destination, const char *source, size_t amount)
Simple wrapper around fwrite to be able to pass it to Packet's TransferOut.
Definition: network_client.cpp:72
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
Packet::Recv_bool
bool Recv_bool()
Read a boolean from the packet.
Definition: packet.cpp:283
PACKET_CLIENT_GAME_PASSWORD
@ PACKET_CLIENT_GAME_PASSWORD
Clients sends the (hashed) game password.
Definition: tcp_game.h:68
GetDrawStringCompanyColour
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
Definition: company_cmd.cpp:147
NetworkClientSetCompanyPassword
void NetworkClientSetCompanyPassword(const std::string &password)
Set/Reset company password on the client side.
Definition: network_client.cpp:1393
_frame_counter
uint32_t _frame_counter
The current frame.
Definition: network.cpp:79
PACKET_CLIENT_GETMAP
@ PACKET_CLIENT_GETMAP
Client requests the actual map.
Definition: tcp_game.h:77
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition: company_type.h:63
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:91
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:126
ClientNetworkGameSocketHandler::STATUS_AUTHORIZED
@ STATUS_AUTHORIZED
The client is authorized at the server.
Definition: network_client.h:29
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
_network_join_waiting
uint8_t _network_join_waiting
The number of clients waiting in front of us.
Definition: network_gui.cpp:2102
NetworkJoinInfo
Information required to join a server.
Definition: network_client.h:111
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:22
ClientNetworkGameSocketHandler::SendError
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
Definition: network_client.cpp:467
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:485
PACKET_CLIENT_MOVE
@ PACKET_CLIENT_MOVE
A client would like to be moved to another company.
Definition: tcp_game.h:112
PACKET_CLIENT_CHAT
@ PACKET_CLIENT_CHAT
Client said something that should be distributed.
Definition: tcp_game.h:103
ClientNetworkGameSocketHandler::ClientError
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
Definition: network_client.cpp:189
ClientNetworkGameSocketHandler::token
byte token
The token we need to send back to the server to prove we're the right client.
Definition: network_client.h:20
_network_join_bytes_total
uint32_t _network_join_bytes_total
The total number of bytes to download.
Definition: network_gui.cpp:2104
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
NetworkSettings::max_companies
uint8_t max_companies
maximum amount of companies
Definition: settings_type.h:326
Pool::PoolItem<&_networkclientinfo_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:309
ClientNetworkGameSocketHandler::STATUS_AUTH_GAME
@ STATUS_AUTH_GAME
Last action was requesting game (server) password.
Definition: network_client.h:27
PacketReader::bufe
byte * bufe
End of the buffer we write to/read from.
Definition: network_client.cpp:48
ClientNetworkGameSocketHandler::Receive_SERVER_WAIT
NetworkRecvStatus Receive_SERVER_WAIT(Packet &p) override
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in...
Definition: network_client.cpp:786
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
ClientNetworkGameSocketHandler::NetworkExecuteLocalCommandQueue
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
Definition: network_command.cpp:245
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:50
ClientNetworkGameSocketHandler::Receive_SERVER_RCON
NetworkRecvStatus Receive_SERVER_RCON(Packet &p) override
Send the result of an issues RCon command back to the client: uint16_t Colour code.
Definition: network_client.cpp:1146
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler
~ClientNetworkGameSocketHandler()
Clear whatever we assigned.
Definition: network_client.cpp:153
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
PACKET_CLIENT_MAP_OK
@ PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
Definition: tcp_game.h:83
PACKET_CLIENT_COMPANY_PASSWORD
@ PACKET_CLIENT_COMPANY_PASSWORD
Client sends the (hashed) company password.
Definition: tcp_game.h:70
NetworkMaxCompaniesAllowed
uint NetworkMaxCompaniesAllowed()
Get the maximum number of companies that are allowed by the server.
Definition: network_client.cpp:1419
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:33
ClientNetworkGameSocketHandler
Class for handling the client side of the game connection.
Definition: network_client.h:16
PACKET_CLIENT_NEWGRFS_CHECKED
@ PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
Definition: tcp_game.h:64
ClientNetworkGameSocketHandler::Receive_SERVER_FRAME
NetworkRecvStatus Receive_SERVER_FRAME(Packet &p) override
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how...
Definition: network_client.cpp:913
NetworkGameSocketHandler::incoming_queue
CommandQueue incoming_queue
The command-queue awaiting handling.
Definition: tcp_game.h:499
network.h
NetworkGameSocketHandler::client_id
ClientID client_id
Client identifier.
Definition: tcp_game.h:496
CommandHelper
Definition: command_func.h:93
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:320
ClientNetworkGameSocketHandler::SendGetMap
static NetworkRecvStatus SendGetMap()
Request the map from the server.
Definition: network_client.cpp:396
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:14
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:636
GRFIdentifier::grfid
uint32_t grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
Randomizer::state
uint32_t state[2]
The state of the randomizer.
Definition: random_func.hpp:23
ClientNetworkGameSocketHandler::SendMapOk
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
Definition: network_client.cpp:409
_sync_frame
uint32_t _sync_frame
The frame to perform the sync check.
Definition: network.cpp:86
NetworkGameSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
Definition: tcp_game.cpp:43
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME
NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p) override
The client is joined and ready to receive their map: uint32_t Own client ID.
Definition: network_client.cpp:768
GenerateCompanyPasswordHash
std::string GenerateCompanyPasswordHash(const std::string &password, const std::string &password_server_id, uint32_t password_game_seed)
Hash the given password using server ID and game seed.
Definition: network.cpp:183
ClientNetworkGameSocketHandler::SendAck
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
Definition: network_client.cpp:422
NETWORK_RECV_STATUS_OKAY
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
Definition: core.h:23
NetworkClientSendChat
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat message.
Definition: network_client.cpp:1384
network_gamelist.h
PACKET_CLIENT_ACK
@ PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
Definition: tcp_game.h:95
PacketReader::PacketReader
PacketReader()
Initialise everything.
Definition: network_client.cpp:54
PACKET_CLIENT_SET_NAME
@ PACKET_CLIENT_SET_NAME
A client changes its name.
Definition: tcp_game.h:117
ClientNetworkGameSocketHandler::SendQuit
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
Definition: network_client.cpp:511
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:75
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
ClientNetworkGameSocketHandler::STATUS_ACTIVE
@ STATUS_ACTIVE
The client is active within in the game.
Definition: network_client.h:32
ClientNetworkGameSocketHandler::status
ServerStatus status
Status of the connection with the server.
Definition: network_client.h:36
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition: openttd.cpp:1434
ClientNetworkGameSocketHandler::Receive_SERVER_CHAT
NetworkRecvStatus Receive_SERVER_CHAT(Packet &p) override
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
Definition: network_client.cpp:984
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:192
Packet::Recv_uint16
uint16_t Recv_uint16()
Read a 16 bits integer from the packet.
Definition: packet.cpp:306
NETWORK_RECV_STATUS_SAVEGAME
@ NETWORK_RECV_STATUS_SAVEGAME
Something went wrong (down)loading the savegame.
Definition: core.h:26
ClientNetworkGameSocketHandler::SendGamePassword
static NetworkRecvStatus SendGamePassword(const std::string &password)
Set the game password as requested.
Definition: network_client.cpp:371
_network_server_max_companies
static uint8_t _network_server_max_companies
Maximum number of companies of the currently joined server.
Definition: network_client.cpp:322
WN_NETWORK_STATUS_WINDOW_JOIN
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
Definition: window_type.h:39
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
NetworkMakeClientNameUnique
bool NetworkMakeClientNameUnique(std::string &new_name)
Check whether a name is unique, and otherwise try to make it unique.
Definition: network_server.cpp:1621
Packet::RemainingBytesToTransfer
size_t RemainingBytesToTransfer() const
Get the amount of bytes that are still available for the Transfer functions.
Definition: packet.cpp:405
_network_join
NetworkJoinInfo _network_join
Information about the game to join to.
Definition: network_client.cpp:327
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3112
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:690
_network_join_bytes
uint32_t _network_join_bytes
The number of bytes we already downloaded.
Definition: network_gui.cpp:2103
ClientNetworkGameSocketHandler::Receive_SERVER_JOIN
NetworkRecvStatus Receive_SERVER_JOIN(Packet &p) override
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
Definition: network_client.cpp:1094
ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet &p) override
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
Definition: network_client.cpp:802
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:51
ClientNetworkGameSocketHandler::SendSetPassword
static NetworkRecvStatus SendSetPassword(const std::string &password)
Tell the server that we like to change the password of the company.
Definition: network_client.cpp:482
ClientNetworkGameSocketHandler::Send
static void Send()
Send the packets of this socket handler.
Definition: network_client.cpp:258
NetworkErrorCode
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:122
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
NetworkIsValidClientName
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Definition: network_client.cpp:1308
_frame_counter_max
uint32_t _frame_counter_max
To where we may go with our clients.
Definition: network.cpp:78
_network_reconnect
uint8_t _network_reconnect
Reconnect timeout.
Definition: network.cpp:73
Packet::Recv_uint8
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:292
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:27
NETWORK_GAME_PASSWORD
@ NETWORK_GAME_PASSWORD
The password of the game.
Definition: network_type.h:83
ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND
NetworkRecvStatus Receive_SERVER_COMMAND(Packet &p) override
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
Definition: network_client.cpp:963
NETWORK_RECV_STATUS_MALFORMED_PACKET
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
Definition: core.h:28
CommandPacket::cmd
Commands cmd
command being executed.
Definition: network_internal.h:102
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37
IConsolePrint
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:91
ClientNetworkGameSocketHandler::Receive_SERVER_BANNED
NetworkRecvStatus Receive_SERVER_BANNED(Packet &p) override
Notification that the client trying to join is banned.
Definition: network_client.cpp:579