Codechange: Use CargoArray for linkgraph refresher. (#13165)
[openttd-github.git] / src / network / core / tcp_stun.h
blob0fce3b2a0774cf62b06e0dc8f20c9ae4012b0a57
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 */
8 /**
9 * @file tcp_stun.h Basic functions to receive and send TCP packets to/from the STUN server.
12 #ifndef NETWORK_CORE_TCP_STUN_H
13 #define NETWORK_CORE_TCP_STUN_H
15 #include "os_abstraction.h"
16 #include "tcp.h"
17 #include "packet.h"
19 /** Enum with all types of TCP STUN packets. The order MUST not be changed. **/
20 enum PacketStunType : uint8_t {
21 PACKET_STUN_SERCLI_STUN, ///< Send a STUN request to the STUN server.
22 PACKET_STUN_END, ///< Must ALWAYS be on the end of this list!! (period)
25 /** Base socket handler for all STUN TCP sockets. */
26 class NetworkStunSocketHandler : public NetworkTCPSocketHandler {
27 protected:
28 bool ReceiveInvalidPacket(PacketStunType type);
30 /**
31 * Send a STUN request to the STUN server letting the Game Coordinator know
32 * what our actually public IP:port is.
34 * uint8_t Game Coordinator protocol version.
35 * string Token to track the current STUN request.
36 * uint8_t Which interface number this is (for example, IPv4 or IPv6).
37 * The Game Coordinator relays this number back in later packets.
39 * @param p The packet that was just received.
40 * @return True upon success, otherwise false.
42 virtual bool Receive_SERCLI_STUN(Packet &p);
44 public:
45 /**
46 * Create a new cs socket handler for a given cs.
47 * @param s the socket we are connected with.
48 * @param address IP etc. of the client.
50 NetworkStunSocketHandler(SOCKET s = INVALID_SOCKET) : NetworkTCPSocketHandler(s) {}
53 #endif /* NETWORK_CORE_TCP_STUN_H */