Skip to content

Commit

Permalink
Update code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Nov 28, 2023
1 parent aba4aaa commit fbaaa2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,5 +666,11 @@ class CGame
int m_iMaxClientTriggeredEventsPerInterval = 100;
int m_iClientTriggeredEventsIntervalMs = 1000;

std::map<CPlayer*, std::pair<int, int>> m_mapClientTriggeredEvents;
struct ClientTriggeredEventsInfo
{
long long m_llTicks;
uint32_t m_uiCounter;
};

std::map<CPlayer*, ClientTriggeredEventsInfo> m_mapClientTriggeredEvents;
};

0 comments on commit fbaaa2a

Please sign in to comment.