OpenTTD

tcp_game.cpp
Go to the documentation of this file.
1 /* $Id: tcp_game.cpp 26482 2014-04-23 20:13:33Z 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 #ifdef ENABLE_NETWORK
15
16 #include "../../stdafx.h"
17
18 #include "../network.h"
19 #include "../network_internal.h"
20 #include "../../debug.h"
21 #include "../../error.h"
22
23 #include "table/strings.h"
24
25 #include "../../safeguards.h"
26
31 NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(NULL), client_id(INVALID_CLIENT_ID),
32 last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick)
33 {
34 this->sock = s;
35 }
36
44 NetworkRecvStatus NetworkGameSocketHandler::CloseConnection(bool error)
45 {
46 /* Clients drop back to the main menu */
47 if (!_network_server && _networking) {
48 _switch_mode = SM_MENU;
49 _networking = false;
50 ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
51
52 return NETWORK_RECV_STATUS_CONN_LOST;
53 }
54
55 return this->CloseConnection(error ? NETWORK_RECV_STATUS_SERVER_ERROR : NETWORK_RECV_STATUS_CONN_LOST);
56 }
57
58
64 NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
65 {
66 PacketGameType type = (PacketGameType)p->Recv_uint8();
67
68 this->last_packet = _realtime_tick;
69
70 switch (this->HasClientQuit() ? PACKET_END : type) {
71 case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
72 case PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p);
73 case PACKET_CLIENT_JOIN: return this->Receive_CLIENT_JOIN(p);
74 case PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p);
75 case PACKET_CLIENT_COMPANY_INFO: return this->Receive_CLIENT_COMPANY_INFO(p);
76 case PACKET_SERVER_COMPANY_INFO: return this->Receive_SERVER_COMPANY_INFO(p);
77 case PACKET_SERVER_CLIENT_INFO: return this->Receive_SERVER_CLIENT_INFO(p);
78 case PACKET_SERVER_NEED_GAME_PASSWORD: return this->Receive_SERVER_NEED_GAME_PASSWORD(p);
79 case PACKET_SERVER_NEED_COMPANY_PASSWORD: return this->Receive_SERVER_NEED_COMPANY_PASSWORD(p);
80 case PACKET_CLIENT_GAME_PASSWORD: return this->Receive_CLIENT_GAME_PASSWORD(p);
81 case PACKET_CLIENT_COMPANY_PASSWORD: return this->Receive_CLIENT_COMPANY_PASSWORD(p);
82 case PACKET_SERVER_WELCOME: return this->Receive_SERVER_WELCOME(p);
83 case PACKET_CLIENT_GETMAP: return this->Receive_CLIENT_GETMAP(p);
84 case PACKET_SERVER_WAIT: return this->Receive_SERVER_WAIT(p);
85 case PACKET_SERVER_MAP_BEGIN: return this->Receive_SERVER_MAP_BEGIN(p);
86 case PACKET_SERVER_MAP_SIZE: return this->Receive_SERVER_MAP_SIZE(p);
87 case PACKET_SERVER_MAP_DATA: return this->Receive_SERVER_MAP_DATA(p);
88 case PACKET_SERVER_MAP_DONE: return this->Receive_SERVER_MAP_DONE(p);
89 case PACKET_CLIENT_MAP_OK: return this->Receive_CLIENT_MAP_OK(p);
90 case PACKET_SERVER_JOIN: return this->Receive_SERVER_JOIN(p);
91 case PACKET_SERVER_FRAME: return this->Receive_SERVER_FRAME(p);
92 case PACKET_SERVER_SYNC: return this->Receive_SERVER_SYNC(p);
93 case PACKET_CLIENT_ACK: return this->Receive_CLIENT_ACK(p);
94 case PACKET_CLIENT_COMMAND: return this->Receive_CLIENT_COMMAND(p);
95 case PACKET_SERVER_COMMAND: return this->Receive_SERVER_COMMAND(p);
96 case PACKET_CLIENT_CHAT: return this->Receive_CLIENT_CHAT(p);
97 case PACKET_SERVER_CHAT: return this->Receive_SERVER_CHAT(p);
98 case PACKET_CLIENT_SET_PASSWORD: return this->Receive_CLIENT_SET_PASSWORD(p);
99 case PACKET_CLIENT_SET_NAME: return this->Receive_CLIENT_SET_NAME(p);
100 case PACKET_CLIENT_QUIT: return this->Receive_CLIENT_QUIT(p);
101 case PACKET_CLIENT_ERROR: return this->Receive_CLIENT_ERROR(p);
102 case PACKET_SERVER_QUIT: return this->Receive_SERVER_QUIT(p);
103 case PACKET_SERVER_ERROR_QUIT: return this->Receive_SERVER_ERROR_QUIT(p);
104 case PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p);
105 case PACKET_SERVER_NEWGAME: return this->Receive_SERVER_NEWGAME(p);
106 case PACKET_SERVER_RCON: return this->Receive_SERVER_RCON(p);
107 case PACKET_CLIENT_RCON: return this->Receive_CLIENT_RCON(p);
108 case PACKET_SERVER_CHECK_NEWGRFS: return this->Receive_SERVER_CHECK_NEWGRFS(p);
109 case PACKET_CLIENT_NEWGRFS_CHECKED: return this->Receive_CLIENT_NEWGRFS_CHECKED(p);
110 case PACKET_SERVER_MOVE: return this->Receive_SERVER_MOVE(p);
111 case PACKET_CLIENT_MOVE: return this->Receive_CLIENT_MOVE(p);
112 case PACKET_SERVER_COMPANY_UPDATE: return this->Receive_SERVER_COMPANY_UPDATE(p);
113 case PACKET_SERVER_CONFIG_UPDATE: return this->Receive_SERVER_CONFIG_UPDATE(p);
114
115 default:
116 this->CloseConnection();
117
118 if (this->HasClientQuit()) {
119 DEBUG(net, 0, "[tcp/game] received invalid packet type %d from client %d", type, this->client_id);
120 } else {
121 DEBUG(net, 0, "[tcp/game] received illegal packet from client %d", this->client_id);
122 }
123 return NETWORK_RECV_STATUS_MALFORMED_PACKET;
124 }
125 }
126
134 NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets()
135 {
136 Packet *p;
137 while ((p = this->ReceivePacket()) != NULL) {
138 NetworkRecvStatus res = HandlePacket(p);
139 delete p;
140 if (res != NETWORK_RECV_STATUS_OKAY) return res;
141 }
142
143 return NETWORK_RECV_STATUS_OKAY;
144 }
145
151 NetworkRecvStatus NetworkGameSocketHandler::ReceiveInvalidPacket(PacketGameType type)
152 {
153 DEBUG(net, 0, "[tcp/game] received illegal packet type %d from client %d", type, this->client_id);
154 return NETWORK_RECV_STATUS_MALFORMED_PACKET;
155 }
156
157 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_FULL); }
158 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_BANNED); }
159 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_JOIN); }
160 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); }
161 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_INFO); }
162 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_INFO); }
163 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); }
164 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_GAME_PASSWORD); }
165 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_COMPANY_PASSWORD); }
166 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_PASSWORD); }
167 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_PASSWORD); }
168 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_WELCOME); }
169 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GETMAP); }
170 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_WAIT); }
171 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_BEGIN); }
172 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_SIZE); }
173 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DATA); }
174 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DONE); }
175 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MAP_OK); }
176 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_JOIN); }
177 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_FRAME); }
178 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SYNC); }
179 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ACK); }
180 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMMAND); }
181 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMMAND); }
182 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_CHAT); }
183 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHAT); }
184 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_PASSWORD); }
185 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_NAME); }
186 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_QUIT); }
187 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); }
188 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); }
189 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); }
190 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); }
191 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEWGAME); }
192 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_RCON); }
193 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_RCON); }
194 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHECK_NEWGRFS); }
195 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_NEWGRFS_CHECKED); }
196 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MOVE); }
197 NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); }
198 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); }
199 NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
200
201 #endif /* ENABLE_NETWORK */
NETWORK_RECV_STATUS_OKAY
Everything is okay.
Definition: core.h:27
PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
Definition: tcp_game.h:60
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:164
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:178
PACKET_SERVER_COMPANY_INFO
Information about a single company.
Definition: tcp_game.h:46
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:56
PACKET_SERVER_MOVE
Server tells everyone that someone is moved to another company.
Definition: tcp_game.h:108
NetworkSocketHandler::HasClientQuit
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
Definition: core.h:71
NetworkGameSocketHandler::Receive_SERVER_FULL
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p)
Notification that the server is full.
Definition: tcp_game.cpp:157
NetworkTCPSocketHandler::sock
SOCKET sock
The socket currently connected to.
Definition: tcp.h:36
_realtime_tick
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:48
Packet
Internal entity of a packet.
Definition: packet.h:44
PACKET_CLIENT_SET_NAME
A client changes its name.
Definition: tcp_game.h:112
NetworkGameSocketHandler::ReceivePackets
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Definition: tcp_game.cpp:134
PACKET_SERVER_ERROR_QUIT
A server tells that a client has hit an error and did quit.
Definition: tcp_game.h:124
SM_MENU
Switch to game intro menu.
Definition: openttd.h:32
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:197
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:166
PACKET_SERVER_FULL
The server is full and has no place for you.
Definition: tcp_game.h:37
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:182
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:194
PACKET_CLIENT_GAME_PASSWORD
Clients sends the (hashed) game password.
Definition: tcp_game.h:64
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:170
PACKET_SERVER_CHAT
Server distributing the message of a client (or itself).
Definition: tcp_game.h:100
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:174
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:165
PACKET_SERVER_FRAME
Server tells the client what frame it is in, and thus to where the client may progress.
Definition: tcp_game.h:90
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:187
NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
Definition: core.h:33
NetworkGameSocketHandler::ReceiveInvalidPacket
NetworkRecvStatus ReceiveInvalidPacket(PacketGameType type)
Helper for logging receiving invalid packets.
Definition: tcp_game.cpp:151
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:168
PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
Definition: tcp_game.h:91
NetworkTCPSocketHandler::ReceivePacket
virtual Packet * ReceivePacket()
Receives a packet for the given client.
Definition: tcp.cpp:149
PACKET_SERVER_SYNC
Server tells the client what the random state should be.
Definition: tcp_game.h:92
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:183
PACKET_SERVER_WELCOME
Server welcomes you and gives you your ClientID.
Definition: tcp_game.h:69
PACKET_CLIENT_RCON
Client asks the server to execute some command.
Definition: tcp_game.h:103
PACKET_SERVER_MAP_BEGIN
Server tells the client that it is beginning to send the map.
Definition: tcp_game.h:75
PACKET_SERVER_RCON
Response of the executed command on the server.
Definition: tcp_game.h:104
PACKET_SERVER_QUIT
A server tells that a client has quit.
Definition: tcp_game.h:122
PACKET_SERVER_COMMAND
Server distributes a command to (all) the clients.
Definition: tcp_game.h:96
WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:26
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Definition: error_gui.cpp:378
PACKET_SERVER_CHECK_NEWGRFS
Server sends NewGRF IDs and MD5 checksums for the client to check.
Definition: tcp_game.h:59
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:185
PACKET_CLIENT_MOVE
A client would like to be moved to another company.
Definition: tcp_game.h:107
PACKET_SERVER_CLIENT_INFO
Server sends you information about a client.
Definition: tcp_game.h:70
NetworkGameSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true)
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
Definition: tcp_game.cpp:44
PACKET_CLIENT_COMPANY_PASSWORD
Client sends the (hashed) company password.
Definition: tcp_game.h:66
PACKET_SERVER_MAP_DATA
Server sends bits of the map to the client.
Definition: tcp_game.h:77
NetworkGameSocketHandler::HandlePacket
NetworkRecvStatus HandlePacket(Packet *p)
Handle the given packet, i.e.
Definition: tcp_game.cpp:64
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:179
NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p)
Request company information (in detail).
Definition: tcp_game.cpp:161
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:180
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:176
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:160
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:173
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:26
PACKET_CLIENT_SET_PASSWORD
A client (re)sets its company&#39;s password.
Definition: tcp_game.h:111
NetworkGameSocketHandler::NetworkGameSocketHandler
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
Definition: tcp_game.cpp:31
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:167
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:175
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:159
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:195
NetworkGameSocketHandler::last_packet
uint last_packet
Time we received the last frame.
Definition: tcp_game.h:525
NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p)
Let the clients know that the server is closing.
Definition: tcp_game.cpp:190
PACKET_SERVER_ERROR
Server sending an error message to the client.
Definition: tcp_game.h:42
PACKET_CLIENT_ERROR
A client reports an error to the server.
Definition: tcp_game.h:123
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:196
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:199
NETWORK_RECV_STATUS_CONN_LOST
The connection is &#39;just&#39; lost.
Definition: core.h:31
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:172
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
PacketGameType
PacketGameType
Enum with all types of TCP packets.
Definition: tcp_game.h:28
NetworkGameSocketHandler::client_id
ClientID client_id
Client identifier.
Definition: tcp_game.h:521
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:163
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:193
Packet::Recv_uint8
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:221
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:188
PACKET_SERVER_JOIN
Tells clients that a new client has joined.
Definition: tcp_game.h:81
PACKET_SERVER_CONFIG_UPDATE
Some network configuration important to the client changed.
Definition: tcp_game.h:114
PACKET_CLIENT_GETMAP
Client requests the actual map.
Definition: tcp_game.h:73
_frame_counter
uint32 _frame_counter
The current frame.
Definition: network.cpp:72
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:191
NetworkGameSocketHandler::Receive_CLIENT_GETMAP
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p)
Request the map from the server.
Definition: tcp_game.cpp:169
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:192
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:184
PACKET_SERVER_NEWGAME
The server is preparing to start a new game.
Definition: tcp_game.h:117
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:171
INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:44
PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
Definition: tcp_game.h:95
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:162
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:110
PACKET_SERVER_MAP_DONE
Server tells it has just sent the last bits of the map to the client.
Definition: tcp_game.h:78
PACKET_SERVER_MAP_SIZE
Server tells the client what the (compressed) size of the map is.
Definition: tcp_game.h:76
PACKET_CLIENT_JOIN
The client telling the server it wants to join.
Definition: tcp_game.h:41
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:177
PACKET_END
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_game.h:126
PACKET_SERVER_WAIT
Server tells the client there are some people waiting for the map as well.
Definition: tcp_game.h:74
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:47
PACKET_CLIENT_QUIT
A client tells the server it is going to quit.
Definition: tcp_game.h:121
_network_server
bool _network_server
network-server is active
Definition: network.cpp:57
PACKET_SERVER_NEED_GAME_PASSWORD
Server requests the (hashed) game password.
Definition: tcp_game.h:63
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:19
NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
Definition: core.h:32
PACKET_SERVER_NEED_COMPANY_PASSWORD
Server requests the (hashed) company password.
Definition: tcp_game.h:65
PACKET_CLIENT_CHAT
Client said something that should be distributed.
Definition: tcp_game.h:99
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:181
PACKET_SERVER_BANNED
The server has banned you.
Definition: tcp_game.h:38
NetworkGameSocketHandler::Receive_SERVER_BANNED
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p)
Notification that the client trying to join is banned.
Definition: tcp_game.cpp:158
PACKET_SERVER_SHUTDOWN
The server is shutting down.
Definition: tcp_game.h:118
NetworkGameSocketHandler::Receive_CLIENT_QUIT
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p)
The client is quitting the game.
Definition: tcp_game.cpp:186
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:189
PACKET_SERVER_COMPANY_UPDATE
Information (password) of a company changed.
Definition: tcp_game.h:113
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:198
PACKET_CLIENT_COMPANY_INFO
Request information about all companies.
Definition: tcp_game.h:45
PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
Definition: tcp_game.h:79