# udp.h

Go to the documentation of this file.

    00001 /* $Id: udp.h 24900 2013-01-08 22:46:42Z planetmaker $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00014 #ifndef NETWORK_CORE_UDP_H
    00015 #define NETWORK_CORE_UDP_H
    00016
    00017 #include "address.h"
    00018 #include "game.h"
    00019 #include "packet.h"
    00020
    00021 #ifdef ENABLE_NETWORK
    00022
    00024 enum PacketUDPType {
    00025   PACKET_UDP_CLIENT_FIND_SERVER,
    00026   PACKET_UDP_SERVER_RESPONSE,
    00027   PACKET_UDP_CLIENT_DETAIL_INFO,
    00028   PACKET_UDP_SERVER_DETAIL_INFO,
    00029   PACKET_UDP_SERVER_REGISTER,
    00030   PACKET_UDP_MASTER_ACK_REGISTER,
    00031   PACKET_UDP_CLIENT_GET_LIST,
    00032   PACKET_UDP_MASTER_RESPONSE_LIST,
    00033   PACKET_UDP_SERVER_UNREGISTER,
    00034   PACKET_UDP_CLIENT_GET_NEWGRFS,
    00035   PACKET_UDP_SERVER_NEWGRFS,
    00036   PACKET_UDP_MASTER_SESSION_KEY,
    00037   PACKET_UDP_END,
    00038 };
    00039
    00041 enum ServerListType {
    00042   SLT_IPv4 = 0,
    00043   SLT_IPv6 = 1,
    00044   SLT_AUTODETECT,
    00045
    00046   SLT_END = SLT_AUTODETECT,
    00047 };
    00048
    00050 class NetworkUDPSocketHandler : public NetworkSocketHandler {
    00051 protected:
    00053   NetworkAddressList bind;
    00055   SocketList sockets;
    00056
    00057   NetworkRecvStatus CloseConnection(bool error = true);
    00058
    00059   void ReceiveInvalidPacket(PacketUDPType, NetworkAddress *client_addr);
    00060
    00066   virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr);
    00067
    00107   virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr);
    00108
    00114   virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
    00115
    00143   virtual void Receive_SERVER_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
    00144
    00154   virtual void Receive_SERVER_REGISTER(Packet *p, NetworkAddress *client_addr);
    00155
    00161   virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr);
    00162
    00170   virtual void Receive_CLIENT_GET_LIST(Packet *p, NetworkAddress *client_addr);
    00171
    00181   virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr);
    00182
    00190   virtual void Receive_SERVER_UNREGISTER(Packet *p, NetworkAddress *client_addr);
    00191
    00201   virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr);
    00202
    00213   virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr);
    00214
    00221   virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr);
    00222
    00223   void HandleUDPPacket(Packet *p, NetworkAddress *client_addr);
    00224
    00232   virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); }
    00233 public:
    00234   NetworkUDPSocketHandler(NetworkAddressList *bind = NULL);
    00235
    00237   virtual ~NetworkUDPSocketHandler() { this->Close(); }
    00238
    00239   bool Listen();
    00240   void Close();
    00241
    00242   void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false);
    00243   void ReceivePackets();
    00244
    00245   void SendNetworkGameInfo(Packet *p, const NetworkGameInfo *info);
    00246   void ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo *info);
    00247 };
    00248
    00249 #endif /* ENABLE_NETWORK */
    00250
    00251 #endif /* NETWORK_CORE_UDP_H */