Initial Upload

This commit is contained in:
Flerp 2025-11-15 17:59:03 -08:00
commit 8ea130bdf0
4 changed files with 106 additions and 0 deletions

0
README.md Normal file
View File

View File

@ -0,0 +1,24 @@
#
# Server Idler configuration
#
# ServerIdler.Enable
# Description: Enable/disable the server idler module.
# Default: 1 - (Enabled)
# 0 - (Disabled)
#
ServerIdler.Enable = 1
# ServerIdler.IntervalIdle
# Description: Map update interval (in milliseconds) when NO players are online.
# Important: Higher values = less CPU usage, but slower world updates.
# Default: 200
#
ServerIdler.IntervalIdle = 200
# ServerIdler.IntervalActive
# Description: Map update interval (in milliseconds) when at least one player is online.
# Important: Typically matches or is close to your MapUpdateInterval in worldserver.conf.
# Default: 10
#
ServerIdler.IntervalActive = 10

74
src/mod_server_idler.cpp Normal file
View File

@ -0,0 +1,74 @@
#include "ScriptMgr.h"
#include "Config.h"
#include "World.h"
#include "Player.h"
namespace
{
bool sEnabled = true;
uint32 sIntervalIdle = 200u;
uint32 sIntervalActive = 10u;
uint32 sPlayersOnline = 0u;
void ApplyInterval()
{
if (!sEnabled)
return;
uint32 newInterval = (sPlayersOnline > 0) ? sIntervalActive : sIntervalIdle;
sWorld->setIntConfig(CONFIG_MAP_UPDATE_INTERVAL, newInterval);
}
}
class ServerIdler_WorldScript : public WorldScript
{
public:
ServerIdler_WorldScript() : WorldScript("ServerIdler_WorldScript") {}
void OnAfterConfigLoad(bool) override
{
sEnabled = sConfigMgr->GetOption<bool>("ServerIdler.Enable", true);
sIntervalIdle = sConfigMgr->GetOption<uint32>("ServerIdler.IntervalIdle", 200u);
sIntervalActive = sConfigMgr->GetOption<uint32>("ServerIdler.IntervalActive", 10u);
if (sIntervalIdle == 0u)
sIntervalIdle = 1u;
if (sIntervalActive == 0u)
sIntervalActive = 1u;
sPlayersOnline = sWorld->GetPlayerCount();
ApplyInterval();
}
};
class ServerIdler_PlayerScript : public PlayerScript
{
public:
ServerIdler_PlayerScript() : PlayerScript("ServerIdler_PlayerScript") {}
void OnLogin(Player*) override
{
if (!sEnabled)
return;
++sPlayersOnline;
ApplyInterval();
}
void OnLogout(Player*) override
{
if (!sEnabled)
return;
if (sPlayersOnline > 0)
--sPlayersOnline;
ApplyInterval();
}
};
void AddSC_server_idler()
{
new ServerIdler_WorldScript();
new ServerIdler_PlayerScript();
}

View File

@ -0,0 +1,8 @@
#include "ScriptMgr.h"
void AddSC_server_idler();
void Addmod_server_idlerScripts()
{
AddSC_server_idler();
}