OpenTTD Source
20240919-master-gdf0233f4c2
|
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"
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;
bool Receive_TURN_CONNECTED(Packet &p) override
TURN server has connected client and server together and will now relay all packets to each other.
std::string connection_string
The connection string of the TURN server we are connecting to.
std::string connection_string
Current address we are connecting to (before resolving).
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.
Connect to the TURN server.
"Helper" class for creating TCP connections in a non-blocking manner
void ConnectFailure(const std::string &token, uint8_t tracking_number)
Callback from a Connecter to let the Game Coordinator know the connection failed.
static const uint8_t NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
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...
SOCKET sock
The socket currently connected to.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
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...
bool Receive_TURN_ERROR(Packet &p) override
TURN server was unable to connect the client or server based on the token.
static const uint16_t NETWORK_TURN_SERVER_PORT
The default port of the TURN server (TCP)
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.
@ PACKET_TURN_SERCLI_CONNECT
Client or server is connecting to the TURN server.
static const uint16_t NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
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.
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.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
uint8_t tracking_number
Tracking number of this 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.