OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
13 #include "../strings_func.h"
17 #include "table/strings.h"
19 #include "../safeguards.h"
37 this->handler->ConnectFailure();
50 this->ConnectFailure();
61 SOCKET game_sock = this->
sock;
62 this->
sock = INVALID_SOCKET;
89 std::unique_ptr<ClientNetworkTurnSocketHandler>
ClientNetworkTurnSocketHandler::Turn(
const std::string &token, uint8 tracking_number,
const std::string &ticket,
const std::string &connection_string)
97 turn_handler->SendPacket(p);
102 void ClientNetworkTurnSocketHandler::ConnectFailure()
128 if (this->
sock == INVALID_SOCKET)
return;
std::string connection_string
The connection string of the TURN server we are connecting to.
static const uint16 NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
void ConnectFailure(const std::string &token, uint8 tracking_number)
Callback from a Connecter to let the Game Coordinator know the connection failed.
std::string connection_string
Current address we are connecting to (before resolving).
bool Receive_TURN_CONNECTED(Packet *p) override
TURN server has connected client and server together and will now relay all packets to each other.
Connect to the TURN server.
"Helper" class for creating TCP connections in a non-blocking manner
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 Kill()
Kill this connecter.
SOCKET sock
The socket currently connected to.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
void OnConnect(SOCKET s) override
Callback when the connection succeeded.
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...
TCPConnecter * connecter
Connecter instance.
Class for handling the client side of the TURN connection.
void OnFailure() override
Callback for when the connection attempt failed.
virtual NetworkRecvStatus CloseConnection(bool error=true)
This will put this socket handler in a close state.
std::string token
Token of this connection.
Internal entity of a packet.
bool ReceivePackets()
Receive a packet at TCP level.
void Connect()
Connect to the TURN server.
NetworkTurnConnecter(ClientNetworkTurnSocketHandler *handler, const std::string &connection_string)
Initiate the connecting.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
bool CanSendReceive()
Check whether this socket can send or receive something.
uint8 tracking_number
Tracking number of this connection.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
bool connect_started
Whether we started the connection.
@ PACKET_TURN_SERCLI_CONNECT
Client or server is connecting to the TURN server.
bool Receive_TURN_ERROR(Packet *p) override
TURN server was unable to connect the client or server based on the token.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void Send_string(const std::string_view data)
Sends a string over the network.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
static const byte NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
static std::unique_ptr< ClientNetworkTurnSocketHandler > Turn(const std::string &token, uint8 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 ...
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
static const uint16 NETWORK_TURN_SERVER_PORT
The default port of the TURN server (TCP)