From e4d216e44b4a5d87094b4478ea4cf18109f99a35 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 29 Apr 2021 15:37:02 +0200 Subject: 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. --- src/network/network_coordinator.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/network/network_coordinator.h') 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 /** * 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 connecter; ///< Based on tokens, the current connecters that are pending. + std::map 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; -- cgit v1.2.3-54-g00ecf