master server dvars (#96)

* add master_server_ip & master_server_port

* fix build

* fix dvars crashing game
This commit is contained in:
m 2022-06-25 07:03:11 -05:00 committed by GitHub
parent 54d8fbbd49
commit 30c34f7b63

View File

@ -10,6 +10,7 @@
#include "command.hpp" #include "command.hpp"
#include "game/game.hpp" #include "game/game.hpp"
#include "game/dvars.hpp"
#include "game/ui_scripting/execution.hpp" #include "game/ui_scripting/execution.hpp"
#include <utils/cryptography.hpp> #include <utils/cryptography.hpp>
@ -51,6 +52,9 @@ namespace server_list
volatile bool update_server_list = false; volatile bool update_server_list = false;
std::chrono::high_resolution_clock::time_point last_scroll{}; std::chrono::high_resolution_clock::time_point last_scroll{};
game::dvar_t* master_server_ip;
game::dvar_t* master_server_port;
size_t get_page_count() size_t get_page_count()
{ {
const auto count = servers.size() / server_limit; const auto count = servers.size() / server_limit;
@ -300,7 +304,8 @@ namespace server_list
bool get_master_server(game::netadr_s& address) bool get_master_server(game::netadr_s& address)
{ {
return game::NET_StringToAdr("master.h1.gg:20810", &address); return game::NET_StringToAdr(utils::string::va("%s:%s",
master_server_ip->current.string, master_server_port->current.string), &address);
} }
void handle_info_response(const game::netadr_s& address, const utils::info_string& info) void handle_info_response(const game::netadr_s& address, const utils::info_string& info)
@ -370,6 +375,15 @@ namespace server_list
{ {
if (!game::environment::is_mp()) return; if (!game::environment::is_mp()) return;
scheduler::once([]()
{
// add dvars to change destination master server ip/port
master_server_ip = dvars::register_string("masterServerIP", "master.h1.gg", game::DVAR_FLAG_NONE,
"IP of the destination master server to connect to");
master_server_port = dvars::register_string("masterServerPort", "20810", game::DVAR_FLAG_NONE,
"Port of the destination master server to connect to");
}, scheduler::pipeline::main);
localized_strings::override("PLATFORM_SYSTEM_LINK_TITLE", "SERVER LIST"); localized_strings::override("PLATFORM_SYSTEM_LINK_TITLE", "SERVER LIST");
// hook LUI_OpenMenu to refresh server list for system link menu // hook LUI_OpenMenu to refresh server list for system link menu