Initial Upload
This commit is contained in:
commit
8ea130bdf0
24
conf/mod-server-idler.conf.dist
Normal file
24
conf/mod-server-idler.conf.dist
Normal 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
74
src/mod_server_idler.cpp
Normal 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();
|
||||||
|
}
|
||||||
8
src/mod_server_idler_loader.cpp
Normal file
8
src/mod_server_idler_loader.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
|
void AddSC_server_idler();
|
||||||
|
|
||||||
|
void Addmod_server_idlerScripts()
|
||||||
|
{
|
||||||
|
AddSC_server_idler();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user