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/>.
9 * @file tcp_turn.h Basic functions to receive and send TCP packets to/from the TURN server.
12 #ifndef NETWORK_CORE_TCP_TURN_H
13 #define NETWORK_CORE_TCP_TURN_H
15 #include "os_abstraction.h"
18 #include "network_game_info.h"
20 /** Enum with all types of TCP TURN packets. The order MUST not be changed. **/
21 enum PacketTurnType
: uint8_t {
22 PACKET_TURN_TURN_ERROR
, ///< TURN server is unable to relay.
23 PACKET_TURN_SERCLI_CONNECT
, ///< Client or server is connecting to the TURN server.
24 PACKET_TURN_TURN_CONNECTED
, ///< TURN server indicates the socket is now being relayed.
25 PACKET_TURN_END
, ///< Must ALWAYS be on the end of this list!! (period)
28 /** Base socket handler for all TURN TCP sockets. */
29 class NetworkTurnSocketHandler
: public NetworkTCPSocketHandler
{
31 bool ReceiveInvalidPacket(PacketTurnType type
);
34 * TURN server was unable to connect the client or server based on the
35 * token. Most likely cause is an invalid token or the other side that
36 * hasn't connected in a reasonable amount of time.
38 * @param p The packet that was just received.
39 * @return True upon success, otherwise false.
41 virtual bool Receive_TURN_ERROR(Packet
&p
);
44 * Client or servers wants to connect to the TURN server (on request by
45 * the Game Coordinator).
47 * uint8_t Game Coordinator protocol version.
48 * string Token to track the current TURN request.
50 * @param p The packet that was just received.
51 * @return True upon success, otherwise false.
53 virtual bool Receive_SERCLI_CONNECT(Packet
&p
);
56 * TURN server has connected client and server together and will now relay
57 * all packets to each other. No further TURN packets should be send over
58 * this socket, and the socket should be handed over to the game protocol.
60 * string Hostname of the peer. This can be used to check if a client is not banned etc.
62 * @param p The packet that was just received.
63 * @return True upon success, otherwise false.
65 virtual bool Receive_TURN_CONNECTED(Packet
&p
);
67 bool HandlePacket(Packet
&p
);
70 * Create a new cs socket handler for a given cs.
71 * @param s the socket we are connected with.
72 * @param address IP etc. of the client.
74 NetworkTurnSocketHandler(SOCKET s
= INVALID_SOCKET
) : NetworkTCPSocketHandler(s
) {}
76 bool ReceivePackets();
79 #endif /* NETWORK_CORE_TCP_TURN_H */