feat(Scripts): add support GameTime (#42)

This commit is contained in:
Kargatum
2022-01-24 19:07:13 +07:00
committed by GitHub
parent 2319489102
commit 3f4c562c55

View File

@@ -22,17 +22,15 @@
#include "Chat.h"
#include "Player.h"
#include "Timer.h"
#include "GameTime.h"
int64 resetTime = 0;
int64 lastIterationPlayer = sWorld->GetUptime() + 30;//TODO: change 30 secs static to a configurable option
Seconds resetTime = 0s;
Seconds lastIterationPlayer = GameTime::GetUptime() + 30s; //TODO: change 30 secs static to a configurable option
class AnticheatPlayerScript : public PlayerScript
{
public:
AnticheatPlayerScript()
: PlayerScript("AnticheatPlayerScript")
{
}
AnticheatPlayerScript() : PlayerScript("AnticheatPlayerScript") { }
void OnLogout(Player* player) override
{
@@ -42,31 +40,32 @@ public:
void OnLogin(Player* player) override
{
sAnticheatMgr->HandlePlayerLogin(player);
if(sConfigMgr->GetOption<bool>("Anticheat.LoginMessage", true))
if (sConfigMgr->GetOption<bool>("Anticheat.LoginMessage", true))
ChatHandler(player->GetSession()).PSendSysMessage("This server is running an Anticheat Module.");
}
};
class AnticheatWorldScript : public WorldScript
{
public:
AnticheatWorldScript()
: WorldScript("AnticheatWorldScript")
AnticheatWorldScript() : WorldScript("AnticheatWorldScript") { }
void OnUpdate(uint32 /* diff */) override // unusued parameter
{
}
void OnUpdate(uint32 /* diff */) override // unusued parameter
{
if (sWorld->GetGameTime() > resetTime)
if (GameTime::GetGameTime() > resetTime)
{
sLog->outString( "Anticheat: Resetting daily report states.");
LOG_INFO("module", "Anticheat: Resetting daily report states.");
sAnticheatMgr->ResetDailyReportStates();
UpdateReportResetTime();
sLog->outString( "Anticheat: Next daily report reset: %ld", resetTime);
FMT_LOG_INFO("module", "Anticheat: Next daily report reset: {}", Acore::Time::TimeToHumanReadable(resetTime));
}
if (sWorld->GetUptime() > lastIterationPlayer)
if (GameTime::GetUptime() > lastIterationPlayer)
{
lastIterationPlayer = sWorld->GetUptime() + sConfigMgr->GetOption<uint32>("Anticheat.SaveReportsTime", 60);
sLog->outString( "Saving reports for %u players.", sWorld->GetPlayerCount());
lastIterationPlayer = GameTime::GetUptime() + Seconds(sConfigMgr->GetOption<uint32>("Anticheat.SaveReportsTime", 60));
FMT_LOG_INFO("module", "Saving reports for {} players.", sWorld->GetPlayerCount());
for (SessionMap::const_iterator itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
if (Player* plr = itr->second->GetPlayer())
@@ -76,27 +75,27 @@ public:
void OnAfterConfigLoad(bool /* reload */) override // unusued parameter
{
sLog->outString("AnticheatModule Loaded.");
LOG_INFO("module", "AnticheatModule Loaded.");
}
void UpdateReportResetTime()
{
resetTime = Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
resetTime = Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
}
};
class AnticheatMovementHandlerScript : public MovementHandlerScript
{
public:
AnticheatMovementHandlerScript()
: MovementHandlerScript("AnticheatMovementHandlerScript")
{
}
public:
AnticheatMovementHandlerScript() : MovementHandlerScript("AnticheatMovementHandlerScript") { }
void OnPlayerMove(Player* player, MovementInfo mi, uint32 opcode) override
{
if (!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || sConfigMgr->GetOption<bool>("Anticheat.EnabledOnGmAccounts", false))
sAnticheatMgr->StartHackDetection(player, mi, opcode);
}
};
void startAnticheatScripts()
{
new AnticheatWorldScript();