diff options
author | Patric Stout <truebrain@openttd.org> | 2021-04-29 15:37:02 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-07-11 20:38:42 +0200 |
commit | e4d216e44b4a5d87094b4478ea4cf18109f99a35 (patch) | |
tree | 837b4b027ebaf0a328d0336ac93c110379a015ba /src/network/network_coordinator.h | |
parent | 1baec41542780cf4fc898df7d2fc9925d823fb44 (diff) | |
download | openttd-e4d216e44b4a5d87094b4478ea4cf18109f99a35.tar.xz |
Feature: join servers based on their invite code
This removes the need to know a server IP to join it. Invite codes
are small (~7 characters) indentifiers for servers, which can be
exchanged with other players to join the servers.
Diffstat (limited to 'src/network/network_coordinator.h')
-rw-r--r-- | src/network/network_coordinator.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/network/network_coordinator.h b/src/network/network_coordinator.h index 7399ce1fc..f846958bf 100644 --- a/src/network/network_coordinator.h +++ b/src/network/network_coordinator.h @@ -1,4 +1,3 @@ - /* * This file is part of OpenTTD. * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. @@ -12,6 +11,7 @@ #define NETWORK_COORDINATOR_H #include "core/tcp_coordinator.h" +#include <map> /** * Game Coordinator communication. @@ -25,17 +25,32 @@ * For clients (listing): * - Client sends CLIENT_LISTING. * - Game Coordinator returns the full list of public servers via GC_LISTING (multiple packets). + * + * For clients (connecting): + * - Client sends CLIENT_CONNECT. + * - Game Coordinator checks what type of connections the servers supports: + * 1) Direct connect? + * - Send the client a GC_CONNECT with the peer address. + * - a) Client connects, client sends CLIENT_CONNECTED to Game Coordinator. + * - b) Client connect fails, client sends CLIENT_CONNECT_FAILED to Game Coordinator. + * - If all fails, Game Coordinator sends GC_CONNECT_FAILED to indicate no connection is possible. */ /** Class for handling the client side of the Game Coordinator connection. */ class ClientNetworkCoordinatorSocketHandler : public NetworkCoordinatorSocketHandler { private: std::chrono::steady_clock::time_point next_update; ///< When to send the next update (if server and public). + std::map<std::string, TCPServerConnecter *> connecter; ///< Based on tokens, the current connecters that are pending. + std::map<std::string, TCPServerConnecter *> connecter_pre; ///< Based on invite codes, the current connecters that are pending. + TCPConnecter *game_connecter = nullptr; ///< Pending connecter to the game server. protected: bool Receive_GC_ERROR(Packet *p) override; bool Receive_GC_REGISTER_ACK(Packet *p) override; bool Receive_GC_LISTING(Packet *p) override; + bool Receive_GC_CONNECTING(Packet *p) override; + bool Receive_GC_CONNECT_FAILED(Packet *p) override; + bool Receive_GC_DIRECT_CONNECT(Packet *p) override; public: /** The idle timeout; when to close the connection because it's idle. */ @@ -49,11 +64,18 @@ public: NetworkRecvStatus CloseConnection(bool error = true) override; void SendReceive(); + void ConnectFailure(const std::string &token, uint8 tracking_number); + void ConnectSuccess(const std::string &token, SOCKET sock); + void Connect(); + void CloseToken(const std::string &token); + void CloseAllTokens(); void Register(); void SendServerUpdate(); void GetListing(); + + void ConnectToServer(const std::string &invite_code, TCPServerConnecter *connecter); }; extern ClientNetworkCoordinatorSocketHandler _network_coordinator_client; |