All Snippets
Lua Snippet
Server-Side Rate Limiter / Anti-Spam Wrapper
Description & Usage
Shields server-side net events against trigger injectors by enforcing execution cooldowns per player source.
Source Code (2 Files)
| 1 | local executionCooldowns = {} |
| 2 | |
| 3 | local function RegisterRateLimitedEvent(eventName, cooldownMs, callback) |
| 4 | RegisterNetEvent(eventName, function(...) |
| 5 | local src = source |
| 6 | local now = GetGameTimer() |
| 7 | |
| 8 | executionCooldowns[eventName] = executionCooldowns[eventName] or {} |
| 9 | local lastRun = executionCooldowns[eventName][src] or 0 |
| 10 | |
| 11 | if (now - lastRun) < cooldownMs then |
| 12 | DropPlayer(src, string.format("[Anti-Cheat] Trigger rate limit exceeded on: %s", eventName)) |
| 13 | return |
| 14 | end |
| 15 | |
| 16 | executionCooldowns[eventName][src] = now |
| 17 | callback(src, ...) |
| 18 | end) |
| 19 | end |
1 likes ·Sign in to like
Community Discussion (0)
Sign in to join the discussion and leave a comment.
Snippet Info
LanguageLua
Lines25
Chars811
Likes1