OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #ifndef NETWORK_COORDINATOR_H
11 #define NETWORK_COORDINATOR_H
57 std::map<std::string, std::pair<std::string, TCPServerConnecter *>>
connecter;
59 std::map<std::string, std::map<int, std::unique_ptr<ClientNetworkStunSocketHandler>>>
stun_handlers;
60 std::map<std::string, std::unique_ptr<ClientNetworkTurnSocketHandler>>
turn_handlers;
80 static constexpr std::chrono::seconds
IDLE_TIMEOUT = std::chrono::seconds(60);
90 void ConnectFailure(
const std::string &token, uint8 tracking_number);
92 void StunResult(
const std::string &token, uint8 family,
bool result);
105 void StartTurnConnection(std::string &token);
void ConnectFailure(const std::string &token, uint8 tracking_number)
Callback from a Connecter to let the Game Coordinator know the connection failed.
"Helper" class for creating TCP connections in a non-blocking manner
bool Receive_GC_CONNECT_FAILED(Packet *p) override
Game Coordinator informs the Client that it failed to find a way to connect the Client to the Server.
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...
bool Receive_GC_STUN_CONNECT(Packet *p) override
Game Coordinator informs the client/server of its STUN peer (the host:ip of the other side).
SOCKET sock
The socket currently connected to.
bool Receive_GC_ERROR(Packet *p) override
Game Coordinator indicates there was an error.
void CloseAllConnections()
Close all pending connection tokens.
bool Receive_GC_STUN_REQUEST(Packet *p) override
Game Coordinator requests the client/server to do a STUN request to the STUN server.
void ConnectToServer(const std::string &invite_code, TCPServerConnecter *connecter)
Join a server based on an invite code.
bool Receive_GC_TURN_CONNECT(Packet *p) override
Game Coordinator requests that we make a connection to the indicated peer, which is a TURN server.
std::map< std::string, std::map< int, std::unique_ptr< ClientNetworkStunSocketHandler > > > stun_handlers
All pending STUN handlers, stored by token:family.
TCPConnecter * game_connecter
Pending connecter to the game server.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
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 GetListing()
Request a listing of all public servers.
void Register()
Register our server to receive our invite code.
Internal entity of a packet.
uint32 newgrf_lookup_table_cursor
Last received cursor for the GameInfoNewGRFLookupTable updates.
GameInfoNewGRFLookupTable newgrf_lookup_table
Table to look up NewGRFs in the GC_LISTING packets.
bool Receive_GC_LISTING(Packet *p) override
Game Coordinator replies with a list of all public servers.
bool Receive_GC_DIRECT_CONNECT(Packet *p) override
Game Coordinator requests that the Client makes a direct connection to the indicated peer,...
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
std::map< std::string, TCPServerConnecter * > connecter_pre
Based on invite codes, the current connecters that are pending.
bool Receive_GC_NEWGRF_LOOKUP(Packet *p) override
Game Coordinator informs the client of updates for the NewGRFs lookup table as used by the NewGRF des...
void SendReceive()
Check whether we received/can send some data from/to the Game Coordinator server and when that's the ...
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
std::chrono::steady_clock::time_point last_activity
The last time there was network activity.
Game Coordinator communication.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
void SendServerUpdate()
Send an update of our server status to the Game Coordinator.
std::chrono::steady_clock::time_point next_update
When to send the next update (if server and public).
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
std::unordered_map< uint32, NamedGRFIdentifier > GameInfoNewGRFLookupTable
Lookup table for the GameInfo in case of NST_LOOKUP_ID.
std::map< std::string, std::unique_ptr< ClientNetworkTurnSocketHandler > > turn_handlers
Pending TURN handler (if any), stored by token.
void CloseToken(const std::string &token)
Close everything related to this connection token.
void CloseTurnHandler(const std::string &token)
Close the TURN handler.
bool Receive_GC_REGISTER_ACK(Packet *p) override
Game Coordinator acknowledges the registration.
Base socket handler for all Game Coordinator TCP sockets.
std::map< std::string, std::pair< std::string, TCPServerConnecter * > > connecter
Based on tokens, the current (invite-code, connecter) that are pending.
bool connecting
Are we connecting to the Game Coordinator?
static constexpr std::chrono::seconds IDLE_TIMEOUT
The idle timeout; when to close the connection because it's idle.
void CloseStunHandler(const std::string &token, uint8 family=AF_UNSPEC)
Close the STUN handler.
bool Receive_GC_CONNECTING(Packet *p) override
Game Coordinator informs the Client under what token it will start the attempt to connect the Server ...