OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
16 #include "../safeguards.h"
33 stun_handler(stun_handler),
53 assert(this->stun_handler->
sock == INVALID_SOCKET);
54 this->stun_handler->
sock = s;
85 auto stun_handler = std::make_unique<ClientNetworkStunSocketHandler>();
94 stun_handler->SendPacket(p);
120 if (this->
sock == INVALID_SOCKET)
return;
TCPConnecter * connecter
Connecter instance.
std::string connection_string
Current address we are connecting to (before resolving).
"Helper" class for creating TCP connections in a non-blocking manner
uint8 family
Family of this STUN handler.
void Kill()
Kill this connecter.
SOCKET sock
The socket currently connected to.
const char * NetworkStunConnectionString()
Get the connection string for the STUN server from the environment variable OTTD_STUN_CS,...
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
@ SPS_ALL_SENT
All packets in the queue are sent.
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
NetworkAddress local_addr
Local addresses of the socket.
void OnFailure() override
Callback for when the connection attempt failed.
@ PACKET_STUN_SERCLI_STUN
Send a STUN request to the STUN server.
static const uint16 NETWORK_STUN_SERVER_PORT
The default port of the STUN server (TCP)
virtual NetworkRecvStatus CloseConnection(bool error=true)
This will put this socket handler in a close state.
void Connect(const std::string &token, uint8 family)
Connect to the STUN server over either IPv4 or IPv6.
void StunResult(const std::string &token, uint8 family, bool result)
Callback from the STUN connecter to inform the Game Coordinator about the result of the STUN.
void OnConnect(SOCKET s) override
Callback when the connection succeeded.
Internal entity of a packet.
std::string token
Token of this STUN handler.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
NetworkStunConnecter(ClientNetworkStunSocketHandler *stun_handler, const std::string &connection_string, const std::string &token, uint8 family)
Initiate the connecting.
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.
void SendReceive()
Check whether we received/can send some data from/to the STUN server and when that's the case handle ...
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(const std::string &token, uint8 family)
Send a STUN packet to the STUN server.
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.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
bool sent_result
Did we sent the result of the STUN connection?
static const byte NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
Class for handling the client side of the STUN connection.
Connect to the STUN server.