Heartbeats
This commit is contained in:
parent
1d81fd35be
commit
7798f1e20e
@ -3,6 +3,7 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
Dvar::Var Dedicated::Dedi;
|
Dvar::Var Dedicated::Dedi;
|
||||||
|
std::vector<Dedicated::Callback> Dedicated::FrameCallbacks;
|
||||||
|
|
||||||
bool Dedicated::IsDedicated()
|
bool Dedicated::IsDedicated()
|
||||||
{
|
{
|
||||||
@ -97,6 +98,37 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dedicated::Heartbeat()
|
||||||
|
{
|
||||||
|
int masterPort = Dvar::Var("masterPort").Get<int>();
|
||||||
|
const char* masterServerName = Dvar::Var("masterServerName").Get<const char*>();
|
||||||
|
|
||||||
|
Network::Address master(Utils::VA("%s:%u", masterServerName, masterPort));
|
||||||
|
|
||||||
|
Logger::Print("Sending heartbeat to master: %s:%u\n", masterServerName, masterPort);
|
||||||
|
|
||||||
|
Network::Send(master, Utils::VA("heartbeat %s\n", "IW4"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dedicated::OnFrame(Dedicated::Callback callback)
|
||||||
|
{
|
||||||
|
Dedicated::FrameCallbacks.push_back(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dedicated::FrameStub()
|
||||||
|
{
|
||||||
|
for (auto callback : Dedicated::FrameCallbacks)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
mov eax, 5A8E80h
|
||||||
|
call eax
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Dedicated::Dedicated()
|
Dedicated::Dedicated()
|
||||||
{
|
{
|
||||||
Dedicated::Dedi = Dvar::Register<int>("dedicated", 0, 0, 2, Game::dvar_flag::DVAR_FLAG_SERVERINFO | Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "Start as dedicated");
|
Dedicated::Dedi = Dvar::Register<int>("dedicated", 0, 0, 2, Game::dvar_flag::DVAR_FLAG_SERVERINFO | Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "Start as dedicated");
|
||||||
@ -159,12 +191,12 @@ namespace Components
|
|||||||
// Map rotation
|
// Map rotation
|
||||||
Utils::Hook::Set(0x4152E8, Dedicated::MapRotate);
|
Utils::Hook::Set(0x4152E8, Dedicated::MapRotate);
|
||||||
|
|
||||||
|
// Dedicated frame handler
|
||||||
|
Utils::Hook(0x4B0F81, Dedicated::FrameStub, HOOK_CALL).Install()->Quick();
|
||||||
|
|
||||||
// isHost script call return 0
|
// isHost script call return 0
|
||||||
Utils::Hook::Set<DWORD>(0x5DEC04, 0);
|
Utils::Hook::Set<DWORD>(0x5DEC04, 0);
|
||||||
|
|
||||||
// map_rotate func
|
|
||||||
//*(DWORD*)0x4152E8 = (DWORD)SV_MapRotate_f;
|
|
||||||
|
|
||||||
// sv_network_fps max 1000, and uncheat
|
// sv_network_fps max 1000, and uncheat
|
||||||
Utils::Hook::Set<BYTE>(0x4D3C67, 0); // ?
|
Utils::Hook::Set<BYTE>(0x4D3C67, 0); // ?
|
||||||
Utils::Hook::Set<DWORD>(0x4D3C69, 1000);
|
Utils::Hook::Set<DWORD>(0x4D3C69, 1000);
|
||||||
@ -180,6 +212,23 @@ namespace Components
|
|||||||
|
|
||||||
// stop saving a config_mp.cfg
|
// stop saving a config_mp.cfg
|
||||||
Utils::Hook::Set<BYTE>(0x60B240, 0xC3);
|
Utils::Hook::Set<BYTE>(0x60B240, 0xC3);
|
||||||
|
|
||||||
|
// Heartbeats
|
||||||
|
Dedicated::OnFrame([] ()
|
||||||
|
{
|
||||||
|
static int LastHeartbeat = 0;
|
||||||
|
|
||||||
|
if (Dvar::Var("sv_maxclients").Get<int>() > 0 && !LastHeartbeat || (Game::Com_Milliseconds() - LastHeartbeat) > 120 * 1000)
|
||||||
|
{
|
||||||
|
LastHeartbeat = Game::Com_Milliseconds();
|
||||||
|
Dedicated::Heartbeat();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dedicated::~Dedicated()
|
||||||
|
{
|
||||||
|
Dedicated::FrameCallbacks.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,24 @@ namespace Components
|
|||||||
class Dedicated : public Component
|
class Dedicated : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef void(*Callback)();
|
||||||
|
|
||||||
Dedicated();
|
Dedicated();
|
||||||
|
~Dedicated();
|
||||||
const char* GetName() { return "Dedicated"; };
|
const char* GetName() { return "Dedicated"; };
|
||||||
|
|
||||||
static bool IsDedicated();
|
static bool IsDedicated();
|
||||||
|
|
||||||
|
static void Heartbeat();
|
||||||
|
|
||||||
|
static void OnFrame(Callback callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Dvar::Var Dedi;
|
static Dvar::Var Dedi;
|
||||||
|
static std::vector<Callback> FrameCallbacks;
|
||||||
|
|
||||||
static void MapRotate();
|
static void MapRotate();
|
||||||
|
static void FrameStub();
|
||||||
static void InitDedicatedServer();
|
static void InitDedicatedServer();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -475,6 +475,8 @@ namespace Components
|
|||||||
|
|
||||||
Menus::Menus()
|
Menus::Menus()
|
||||||
{
|
{
|
||||||
|
if (Dedicated::IsDedicated()) return;
|
||||||
|
|
||||||
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_MENUFILE, Menus::MenuFileLoad);
|
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_MENUFILE, Menus::MenuFileLoad);
|
||||||
//Utils::Hook(0x63FE80, Menus::MenuFileLoad, HOOK_JUMP).Install()->Quick();
|
//Utils::Hook(0x63FE80, Menus::MenuFileLoad, HOOK_JUMP).Install()->Quick();
|
||||||
|
|
||||||
|
@ -140,7 +140,14 @@ namespace Components
|
|||||||
{
|
{
|
||||||
int clientCount = 0;
|
int clientCount = 0;
|
||||||
|
|
||||||
for (int i = 0; i < *Game::svs_numclients; i++)
|
int maxClients = *Game::svs_numclients;
|
||||||
|
|
||||||
|
if (!maxClients)
|
||||||
|
{
|
||||||
|
maxClients = Dvar::Var("sv_maxclients").Get<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < maxClients; i++)
|
||||||
{
|
{
|
||||||
if (Game::svs_clients[i].state >= 3)
|
if (Game::svs_clients[i].state >= 3)
|
||||||
{
|
{
|
||||||
@ -157,7 +164,9 @@ namespace Components
|
|||||||
info.Set("fs_game", Dvar::Var("fs_game").Get<const char*>());
|
info.Set("fs_game", Dvar::Var("fs_game").Get<const char*>());
|
||||||
info.Set("xuid", Utils::VA("%llX", Steam::SteamUser()->GetSteamID().Bits));
|
info.Set("xuid", Utils::VA("%llX", Steam::SteamUser()->GetSteamID().Bits));
|
||||||
info.Set("clients", Utils::VA("%i", clientCount));
|
info.Set("clients", Utils::VA("%i", clientCount));
|
||||||
info.Set("sv_maxclients", Utils::VA("%i", *Game::svs_numclients));
|
info.Set("sv_maxclients", Utils::VA("%i", maxClients));
|
||||||
|
info.Set("protocol", Utils::VA("%i", PROTOCOL));
|
||||||
|
info.Set("checksum", Utils::VA("%d", Game::Com_Milliseconds()));
|
||||||
|
|
||||||
// Set matchtype
|
// Set matchtype
|
||||||
// 0 - No match, connecting not possible
|
// 0 - No match, connecting not possible
|
||||||
@ -177,7 +186,7 @@ namespace Components
|
|||||||
info.Set("matchtype", "0");
|
info.Set("matchtype", "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
Network::Send(address, Utils::VA("infoResponse\n%s\n", info.Build().data()));
|
Network::Send(address, Utils::VA("infoResponse\n\\%s\n", info.Build().data()));
|
||||||
});
|
});
|
||||||
|
|
||||||
Network::Handle("infoResponse", [] (Network::Address address, std::string data)
|
Network::Handle("infoResponse", [] (Network::Address address, std::string data)
|
||||||
|
@ -84,7 +84,7 @@ namespace Components
|
|||||||
|
|
||||||
Logger::Print("Sending serverlist request to master: %s:%u\n", masterServerName, masterPort);
|
Logger::Print("Sending serverlist request to master: %s:%u\n", masterServerName, masterPort);
|
||||||
|
|
||||||
Network::Send(ServerList::RefreshContainer.Host, "getservers IW4 145 full empty");
|
Network::Send(ServerList::RefreshContainer.Host, Utils::VA("getservers IW4 %i full empty", PROTOCOL));
|
||||||
//Network::Send(ServerList::RefreshContainer.Host, "getservers 0 full empty\n");
|
//Network::Send(ServerList::RefreshContainer.Host, "getservers 0 full empty\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,10 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server.MatchType)
|
||||||
|
{
|
||||||
ServerList::OnlineList.push_back(server);
|
ServerList::OnlineList.push_back(server);
|
||||||
|
}
|
||||||
|
|
||||||
ServerList::RefreshContainer.Servers.erase(i);
|
ServerList::RefreshContainer.Servers.erase(i);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user