summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/network.cpp8
-rw-r--r--src/network/network_func.h1
-rw-r--r--src/network/network_server.cpp3
-rw-r--r--src/network/network_udp.cpp160
-rw-r--r--src/network/network_udp.h2
5 files changed, 3 insertions, 171 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 361517c96..395c374b8 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -61,7 +61,6 @@ bool _is_network_server; ///< Does this client wants to be a network-server?
NetworkCompanyState *_network_company_states = nullptr; ///< Statistics about some companies.
ClientID _network_own_client_id; ///< Our client identifier.
ClientID _redirect_console_to_client; ///< If not invalid, redirect the console output to a client.
-bool _network_need_advertise; ///< Whether we need to advertise.
uint8 _network_reconnect; ///< Reconnect timeout
StringList _network_bind_list; ///< The addresses to bind on.
StringList _network_host_list; ///< The servers we know.
@@ -944,10 +943,6 @@ bool NetworkServerStart()
/* if the server is dedicated ... add some other script */
if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
- /* Try to register us to the master server */
- _network_need_advertise = true;
- NetworkUDPAdvertise();
-
/* welcome possibly still connected admins - this can only happen on a dedicated server. */
if (_network_dedicated) ServerNetworkAdminSocketHandler::WelcomeAll();
@@ -996,8 +991,6 @@ void NetworkDisconnect(bool blocking, bool close_admins)
}
}
- if (_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(blocking);
-
CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
NetworkClose(close_admins);
@@ -1269,7 +1262,6 @@ void NetworkStartUp()
/* Network is available */
_network_available = NetworkCoreInitialize();
_network_dedicated = false;
- _network_need_advertise = true;
/* Generate an server id when there is none yet */
if (_settings_client.network.network_id.empty()) NetworkGenerateServerId();
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 0dd9328eb..6da8fb5cc 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -28,7 +28,6 @@ extern NetworkCompanyState *_network_company_states;
extern ClientID _network_own_client_id;
extern ClientID _redirect_console_to_client;
-extern bool _network_need_advertise;
extern uint8 _network_reconnect;
extern StringList _network_bind_list;
extern StringList _network_host_list;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index d44b61d3d..46d6918ac 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1879,9 +1879,6 @@ void NetworkServer_Tick(bool send_frame)
#endif
}
}
-
- /* See if we need to advertise */
- NetworkUDPAdvertise();
}
/** Yearly "callback". Called whenever the year changes. */
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 5e5da27bb..ffa07f087 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -8,7 +8,7 @@
/**
* @file network_udp.cpp This file handles the UDP related communication.
*
- * This is the GameServer <-> MasterServer and GameServer <-> GameClient
+ * This is the GameServer <-> GameClient
* communication before the game is being joined.
*/
@@ -34,16 +34,8 @@
#include "../safeguards.h"
-/** Session key to register ourselves to the master server */
-static uint64 _session_key = 0;
-
-static const std::chrono::minutes ADVERTISE_NORMAL_INTERVAL(15); ///< interval between advertising.
-static const std::chrono::seconds ADVERTISE_RETRY_INTERVAL(10); ///< re-advertise when no response after this amount of time.
-static const uint32 ADVERTISE_RETRY_TIMES = 3; ///< give up re-advertising after this much failed retries
-
static bool _network_udp_server; ///< Is the UDP server started?
static uint16 _network_udp_broadcast; ///< Timeout for the UDP broadcasts.
-static uint8 _network_advertise_retries; ///< The number of advertisement retries we did.
/** Some information about a socket, which exists before the actual socket has been created to provide locking and the likes. */
struct UDPSocket {
@@ -79,7 +71,6 @@ struct UDPSocket {
static UDPSocket _udp_client("Client"); ///< udp client socket
static UDPSocket _udp_server("Server"); ///< udp server socket
-static UDPSocket _udp_master("Master"); ///< udp master socket
/**
* Helper function doing the actual work for querying the server.
@@ -114,37 +105,6 @@ void NetworkUDPQueryServer(const std::string &connection_string, bool manually)
}
}
-///*** Communication with the masterserver ***/
-
-/** Helper class for connecting to the master server. */
-class MasterNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
-protected:
- void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr) override;
- void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr) override;
-public:
- /**
- * Create the socket.
- * @param addresses The addresses to bind on.
- */
- MasterNetworkUDPSocketHandler(NetworkAddressList *addresses) : NetworkUDPSocketHandler(addresses) {}
- virtual ~MasterNetworkUDPSocketHandler() {}
-};
-
-void MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr)
-{
- _network_advertise_retries = 0;
- Debug(net, 3, "Advertising on master server successful ({})", NetworkAddress::AddressFamilyAsString(client_addr->GetAddress()->ss_family));
-
- /* We are advertised, but we don't want to! */
- if (!_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(false);
-}
-
-void MasterNetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr)
-{
- _session_key = p->Recv_uint64();
- Debug(net, 6, "Received new session key from master server ({})", NetworkAddress::AddressFamilyAsString(client_addr->GetAddress()->ss_family));
-}
-
///*** Communication with clients (we are server) ***/
/** Helper class for handling all server side communication. */
@@ -477,113 +437,6 @@ void NetworkUDPSearchGame()
_network_udp_broadcast = 300; // Stay searching for 300 ticks
}
-/**
- * Thread entry point for de-advertising.
- */
-static void NetworkUDPRemoveAdvertiseThread()
-{
- Debug(net, 3, "Removing advertise from master server");
-
- /* Find somewhere to send */
- NetworkAddress out_addr(NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT);
-
- /* Send the packet */
- Packet p(PACKET_UDP_SERVER_UNREGISTER);
- /* Packet is: Version, server_port */
- p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
- p.Send_uint16(_settings_client.network.server_port);
-
- std::lock_guard<std::mutex> lock(_udp_master.mutex);
- if (_udp_master.socket != nullptr) _udp_master.socket->SendPacket(&p, &out_addr, true);
-}
-
-/**
- * Remove our advertise from the master-server.
- * @param blocking whether to wait until the removal has finished.
- */
-void NetworkUDPRemoveAdvertise(bool blocking)
-{
- /* Check if we are advertising */
- if (!_networking || !_network_server || !_network_udp_server) return;
-
- if (blocking || !StartNewThread(nullptr, "ottd:udp-advert", &NetworkUDPRemoveAdvertiseThread)) {
- NetworkUDPRemoveAdvertiseThread();
- }
-}
-
-/**
- * Thread entry point for advertising.
- */
-static void NetworkUDPAdvertiseThread()
-{
- /* Find somewhere to send */
- NetworkAddress out_addr(NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT);
-
- Debug(net, 3, "Advertising to master server");
-
- /* Add a bit more messaging when we cannot get a session key */
- static byte session_key_retries = 0;
- if (_session_key == 0 && session_key_retries++ == 2) {
- Debug(net, 0, "Advertising to the master server is failing");
- Debug(net, 0, " we are not receiving the session key from the server");
- Debug(net, 0, " please allow udp packets from {} to you to be delivered", out_addr.GetAddressAsString(false));
- Debug(net, 0, " please allow udp packets from you to {} to be delivered", out_addr.GetAddressAsString(false));
- }
- if (_session_key != 0 && _network_advertise_retries == 0) {
- Debug(net, 0, "Advertising to the master server is failing");
- Debug(net, 0, " we are not receiving the acknowledgement from the server");
- Debug(net, 0, " this usually means that the master server cannot reach us");
- Debug(net, 0, " please allow udp and tcp packets to port {} to be delivered", _settings_client.network.server_port);
- Debug(net, 0, " please allow udp and tcp packets from port {} to be delivered", _settings_client.network.server_port);
- }
-
- /* Send the packet */
- Packet p(PACKET_UDP_SERVER_REGISTER);
- /* Packet is: WELCOME_MESSAGE, Version, server_port */
- p.Send_string(NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
- p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
- p.Send_uint16(_settings_client.network.server_port);
- p.Send_uint64(_session_key);
-
- std::lock_guard<std::mutex> lock(_udp_master.mutex);
- if (_udp_master.socket != nullptr) _udp_master.socket->SendPacket(&p, &out_addr, true);
-}
-
-/**
- * Register us to the master server
- * This function checks if it needs to send an advertise
- */
-void NetworkUDPAdvertise()
-{
- static std::chrono::steady_clock::time_point _last_advertisement = {}; ///< The last time we performed an advertisement.
-
- /* Check if we should send an advertise */
- if (!_networking || !_network_server || !_network_udp_server || !_settings_client.network.server_advertise) return;
-
- if (_network_need_advertise) {
- /* Forced advertisement. */
- _network_need_advertise = false;
- _network_advertise_retries = ADVERTISE_RETRY_TIMES;
- } else {
- /* Only send once every ADVERTISE_NORMAL_INTERVAL ticks */
- if (_network_advertise_retries == 0) {
- if (std::chrono::steady_clock::now() <= _last_advertisement + ADVERTISE_NORMAL_INTERVAL) return;
-
- _network_advertise_retries = ADVERTISE_RETRY_TIMES;
- } else {
- /* An actual retry. */
- if (std::chrono::steady_clock::now() <= _last_advertisement + ADVERTISE_RETRY_INTERVAL) return;
- }
- }
-
- _network_advertise_retries--;
- _last_advertisement = std::chrono::steady_clock::now();
-
- if (!StartNewThread(nullptr, "ottd:udp-advert", &NetworkUDPAdvertiseThread)) {
- NetworkUDPAdvertiseThread();
- }
-}
-
/** Initialize the whole UDP bit. */
void NetworkUDPInitialize()
{
@@ -591,9 +444,9 @@ void NetworkUDPInitialize()
if (_udp_server.socket != nullptr) NetworkUDPClose();
Debug(net, 3, "Initializing UDP listeners");
- assert(_udp_client.socket == nullptr && _udp_server.socket == nullptr && _udp_master.socket == nullptr);
+ assert(_udp_client.socket == nullptr && _udp_server.socket == nullptr);
- std::scoped_lock lock(_udp_client.mutex, _udp_server.mutex, _udp_master.mutex);
+ std::scoped_lock lock(_udp_client.mutex, _udp_server.mutex);
_udp_client.socket = new ClientNetworkUDPSocketHandler();
@@ -601,13 +454,8 @@ void NetworkUDPInitialize()
GetBindAddresses(&server, _settings_client.network.server_port);
_udp_server.socket = new ServerNetworkUDPSocketHandler(&server);
- server.clear();
- GetBindAddresses(&server, 0);
- _udp_master.socket = new MasterNetworkUDPSocketHandler(&server);
-
_network_udp_server = false;
_network_udp_broadcast = 0;
- _network_advertise_retries = 0;
}
/** Start the listening of the UDP server component. */
@@ -622,7 +470,6 @@ void NetworkUDPClose()
{
_udp_client.CloseSocket();
_udp_server.CloseSocket();
- _udp_master.CloseSocket();
_network_udp_server = false;
_network_udp_broadcast = 0;
@@ -634,7 +481,6 @@ void NetworkBackgroundUDPLoop()
{
if (_network_udp_server) {
_udp_server.ReceivePackets();
- _udp_master.ReceivePackets();
} else {
_udp_client.ReceivePackets();
if (_network_udp_broadcast > 0) _network_udp_broadcast--;
diff --git a/src/network/network_udp.h b/src/network/network_udp.h
index ced949cd3..735e5f223 100644
--- a/src/network/network_udp.h
+++ b/src/network/network_udp.h
@@ -16,8 +16,6 @@ void NetworkUDPInitialize();
void NetworkUDPSearchGame();
void NetworkUDPQueryMasterServer();
void NetworkUDPQueryServer(const std::string &connection_string, bool manually = false);
-void NetworkUDPAdvertise();
-void NetworkUDPRemoveAdvertise(bool blocking);
void NetworkUDPClose();
void NetworkUDPServerListen();
void NetworkBackgroundUDPLoop();