From 44090244bc078e927035c4f12e8dd04d150d85d1 Mon Sep 17 00:00:00 2001 From: m Date: Tue, 3 May 2022 00:17:31 -0500 Subject: [PATCH] use X Labs master server, node fallback --- src/Components/Modules/Dedicated.cpp | 2 -- src/Components/Modules/Node.cpp | 2 ++ src/Components/Modules/ServerList.cpp | 47 ++++++++++++++++++--------- src/Components/Modules/ServerList.hpp | 3 ++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index b56e9ccb..6043607a 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -374,7 +374,6 @@ namespace Components } }); -#ifdef USE_LEGACY_SERVER_LIST // Heartbeats Scheduler::Once(Dedicated::Heartbeat); Scheduler::OnFrame([]() @@ -387,7 +386,6 @@ namespace Components Dedicated::Heartbeat(); } }); -#endif Dvar::OnInit([]() { diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 50797f93..e08a597a 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -114,6 +114,7 @@ namespace Components void Node::StoreNodes(bool force) { + if (ServerList::useMasterServer) return; if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get()) return; static Utils::Time::Interval interval; @@ -167,6 +168,7 @@ namespace Components void Node::RunFrame() { + if (ServerList::useMasterServer) return; if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get()) return; if (!Dedicated::IsEnabled() && *Game::clcState > 0) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 586c61e6..9e0099f4 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -19,6 +19,8 @@ namespace Components Dvar::Var ServerList::NETServerQueryLimit; Dvar::Var ServerList::NETServerFrames; + bool ServerList::useMasterServer = true; + std::vector* ServerList::GetList() { if (ServerList::IsOnlineList()) @@ -274,22 +276,31 @@ namespace Components } else if (ServerList::IsOnlineList()) { -#ifdef USE_LEGACY_SERVER_LIST - ServerList::RefreshContainer.awatingList = true; - ServerList::RefreshContainer.awaitTime = Game::Sys_Milliseconds(); + const auto masterPort = Dvar::Var("masterPort").get(); + const auto masterServerName = Dvar::Var("masterServerName").get(); - int masterPort = Dvar::Var("masterPort").get(); - const char* masterServerName = Dvar::Var("masterServerName").get(); + Game::netadr_t masterServerAddr; + if (ServerList::GetMasterServer(masterServerAddr)) + { + Logger::Print("A valid master server was found at %s:%u\n", masterServerName, masterPort); - ServerList::RefreshContainer.host = Network::Address(Utils::String::VA("%s:%u", masterServerName, masterPort)); + ServerList::RefreshContainer.awatingList = true; + ServerList::RefreshContainer.awaitTime = Game::Sys_Milliseconds(); - Logger::Print("Sending serverlist request to master: %s:%u\n", masterServerName, masterPort); + ServerList::RefreshContainer.host = Network::Address(Utils::String::VA("%s:%u", masterServerName, masterPort)); - Network::SendCommand(ServerList::RefreshContainer.host, "getservers", Utils::String::VA("IW4 %i full empty", PROTOCOL)); - //Network::SendCommand(ServerList::RefreshContainer.Host, "getservers", "0 full empty"); -#else - Node::Synchronize(); -#endif + Logger::Print("Sending serverlist request to master\n"); + Network::SendCommand(ServerList::RefreshContainer.host, "getservers", Utils::String::VA("IW4 %i full empty", PROTOCOL)); + } + else + { + // this should only be getting called if no master server is found or reached + Logger::Print("No valid master server was found, using node as fallback\n"); + + useMasterServer = false; + + Node::Synchronize(); + } } else if (ServerList::IsFavouriteList()) { @@ -733,6 +744,14 @@ namespace Components } } + bool ServerList::GetMasterServer(Game::netadr_t& address) + { + auto masterPort = Dvar::Var("masterPort").get(); + auto masterServerName = Dvar::Var("masterServerName").get(); + + return Game::NET_StringToAdr(Utils::String::VA("%s:%u"), &address); + } + ServerList::ServerList() { ServerList::OnlineList.clear(); @@ -792,11 +811,9 @@ namespace Components }); // Set default masterServerName + port and save it -#ifdef USE_LEGACY_SERVER_LIST - Utils::Hook::Set(0x60AD92, "127.0.0.1"); + Utils::Hook::Set(0x60AD92, "master.xlabs.dev"); Utils::Hook::Set(0x60AD90, Game::dvar_flag::DVAR_ARCHIVE); // masterServerName Utils::Hook::Set(0x60ADC6, Game::dvar_flag::DVAR_ARCHIVE); // masterPort -#endif // Add server list feeder UIFeeder::Add(2.0f, ServerList::GetServerCount, ServerList::GetServerText, ServerList::SelectServer); diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 87e4526f..43f7c534 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -50,6 +50,9 @@ namespace Components static void UpdateVisibleInfo(); + static bool GetMasterServer(Game::netadr_t& address); + static bool useMasterServer; + private: enum Column {