OpenTTD
udp.h
Go to the documentation of this file.
1 /* $Id: udp.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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_UDP_H
15 #define NETWORK_CORE_UDP_H
16 
17 #include "address.h"
18 #include "game.h"
19 #include "packet.h"
20 
21 #ifdef ENABLE_NETWORK
22 
38 };
39 
42  SLT_IPv4 = 0,
43  SLT_IPv6 = 1,
45 
47 };
48 
51 protected:
56 
58 
60 
66  virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr);
67 
107  virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr);
108 
114  virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
115 
143  virtual void Receive_SERVER_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
144 
154  virtual void Receive_SERVER_REGISTER(Packet *p, NetworkAddress *client_addr);
155 
161  virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr);
162 
170  virtual void Receive_CLIENT_GET_LIST(Packet *p, NetworkAddress *client_addr);
171 
181  virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr);
182 
190  virtual void Receive_SERVER_UNREGISTER(Packet *p, NetworkAddress *client_addr);
191 
201  virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr);
202 
213  virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr);
214 
221  virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr);
222 
223  void HandleUDPPacket(Packet *p, NetworkAddress *client_addr);
224 
232  virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); }
233 public:
235 
237  virtual ~NetworkUDPSocketHandler() { this->Close(); }
238 
239  bool Listen();
240  void Close();
241 
242  void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false);
243  void ReceivePackets();
244 
245  void SendNetworkGameInfo(Packet *p, const NetworkGameInfo *info);
247 };
248 
249 #endif /* ENABLE_NETWORK */
250 
251 #endif /* NETWORK_CORE_UDP_H */
Autodetect the type based on the connection.
Definition: udp.h:44
virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr)
The client requests information about some NewGRFs.
Definition: udp.cpp:349
Internal entity of a packet.
Definition: packet.h:44
Sends a fresh session key to the client.
Definition: udp.h:36
NetworkUDPSocketHandler(NetworkAddressList *bind=NULL)
Create an UDP socket but don&#39;t listen yet.
Definition: udp.cpp:27
virtual void Receive_SERVER_REGISTER(Packet *p, NetworkAddress *client_addr)
Registers the server to the master server.
Definition: udp.cpp:344
Queries a game server for game information.
Definition: udp.h:25
virtual ~NetworkUDPSocketHandler()
On destructing of this class, the socket needs to be closed.
Definition: udp.h:237
Requests the name for a list of GRFs (GRF_ID and MD5)
Definition: udp.h:34
void ReceivePackets()
Receive a packet at UDP level.
Definition: udp.cpp:121
virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr)
Return of server information to the client.
Definition: udp.cpp:341
Get the IPv4 addresses.
Definition: udp.h:42
Request for serverlist from master server.
Definition: udp.h:31
void SendNetworkGameInfo(Packet *p, const NetworkGameInfo *info)
Serializes the NetworkGameInfo struct to the packet.
Definition: udp.cpp:161
Get the IPv6 addresses.
Definition: udp.h:43
virtual void Receive_SERVER_UNREGISTER(Packet *p, NetworkAddress *client_addr)
A server unregisters itself at the master server.
Definition: udp.cpp:348
SocketList sockets
The opened sockets.
Definition: udp.h:55
virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr)
The master server sends us a session key.
Definition: udp.cpp:351
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:31
PacketUDPType
Enum with all types of UDP packets.
Definition: udp.h:24
Base socket handler for all UDP sockets.
Definition: udp.h:50
Request to be removed from the server-list.
Definition: udp.h:33
Information about a game that is sent between a game server, game client and masterserver.
void ReceiveInvalidPacket(PacketUDPType, NetworkAddress *client_addr)
Helper for logging receiving invalid packets.
Definition: udp.cpp:335
The game information that is sent from the server to the clients.
Definition: game.h:36
virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr)
Queries to the server for information about the game.
Definition: udp.cpp:340
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.
Definition: udp.h:232
Must ALWAYS be on the end of this list!! (period)
Definition: udp.h:37
Information about GRF, used in the game and (part of it) in savegames.
virtual void Receive_CLIENT_GET_LIST(Packet *p, NetworkAddress *client_addr)
The client requests a list of servers.
Definition: udp.cpp:346
Packet to register itself to the master server.
Definition: udp.h:29
Packet indicating registration has succeeded.
Definition: udp.h:30
virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr)
The server returns information about some NewGRFs.
Definition: udp.cpp:350
Reply of the game server about details of the game, such as companies.
Definition: udp.h:28
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:26
ServerListType
The types of server lists we can get.
Definition: udp.h:41
Wrapper for network addresses.
virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr)
Query for detailed information about companies.
Definition: udp.cpp:342
virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr)
The master server acknowledges the registration.
Definition: udp.cpp:345
bool Listen()
Start listening on the given host and port.
Definition: udp.cpp:47
void SendPacket(Packet *p, NetworkAddress *recv, bool all=false, bool broadcast=false)
Send a packet over UDP.
Definition: udp.cpp:83
Sends the list of NewGRF&#39;s requested.
Definition: udp.h:35
void HandleUDPPacket(Packet *p, NetworkAddress *client_addr)
Handle an incoming packets by sending it to the correct function.
Definition: udp.cpp:297
void Close()
Close the given UDP socket.
Definition: udp.cpp:62
virtual void Receive_SERVER_DETAIL_INFO(Packet *p, NetworkAddress *client_addr)
Reply with detailed company information.
Definition: udp.cpp:343
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:110
Basic functions to create, fill and read packets.
Response from master server with server ip&#39;s + port&#39;s.
Definition: udp.h:32
NetworkAddressList bind
The address to bind to.
Definition: udp.h:53
void ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo *info)
Deserializes the NetworkGameInfo struct from the packet.
Definition: udp.cpp:223
NetworkRecvStatus CloseConnection(bool error=true)
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
Definition: udp.cpp:70
Queries a game server about details of the game, such as companies.
Definition: udp.h:27
Reply of the game server with game information.
Definition: udp.h:26
virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr)
The server sends a list of servers.
Definition: udp.cpp:347
End of &#39;arrays&#39; marker.
Definition: udp.h:46
SocketHandler for all network sockets in OpenTTD.
Definition: core.h:45