summaryrefslogtreecommitdiff
path: root/src/network/network_coordinator.h
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-07-03 11:04:32 +0200
committerPatric Stout <github@truebrain.nl>2021-07-10 20:17:07 +0200
commitb1280fd17ebaf9e4df086b63074d0bd8b8c9155d (patch)
tree6a421d4e079a765ba21181ad01ab21d13434ba9a /src/network/network_coordinator.h
parente1e2212e0e09c7739f2eb8a4421a9ed7982801f5 (diff)
downloadopenttd-b1280fd17ebaf9e4df086b63074d0bd8b8c9155d.tar.xz
Add: use Game Coordinator to annouce public servers
Diffstat (limited to 'src/network/network_coordinator.h')
-rw-r--r--src/network/network_coordinator.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/network/network_coordinator.h b/src/network/network_coordinator.h
new file mode 100644
index 000000000..1dbce063b
--- /dev/null
+++ b/src/network/network_coordinator.h
@@ -0,0 +1,51 @@
+
+/*
+ * 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.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file network_coordinator.h Part of the network protocol handling Game Coordinator requests. */
+
+#ifndef NETWORK_COORDINATOR_H
+#define NETWORK_COORDINATOR_H
+
+#include "core/tcp_coordinator.h"
+
+/**
+ * Game Coordinator communication.
+ *
+ * For servers:
+ * - Server sends SERVER_REGISTER.
+ * - Game Coordinator probes server to check if it can directly connect.
+ * - Game Coordinator sends GC_REGISTER_ACK with type of connection.
+ * - Server sends every 30 seconds SERVER_UPDATE.
+ */
+
+/** 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).
+
+protected:
+ bool Receive_GC_ERROR(Packet *p) override;
+ bool Receive_GC_REGISTER_ACK(Packet *p) override;
+
+public:
+ bool connecting; ///< Are we connecting to the Game Coordinator?
+
+ ClientNetworkCoordinatorSocketHandler() : connecting(false) {}
+
+ NetworkRecvStatus CloseConnection(bool error = true) override;
+ void SendReceive();
+
+ void Connect();
+
+ void Register();
+ void SendServerUpdate();
+};
+
+extern ClientNetworkCoordinatorSocketHandler _network_coordinator_client;
+
+#endif /* NETWORK_COORDINATOR_H */