a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Shared / RateLimitPerPlayer
RateLimitPerPlayer(
calls
,interval
): (_target
,propertyKey
,descriptor
) =>void
A decorator to enforce a rate limit on a method, restricting the number of times it can be called by each player within a specified time interval.
• calls: number
The maximum number of allowed calls per player within the specified interval.
• interval: number
The time window (in milliseconds) within which the call limit is enforced.
Function
A method decorator that enforces the rate limit per player.
• _target: unknown
• propertyKey: string
• descriptor: PropertyDescriptor
void
class Game {
// Allow each player to call the `performAction` method a maximum of 5 times per minute.
@RateLimitPerPlayer(5, 60000)
performAction(playerId: number, action: string) {
console.log(`Action ${action} performed for player ${playerId}`)
}
}
const game = new Game();
game.performAction(1, 'test') // Action test performed for player 1
game.performAction(1, 'test') // Action test performed for player 1
game.performAction(1, 'test') // Action test performed for player 1
game.performAction(1, 'test') // Action test performed for player 1
game.performAction(1, 'test') // Action test performed for player 1
game.performAction(1, 'test') // Rate limit exceeded for player 1 on function: performAction
playerId
is expected to be the first argument of the decorated method.