From 0467ed0f5112d9d74de28ca739b3c39b487b0970 Mon Sep 17 00:00:00 2001 From: Kargatum Date: Wed, 3 Nov 2021 16:43:38 +0700 Subject: [PATCH] feat(Config): update to new API (#40) --- src/AnticheatMgr.cpp | 42 ++++++++++++++++++++-------------------- src/AnticheatScripts.cpp | 6 +++--- src/cs_anticheat.cpp | 10 +++++----- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/AnticheatMgr.cpp b/src/AnticheatMgr.cpp index 7a4169d..7ab6da7 100644 --- a/src/AnticheatMgr.cpp +++ b/src/AnticheatMgr.cpp @@ -31,7 +31,7 @@ AnticheatMgr::~AnticheatMgr() void AnticheatMgr::JumpHackDetection(Player* player, MovementInfo /* movementInfo */, uint32 opcode) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectJumpHack", true)) + if (!sConfigMgr->GetOption("Anticheat.DetectJumpHack", true)) return; ObjectGuid key = player->GetGUID(); @@ -45,7 +45,7 @@ void AnticheatMgr::JumpHackDetection(Player* player, MovementInfo /* movementInf void AnticheatMgr::WalkOnWaterHackDetection(Player* player, MovementInfo movementInfo) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectWaterWalkHack", true)) + if (!sConfigMgr->GetOption("Anticheat.DetectWaterWalkHack", true)) return; ObjectGuid key = player->GetGUID(); @@ -61,13 +61,13 @@ void AnticheatMgr::WalkOnWaterHackDetection(Player* player, MovementInfo moveme player->HasAuraType(SPELL_AURA_SAFE_FALL) || player->HasAuraType(SPELL_AURA_WATER_WALK)) return; - if (sConfigMgr->GetBoolDefault("Anticheat.KickPlayerWaterWalkHack", false)) + if (sConfigMgr->GetOption("Anticheat.KickPlayerWaterWalkHack", false)) { - if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) sLog->outString("AnticheatMgr:: Walk on Water - Hack detected and counteracted by kicking player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); player->GetSession()->KickPlayer(true); - if(sConfigMgr->GetBoolDefault("Anticheat.AnnounceKick", true)) + if(sConfigMgr->GetOption("Anticheat.AnnounceKick", true)) { std::string plr = player->GetName(); std::string tag_colour = "7bbef7"; @@ -79,7 +79,7 @@ void AnticheatMgr::WalkOnWaterHackDetection(Player* player, MovementInfo moveme sWorld->SendServerMessage(SERVER_MSG_STRING, stream.str().c_str()); } } - else if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) { + else if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) { sLog->outString("AnticheatMgr:: Walk on Water - Hack detected player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); } BuildReport(player, WALK_WATER_HACK_REPORT); @@ -88,7 +88,7 @@ void AnticheatMgr::WalkOnWaterHackDetection(Player* player, MovementInfo moveme void AnticheatMgr::FlyHackDetection(Player* player, MovementInfo movementInfo) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectFlyHack", true)) + if (!sConfigMgr->GetOption("Anticheat.DetectFlyHack", true)) { return; } @@ -100,7 +100,7 @@ void AnticheatMgr::FlyHackDetection(Player* player, MovementInfo movementInfo) /*Thanks to @LilleCarl for info to check extra flag*/ bool stricterChecks = true; - if (sConfigMgr->GetBoolDefault("Anticheat.StricterFlyHackCheck", false)) + if (sConfigMgr->GetOption("Anticheat.StricterFlyHackCheck", false)) { stricterChecks = !(movementInfo.HasMovementFlag(MOVEMENTFLAG_ASCENDING) && !player->IsInWater()); } @@ -110,15 +110,15 @@ void AnticheatMgr::FlyHackDetection(Player* player, MovementInfo movementInfo) return; } - if (sConfigMgr->GetBoolDefault("Anticheat.KickPlayerFlyHack", false)) + if (sConfigMgr->GetOption("Anticheat.KickPlayerFlyHack", false)) { - if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) { sLog->outString("AnticheatMgr:: Fly-Hack detected and counteracted by kicking player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); } player->GetSession()->KickPlayer(true); - if(sConfigMgr->GetBoolDefault("Anticheat.AnnounceKick", true)) + if(sConfigMgr->GetOption("Anticheat.AnnounceKick", true)) { std::string plr = player->GetName(); std::string tag_colour = "7bbef7"; @@ -129,7 +129,7 @@ void AnticheatMgr::FlyHackDetection(Player* player, MovementInfo movementInfo) " has been kicked.|r"; sWorld->SendServerMessage(SERVER_MSG_STRING, stream.str().c_str()); } - } else if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + } else if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) { sLog->outString( "AnticheatMgr:: Fly-Hack detected player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); } @@ -139,7 +139,7 @@ void AnticheatMgr::FlyHackDetection(Player* player, MovementInfo movementInfo) void AnticheatMgr::TeleportPlaneHackDetection(Player* player, MovementInfo movementInfo) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectTelePlaneHack", true)) + if (!sConfigMgr->GetOption("Anticheat.DetectTelePlaneHack", true)) return; ObjectGuid key = player->GetGUID(); @@ -162,7 +162,7 @@ void AnticheatMgr::TeleportPlaneHackDetection(Player* player, MovementInfo movem // we are not really walking there if (z_diff > 1.0f) { - if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) sLog->outString("AnticheatMgr:: Teleport To Plane - Hack detected player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); BuildReport(player, TELEPORT_PLANE_HACK_REPORT); @@ -171,7 +171,7 @@ void AnticheatMgr::TeleportPlaneHackDetection(Player* player, MovementInfo movem void AnticheatMgr::StartHackDetection(Player* player, MovementInfo movementInfo, uint32 opcode) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) return; if (player->IsGameMaster()) @@ -200,7 +200,7 @@ void AnticheatMgr::StartHackDetection(Player* player, MovementInfo movementInfo, // basic detection void AnticheatMgr::ClimbHackDetection(Player *player, MovementInfo movementInfo, uint32 opcode) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectClimbHack", false)) + if (!sConfigMgr->GetOption("Anticheat.DetectClimbHack", false)) return; ObjectGuid key = player->GetGUID(); @@ -225,7 +225,7 @@ void AnticheatMgr::ClimbHackDetection(Player *player, MovementInfo movementInfo, if (angle > CLIMB_ANGLE) { - if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) sLog->outString("AnticheatMgr:: Climb-Hack detected player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); BuildReport(player, CLIMB_HACK_REPORT); @@ -234,7 +234,7 @@ void AnticheatMgr::ClimbHackDetection(Player *player, MovementInfo movementInfo, void AnticheatMgr::SpeedHackDetection(Player* player, MovementInfo movementInfo) { - if (!sConfigMgr->GetBoolDefault("Anticheat.DetectSpeedHack", true)) + if (!sConfigMgr->GetOption("Anticheat.DetectSpeedHack", true)) return; ObjectGuid key = player->GetGUID(); @@ -274,7 +274,7 @@ void AnticheatMgr::SpeedHackDetection(Player* player, MovementInfo movementInfo) // we did the (uint32) cast to accept a margin of tolerance if (clientSpeedRate > speedRate) { - if (sConfigMgr->GetBoolDefault("Anticheat.WriteLog", false)) + if (sConfigMgr->GetOption("Anticheat.WriteLog", false)) sLog->outString("AnticheatMgr:: Speed-Hack detected player %s (%s)", player->GetName().c_str(), player->GetGUID().ToString().c_str()); BuildReport(player, SPEED_HACK_REPORT); @@ -377,7 +377,7 @@ void AnticheatMgr::BuildReport(Player* player, uint8 reportType) m_Players[key].SetAverage(average); } - if ((uint32)sConfigMgr->GetIntDefault("Anticheat.MaxReportsForDailyReport", 70) < m_Players[key].GetTotalReports()) + if (sConfigMgr->GetOption("Anticheat.MaxReportsForDailyReport", 70) < m_Players[key].GetTotalReports()) { if (!m_Players[key].GetDailyReportState()) { @@ -386,7 +386,7 @@ void AnticheatMgr::BuildReport(Player* player, uint8 reportType) } } - if (m_Players[key].GetTotalReports() > (uint32)sConfigMgr->GetIntDefault("Anticheat.ReportsForIngameWarnings", 70)) + if (m_Players[key].GetTotalReports() > sConfigMgr->GetOption("Anticheat.ReportsForIngameWarnings", 70)) { // display warning at the center of the screen, hacky way? std::string str = ""; diff --git a/src/AnticheatScripts.cpp b/src/AnticheatScripts.cpp index 3ac29e5..d5c2848 100644 --- a/src/AnticheatScripts.cpp +++ b/src/AnticheatScripts.cpp @@ -23,7 +23,7 @@ public: void OnLogin(Player* player) override { sAnticheatMgr->HandlePlayerLogin(player); - if(sConfigMgr->GetBoolDefault("Anticheat.LoginMessage", true)) + if(sConfigMgr->GetOption("Anticheat.LoginMessage", true)) ChatHandler(player->GetSession()).PSendSysMessage("This server is running an Anticheat Module."); } }; @@ -45,7 +45,7 @@ public: } if (sWorld->GetUptime() > lastIterationPlayer) { - lastIterationPlayer = sWorld->GetUptime() + sConfigMgr->GetIntDefault("Anticheat.SaveReportsTime", 60); + lastIterationPlayer = sWorld->GetUptime() + sConfigMgr->GetOption("Anticheat.SaveReportsTime", 60); sLog->outString( "Saving reports for %u players.", sWorld->GetPlayerCount()); for (SessionMap::const_iterator itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr) @@ -71,7 +71,7 @@ class AnticheatMovementHandlerScript : public MovementHandlerScript } void OnPlayerMove(Player* player, MovementInfo mi, uint32 opcode) override { - if (!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || sConfigMgr->GetBoolDefault("Anticheat.EnabledOnGmAccounts", false)) + if (!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || sConfigMgr->GetOption("Anticheat.EnabledOnGmAccounts", false)) sAnticheatMgr->StartHackDetection(player, mi, opcode); } }; diff --git a/src/cs_anticheat.cpp b/src/cs_anticheat.cpp index d172718..8c7b571 100644 --- a/src/cs_anticheat.cpp +++ b/src/cs_anticheat.cpp @@ -52,7 +52,7 @@ public: static bool HandleAnticheatWarnCommand(ChatHandler* handler, const char* args) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) return false; Player* pTarget = NULL; @@ -91,7 +91,7 @@ public: static bool HandleAnticheatJailCommand(ChatHandler* handler, const char* args) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) return false; Player* pTarget = NULL; @@ -140,7 +140,7 @@ public: static bool HandleAntiCheatDeleteCommand(ChatHandler* handler, const char* args) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) return false; std::string strCommand; @@ -169,7 +169,7 @@ public: static bool HandleAntiCheatPlayerCommand(ChatHandler* handler, const char* args) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) return false; std::string strCommand; @@ -221,7 +221,7 @@ public: static bool HandleAntiCheatGlobalCommand(ChatHandler* handler, const char* /* args */) { - if (!sConfigMgr->GetBoolDefault("Anticheat.Enabled", 0)) + if (!sConfigMgr->GetOption("Anticheat.Enabled", 0)) { handler->PSendSysMessage("The Anticheat System is disabled."); return true;