From fbaaa2acf9d994538bd958aa44366426d725161f Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:08:22 +0000 Subject: [PATCH] Update code review comments --- Server/mods/deathmatch/logic/CGame.cpp | 14 +++++++------- Server/mods/deathmatch/logic/CGame.h | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 7c3b57f91f..29728cf90c 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -4710,26 +4710,26 @@ void CGame::RegisterClientTriggeredEventUsage(CPlayer* pPlayer) if (!pPlayer || !pPlayer->IsPlayer() || pPlayer->IsBeingDeleted()) return; - int now = GetTickCount64_(); + auto now = GetTickCount64_(); // If key/player doesn't exist in map, store time of entry if (m_mapClientTriggeredEvents.find(pPlayer) == m_mapClientTriggeredEvents.end()) - m_mapClientTriggeredEvents[pPlayer].second = now; + m_mapClientTriggeredEvents[pPlayer].m_llTicks = now; // Only increment if we haven't reached the interval time already - if (now - m_mapClientTriggeredEvents[pPlayer].second <= m_iClientTriggeredEventsIntervalMs) - m_mapClientTriggeredEvents[pPlayer].first++; + if (now - m_mapClientTriggeredEvents[pPlayer].m_llTicks <= m_iClientTriggeredEventsIntervalMs) + m_mapClientTriggeredEvents[pPlayer].m_uiCounter++; } void CGame::ProcessClientTriggeredEventSpam() { - for (const auto& [player, pair]: m_mapClientTriggeredEvents) + for (const auto& [player, data]: m_mapClientTriggeredEvents) { if (player && player->IsPlayer() && !player->IsBeingDeleted()) { - if (GetTickCount64_() - pair.second >= m_iClientTriggeredEventsIntervalMs) + if (GetTickCount64_() - data.m_llTicks >= m_iClientTriggeredEventsIntervalMs) { - if (pair.first > m_iMaxClientTriggeredEventsPerInterval) + if (data.m_uiCounter > m_iMaxClientTriggeredEventsPerInterval) player->CallEvent("onPlayerTriggerEventThreshold", {}); m_mapClientTriggeredEvents.erase(player); diff --git a/Server/mods/deathmatch/logic/CGame.h b/Server/mods/deathmatch/logic/CGame.h index 58acdb9f81..7194b2a021 100644 --- a/Server/mods/deathmatch/logic/CGame.h +++ b/Server/mods/deathmatch/logic/CGame.h @@ -666,5 +666,11 @@ class CGame int m_iMaxClientTriggeredEventsPerInterval = 100; int m_iClientTriggeredEventsIntervalMs = 1000; - std::map> m_mapClientTriggeredEvents; + struct ClientTriggeredEventsInfo + { + long long m_llTicks; + uint32_t m_uiCounter; + }; + + std::map m_mapClientTriggeredEvents; };