From 317c26d1701102e45fc88fb47230a62e613d07d5 Mon Sep 17 00:00:00 2001 From: Synful-Syn Date: Sat, 5 Aug 2023 00:05:56 -0400 Subject: [PATCH] tracks last map id (#123) --- src/AnticheatData.cpp | 6 ++++-- src/AnticheatData.h | 8 ++++++-- src/AnticheatMgr.cpp | 16 ++++++++-------- src/AnticheatMgr.h | 3 --- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/AnticheatData.cpp b/src/AnticheatData.cpp index babfa24..06973ff 100644 --- a/src/AnticheatData.cpp +++ b/src/AnticheatData.cpp @@ -45,10 +45,11 @@ AnticheatData::~AnticheatData() { } -void AnticheatData::SetLastInformations(MovementInfo movementInfo, uint32 opcode, float speedRate) +void AnticheatData::SetLastInformations(MovementInfo movementInfo, uint32 opcode, uint32 mapId, float speedRate) { SetLastMovementInfo(movementInfo); SetLastOpcode(opcode); + SetLastMapId(mapId); SetLastSpeedRate(speedRate); } @@ -67,9 +68,10 @@ void AnticheatData::SetLastOpcode(uint32 opcode) lastOpcode = opcode; } -void AnticheatData::SetPosition(float x, float y, float z, float o) +void AnticheatData::SetPosition(float x, float y, float z, float o, uint32 mapId) { lastMovementInfo.pos = { x, y, z, o }; + SetLastMapId(mapId); } uint32 AnticheatData::GetLastOpcode() const diff --git a/src/AnticheatData.h b/src/AnticheatData.h index 5f6cc2b..8211f71 100644 --- a/src/AnticheatData.h +++ b/src/AnticheatData.h @@ -35,7 +35,7 @@ public: AnticheatData(); ~AnticheatData(); - void SetLastInformations(MovementInfo movementInfo, uint32 opcode, float speedRate); + void SetLastInformations(MovementInfo movementInfo, uint32 opcode, uint32 mapId, float speedRate); void SetLastOpcode(uint32 opcode); uint32 GetLastOpcode() const; @@ -43,10 +43,13 @@ public: const MovementInfo& GetLastMovementInfo() const; void SetLastMovementInfo(MovementInfo& moveInfo); + [[nodiscard]] uint32 GetLastMapId() const { return lastMapId; } + void SetLastMapId(float mapId) { lastMapId = mapId; } + [[nodiscard]] float GetLastSpeedRate() const { return lastSpeedRate; } void SetLastSpeedRate(float speedRate) { lastSpeedRate = speedRate; } - void SetPosition(float x, float y, float z, float o); + void SetPosition(float x, float y, float z, float o, uint32 mapId); uint32 GetTotalReports() const; void SetTotalReports(uint32 _totalReports); @@ -74,6 +77,7 @@ public: private: uint32 lastOpcode; MovementInfo lastMovementInfo; + uint32 lastMapId; float lastSpeedRate; uint32 totalReports; uint32 typeReports[MAX_REPORT_TYPES]; diff --git a/src/AnticheatMgr.cpp b/src/AnticheatMgr.cpp index af62cef..44e755d 100644 --- a/src/AnticheatMgr.cpp +++ b/src/AnticheatMgr.cpp @@ -100,7 +100,7 @@ void AnticheatMgr::StartHackDetection(Player* player, MovementInfo movementInfo, if (player->IsInFlight() || player->GetTransport() || player->GetVehicle()) { - m_Players[key].SetLastInformations(movementInfo, opcode, GetPlayerCurrentSpeedRate(player)); + m_Players[key].SetLastInformations(movementInfo, opcode, player->GetMapId(), GetPlayerCurrentSpeedRate(player)); return; } @@ -133,7 +133,7 @@ void AnticheatMgr::StartHackDetection(Player* player, MovementInfo movementInfo, BGStartExploit(player, movementInfo); } } - m_Players[key].SetLastInformations(movementInfo, opcode, GetPlayerCurrentSpeedRate(player)); + m_Players[key].SetLastInformations(movementInfo, opcode, player->GetMapId(), GetPlayerCurrentSpeedRate(player)); } void AnticheatMgr::SendMiddleScreenGMMessage(std::string str) @@ -376,10 +376,13 @@ void AnticheatMgr::SpeedHackDetection(Player* player, MovementInfo movementInfo) ObjectGuid key = player->GetGUID(); + if (m_Players[key].GetLastMapId() != player->GetMapId()) + return; + // We also must check the map because the movementFlag can be modified by the client. // If we just check the flag, they could always add that flag and always skip the speed hacking detection. - if (m_Players[key].GetLastMovementInfo().HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && player->GetMapId()) + if (m_Players[key].GetLastMovementInfo().HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT)) { switch (player->GetMapId()) { @@ -829,9 +832,6 @@ void AnticheatMgr::TeleportHackDetection(Player* player, MovementInfo movementIn ObjectGuid key = player->GetGUID(); - if (m_Players[key].GetLastMovementInfo().pos.GetPositionX() == movementInfo.pos.GetPositionX()) - return; - if (m_Players[key].GetLastOpcode() == MSG_DELAY_GHOST_TELEPORT) return; @@ -851,7 +851,7 @@ void AnticheatMgr::TeleportHackDetection(Player* player, MovementInfo movementIn if (player->IsFalling() || (player->IsFalling() && player->IsMounted())) return; - if (m_Players[key].GetLastMovementInfo().HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && player->GetMapId()) + if (m_Players[key].GetLastMovementInfo().HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT)) { switch (player->GetMapId()) { @@ -1496,7 +1496,7 @@ void AnticheatMgr::HandlePlayerLogin(Player* player) // we must delete this to prevent errors in case of crash CharacterDatabase.Execute("DELETE FROM `players_reports_status` WHERE `guid` = {}", player->GetGUID().GetCounter()); // we initialize the pos of lastMovementPosition var. - m_Players[player->GetGUID()].SetPosition(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation()); + m_Players[player->GetGUID()].SetPosition(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), player->GetMapId()); if (CharacterDatabase.Query("SELECT 0 FROM `daily_players_reports` WHERE `guid` = {};", player->GetGUID().GetCounter())) m_Players[player->GetGUID()].SetDailyReportState(true); diff --git a/src/AnticheatMgr.h b/src/AnticheatMgr.h index b33239d..32909d5 100644 --- a/src/AnticheatMgr.h +++ b/src/AnticheatMgr.h @@ -111,8 +111,6 @@ class AnticheatMgr void AnticheatDeleteCommand(ObjectGuid guid); void AnticheatPurgeCommand(ChatHandler* handler); void ResetDailyReportStates(); - void SetMapId(uint32 MapID) { m_MapId = MapID; } - [[nodiscard]] uint32 GetMapId() const { return m_MapId; } private: void SpeedHackDetection(Player* player, MovementInfo movementInfo); @@ -144,7 +142,6 @@ class AnticheatMgr [[nodiscard]] float GetTeleportSkillDistanceInYards(Player* player) const; [[nodiscard]] float GetPlayerCurrentSpeedRate(Player* player) const; uint32 _updateCheckTimer = 4000; - uint32 m_MapId; std::array _startPosition; Position const* GetTeamStartPosition(TeamId teamId) const; AnticheatPlayersDataMap m_Players; ///< Player data