OpenTTD Source: src/network/core/tcp_game.h Source File

OpenTTD Source 1.11.0-RC1

tcp_game.h
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
12 #ifndef NETWORK_CORE_TCP_GAME_H
13 #define NETWORK_CORE_TCP_GAME_H
14
15 #include "os_abstraction.h"
16 #include "tcp.h"
17 #include "../network_type.h"
18 #include "../../core/pool_type.hpp"
19 #include <chrono>
20
25 enum PacketGameType {
26 /*
27 * These first three pair of packets (thus six in
28 * total) must remain in this order for backward
29 * and forward compatibility between clients that
30 * are trying to join directly.
31 */
32
33 /* Packets sent by socket accepting code without ever constructing a client socket instance. */
34 PACKET_SERVER_FULL,
35 PACKET_SERVER_BANNED,
36
37 /* Packets used by the client to join and an error message when the revision is wrong. */
38 PACKET_CLIENT_JOIN,
39 PACKET_SERVER_ERROR,
40
41 /* Packets used for the pre-game lobby. */
42 PACKET_CLIENT_COMPANY_INFO,
43 PACKET_SERVER_COMPANY_INFO,
44
45 /*
46 * Packets after here assume that the client
47 * and server are running the same version. As
48 * such ordering is unimportant from here on.
49 *
50 * The following is the remainder of the packets
51 * sent as part of authenticating and getting
52 * the map and other important data.
53 */
54
55 /* After the join step, the first is checking NewGRFs. */
56 PACKET_SERVER_CHECK_NEWGRFS,
57 PACKET_CLIENT_NEWGRFS_CHECKED,
58
59 /* Checking the game, and then company passwords. */
60 PACKET_SERVER_NEED_GAME_PASSWORD,
61 PACKET_CLIENT_GAME_PASSWORD,
62 PACKET_SERVER_NEED_COMPANY_PASSWORD,
63 PACKET_CLIENT_COMPANY_PASSWORD,
64
65 /* The server welcomes the authenticated client and sends information of other clients. */
66 PACKET_SERVER_WELCOME,
67 PACKET_SERVER_CLIENT_INFO,
68
69 /* Getting the savegame/map. */
70 PACKET_CLIENT_GETMAP,
71 PACKET_SERVER_WAIT,
72 PACKET_SERVER_MAP_BEGIN,
73 PACKET_SERVER_MAP_SIZE,
74 PACKET_SERVER_MAP_DATA,
75 PACKET_SERVER_MAP_DONE,
76 PACKET_CLIENT_MAP_OK,
77
78 PACKET_SERVER_JOIN,
79
80 /*
81 * At this moment the client has the map and
82 * the client is fully authenticated. Now the
83 * normal communication starts.
84 */
85
86 /* Game progress monitoring. */
87 PACKET_SERVER_FRAME,
88 PACKET_CLIENT_ACK,
89 PACKET_SERVER_SYNC,
90
91 /* Sending commands around. */
92 PACKET_CLIENT_COMMAND,
93 PACKET_SERVER_COMMAND,
94
95 /* Human communication! */
96 PACKET_CLIENT_CHAT,
97 PACKET_SERVER_CHAT,
98
99 /* Remote console. */
100 PACKET_CLIENT_RCON,
101 PACKET_SERVER_RCON,
102
103 /* Moving a client.*/
104 PACKET_CLIENT_MOVE,
105 PACKET_SERVER_MOVE,
106
107 /* Configuration updates. */
108 PACKET_CLIENT_SET_PASSWORD,
109 PACKET_CLIENT_SET_NAME,
110 PACKET_SERVER_COMPANY_UPDATE,
111 PACKET_SERVER_CONFIG_UPDATE,
112
113 /* A server quitting this game. */
114 PACKET_SERVER_NEWGAME,
115 PACKET_SERVER_SHUTDOWN,
116
117 /* A client quitting. */
118 PACKET_CLIENT_QUIT,
119 PACKET_SERVER_QUIT,
120 PACKET_CLIENT_ERROR,
121 PACKET_SERVER_ERROR_QUIT,
122
123 PACKET_END,
124 };
125
127 struct CommandPacket;
128
130 class CommandQueue {
131 CommandPacket *first;
132 CommandPacket *last;
133 uint count;
134
135 public:
137 CommandQueue() : first(nullptr), last(nullptr), count(0) {}
139 ~CommandQueue() { this->Free(); }
140 void Append(CommandPacket *p);
141 CommandPacket *Pop(bool ignore_paused = false);
142 CommandPacket *Peek(bool ignore_paused = false);
143 void Free();
145 uint Count() const { return this->count; }
146 };
147
149 class NetworkGameSocketHandler : public NetworkTCPSocketHandler {
150 /* TODO: rewrite into a proper class */
151 private:
152 NetworkClientInfo *info;
153
154 protected:
155 NetworkRecvStatus ReceiveInvalidPacket(PacketGameType type);
156
161 virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
162
167 virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
168
177 virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p);
178
184 virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
185
190 virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p);
191
218 virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
219
227 virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
228
233 virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
234
241 virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
242
249 virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p);
250
257 virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p);
258
266 virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
267
273 virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p);
274
280 virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
281
287 virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
288
294 virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
295
301 virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
302
307 virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
308
313 virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p);
314
320 virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
321
331 virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
332
340 virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
341
348 virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p);
349
361 virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p);
362
375 virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
376
386 virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p);
387
396 virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
397
403 virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p);
404
410 virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p);
411
416 virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p);
417
423 virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
424
430 virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
431
438 virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
439
444 virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
445
450 virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
451
458 virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
459
466 virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p);
467
475 virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
476
481 virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p);
482
489 virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
490
497 virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p);
498
504 virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
505
512 virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
513
514 NetworkRecvStatus HandlePacket(Packet *p);
515
516 NetworkGameSocketHandler(SOCKET s);
517 public:
518 ClientID client_id;
519 uint32 last_frame;
520 uint32 last_frame_server;
521 CommandQueue incoming_queue;
522 std::chrono::steady_clock::time_point last_packet;
523
524 NetworkRecvStatus CloseConnection(bool error = true) override;
525
530 virtual NetworkRecvStatus CloseConnection(NetworkRecvStatus status) = 0;
531 virtual ~NetworkGameSocketHandler() {}
532
537 inline void SetInfo(NetworkClientInfo *info)
538 {
539 assert(info != nullptr && this->info == nullptr);
540 this->info = info;
541 }
542
547 inline NetworkClientInfo *GetInfo() const
548 {
549 return this->info;
550 }
551
552 NetworkRecvStatus ReceivePackets();
553
554 const char *ReceiveCommand(Packet *p, CommandPacket *cp);
555 void SendCommand(Packet *p, const CommandPacket *cp);
556 };
557
558 #endif /* NETWORK_CORE_TCP_GAME_H */
CommandQueue::last
CommandPacket * last
The last packet in the queue; only valid when first != nullptr.
Definition: tcp_game.h:132
PACKET_CLIENT_ERROR
@ PACKET_CLIENT_ERROR
A client reports an error to the server.
Definition: tcp_game.h:120
PACKET_SERVER_ERROR
@ PACKET_SERVER_ERROR
Server sending an error message to the client.
Definition: tcp_game.h:39
NetworkGameSocketHandler::Receive_CLIENT_SET_NAME
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p)
Gives the client a new name: string New name of the client.
Definition: tcp_game.cpp:184
NetworkGameSocketHandler::ReceivePackets
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Definition: tcp_game.cpp:133
NetworkGameSocketHandler::Receive_CLIENT_MAP_OK
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p)
Tell the server that we are done receiving/loading the map.
Definition: tcp_game.cpp:174
NetworkGameSocketHandler::NetworkGameSocketHandler
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
Definition: tcp_game.cpp:27
NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p)
Sends that the server will begin with sending the map to the client: uint32 Current frame.
Definition: tcp_game.cpp:170
CommandQueue::Count
uint Count() const
Get the number of items in the queue.
Definition: tcp_game.h:145
PACKET_SERVER_CONFIG_UPDATE
@ PACKET_SERVER_CONFIG_UPDATE
Some network configuration important to the client changed.
Definition: tcp_game.h:111
PacketGameType
PacketGameType
Enum with all types of TCP packets.
Definition: tcp_game.h:25
NetworkGameSocketHandler::last_packet
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
Definition: tcp_game.h:522
NetworkGameSocketHandler::SetInfo
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
Definition: tcp_game.h:537
NetworkGameSocketHandler::ReceiveInvalidPacket
NetworkRecvStatus ReceiveInvalidPacket(PacketGameType type)
Helper for logging receiving invalid packets.
Definition: tcp_game.cpp:150
PACKET_CLIENT_COMMAND
@ PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
Definition: tcp_game.h:92
PACKET_SERVER_NEWGAME
@ PACKET_SERVER_NEWGAME
The server is preparing to start a new game.
Definition: tcp_game.h:114
NetworkGameSocketHandler::last_frame_server
uint32 last_frame_server
Last frame the server has executed.
Definition: tcp_game.h:520
NetworkGameSocketHandler::Receive_SERVER_RCON
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p)
Send the result of an issues RCon command back to the client: uint16 Colour code.
Definition: tcp_game.cpp:191
PACKET_SERVER_WAIT
@ PACKET_SERVER_WAIT
Server tells the client there are some people waiting for the map as well.
Definition: tcp_game.h:71
PACKET_SERVER_JOIN
@ PACKET_SERVER_JOIN
Tells clients that a new client has joined.
Definition: tcp_game.h:78
PACKET_CLIENT_QUIT
@ PACKET_CLIENT_QUIT
A client tells the server it is going to quit.
Definition: tcp_game.h:118
PACKET_CLIENT_GETMAP
@ PACKET_CLIENT_GETMAP
Client requests the actual map.
Definition: tcp_game.h:70
NetworkGameSocketHandler::Receive_CLIENT_ACK
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p)
Tell the server we are done with this frame: uint32 Current frame counter of the client.
Definition: tcp_game.cpp:178
NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p)
Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of th...
Definition: tcp_game.cpp:188
NetworkGameSocketHandler::Receive_SERVER_SYNC
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p)
Sends a sync-check to the client: uint32 Frame counter.
Definition: tcp_game.cpp:177
NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p)
Indication to the client that the server needs a company password: uint32 Generation seed.
Definition: tcp_game.cpp:164
NetworkGameSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp_game.h:149
NetworkGameSocketHandler::Receive_SERVER_MAP_DATA
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p)
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
Definition: tcp_game.cpp:172
PACKET_CLIENT_CHAT
@ PACKET_CLIENT_CHAT
Client said something that should be distributed.
Definition: tcp_game.h:96
PACKET_SERVER_MAP_SIZE
@ PACKET_SERVER_MAP_SIZE
Server tells the client what the (compressed) size of the map is.
Definition: tcp_game.h:73
PACKET_SERVER_MAP_DONE
@ PACKET_SERVER_MAP_DONE
Server tells it has just sent the last bits of the map to the client.
Definition: tcp_game.h:75
PACKET_CLIENT_JOIN
@ PACKET_CLIENT_JOIN
The client telling the server it wants to join.
Definition: tcp_game.h:38
NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p)
Sends information about the companies (one packet per company): uint8 Version of the structure of thi...
Definition: tcp_game.cpp:161
PACKET_END
@ PACKET_END
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_game.h:123
CommandQueue::Append
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
Definition: network_command.cpp:57
NetworkGameSocketHandler::Receive_CLIENT_MOVE
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p)
Request the server to move this client into another company: uint8 ID of the company the client wants...
Definition: tcp_game.cpp:196
NetworkGameSocketHandler::Receive_SERVER_MOVE
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p)
Move a client from one company into another: uint32 ID of the client.
Definition: tcp_game.cpp:195
NetworkGameSocketHandler::HandlePacket
NetworkRecvStatus HandlePacket(Packet *p)
Handle the given packet, i.e.
Definition: tcp_game.cpp:63
PACKET_SERVER_NEED_GAME_PASSWORD
@ PACKET_SERVER_NEED_GAME_PASSWORD
Server requests the (hashed) game password.
Definition: tcp_game.h:60
NetworkGameSocketHandler::Receive_CLIENT_RCON
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p)
Send an RCon command to the server: string RCon password.
Definition: tcp_game.cpp:192
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:149
PACKET_SERVER_SHUTDOWN
@ PACKET_SERVER_SHUTDOWN
The server is shutting down.
Definition: tcp_game.h:115
PACKET_SERVER_NEED_COMPANY_PASSWORD
@ PACKET_SERVER_NEED_COMPANY_PASSWORD
Server requests the (hashed) company password.
Definition: tcp_game.h:62
NetworkGameSocketHandler::Receive_SERVER_QUIT
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p)
Notification that a client left the game: uint32 ID of the client.
Definition: tcp_game.cpp:187
PACKET_SERVER_COMPANY_UPDATE
@ PACKET_SERVER_COMPANY_UPDATE
Information (password) of a company changed.
Definition: tcp_game.h:110
NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p)
Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
Definition: tcp_game.cpp:165
PACKET_CLIENT_COMPANY_INFO
@ PACKET_CLIENT_COMPANY_INFO
Request information about all companies.
Definition: tcp_game.h:42
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:39
CommandQueue::~CommandQueue
~CommandQueue()
Clear the command queue.
Definition: tcp_game.h:139
PACKET_SERVER_BANNED
@ PACKET_SERVER_BANNED
The server has banned you.
Definition: tcp_game.h:35
NetworkGameSocketHandler::Receive_SERVER_WELCOME
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p)
The client is joined and ready to receive his map: uint32 Own client ID.
Definition: tcp_game.cpp:167
PACKET_CLIENT_NEWGRFS_CHECKED
@ PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
Definition: tcp_game.h:57
NetworkGameSocketHandler::Receive_SERVER_MAP_DONE
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p)
Sends that all data of the map are sent to the client:
Definition: tcp_game.cpp:173
CommandQueue::CommandQueue
CommandQueue()
Initialise the command queue.
Definition: tcp_game.h:137
NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p)
Indication to the client that the server needs a game password.
Definition: tcp_game.cpp:163
NetworkGameSocketHandler::Receive_CLIENT_GETMAP
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p)
Request the map from the server.
Definition: tcp_game.cpp:168
CommandQueue
A queue of CommandPackets.
Definition: tcp_game.h:130
NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p)
Sends the size of the map to the client.
Definition: tcp_game.cpp:171
NetworkGameSocketHandler::Receive_CLIENT_CHAT
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p)
Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
Definition: tcp_game.cpp:181
NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p)
Set the password for the clients current company: string The password.
Definition: tcp_game.cpp:183
PACKET_CLIENT_MAP_OK
@ PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
Definition: tcp_game.h:76
Packet
Internal entity of a packet.
Definition: packet.h:40
NetworkGameSocketHandler::ReceiveCommand
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
Definition: network_command.cpp:296
PACKET_SERVER_COMPANY_INFO
@ PACKET_SERVER_COMPANY_INFO
Information about a single company.
Definition: tcp_game.h:43
NetworkGameSocketHandler::Receive_CLIENT_COMMAND
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p)
Send a DoCommand to the Server: uint8 ID of the company (0..MAX_COMPANIES-1).
Definition: tcp_game.cpp:179
PACKET_SERVER_MOVE
@ PACKET_SERVER_MOVE
Server tells everyone that someone is moved to another company.
Definition: tcp_game.h:105
NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p)
Request company information (in detail).
Definition: tcp_game.cpp:160
PACKET_SERVER_FULL
@ PACKET_SERVER_FULL
The server is full and has no place for you.
Definition: tcp_game.h:34
NetworkGameSocketHandler::Receive_SERVER_WAIT
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p)
Notification that another client is currently receiving the map: uint8 Number of clients waiting in f...
Definition: tcp_game.cpp:169
PACKET_CLIENT_SET_NAME
@ PACKET_CLIENT_SET_NAME
A client changes its name.
Definition: tcp_game.h:109
NetworkGameSocketHandler::Receive_SERVER_FULL
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p)
Notification that the server is full.
Definition: tcp_game.cpp:156
NetworkGameSocketHandler::GetInfo
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
Definition: tcp_game.h:547
CommandQueue::first
CommandPacket * first
The first packet in the queue.
Definition: tcp_game.h:131
NetworkGameSocketHandler::Receive_SERVER_JOIN
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p)
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
Definition: tcp_game.cpp:175
NetworkGameSocketHandler::Receive_SERVER_COMMAND
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p)
Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
Definition: tcp_game.cpp:180
NetworkGameSocketHandler::Receive_SERVER_NEWGAME
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p)
Let the clients know that the server is loading a new map.
Definition: tcp_game.cpp:190
PACKET_SERVER_ERROR_QUIT
@ PACKET_SERVER_ERROR_QUIT
A server tells that a client has hit an error and did quit.
Definition: tcp_game.h:121
CommandQueue::Free
void Free()
Free everything that is in the queue.
Definition: network_command.cpp:112
PACKET_CLIENT_GAME_PASSWORD
@ PACKET_CLIENT_GAME_PASSWORD
Clients sends the (hashed) game password.
Definition: tcp_game.h:61
NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p)
Send information about a client: uint32 ID of the client (always unique on a server.
Definition: tcp_game.cpp:162
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:22
tcp.h
NetworkGameSocketHandler::info
NetworkClientInfo * info
Client info related to this socket.
Definition: tcp_game.h:152
CommandQueue::count
uint count
The number of items in the queue.
Definition: tcp_game.h:133
PACKET_SERVER_SYNC
@ PACKET_SERVER_SYNC
Server tells the client what the random state should be.
Definition: tcp_game.h:89
NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p)
Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repe...
Definition: tcp_game.cpp:193
PACKET_SERVER_MAP_BEGIN
@ PACKET_SERVER_MAP_BEGIN
Server tells the client that it is beginning to send the map.
Definition: tcp_game.h:72
PACKET_CLIENT_RCON
@ PACKET_CLIENT_RCON
Client asks the server to execute some command.
Definition: tcp_game.h:100
PACKET_SERVER_CHAT
@ PACKET_SERVER_CHAT
Server distributing the message of a client (or itself).
Definition: tcp_game.h:97
PACKET_SERVER_RCON
@ PACKET_SERVER_RCON
Response of the executed command on the server.
Definition: tcp_game.h:101
PACKET_SERVER_QUIT
@ PACKET_SERVER_QUIT
A server tells that a client has quit.
Definition: tcp_game.h:119
NetworkGameSocketHandler::incoming_queue
CommandQueue incoming_queue
The command-queue awaiting handling.
Definition: tcp_game.h:521
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:131
NetworkGameSocketHandler::client_id
ClientID client_id
Client identifier.
Definition: tcp_game.h:518
CommandQueue::Peek
CommandPacket * Peek(bool ignore_paused=false)
Return the first item in the queue, but don't remove it.
Definition: network_command.cpp:101
NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p)
Tell the server that we have the required GRFs.
Definition: tcp_game.cpp:194
PACKET_SERVER_COMMAND
@ PACKET_SERVER_COMMAND
Server distributes a command to (all) the clients.
Definition: tcp_game.h:93
NetworkGameSocketHandler::Receive_CLIENT_QUIT
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p)
The client is quitting the game.
Definition: tcp_game.cpp:185
PACKET_SERVER_FRAME
@ PACKET_SERVER_FRAME
Server tells the client what frame it is in, and thus to where the client may progress.
Definition: tcp_game.h:87
os_abstraction.h
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
PACKET_CLIENT_ACK
@ PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
Definition: tcp_game.h:88
PACKET_CLIENT_MOVE
@ PACKET_CLIENT_MOVE
A client would like to be moved to another company.
Definition: tcp_game.h:104
NetworkGameSocketHandler::Receive_SERVER_ERROR
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p)
The client made an error: uint8 Error code caused (see NetworkErrorCode).
Definition: tcp_game.cpp:159
PACKET_SERVER_CLIENT_INFO
@ PACKET_SERVER_CLIENT_INFO
Server sends you information about a client.
Definition: tcp_game.h:67
NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p)
Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
Definition: tcp_game.cpp:198
NetworkGameSocketHandler::SendCommand
void SendCommand(Packet *p, const CommandPacket *cp)
Sends a command over the network.
Definition: network_command.cpp:321
NetworkGameSocketHandler::Receive_SERVER_CHAT
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p)
Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
Definition: tcp_game.cpp:182
PACKET_SERVER_WELCOME
@ PACKET_SERVER_WELCOME
Server welcomes you and gives you your ClientID.
Definition: tcp_game.h:66
NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p)
Update the clients knowledge of which company is password protected: uint16 Bitwise representation of...
Definition: tcp_game.cpp:197
PACKET_SERVER_CHECK_NEWGRFS
@ PACKET_SERVER_CHECK_NEWGRFS
Server sends NewGRF IDs and MD5 checksums for the client to check.
Definition: tcp_game.h:56
NetworkGameSocketHandler::Receive_SERVER_FRAME
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p)
Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far...
Definition: tcp_game.cpp:176
NetworkGameSocketHandler::Receive_SERVER_BANNED
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p)
Notification that the client trying to join is banned.
Definition: tcp_game.cpp:157
NetworkGameSocketHandler::last_frame
uint32 last_frame
Last frame we have executed.
Definition: tcp_game.h:519
NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p)
Let the clients know that the server is closing.
Definition: tcp_game.cpp:189
NetworkGameSocketHandler::Receive_CLIENT_ERROR
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p)
The client made an error and is quitting the game.
Definition: tcp_game.cpp:186
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:23
NetworkGameSocketHandler::Receive_CLIENT_JOIN
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p)
Try to join the server: string OpenTTD revision (norev000 if no revision).
Definition: tcp_game.cpp:158
PACKET_CLIENT_SET_PASSWORD
@ PACKET_CLIENT_SET_PASSWORD
A client (re)sets its company's password.
Definition: tcp_game.h:108
PACKET_CLIENT_COMPANY_PASSWORD
@ PACKET_CLIENT_COMPANY_PASSWORD
Client sends the (hashed) company password.
Definition: tcp_game.h:63
PACKET_SERVER_MAP_DATA
@ PACKET_SERVER_MAP_DATA
Server sends bits of the map to the client.
Definition: tcp_game.h:74
NetworkTCPSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp.h:29
NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p)
Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
Definition: tcp_game.cpp:166
CommandQueue::Pop
CommandPacket * Pop(bool ignore_paused=false)
Return the first item in the queue and remove it from the queue.
Definition: network_command.cpp:76