10 #include "../stdafx.h"
16 #include "../safeguards.h"
33 stun_handler(stun_handler),
41 Debug(net, 9,
"Stun::OnFailure(): family={}", this->family);
51 void OnConnect(SOCKET s)
override
53 Debug(net, 9,
"Stun::OnConnect(): family={}", this->family);
57 assert(this->stun_handler->
sock == INVALID_SOCKET);
58 this->stun_handler->
sock = s;
78 Debug(net, 9,
"Stun::Connect(): family={}", this->family);
91 auto stun_handler = std::make_unique<ClientNetworkStunSocketHandler>();
97 p->Send_string(
token);
100 stun_handler->SendPacket(std::move(p));
118 ClientNetworkStunSocketHandler::~ClientNetworkStunSocketHandler()
132 if (this->
sock == INVALID_SOCKET)
return;
void StunResult(const std::string &token, uint8_t family, bool result)
Callback from the STUN connecter to inform the Game Coordinator about the result of the STUN.
Class for handling the client side of the STUN connection.
void Connect(const std::string &token, uint8_t family)
Connect to the STUN server over either IPv4 or IPv6.
std::string token
Token of this STUN handler.
void SendReceive()
Check whether we received/can send some data from/to the STUN server and when that's the case handle ...
uint8_t family
Family of this STUN handler.
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(const std::string &token, uint8_t family)
Send a STUN packet to the STUN server.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
NetworkAddress local_addr
Local addresses of the socket.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
bool sent_result
Did we sent the result of the STUN connection?
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
Connect to the STUN server.
NetworkStunConnecter(ClientNetworkStunSocketHandler *stun_handler, const std::string &connection_string, const std::string &token, uint8_t family)
Initiate the connecting.
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.
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.
"Helper" class for creating TCP connections in a non-blocking manner
std::string connection_string
Current address we are connecting to (before resolving).
const char * NetworkStunConnectionString()
Get the connection string for the STUN server from the environment variable OTTD_STUN_CS,...
static const uint16_t NETWORK_STUN_SERVER_PORT
The default port of the STUN server (TCP)
static const uint8_t NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
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.
Basic functions/variables used all over the place.
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 STUN requests.
@ SPS_ALL_SENT
All packets in the queue are sent.
@ PACKET_STUN_SERCLI_STUN
Send a STUN request to the STUN server.