OpenTTD
tcp_game.h
Go to the documentation of this file.
1 /* $Id: tcp_game.h 26056 2013-11-22 21:50:43Z rubidium $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
14 #ifndef NETWORK_CORE_TCP_GAME_H
15 #define NETWORK_CORE_TCP_GAME_H
16 
17 #include "os_abstraction.h"
18 #include "tcp.h"
19 #include "../network_type.h"
20 #include "../../core/pool_type.hpp"
21 
22 #ifdef ENABLE_NETWORK
23 
29  /*
30  * These first three pair of packets (thus six in
31  * total) must remain in this order for backward
32  * and forward compatibility between clients that
33  * are trying to join directly.
34  */
35 
36  /* Packets sent by socket accepting code without ever constructing a client socket instance. */
39 
40  /* Packets used by the client to join and an error message when the revision is wrong. */
43 
44  /* Packets used for the pre-game lobby. */
47 
48  /*
49  * Packets after here assume that the client
50  * and server are running the same version. As
51  * such ordering is unimportant from here on.
52  *
53  * The following is the remainder of the packets
54  * sent as part of authenticating and getting
55  * the map and other important data.
56  */
57 
58  /* After the join step, the first is checking NewGRFs. */
61 
62  /* Checking the game, and then company passwords. */
67 
68  /* The server welcomes the authenticated client and sends information of other clients. */
71 
72  /* Getting the savegame/map. */
80 
82 
83  /*
84  * At this moment the client has the map and
85  * the client is fully authenticated. Now the
86  * normal communication starts.
87  */
88 
89  /* Game progress monitoring. */
93 
94  /* Sending commands around. */
97 
98  /* Human communication! */
101 
102  /* Remote console. */
105 
106  /* Moving a client.*/
109 
110  /* Configuration updates. */
115 
116  /* A server quitting this game. */
119 
120  /* A client quitting. */
125 
127 };
128 
130 struct CommandPacket;
131 
136  uint count;
137 
138 public:
140  CommandQueue() : first(NULL), last(NULL), count(0) {}
142  ~CommandQueue() { this->Free(); }
143  void Append(CommandPacket *p);
144  CommandPacket *Pop(bool ignore_paused = false);
145  CommandPacket *Peek(bool ignore_paused = false);
146  void Free();
148  uint Count() const { return this->count; }
149 };
150 
153 /* TODO: rewrite into a proper class */
154 private:
156 
157 protected:
159 
165 
171 
181 
188 
194 
222 
231 
237 
245 
253 
261 
270 
277 
284 
291 
298 
305 
311 
317 
324 
335 
344 
352 
365 
379 
390 
400 
407 
414 
420 
427 
434 
442 
448 
454 
462 
470 
479 
485 
493 
501 
508 
516 
518 
519  NetworkGameSocketHandler(SOCKET s);
520 public:
522  uint32 last_frame;
525  uint last_packet;
526 
528 
534  virtual ~NetworkGameSocketHandler() {}
535 
541  {
542  assert(info != NULL && this->info == NULL);
543  this->info = info;
544  }
545 
550  inline NetworkClientInfo *GetInfo() const
551  {
552  return this->info;
553  }
554 
556 
557  const char *ReceiveCommand(Packet *p, CommandPacket *cp);
558  void SendCommand(Packet *p, const CommandPacket *cp);
559 };
560 
561 #endif /* ENABLE_NETWORK */
562 
563 #endif /* NETWORK_CORE_TCP_GAME_H */