10 #include "../stdafx.h"
13 #include "../strings_func.h"
17 #include "table/strings.h"
19 #include "../safeguards.h"
35 Debug(net, 9,
"Turn::OnFailure()");
39 this->handler->ConnectFailure();
42 void OnConnect(SOCKET s)
override
44 Debug(net, 9,
"Turn::OnConnect()");
48 this->handler->
sock = s;
54 Debug(net, 9,
"Receive_TURN_ERROR()");
56 this->ConnectFailure();
63 Debug(net, 9,
"Receive_TURN_CONNECTED()");
69 SOCKET game_sock = this->
sock;
70 this->
sock = INVALID_SOCKET;
83 Debug(net, 9,
"Turn::Connect()");
99 std::unique_ptr<ClientNetworkTurnSocketHandler>
ClientNetworkTurnSocketHandler::Turn(
const std::string &token, uint8_t tracking_number,
const std::string &ticket,
const std::string &connection_string)
105 p->Send_string(ticket);
107 turn_handler->SendPacket(std::move(p));
112 void ClientNetworkTurnSocketHandler::ConnectFailure()
130 ClientNetworkTurnSocketHandler::~ClientNetworkTurnSocketHandler()
144 if (this->
sock == INVALID_SOCKET)
return;
void ConnectSuccess(const std::string &token, SOCKET sock, NetworkAddress &address)
Callback from a Connecter to let the Game Coordinator know the connection to the game server is estab...
void ConnectFailure(const std::string &token, uint8_t tracking_number)
Callback from a Connecter to let the Game Coordinator know the connection failed.
Class for handling the client side of the TURN connection.
bool Receive_TURN_ERROR(Packet &p) override
TURN server was unable to connect the client or server based on the token.
bool connect_started
Whether we started the connection.
uint8_t tracking_number
Tracking number of this connection.
std::string token
Token of this connection.
void Connect()
Connect to the TURN server.
bool Receive_TURN_CONNECTED(Packet &p) override
TURN server has connected client and server together and will now relay all packets to each other.
static std::unique_ptr< ClientNetworkTurnSocketHandler > Turn(const std::string &token, uint8_t tracking_number, const std::string &ticket, const std::string &connection_string)
Prepare a TURN connection.
void SendReceive()
Check whether we received/can send some data from/to the TURN server and when that's the case handle ...
std::string connection_string
The connection string of the TURN server we are connecting to.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
virtual NetworkRecvStatus CloseConnection(bool error=true)
This will put this socket handler in a close state.
SOCKET sock
The socket currently connected to.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
bool CanSendReceive()
Check whether this socket can send or receive something.
Connect to the TURN server.
NetworkTurnConnecter(ClientNetworkTurnSocketHandler *handler, const std::string &connection_string)
Initiate the connecting.
void OnFailure() override
Callback for when the connection attempt failed.
bool ReceivePackets()
Receive a packet at TCP level.
"Helper" class for creating TCP connections in a non-blocking manner
std::string connection_string
Current address we are connecting to (before resolving).
static const uint16_t NETWORK_TURN_SERVER_PORT
The default port of the TURN server (TCP)
static const uint8_t NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
static const uint16_t NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
Part of the network protocol handling Game Coordinator requests.
Part of the network protocol handling TURN requests.
Internal entity of a packet.
std::string Recv_string(size_t length, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads characters (bytes) from the packet until it finds a '\0', or reaches a maximum of length charac...
@ PACKET_TURN_SERCLI_CONNECT
Client or server is connecting to the TURN server.