OpenTTD Source  1.11.2
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 "../core/random_func.hpp"
22 #include "../date_func.h"
23 #include "../gfx_func.h"
24 #include "../error.h"
25 #include "../rev.h"
26 #include "core/game_info.h"
27 #include "network.h"
28 #include "network_base.h"
29 #include "network_client.h"
30 #include "../core/backup_type.hpp"
31 #include "../thread.h"
32 
33 #include "table/strings.h"
34 
35 #include "../safeguards.h"
36 
37 /* This file handles all the client-commands */
38 
39 
42  static const size_t CHUNK = 32 * 1024;
43 
44  std::vector<byte *> blocks;
45  byte *buf;
46  byte *bufe;
47  byte **block;
48  size_t written_bytes;
49  size_t read_bytes;
50 
52  PacketReader() : LoadFilter(nullptr), buf(nullptr), bufe(nullptr), block(nullptr), written_bytes(0), read_bytes(0)
53  {
54  }
55 
56  ~PacketReader() override
57  {
58  for (auto p : this->blocks) {
59  free(p);
60  }
61  }
62 
67  void AddPacket(const Packet *p)
68  {
69  assert(this->read_bytes == 0);
70 
71  size_t in_packet = p->size - p->pos;
72  size_t to_write = std::min<size_t>(this->bufe - this->buf, in_packet);
73  const byte *pbuf = p->buffer + p->pos;
74 
75  this->written_bytes += in_packet;
76  if (to_write != 0) {
77  memcpy(this->buf, pbuf, to_write);
78  this->buf += to_write;
79  }
80 
81  /* Did everything fit in the current chunk, then we're done. */
82  if (to_write == in_packet) return;
83 
84  /* Allocate a new chunk and add the remaining data. */
85  pbuf += to_write;
86  to_write = in_packet - to_write;
87  this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
88  this->bufe = this->buf + CHUNK;
89 
90  memcpy(this->buf, pbuf, to_write);
91  this->buf += to_write;
92  }
93 
94  size_t Read(byte *rbuf, size_t size) override
95  {
96  /* Limit the amount to read to whatever we still have. */
97  size_t ret_size = size = std::min(this->written_bytes - this->read_bytes, size);
98  this->read_bytes += ret_size;
99  const byte *rbufe = rbuf + ret_size;
100 
101  while (rbuf != rbufe) {
102  if (this->buf == this->bufe) {
103  this->buf = *this->block++;
104  this->bufe = this->buf + CHUNK;
105  }
106 
107  size_t to_write = std::min(this->bufe - this->buf, rbufe - rbuf);
108  memcpy(rbuf, this->buf, to_write);
109  rbuf += to_write;
110  this->buf += to_write;
111  }
112 
113  return ret_size;
114  }
115 
116  void Reset() override
117  {
118  this->read_bytes = 0;
119 
120  this->block = this->blocks.data();
121  this->buf = *this->block++;
122  this->bufe = this->buf + CHUNK;
123  }
124 };
125 
126 
131 {
133  if (!_networking) return;
134 
135  const char *filename = "netsave.sav";
136  DEBUG(net, 0, "Client: Performing emergency save (%s)", filename);
137  SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
138 }
139 
140 
145 ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s), savegame(nullptr), status(STATUS_INACTIVE)
146 {
149 }
150 
153 {
156 
157  delete this->savegame;
158 }
159 
161 {
162  assert(status != NETWORK_RECV_STATUS_OKAY);
163  /*
164  * Sending a message just before leaving the game calls cs->SendPackets.
165  * This might invoke this function, which means that when we close the
166  * connection after cs->SendPackets we will close an already closed
167  * connection. This handles that case gracefully without having to make
168  * that code any more complex or more aware of the validity of the socket.
169  */
170  if (this->sock == INVALID_SOCKET) return status;
171 
172  DEBUG(net, 1, "Closed client connection %d", this->client_id);
173 
174  this->SendPackets(true);
175 
176  /* Wait a number of ticks so our leave message can reach the server.
177  * This is especially needed for Windows servers as they seem to get
178  * the "socket is closed" message before receiving our leave message,
179  * which would trigger the server to close the connection as well. */
181 
182  delete this->GetInfo();
183  delete this;
184 
185  return status;
186 }
187 
193 {
194  /* First, send a CLIENT_ERROR to the server, so he knows we are
195  * disconnection (and why!) */
196  NetworkErrorCode errorno;
197 
198  /* We just want to close the connection.. */
199  if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
201  this->CloseConnection(res);
202  _networking = false;
203 
205  return;
206  }
207 
208  switch (res) {
209  case NETWORK_RECV_STATUS_DESYNC: errorno = NETWORK_ERROR_DESYNC; break;
210  case NETWORK_RECV_STATUS_SAVEGAME: errorno = NETWORK_ERROR_SAVEGAME_FAILED; break;
211  case NETWORK_RECV_STATUS_NEWGRF_MISMATCH: errorno = NETWORK_ERROR_NEWGRF_MISMATCH; break;
212  default: errorno = NETWORK_ERROR_GENERAL; break;
213  }
214 
217  /* This means the server closed the connection. Emergency save is
218  * already created if this was appropriate during handling of the
219  * disconnect. */
220  this->CloseConnection(res);
221  } else {
222  /* This means we as client made a boo-boo. */
223  SendError(errorno);
224 
225  /* Close connection before we make an emergency save, as the save can
226  * take a bit of time; better that the server doesn't stall while we
227  * are doing the save, and already disconnects us. */
228  this->CloseConnection(res);
230  }
231 
233  _networking = false;
234 }
235 
236 
243 {
244  if (my_client->CanSendReceive()) {
246  if (res != NETWORK_RECV_STATUS_OKAY) {
247  /* The client made an error of which we can not recover.
248  * Close the connection and drop back to the main menu. */
249  my_client->ClientError(res);
250  return false;
251  }
252  }
253  return _networking;
254 }
255 
258 {
261 }
262 
268 {
269  _frame_counter++;
270 
272 
273  extern void StateGameLoop();
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", _date, _date_fract);
286  DEBUG(net, 0, "Sync error detected!");
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 he 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 (%d / %d)", _sync_frame, _frame_counter);
302  _sync_frame = 0;
303  }
304  }
305 
306  return true;
307 }
308 
309 
312 
314 static uint32 last_ack_frame;
315 
317 static uint32 _password_game_seed;
320 
325 
328 
330 const char *_network_join_server_password = nullptr;
332 const char *_network_join_company_password = nullptr;
333 
335 static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
336 
337 /***********
338  * Sending functions
339  * DEF_CLIENT_SEND_COMMAND has no parameters
340  ************/
341 
344 {
346  _network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO;
348 
350  my_client->SendPacket(p);
352 }
353 
356 {
358  _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING;
360 
361  Packet *p = new Packet(PACKET_CLIENT_JOIN);
363  p->Send_uint32(_openttd_newgrf_version);
364  p->Send_string(_settings_client.network.client_name); // Client name
365  p->Send_uint8 (_network_join_as); // PlayAs
366  p->Send_uint8 (NETLANG_ANY); // Language
367  my_client->SendPacket(p);
369 }
370 
373 {
375  my_client->SendPacket(p);
377 }
378 
384 {
386  p->Send_string(password);
387  my_client->SendPacket(p);
389 }
390 
396 {
399  my_client->SendPacket(p);
401 }
402 
405 {
407 
409  my_client->SendPacket(p);
411 }
412 
415 {
417 
419  my_client->SendPacket(p);
421 }
422 
425 {
426  Packet *p = new Packet(PACKET_CLIENT_ACK);
427 
429  p->Send_uint8 (my_client->token);
430  my_client->SendPacket(p);
432 }
433 
439 {
441  my_client->NetworkGameSocketHandler::SendCommand(p, cp);
442 
443  my_client->SendPacket(p);
445 }
446 
448 NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
449 {
450  Packet *p = new Packet(PACKET_CLIENT_CHAT);
451 
452  p->Send_uint8 (action);
453  p->Send_uint8 (type);
454  p->Send_uint32(dest);
455  p->Send_string(msg);
456  p->Send_uint64(data);
457 
458  my_client->SendPacket(p);
460 }
461 
464 {
466 
467  p->Send_uint8(errorno);
468  my_client->SendPacket(p);
470 }
471 
477 {
479 
481  my_client->SendPacket(p);
483 }
484 
490 {
492 
493  p->Send_string(name);
494  my_client->SendPacket(p);
496 }
497 
502 {
503  Packet *p = new Packet(PACKET_CLIENT_QUIT);
504 
505  my_client->SendPacket(p);
507 }
508 
514 NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const char *pass, const char *command)
515 {
516  Packet *p = new Packet(PACKET_CLIENT_RCON);
517  p->Send_string(pass);
518  p->Send_string(command);
519  my_client->SendPacket(p);
521 }
522 
529 {
530  Packet *p = new Packet(PACKET_CLIENT_MOVE);
531  p->Send_uint8(company);
533  my_client->SendPacket(p);
535 }
536 
542 {
543  return my_client != nullptr && my_client->status == STATUS_ACTIVE;
544 }
545 
546 
547 /***********
548  * Receiving functions
549  * DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
550  ************/
551 
552 extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
553 
555 {
556  /* We try to join a server which is full */
557  ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
559 
561 }
562 
564 {
565  /* We try to join a server where we are banned */
566  ShowErrorMessage(STR_NETWORK_ERROR_SERVER_BANNED, INVALID_STRING_ID, WL_CRITICAL);
568 
570 }
571 
573 {
575 
576  byte company_info_version = p->Recv_uint8();
577 
578  if (!this->HasClientQuit() && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
579  /* We have received all data... (there are no more packets coming) */
580  if (!p->Recv_bool()) return NETWORK_RECV_STATUS_CLOSE_QUERY;
581 
582  CompanyID current = (Owner)p->Recv_uint8();
583  if (current >= MAX_COMPANIES) return NETWORK_RECV_STATUS_CLOSE_QUERY;
584 
585  NetworkCompanyInfo *company_info = GetLobbyCompanyInfo(current);
586  if (company_info == nullptr) return NETWORK_RECV_STATUS_CLOSE_QUERY;
587 
588  p->Recv_string(company_info->company_name, sizeof(company_info->company_name));
589  company_info->inaugurated_year = p->Recv_uint32();
590  company_info->company_value = p->Recv_uint64();
591  company_info->money = p->Recv_uint64();
592  company_info->income = p->Recv_uint64();
593  company_info->performance = p->Recv_uint16();
594  company_info->use_password = p->Recv_bool();
595  for (uint i = 0; i < NETWORK_VEH_END; i++) {
596  company_info->num_vehicle[i] = p->Recv_uint16();
597  }
598  for (uint i = 0; i < NETWORK_VEH_END; i++) {
599  company_info->num_station[i] = p->Recv_uint16();
600  }
601  company_info->ai = p->Recv_bool();
602 
603  p->Recv_string(company_info->clients, sizeof(company_info->clients));
604 
606 
608  }
609 
611 }
612 
613 /* This packet contains info about the client (playas and name)
614  * as client we save this in NetworkClientInfo, linked via 'client_id'
615  * which is always an unique number on a server. */
617 {
618  NetworkClientInfo *ci;
620  CompanyID playas = (CompanyID)p->Recv_uint8();
621  char name[NETWORK_NAME_LENGTH];
622 
623  p->Recv_string(name, sizeof(name));
624 
626  if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
627 
629  if (ci != nullptr) {
630  if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
631  /* Client name changed, display the change */
632  NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, name);
633  } else if (playas != ci->client_playas) {
634  /* The client changed from client-player..
635  * Do not display that for now */
636  }
637 
638  /* Make sure we're in the company the server tells us to be in,
639  * for the rare case that we get moved while joining. */
641 
642  ci->client_playas = playas;
643  strecpy(ci->client_name, name, lastof(ci->client_name));
644 
646 
648  }
649 
650  /* There are at most as many ClientInfo as ClientSocket objects in a
651  * server. Having more info than a server can have means something
652  * has gone wrong somewhere, i.e. the server has more info than it
653  * has actual clients. That means the server is feeding us an invalid
654  * state. So, bail out! This server is broken. */
656 
657  /* We don't have this client_id yet, find an empty client_id, and put the data there */
658  ci = new NetworkClientInfo(client_id);
659  ci->client_playas = playas;
660  if (client_id == _network_own_client_id) this->SetInfo(ci);
661 
662  strecpy(ci->client_name, name, lastof(ci->client_name));
663 
665 
667 }
668 
670 {
671  static const StringID network_error_strings[] = {
672  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_GENERAL
673  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_DESYNC
674  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_SAVEGAME_FAILED
675  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_CONNECTION_LOST
676  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_ILLEGAL_PACKET
677  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NEWGRF_MISMATCH
678  STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_AUTHORIZED
679  STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_EXPECTED
680  STR_NETWORK_ERROR_WRONG_REVISION, // NETWORK_ERROR_WRONG_REVISION
681  STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NAME_IN_USE
682  STR_NETWORK_ERROR_WRONG_PASSWORD, // NETWORK_ERROR_WRONG_PASSWORD
683  STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_COMPANY_MISMATCH
684  STR_NETWORK_ERROR_KICKED, // NETWORK_ERROR_KICKED
685  STR_NETWORK_ERROR_CHEATER, // NETWORK_ERROR_CHEATER
686  STR_NETWORK_ERROR_SERVER_FULL, // NETWORK_ERROR_FULL
687  STR_NETWORK_ERROR_TOO_MANY_COMMANDS, // NETWORK_ERROR_TOO_MANY_COMMANDS
688  STR_NETWORK_ERROR_TIMEOUT_PASSWORD, // NETWORK_ERROR_TIMEOUT_PASSWORD
689  STR_NETWORK_ERROR_TIMEOUT_COMPUTER, // NETWORK_ERROR_TIMEOUT_COMPUTER
690  STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP
691  STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN
692  };
693  static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
694 
696 
697  StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
698  if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
699  /* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
700  if (error == NETWORK_ERROR_KICKED && p->CanReadFromPacket(1)) {
701  char kick_msg[255];
702  p->Recv_string(kick_msg, sizeof(kick_msg));
703  SetDParamStr(0, kick_msg);
704  ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
705  } else {
707  }
708 
709  /* Perform an emergency save if we had already entered the game */
711 
713 
715 }
716 
718 {
720 
721  uint grf_count = p->Recv_uint8();
723 
724  /* Check all GRFs */
725  for (; grf_count > 0; grf_count--) {
726  GRFIdentifier c;
728 
729  /* Check whether we know this GRF */
730  const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
731  if (f == nullptr) {
732  /* We do not know this GRF, bail out of initialization */
733  char buf[sizeof(c.md5sum) * 2 + 1];
734  md5sumToString(buf, lastof(buf), c.md5sum);
735  DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf);
737  }
738  }
739 
740  if (ret == NETWORK_RECV_STATUS_OKAY) {
741  /* Start receiving the map */
742  return SendNewGRFsOk();
743  }
744 
745  /* NewGRF mismatch, bail out */
746  ShowErrorMessage(STR_NETWORK_ERROR_NEWGRF_MISMATCH, INVALID_STRING_ID, WL_CRITICAL);
747  return ret;
748 }
749 
751 {
752  if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
753  this->status = STATUS_AUTH_GAME;
754 
755  const char *password = _network_join_server_password;
756  if (!StrEmpty(password)) {
757  return SendGamePassword(password);
758  }
759 
760  ShowNetworkNeedPassword(NETWORK_GAME_PASSWORD);
761 
763 }
764 
766 {
767  if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_COMPANY) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
768  this->status = STATUS_AUTH_COMPANY;
769 
770  _password_game_seed = p->Recv_uint32();
773 
774  const char *password = _network_join_company_password;
775  if (!StrEmpty(password)) {
776  return SendCompanyPassword(password);
777  }
778 
779  ShowNetworkNeedPassword(NETWORK_COMPANY_PASSWORD);
780 
782 }
783 
785 {
786  if (this->status < STATUS_JOIN || this->status >= STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
787  this->status = STATUS_AUTHORIZED;
788 
790 
791  /* Initialize the password hash salting variables, even if they were previously. */
794 
795  /* Start receiving the map */
796  return SendGetMap();
797 }
798 
800 {
801  /* We set the internal wait state when requesting the map. */
803 
804  /* But... only now we set the join status to waiting, instead of requesting. */
805  _network_join_status = NETWORK_JOIN_STATUS_WAITING;
808 
810 }
811 
813 {
814  if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
815  this->status = STATUS_MAP;
816 
817  if (this->savegame != nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
818 
819  this->savegame = new PacketReader();
820 
822 
825 
826  _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
828 
830 }
831 
833 {
835  if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
836 
839 
841 }
842 
844 {
846  if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
847 
848  /* We are still receiving data, put it to the file */
849  this->savegame->AddPacket(p);
850 
851  _network_join_bytes = (uint32)this->savegame->written_bytes;
853 
855 }
856 
858 {
860  if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
861 
862  _network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
864 
865  /*
866  * Make sure everything is set for reading.
867  *
868  * We need the local copy and reset this->savegame because when
869  * loading fails the network gets reset upon loading the intro
870  * game, which would cause us to free this->savegame twice.
871  */
872  LoadFilter *lf = this->savegame;
873  this->savegame = nullptr;
874  lf->Reset();
875 
876  /* The map is done downloading, load it */
878  bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
879 
880  /* Long savegame loads shouldn't affect the lag calculation! */
881  this->last_packet = std::chrono::steady_clock::now();
882 
883  if (!load_success) {
885  ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, INVALID_STRING_ID, WL_CRITICAL);
887  }
888  /* If the savegame has successfully loaded, ALL windows have been removed,
889  * only toolbar/statusbar and gamefield are visible */
890 
891  /* Say we received the map and loaded it correctly! */
892  SendMapOk();
893 
894  /* New company/spectator (invalid company) or company we want to join is not active
895  * Switch local company to spectator and await the server's judgement */
898 
900  /* We have arrived and ready to start playing; send a command to make a new company;
901  * the server will give us a client-id and let us in */
902  _network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
903  ShowJoinStatusWindow();
904  NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
905  }
906  } else {
907  /* take control over an existing company */
909  }
910 
912 }
913 
915 {
917 
920 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
921  /* Test if the server supports this option
922  * and if we are at the frame the server is */
923  if (p->pos + 1 < p->size) {
925  _sync_seed_1 = p->Recv_uint32();
926 #ifdef NETWORK_SEND_DOUBLE_SEED
927  _sync_seed_2 = p->Recv_uint32();
928 #endif
929  }
930 #endif
931  /* Receive the token. */
932  if (p->pos != p->size) this->token = p->Recv_uint8();
933 
934  DEBUG(net, 5, "Received FRAME %d", _frame_counter_server);
935 
936  /* Let the server know that we received this frame correctly
937  * We do this only once per day, to save some bandwidth ;) */
940  DEBUG(net, 4, "Sent ACK at %d", _frame_counter);
941  SendAck();
942  }
943 
945 }
946 
948 {
950 
951  _sync_frame = p->Recv_uint32();
952  _sync_seed_1 = p->Recv_uint32();
953 #ifdef NETWORK_SEND_DOUBLE_SEED
954  _sync_seed_2 = p->Recv_uint32();
955 #endif
956 
958 }
959 
961 {
963 
964  CommandPacket cp;
965  const char *err = this->ReceiveCommand(p, &cp);
966  cp.frame = p->Recv_uint32();
967  cp.my_cmd = p->Recv_bool();
968 
969  if (err != nullptr) {
970  IConsolePrintF(CC_ERROR, "WARNING: %s from server, dropping...", err);
972  }
973 
974  this->incoming_queue.Append(&cp);
975 
977 }
978 
980 {
982 
983  char name[NETWORK_NAME_LENGTH], msg[NETWORK_CHAT_LENGTH];
984  const NetworkClientInfo *ci = nullptr, *ci_to;
985 
986  NetworkAction action = (NetworkAction)p->Recv_uint8();
988  bool self_send = p->Recv_bool();
990  int64 data = p->Recv_uint64();
991 
993  if (ci_to == nullptr) return NETWORK_RECV_STATUS_OKAY;
994 
995  /* Did we initiate the action locally? */
996  if (self_send) {
997  switch (action) {
998  case NETWORK_ACTION_CHAT_CLIENT:
999  /* For speaking to client we need the client-name */
1000  seprintf(name, lastof(name), "%s", ci_to->client_name);
1002  break;
1003 
1004  /* For speaking to company, we need the company-name */
1005  case NETWORK_ACTION_CHAT_COMPANY: {
1006  StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
1007  SetDParam(0, ci_to->client_playas);
1008 
1009  GetString(name, str, lastof(name));
1011  break;
1012  }
1013 
1014  default: return NETWORK_RECV_STATUS_MALFORMED_PACKET;
1015  }
1016  } else {
1017  /* Display message from somebody else */
1018  seprintf(name, lastof(name), "%s", ci_to->client_name);
1019  ci = ci_to;
1020  }
1021 
1022  if (ci != nullptr) {
1023  NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), self_send, name, msg, data);
1024  }
1025  return NETWORK_RECV_STATUS_OKAY;
1026 }
1027 
1029 {
1031 
1033 
1035  if (ci != nullptr) {
1036  NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
1037  delete ci;
1038  }
1039 
1041 
1042  return NETWORK_RECV_STATUS_OKAY;
1043 }
1044 
1046 {
1048 
1050 
1052  if (ci != nullptr) {
1053  NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
1054  delete ci;
1055  } else {
1056  DEBUG(net, 0, "Unknown client (%d) is leaving the game", client_id);
1057  }
1058 
1060 
1061  /* If we come here it means we could not locate the client.. strange :s */
1062  return NETWORK_RECV_STATUS_OKAY;
1063 }
1064 
1066 {
1068 
1070 
1072  if (ci != nullptr) {
1073  NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name);
1074  }
1075 
1077 
1078  return NETWORK_RECV_STATUS_OKAY;
1079 }
1080 
1082 {
1083  /* Only when we're trying to join we really
1084  * care about the server shutting down. */
1085  if (this->status >= STATUS_JOIN) {
1086  ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_SHUTDOWN, INVALID_STRING_ID, WL_CRITICAL);
1087  }
1088 
1090 
1092 }
1093 
1095 {
1096  /* Only when we're trying to join we really
1097  * care about the server shutting down. */
1098  if (this->status >= STATUS_JOIN) {
1099  /* To throttle the reconnects a bit, every clients waits its
1100  * Client ID modulo 16. This way reconnects should be spread
1101  * out a bit. */
1103  ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_REBOOT, INVALID_STRING_ID, WL_CRITICAL);
1104  }
1105 
1107 
1109 }
1110 
1112 {
1114 
1115  TextColour colour_code = (TextColour)p->Recv_uint16();
1117 
1118  char rcon_out[NETWORK_RCONCOMMAND_LENGTH];
1119  p->Recv_string(rcon_out, sizeof(rcon_out));
1120 
1121  IConsolePrint(colour_code, rcon_out);
1122 
1123  return NETWORK_RECV_STATUS_OKAY;
1124 }
1125 
1127 {
1129 
1130  /* Nothing more in this packet... */
1132  CompanyID company_id = (CompanyID)p->Recv_uint8();
1133 
1134  if (client_id == 0) {
1135  /* definitely an invalid client id, debug message and do nothing. */
1136  DEBUG(net, 0, "[move] received invalid client index = 0");
1138  }
1139 
1141  /* Just make sure we do not try to use a client_index that does not exist */
1142  if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY;
1143 
1144  /* if not valid player, force spectator, else check player exists */
1145  if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
1146 
1148  SetLocalCompany(company_id);
1149  }
1150 
1151  return NETWORK_RECV_STATUS_OKAY;
1152 }
1153 
1155 {
1157 
1158  _network_server_max_companies = p->Recv_uint8();
1160 
1161  return NETWORK_RECV_STATUS_OKAY;
1162 }
1163 
1165 {
1167 
1170 
1171  return NETWORK_RECV_STATUS_OKAY;
1172 }
1173 
1178 {
1179  /* Only once we're authorized we can expect a steady stream of packets. */
1180  if (this->status < STATUS_AUTHORIZED) return;
1181 
1182  /* 5 seconds are roughly twice the server's "you're slow" threshold (1 game day). */
1183  std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->last_packet;
1184  if (lag < std::chrono::seconds(5)) return;
1185 
1186  /* 20 seconds are (way) more than 4 game days after which
1187  * the server will forcefully disconnect you. */
1188  if (lag > std::chrono::seconds(20)) {
1190  return;
1191  }
1192 
1193  /* Prevent showing the lag message every tick; just update it when needed. */
1194  static std::chrono::steady_clock::duration last_lag = {};
1195  if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag)) return;
1196 
1197  last_lag = lag;
1198  SetDParam(0, std::chrono::duration_cast<std::chrono::seconds>(lag).count());
1199  ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO);
1200 }
1201 
1202 
1205 {
1206  /* Set the frame-counter to 0 so nothing happens till we are ready */
1207  _frame_counter = 0;
1209  last_ack_frame = 0;
1210  /* Request the game-info */
1212 }
1213 
1219 void NetworkClientSendRcon(const char *password, const char *command)
1220 {
1221  MyClient::SendRCon(password, command);
1222 }
1223 
1230 void NetworkClientRequestMove(CompanyID company_id, const char *pass)
1231 {
1232  MyClient::SendMove(company_id, pass);
1233 }
1234 
1240 {
1241  Backup<CompanyID> cur_company(_current_company, FILE_LINE);
1242  /* If our company is changing owner, go to spectators */
1244 
1246  if (ci->client_playas != cid) continue;
1247  NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR, CC_DEFAULT, false, ci->client_name);
1248  ci->client_playas = COMPANY_SPECTATOR;
1249  }
1250 
1251  cur_company.Restore();
1252 }
1253 
1258 {
1260 
1261  if (ci == nullptr) return;
1262 
1263  /* Don't change the name if it is the same as the old name */
1264  if (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
1265  if (!_network_server) {
1267  } else {
1269  NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, _settings_client.network.client_name);
1272  }
1273  }
1274  }
1275 }
1276 
1285 void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
1286 {
1287  MyClient::SendChat(action, type, dest, msg, data);
1288 }
1289 
1294 void NetworkClientSetCompanyPassword(const char *password)
1295 {
1296  MyClient::SendSetPassword(password);
1297 }
1298 
1305 {
1306  /* Only companies actually playing can speak to team. Eg spectators cannot */
1308 
1309  for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
1310  if (ci->client_playas == cio->client_playas && ci != cio) return true;
1311  }
1312 
1313  return false;
1314 }
1315 
1321 {
1323 }
1324 
1330 {
1332 }
ClientNetworkGameSocketHandler::Receive_SERVER_FRAME
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override
Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far...
Definition: network_client.cpp:914
NetworkCompanyStats::num_station
uint16 num_station[NETWORK_VEH_END]
How many stations are there of this type?
Definition: network_type.h:59
_network_join_bytes_total
uint32 _network_join_bytes_total
The total number of bytes to download.
Definition: network_gui.cpp:1980
NetworkClientSendRcon
void NetworkClientSendRcon(const char *password, const char *command)
Send a remote console command.
Definition: network_client.cpp:1219
NetworkCompanyInfo::inaugurated_year
Year inaugurated_year
What year the company started in.
Definition: network_gui.h:30
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:81
NetworkSettings::client_name
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
Definition: settings_type.h:270
ClientNetworkGameSocketHandler::SendNewGRFsOk
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
Definition: network_client.cpp:372
ClientNetworkGameSocketHandler::Receive_SERVER_CHAT
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override
Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
Definition: network_client.cpp:979
_frame_counter
uint32 _frame_counter
The current frame.
Definition: network.cpp:67
PACKET_CLIENT_ERROR
@ PACKET_CLIENT_ERROR
A client reports an error to the server.
Definition: tcp_game.h:124
NetworkClientSetCompanyPassword
void NetworkClientSetCompanyPassword(const char *password)
Set/Reset company password on the client side.
Definition: network_client.cpp:1294
ClientNetworkGameSocketHandler::SendSetName
static NetworkRecvStatus SendSetName(const char *name)
Tell the server that we like to change the name of the client.
Definition: network_client.cpp:489
ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO
NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override
Sends information about the companies (one packet per company): uint8 Version of the structure of thi...
Definition: network_client.cpp:572
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
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
NetworkSettings::max_spectators
uint8 max_spectators
maximum amount of spectators
Definition: settings_type.h:280
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:738
NetworkGameSocketHandler::ReceivePackets
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Definition: tcp_game.cpp:135
CSleep
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
Definition: thread.h:22
NETWORK_RECV_STATUS_DESYNC
@ NETWORK_RECV_STATUS_DESYNC
A desync did occur.
Definition: core.h:24
ClientNetworkGameSocketHandler::STATUS_AUTH_COMPANY
@ STATUS_AUTH_COMPANY
Last action was requesting company password.
Definition: network_client.h:28
_network_server_max_spectators
static uint8 _network_server_max_spectators
Maximum number of spectators of the currently joined server.
Definition: network_client.cpp:324
_password_game_seed
static uint32 _password_game_seed
One bit of 'entropy' used to generate a salt for the company passwords.
Definition: network_client.cpp:317
ClientNetworkGameSocketHandler::SendChat
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat-packet over the network.
Definition: network_client.cpp:448
NetworkMaxSpectatorsReached
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
Definition: network_client.cpp:1329
_network_join_waiting
uint8 _network_join_waiting
The number of clients waiting in front of us.
Definition: network_gui.cpp:1978
Packet::buffer
byte * buffer
The buffer of this packet, of basically variable length up to SEND_MTU.
Definition: packet.h:52
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
NetworkCompanyInfo::company_value
Money company_value
The company value.
Definition: network_gui.h:31
ClientNetworkGameSocketHandler::Receive_SERVER_BANNED
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override
Notification that the client trying to join is banned.
Definition: network_client.cpp:563
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:40
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:28
PacketReader::AddPacket
void AddPacket(const Packet *p)
Add a packet to this buffer.
Definition: network_client.cpp:67
ClientNetworkEmergencySave
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
Definition: network_client.cpp:130
_network_join_as
CompanyID _network_join_as
Who would we like to join as.
Definition: network_client.cpp:327
SaveOrLoad
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
Definition: saveload.cpp:2764
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
_network_server
bool _network_server
network-server is active
Definition: network.cpp:53
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
_network_company_passworded
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
Definition: network.cpp:76
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:91
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
Definition: network_client.cpp:1304
ClientNetworkGameSocketHandler::SendMove
static NetworkRecvStatus SendMove(CompanyID company, const char *password)
Ask the server to move us.
Definition: network_client.cpp:528
NetworkClientInfo::client_name
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Definition: network_base.h:26
CommandPacket::frame
uint32 frame
the frame in which this packet is executed
Definition: network_internal.h:147
NetworkGameSocketHandler::last_packet
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
Definition: tcp_game.h:539
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition: window_type.h:472
ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override
Update the clients knowledge of which company is password protected: uint16 Bitwise representation of...
Definition: network_client.cpp:1164
ClientNetworkGameSocketHandler::CheckConnection
void CheckConnection()
Check the connection's state, i.e.
Definition: network_client.cpp:1177
DeserializeGRFIdentifier
void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Definition: game_info.cpp:319
NetworkGameSocketHandler::SetInfo
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
Definition: tcp_game.h:554
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition: network_server.cpp:1623
ClientNetworkGameSocketHandler::GameLoop
static bool GameLoop()
Actual game loop for the client.
Definition: network_client.cpp:267
PacketReader::block
byte ** block
The block we're reading from/writing to.
Definition: network_client.cpp:47
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Definition: config.h:50
PACKET_CLIENT_COMMAND
@ PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
Definition: tcp_game.h:96
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:102
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:34
NetworkFindName
bool NetworkFindName(char *new_name, const char *last)
Check whether a name is unique, and otherwise try to make it unique.
Definition: network_server.cpp:1739
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
PacketReader::written_bytes
size_t written_bytes
The total number of bytes we've written.
Definition: network_client.cpp:48
NetworkUpdateClientName
void NetworkUpdateClientName()
Send the server our name.
Definition: network_client.cpp:1257
_random
Randomizer _random
Random used in the game state calculations.
Definition: random_func.cpp:25
AUTOSAVE_DIR
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition: fileio_type.h:111
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
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:1977
PACKET_CLIENT_GETMAP
@ PACKET_CLIENT_GETMAP
Client requests the actual map.
Definition: tcp_game.h:74
ClientNetworkGameSocketHandler::Receive_SERVER_ERROR
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override
The client made an error: uint8 Error code caused (see NetworkErrorCode).
Definition: network_client.cpp:669
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:362
GetNetworkErrorMsg
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Definition: network.cpp:294
ClientNetworkGameSocketHandler::my_client
static ClientNetworkGameSocketHandler * my_client
This is us!
Definition: network_client.h:41
NetworkSocketHandler::CloseConnection
virtual NetworkRecvStatus CloseConnection(bool error=true)
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
Definition: core.h:59
_network_join_company_password
const char * _network_join_company_password
Company password from -P argument.
Definition: network_client.cpp:332
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 Current frame.
Definition: network_client.cpp:812
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:160
NetworkGameSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp_game.h:153
GenerateCompanyPasswordHash
const char * GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed)
Hash the given password using server ID and game seed.
Definition: network.cpp:174
Packet::Send_uint8
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Definition: packet.cpp:96
LoadFilter::Reset
virtual void Reset()
Reset this filter to read from the beginning of the file.
Definition: saveload_filter.h:43
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
PacketReader::Read
size_t Read(byte *rbuf, size_t size) override
Read a given number of bytes from the savegame.
Definition: network_client.cpp:94
ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override
Send information about a client: uint32 ID of the client (always unique on a server.
Definition: network_client.cpp:616
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
CC_DEFAULT
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
_frame_counter_max
uint32 _frame_counter_max
To where we may go with our clients.
Definition: network.cpp:66
PacketReader
Read some packets, and when do use that data as initial load filter.
Definition: network_client.cpp:41
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
_network_first_time
bool _network_first_time
Whether we have finished joining or not.
Definition: network.cpp:75
PACKET_CLIENT_CHAT
@ PACKET_CLIENT_CHAT
Client said something that should be distributed.
Definition: tcp_game.h:100
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:1094
network_base.h
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
PacketReader::read_bytes
size_t read_bytes
The total number of read bytes.
Definition: network_client.cpp:49
Packet::Send_uint32
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
Definition: packet.cpp:117
PACKET_CLIENT_JOIN
@ PACKET_CLIENT_JOIN
The client telling the server it wants to join.
Definition: tcp_game.h:38
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 Generation seed.
Definition: network_client.cpp:765
CommandQueue::Append
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
Definition: network_command.cpp:57
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:750
ClientNetworkGameSocketHandler::SendJoin
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
Definition: network_client.cpp:355
last_ack_frame
static uint32 last_ack_frame
Last frame we performed an ack.
Definition: network_client.cpp:314
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:111
_frame_counter_server
uint32 _frame_counter_server
The frame_counter of the server, if in network-mode.
Definition: network.cpp:65
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
ClientNetworkGameSocketHandler::STATUS_MAP
@ STATUS_MAP
The client is downloading the map.
Definition: network_client.h:31
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:330
NetworkCompanyInfo::clients
char clients[NETWORK_CLIENTS_LENGTH]
The clients that control this company (Name1, name2, ..)
Definition: network_gui.h:36
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:843
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:34
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:554
_network_join_server_password
const char * _network_join_server_password
Login password from -p argument.
Definition: network_client.cpp:330
NetworkCompanyStats::num_vehicle
uint16 num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
Definition: network_type.h:58
PacketReader::CHUNK
static const size_t CHUNK
32 KiB chunks of memory.
Definition: network_client.cpp:42
Packet::Recv_uint32
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:246
NETWORK_RECV_STATUS_CONN_LOST
@ NETWORK_RECV_STATUS_CONN_LOST
The connection is 'just' lost.
Definition: core.h:27
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:142
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition: fileio_type.h:50
ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override
Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repe...
Definition: network_client.cpp:717
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:152
PacketReader::blocks
std::vector< byte * > blocks
Buffer with blocks of allocated memory.
Definition: network_client.cpp:44
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:1320
NETWORK_RECV_STATUS_SERVER_FULL
@ NETWORK_RECV_STATUS_SERVER_FULL
The server is full.
Definition: core.h:30
ClientNetworkGameSocketHandler::IsConnected
static bool IsConnected()
Check whether the client is actually connected (and in the game).
Definition: network_client.cpp:541
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
NETWORK_RECV_STATUS_SERVER_ERROR
@ NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
Definition: core.h:29
PACKET_CLIENT_COMPANY_INFO
@ PACKET_CLIENT_COMPANY_INFO
Request information about all companies.
Definition: tcp_game.h:42
ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override
The client is joined and ready to receive his map: uint32 Own client ID.
Definition: network_client.cpp:784
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
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:1065
NETWORK_RECV_STATUS_SERVER_BANNED
@ NETWORK_RECV_STATUS_SERVER_BANNED
The server has banned us.
Definition: core.h:31
NetworkCompanyInfo::company_name
char company_name[NETWORK_COMPANY_NAME_LENGTH]
Company name.
Definition: network_gui.h:29
NetworkClient_Connected
void NetworkClient_Connected()
Is called after a client is connected to the server.
Definition: network_client.cpp:1204
ClientNetworkGameSocketHandler::STATUS_COMPANY_INFO
@ STATUS_COMPANY_INFO
We are trying to get company information.
Definition: network_client.h:24
PACKET_CLIENT_NEWGRFS_CHECKED
@ PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
Definition: tcp_game.h:61
CCA_NEW
@ CCA_NEW
Create a new company.
Definition: company_type.h:65
_sync_seed_1
uint32 _sync_seed_1
Seed to compare during sync checks.
Definition: network.cpp:70
PacketReader::Reset
void Reset() override
Reset this filter to read from the beginning of the file.
Definition: network_client.cpp:116
NetworkClientsToSpectators
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
Definition: network_client.cpp:1239
GUISettings::autosave_on_network_disconnect
bool autosave_on_network_disconnect
save an autosave when you get disconnected from a network game with an error?
Definition: settings_type.h:125
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
ClientNetworkGameSocketHandler::STATUS_JOIN
@ STATUS_JOIN
We are trying to join a server.
Definition: network_client.h:25
NETWORK_COMPANY_PASSWORD
@ NETWORK_COMPANY_PASSWORD
The password of the company.
Definition: network_type.h:74
IsValidConsoleColour
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Definition: console_gui.cpp:523
NETWORK_RECV_STATUS_CLOSE_QUERY
@ NETWORK_RECV_STATUS_CLOSE_QUERY
Done querying the server.
Definition: core.h:32
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
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:43
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:52
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:148
Packet::CanReadFromPacket
bool CanReadFromPacket(uint bytes_to_read)
Is it safe to read from the packet, i.e.
Definition: packet.cpp:169
_password_server_id
static char _password_server_id[NETWORK_SERVER_ID_LENGTH]
The other bit of 'entropy' used to generate a salt for the company passwords.
Definition: network_client.cpp:319
_network_reconnect
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:61
PACKET_CLIENT_MAP_OK
@ PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
Definition: tcp_game.h:80
Packet
Internal entity of a packet.
Definition: packet.h:40
NETWORK_COMPANY_INFO_VERSION
static const byte NETWORK_COMPANY_INFO_VERSION
What version of company info is this?
Definition: config.h:37
GameMode
GameMode
Mode which defines the state of the game.
Definition: openttd.h:16
IConsolePrint
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:85
NetworkGameSocketHandler::ReceiveCommand
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
Definition: network_command.cpp:296
Randomizer::state
uint32 state[2]
The state of the randomizer.
Definition: random_func.hpp:23
PacketReader::buf
byte * buf
Buffer we're going to write to/read from.
Definition: network_client.cpp:45
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:380
GUISettings::prefer_teamchat
bool prefer_teamchat
choose the chat message target with <ENTER>, true=all clients, false=your team
Definition: settings_type.h:110
_network_server_max_companies
static uint8 _network_server_max_companies
Maximum number of companies of the currently joined server.
Definition: network_client.cpp:322
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition: openttd.cpp:1350
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:58
ClientNetworkGameSocketHandler::SendCompanyInformationQuery
static NetworkRecvStatus SendCompanyInformationQuery()
Make sure the server ID length is the same as a md5 hash.
Definition: network_client.cpp:343
ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler
ClientNetworkGameSocketHandler(SOCKET s)
Create a new socket for the client side of the game connection.
Definition: network_client.cpp:145
PACKET_CLIENT_SET_NAME
@ PACKET_CLIENT_SET_NAME
A client changes its name.
Definition: tcp_game.h:113
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:242
NetworkGameSocketHandler::GetInfo
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
Definition: tcp_game.h:564
ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override
Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
Definition: network_client.cpp:1154
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NetworkSocketHandler::HasClientQuit
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
Definition: core.h:67
NetworkTCPSocketHandler::SendPackets
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
Definition: tcp.cpp:95
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
NETWORK_RCONCOMMAND_LENGTH
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
Definition: config.h:48
NetworkTCPSocketHandler::CanSendReceive
bool CanSendReceive()
Check whether this socket can send or receive something.
Definition: tcp.cpp:225
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:378
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
ClientNetworkGameSocketHandler::SendSetPassword
static NetworkRecvStatus SendSetPassword(const char *password)
Tell the server that we like to change the password of the company.
Definition: network_client.cpp:476
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:28
ClientNetworkGameSocketHandler::SendRCon
static NetworkRecvStatus SendRCon(const char *password, const char *command)
Send a console command.
Definition: network_client.cpp:514
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:359
ClientNetworkGameSocketHandler::SendCommand
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
Definition: network_client.cpp:438
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:208
Packet::Send_uint64
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
Definition: packet.cpp:130
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 ID of th...
Definition: network_client.cpp:1028
NetworkSendCommand
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
Definition: network_command.cpp:136
GetDrawStringCompanyColour
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
Definition: company_cmd.cpp:131
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:125
ClientNetworkGameSocketHandler::STATUS_AUTHORIZED
@ STATUS_AUTHORIZED
The client is authorized at the server.
Definition: network_client.h:29
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:466
PACKET_CLIENT_GAME_PASSWORD
@ PACKET_CLIENT_GAME_PASSWORD
Clients sends the (hashed) game password.
Definition: tcp_game.h:65
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:463
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:485
ClientNetworkGameSocketHandler::Receive_SERVER_SYNC
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override
Sends a sync-check to the client: uint32 Frame counter.
Definition: network_client.cpp:947
ClientNetworkGameSocketHandler::ClientError
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
Definition: network_client.cpp:192
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:19
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:299
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:46
ClientNetworkGameSocketHandler::SendCompanyPassword
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
Definition: network_client.cpp:395
NetworkCompanyInfo::money
Money money
The amount of money the company has.
Definition: network_gui.h:32
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:460
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
game_info.h
NetworkCompanyInfo::performance
uint16 performance
What was his performance last month?
Definition: network_gui.h:34
NetworkCompanyStats::ai
bool ai
Is this company an AI.
Definition: network_type.h:60
ClientNetworkGameSocketHandler::NetworkExecuteLocalCommandQueue
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
Definition: network_command.cpp:191
PACKET_CLIENT_RCON
@ PACKET_CLIENT_RCON
Client asks the server to execute some command.
Definition: tcp_game.h:104
Packet::Recv_uint8
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:217
GetNetworkRevisionString
const char * GetNetworkRevisionString()
Get the network version string used by this build.
Definition: game_info.cpp:41
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler
~ClientNetworkGameSocketHandler()
Clear whatever we assigned.
Definition: network_client.cpp:152
CC_ERROR
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override
Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
Definition: network_client.cpp:960
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:31
ClientNetworkGameSocketHandler
Class for handling the client side of the game connection.
Definition: network_client.h:16
CMD_COMPANY_CTRL
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
Definition: command_type.h:281
ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override
Let the clients know that the server is closing.
Definition: network_client.cpp:1081
NetworkGameSocketHandler::incoming_queue
CommandQueue incoming_queue
The command-queue awaiting handling.
Definition: tcp_game.h:538
_sync_frame
uint32 _sync_frame
The frame to perform the sync check.
Definition: network.cpp:74
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:132
network.h
NetworkGameSocketHandler::client_id
ClientID client_id
Client identifier.
Definition: tcp_game.h:535
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:310
ClientNetworkGameSocketHandler::SendGetMap
static NetworkRecvStatus SendGetMap()
Request the map from the server.
Definition: network_client.cpp:404
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:14
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
ClientNetworkGameSocketHandler::Receive_SERVER_RCON
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override
Send the result of an issues RCon command back to the client: uint16 Colour code.
Definition: network_client.cpp:1111
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:582
WN_NETWORK_WINDOW_LOBBY
@ WN_NETWORK_WINDOW_LOBBY
Network lobby window.
Definition: window_type.h:28
Packet::Recv_uint64
uint64 Recv_uint64()
Read a 64 bits integer from the packet.
Definition: packet.cpp:263
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1230
ClientNetworkGameSocketHandler::SendMapOk
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
Definition: network_client.cpp:414
NetworkGameSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
Definition: tcp_game.cpp:41
NetworkCompanyInfo::income
Money income
How much did the company earned last year.
Definition: network_gui.h:33
PACKET_CLIENT_ACK
@ PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
Definition: tcp_game.h:92
PACKET_CLIENT_MOVE
@ PACKET_CLIENT_MOVE
A client would like to be moved to another company.
Definition: tcp_game.h:108
ClientNetworkGameSocketHandler::savegame
struct PacketReader * savegame
Packet reader for reading the savegame.
Definition: network_client.h:18
ClientNetworkGameSocketHandler::SendAck
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
Definition: network_client.cpp:424
NETWORK_RECV_STATUS_OKAY
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
Definition: core.h:23
SafeLoad
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=nullptr)
Load the specified savegame but on error do different things.
Definition: openttd.cpp:954
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:857
PacketReader::PacketReader
PacketReader()
Initialise everything.
Definition: network_client.cpp:52
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:478
ClientNetworkGameSocketHandler::SendQuit
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
Definition: network_client.cpp:501
NetworkClientSendChat
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
Definition: network_client.cpp:1285
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:318
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
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:193
NETWORK_RECV_STATUS_SAVEGAME
@ NETWORK_RECV_STATUS_SAVEGAME
Something went wrong (down)loading the savegame.
Definition: core.h:26
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:832
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
WN_NETWORK_STATUS_WINDOW_JOIN
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
Definition: window_type.h:32
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:456
ClientNetworkGameSocketHandler::Receive_SERVER_QUIT
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override
Notification that a client left the game: uint32 ID of the client.
Definition: network_client.cpp:1045
NetworkCompanyInfo
Company information stored at the client side.
Definition: network_gui.h:28
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3248
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:385
ClientNetworkGameSocketHandler::Receive_SERVER_MOVE
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override
Move a client from one company into another: uint32 ID of the client.
Definition: network_client.cpp:1126
ClientNetworkGameSocketHandler::Send
static void Send()
Send the packets of this socket handler.
Definition: network_client.cpp:257
_network_join_bytes
uint32 _network_join_bytes
The number of bytes we already downloaded.
Definition: network_gui.cpp:1979
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
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:24
PACKET_CLIENT_SET_PASSWORD
@ PACKET_CLIENT_SET_PASSWORD
A client (re)sets its company's password.
Definition: tcp_game.h:112
IConsolePrintF
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:125
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
PACKET_CLIENT_COMPANY_PASSWORD
@ PACKET_CLIENT_COMPANY_PASSWORD
Client sends the (hashed) company password.
Definition: tcp_game.h:67
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
GetLobbyCompanyInfo
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
Definition: network_gui.cpp:1631
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:581
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
NETWORK_GAME_PASSWORD
@ NETWORK_GAME_PASSWORD
The password of the game.
Definition: network_type.h:73
Packet::Recv_uint16
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
Definition: packet.cpp:231
ClientNetworkGameSocketHandler::SendGamePassword
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
Definition: network_client.cpp:383
NetworkSettings::max_companies
uint8 max_companies
maximum amount of companies
Definition: settings_type.h:278
Packet::pos
PacketSize pos
The current read/write position in the packet.
Definition: packet.h:50
ClientNetworkGameSocketHandler::Receive_SERVER_WAIT
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override
Notification that another client is currently receiving the map: uint8 Number of clients waiting in f...
Definition: network_client.cpp:799
NETWORK_RECV_STATUS_MALFORMED_PACKET
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
Definition: core.h:28
NetworkCompanyInfo::use_password
bool use_password
Is there a password.
Definition: network_gui.h:35