VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Cooldown< TKey, TMap > Class Template Reference

A per-key cooldown, such as one notice per player per minute. More...

#include <Cooldown.hpp>

Public Member Functions

 Cooldown ()=default
 
 Cooldown (int64_t seconds)
 
bool TryStart (const TKey &key, int64_t nowSec, int64_t seconds)
 
bool TryStart (const TKey &key, int64_t nowSec)
 
int64_t SecondsLeft (const TKey &key, int64_t nowSec, int64_t seconds) const
 
int64_t SecondsLeft (const TKey &key, int64_t nowSec) const
 
void Start (const TKey &key, int64_t nowSec)
 
void Reset (const TKey &key)
 
void RemoveExpired (int64_t nowSec, int64_t maxAgeSec)
 

Detailed Description

template<class TKey, class TMap = std::unordered_map<TKey, int64_t>>
class VoltMod::Cooldown< TKey, TMap >

A per-key cooldown, such as one notice per player per minute.

A slot key resets when a player rejoins into another slot; a SteamID key does not.

Definition at line 17 of file Cooldown.hpp.

Constructor & Destructor Documentation

◆ Cooldown() [1/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
VoltMod::Cooldown< TKey, TMap >::Cooldown ( )
default

◆ Cooldown() [2/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
VoltMod::Cooldown< TKey, TMap >::Cooldown ( int64_t  seconds)
inlineexplicit

Definition at line 21 of file Cooldown.hpp.

Member Function Documentation

◆ RemoveExpired()

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
void VoltMod::Cooldown< TKey, TMap >::RemoveExpired ( int64_t  nowSec,
int64_t  maxAgeSec 
)
inline

Removes keys started more than maxAgeSec ago.

Definition at line 64 of file Cooldown.hpp.

References VoltMod::ReadFile().

◆ Reset()

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
void VoltMod::Cooldown< TKey, TMap >::Reset ( const TKey &  key)
inline

Definition at line 61 of file Cooldown.hpp.

References VoltMod::ReadFile().

◆ SecondsLeft() [1/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
int64_t VoltMod::Cooldown< TKey, TMap >::SecondsLeft ( const TKey &  key,
int64_t  nowSec 
) const
inline

◆ SecondsLeft() [2/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
int64_t VoltMod::Cooldown< TKey, TMap >::SecondsLeft ( const TKey &  key,
int64_t  nowSec,
int64_t  seconds 
) const
inline

0 when key is free, also after the clock jumped back.

Definition at line 37 of file Cooldown.hpp.

References VoltMod::ReadFile().

Referenced by VoltMod::Cooldown< TKey, TMap >::TryStart().

◆ Start()

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
void VoltMod::Cooldown< TKey, TMap >::Start ( const TKey &  key,
int64_t  nowSec 
)
inline

Starts it without checking, for a caller that already checked.

Definition at line 59 of file Cooldown.hpp.

References VoltMod::ReadFile().

◆ TryStart() [1/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
bool VoltMod::Cooldown< TKey, TMap >::TryStart ( const TKey &  key,
int64_t  nowSec 
)
inline

◆ TryStart() [2/2]

template<class TKey , class TMap = std::unordered_map<TKey, int64_t>>
bool VoltMod::Cooldown< TKey, TMap >::TryStart ( const TKey &  key,
int64_t  nowSec,
int64_t  seconds 
)
inline

Starts key's cooldown and returns true, or false while it is still running. 0 seconds never blocks.

Definition at line 24 of file Cooldown.hpp.

References VoltMod::ReadFile(), and VoltMod::Cooldown< TKey, TMap >::SecondsLeft().


The documentation for this class was generated from the following file: