Esc to clear, Enter to open the best match, click an export to open it in its page
Security

Secure Events

Any player can send your server any event, with any values, as often as they like. With SecureEvent you write down what a call must look like, and WHIP checks it before your handler runs.

A call that fails never reaches your code, and the Monitor shows who sent it and why. SecureCallback does the same for a question the client waits on.

Before and after

A purchase with RegisterNetEvent, checked by hand:

local lastBuy = {}

RegisterNetEvent('myshop:buy', function(itemKey, amount)
    local source = source
    local player = exports.whip_core:GetPlayer(source)
    if not player or player.isDead then return end                -- loaded, and alive

    local now = GetGameTimer()                                     -- a rate limit, and a table
    if lastBuy[source] and now - lastBuy[source] < 500 then return end  -- to clean up when they leave
    lastBuy[source] = now

    if type(itemKey) ~= 'string' or not itemKey:match('^[%w_]+$') then return end
    amount = tonumber(amount)
    if not amount or amount ~= math.floor(amount) or amount < 1 or amount > 100 then return end

    local pos = GetEntityCoords(GetPlayerPed(source))              -- at the counter
    if #(pos - COUNTER) > 5.0 then return end

    buy(source, player, itemKey, amount)   -- every return above was silent: nobody sees why
end)

The same purchase as a SecureEvent:

exports.whip_core:SecureEvent('myshop:buy', {
    rateLimit = 500,
    params = {
        {'itemKey', 'key', 60},       -- letters, digits, _ and -
        {'amount',  'amount', 100},   -- a whole number from 1 to 100
    },
    near = { at = COUNTER, range = 5.0 },
}, function(source, player, itemKey, amount)
    buy(source, player, itemKey, amount)   -- loaded, alive, checked, at the counter
end)

What WHIP checks for you

CheckWhat it stopsYou write
A loaded characterCalls from character select, or from someone logging outNothing: on by default
AliveA dead player buying, looting or using itemsNothing: on by default
How oftenA call fired hundreds of times a secondNothing (10 in a row, then one every 100 ms), or rateLimit
Every valueThe wrong type, a negative amount, text where a number goesparams
Where they areBuying from across the mapnear
What they ownNaming somebody else's slot, stash or carThe slot, addr and vehicle types
Who they areAdmin and staff actions from everyone elseace or permission

What your handler saves lands in one transaction (Save system), but return false or an error doesn't undo it: refund it yourself.

What it doesn't do. near trusts the position the player's game reports, so teleports, god mode and aimbots still need an anticheat. And never let a client handler decide anything that matters: a cheat can fire those too.

Writing one#

Pass the event's name, its rules (the schema) and your handler. A tip jar for the coffee stand from Your First Resource:

-- server.lua
Whip.register(function()
    Whip.core:SecureEvent('mycafe:tip', {
        rateLimit = 2000,                                   -- one tip every 2 seconds
        params    = { {'amount', 'amount', 500} },          -- $1 to $500
        near      = { at = Config.Counter, range = 3.0 },
    }, function(source, player, amount)
        local receipt, err = exports.whip_core:ChargePlayer(source, amount, { reason = 'Tip' })
        if not receipt then return false, err end          -- refused: they are shown why
        exports.whip_core:NotifyPlayer(source, ('Thanks for the tip, %s'):format(player.firstName), 'success')
    end)
end)

-- client.lua: sent like any other event
TriggerServerEvent('mycafe:tip', 20)

Send TriggerServerEvent('mycafe:tip', -50) and /whip → System → Monitor shows it refused: amount: Amount must be a whole number of 1 or more. It keeps the last 500 accepted and 500 refused calls until whip_core restarts (Dev Tools). The console prints refusals too, unless Config.LogSecureRejections = false.

Checking the values: params#

One line per value the client sends, in order: a name, a type, then its limits, as in {'amount', 'amount', 100}. Only listed values reach your handler; one you leave out arrives as nil.

Numbers sent as text count as numbers, except in an enum. Every rule is in the types table.

Checking what they own: slot, vehicle, addr#

These check the player may use the thing, and hand your handler the thing itself.

exports.whip_core:SecureEvent('mykit:install', {
    params = { {'kit', 'slot', { item = 'mykit_turbo' }}, {'vehicle', 'vehicle'} },
    near = { at = 'vehicle', range = 5.0 },
}, function(source, player, kit, v)
    local taken, why = exports.whip_core:StoreTake(kit.addr, 1, { reason = 'fitted to ' .. v.plate })
    if not taken then return false, why end
    exports.whip_core:SetVehicleData(v.vehicleId, 'mykit_turbo', { fittedAt = os.time() })
end)

Refusals a real player can meet ("That item is not there any more") are shown to them; forged values, like someone else's pocket, are refused silently.

Checking where they are: near#

near refuses a call unless the player is within range metres (default 5) of at, which is a fixed vector3 or { x, y, z }; 'vehicle', the schema's vehicle value (sitting in it counts); or a function of the checked values:

near = {
    range = 15.0,
    at = function(source, player, shopId)
        local shop = exports.whip_core:GetShop(shopId)
        if not shop then return nil end          -- refused as too far
        return shop.x, shop.y, shop.z            -- or a vector3 or { x, y, z }
    end,
    message = 'You are too far from the shop', -- default 'Too far away'; false for timer calls
},

allowUnknown = true lets a call through when at finds no position, and range can be a function, to follow a setting.

How often: rateLimit and burst#

You writeA player may send
nothing10 in a row, then one every 100 ms
rateLimit = 2000One, then one every 2 seconds: a cooldown
rateLimit = 2000, burst = 55 in a row, then one every 2 seconds
rateLimit = falseAny number

A pause earns calls back, up to the burst. Give a burst to anything done quickly by hand, and to anything that closes something: a refused close leaves it open.

Who may send it#

Saying no#

Your handler returnsThe player seesThe Monitor records
false, 'You need a wrench'The message, as an errorRefused, with the message
falseNothingRefused
anything else, or nothingOnly what you send themAccepted

To record a reason without showing one, call RecordEventRejection, then return.

Asking the server: SecureCallback#

For a question the client waits on, register a SecureCallback and ask it with Callback. Your handler returns the answer.

local PRICES = { mycafe_coffee = 15, mycafe_muffin = 8 }   -- the server's prices, never the client's

-- server.lua, inside Whip.register
Whip.core:SecureCallback('mycafe:getPrice', {
    rateLimit = 500,
    params    = { {'itemKey', 'key', 60} },
}, function(source, player, itemKey)
    local price = PRICES[itemKey]
    if not price then return false, 'Not sold here' end   -- not nil: that would lose the why
    return price
end)

-- client.lua, in a command or event handler
local price, why = exports.whip_core:Callback('mycafe:getPrice', 'mycafe_coffee')
if not price then return exports.whip_core:Notify(why, 'error') end

The answer arrives up to its first nil, so refuse with false, why. With no answer, the client gets false and a reason:

The reasonWhen
'Rate limited', 'Player is dead', 'No player session', 'Too far away', 'itemKey: invalid key' …WHIP's checks refused the call
YoursYour handler returned false, 'Not sold here'
'Server error'Your handler errored (see the server console)
'Unknown callback'No callback has that name
'That is no longer available'Its resource has stopped
'No answer from the server'Nothing came back within 10 seconds

So answer an ordinary "no" with a word or a table, not false. The Monitor records every answer as accepted; RecordEventRejection records a refusal.

Less common options

ownerOf, onReject and sheet = 'light' are on the SecureEvent card. A handler that takes a lock can use TrackInvocationLock.

Common mistakes#

Coming from ESX, QBCore or ox_lib#

You use todayIn WHIP
RegisterNetEvent + AddEventHandlerSecureEvent
ESX.RegisterServerCallback, QBCore.Functions.CreateCallback, lib.callback.registerSecureCallback: return the answer, no cb
ESX.TriggerServerCallback, QBCore.Functions.TriggerCallback, lib.callback.awaitCallback: waits, and returns the answer

Moving an event over: swap the call, list its values in params, delete your own checks, declare it in Whip.register, and treat return false as "refused". You can move one event at a time. The rest: Coming from QBCore, ESX or ox.