Fix memory leak and implement sv_lanOnly

This commit is contained in:
momo5502 2016-04-13 19:31:16 +02:00
parent 1e0fe1c060
commit 377ba8d4cb
3 changed files with 25 additions and 4 deletions

View File

@ -228,7 +228,7 @@ namespace Components
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P
{
Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't register at the master server");
Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node");
Utils::Hook(0x60BE98, Dedicated::InitDedicatedServer, HOOK_CALL).Install()->Quick();

View File

@ -20,17 +20,18 @@ namespace Components
void Flags::ParseFlags()
{
int numArgs;
LPCWSTR commandLine = GetCommandLineW();
LPWSTR* argv = CommandLineToArgvW(commandLine, &numArgs);
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
for (int i = 0; i < numArgs; ++i)
{
std::wstring wFlag = argv[i];
std::wstring wFlag(argv[i]);
if (wFlag[0] == L'-')
{
Flags::EnabledFlags.push_back(std::string(++wFlag.begin(), wFlag.end()));
}
}
LocalFree(argv);
}
Flags::Flags()

View File

@ -37,6 +37,8 @@ namespace Components
}
void Node::StoreNodes(bool force)
{
if (Dedicated::IsDedicated() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
static int lastStorage = 0;
// Don't store nodes if the delta is too small and were not forcing it
@ -246,6 +248,8 @@ namespace Components
void Node::FrameHandler()
{
if (Dedicated::IsDedicated() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Frame limit
static int lastFrame = 0;
if ((Game::Com_Milliseconds() - lastFrame) < (1000 / NODE_FRAME_LOCK) || Game::Com_Milliseconds() < 5000) return;
@ -360,6 +364,8 @@ namespace Components
{
QuickPatch::OnShutdown([] ()
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
std::string challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt());
Proto::Node::Packet packet;
@ -376,6 +382,8 @@ namespace Components
// If you want to get accepted as node, you have to send a request to this handler
Network::Handle("nodeRegisterRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
Node::NodeEntry* entry = Node::FindNode(address);
// Create a new entry, if we don't already know it
@ -422,6 +430,8 @@ namespace Components
Network::Handle("nodeRegisterSynchronize", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
Node::NodeEntry* entry = Node::FindNode(address);
if (!entry || entry->state != Node::STATE_NEGOTIATING) return;
@ -470,6 +480,8 @@ namespace Components
Network::Handle("nodeRegisterAcknowledge", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Ignore requests from nodes we don't know
Node::NodeEntry* entry = Node::FindNode(address);
if (!entry || entry->state != Node::STATE_NEGOTIATING) return;
@ -507,6 +519,8 @@ namespace Components
Network::Handle("nodeListRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Check if this is a registered node
bool allowed = false;
Node::NodeEntry* entry = Node::FindNode(address);
@ -541,6 +555,8 @@ namespace Components
Network::Handle("nodeDeregister", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
Node::NodeEntry* entry = Node::FindNode(address);
if (!entry || !entry->registered) return;
@ -571,6 +587,8 @@ namespace Components
Network::Handle("sessionRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Search an active session, if we haven't found one, register a template
if (!Node::FindSession(address))
{
@ -597,6 +615,8 @@ namespace Components
Network::Handle("sessionSynchronize", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Return if we don't have a session for this address
Node::ClientSession* session = Node::FindSession(address);
if (!session || session->valid) return;