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

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
24 enum PacketUDPType {
25 PACKET_UDP_CLIENT_FIND_SERVER,
26 PACKET_UDP_SERVER_RESPONSE,
27 PACKET_UDP_CLIENT_DETAIL_INFO,
28 PACKET_UDP_SERVER_DETAIL_INFO,
29 PACKET_UDP_SERVER_REGISTER,
30 PACKET_UDP_MASTER_ACK_REGISTER,
31 PACKET_UDP_CLIENT_GET_LIST,
32 PACKET_UDP_MASTER_RESPONSE_LIST,
33 PACKET_UDP_SERVER_UNREGISTER,
34 PACKET_UDP_CLIENT_GET_NEWGRFS,
35 PACKET_UDP_SERVER_NEWGRFS,
36 PACKET_UDP_MASTER_SESSION_KEY,
37 PACKET_UDP_END,
38 };
39
41 enum ServerListType {
42 SLT_IPv4 = 0,
43 SLT_IPv6 = 1,
44 SLT_AUTODETECT,
45
46 SLT_END = SLT_AUTODETECT,
47 };
48
50 class NetworkUDPSocketHandler : public NetworkSocketHandler {
51 protected:
53 NetworkAddressList bind;
55 SocketList sockets;
56
57 NetworkRecvStatus CloseConnection(bool error = true);
58
59 void ReceiveInvalidPacket(PacketUDPType, NetworkAddress *client_addr);
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:
234 NetworkUDPSocketHandler(NetworkAddressList *bind = NULL);
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);
246 void ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo *info);
247 };
248
249 #endif /* ENABLE_NETWORK */
250
251 #endif /* NETWORK_CORE_UDP_H */