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

SecureEvent & SecureCallback

Server exports for checked events and callbacks, and the client's Callback. New to them? Read Secure Events first.

Registering

SecureEvent(eventName, schema, handler)SERVER#

Registers a net event whose every call is checked against schema before handler runs.

ParamTypeDescription
eventNamestringStarts with your resource's name ('myshop:buy'); up to 128 characters
schematableThe rules, below. {} takes every default and passes no values
handlerfunctionfunction(source, player, ...values), values in params order; player lacks metadata. return false, 'why' refuses (Saying no)
Schema fieldDefaultDescription
params{}One {name, type, …} per value (types below). Only these reach the handler
rateLimit10 in a row, then one per 100 msLeast ms between calls, per player. false: no limit. 0 is refused (rate limits)
burst1 with a rateLimit, else 10Calls allowed back to back before rateLimit applies; a whole number, 1 or more
nearnone{ at, range = 5.0, message?, allowUnknown? } (near)
acenoneAn ACE the player must have. A dead player with it is let through
permissionnoneA WHIP permission, or a list (any one)
whileDeadfalsetrue lets a dead player send it
requirePlayertruefalse accepts players with no character loaded
ownerOfnoneNames an id value holding a netId: only that entity's network owner may send it (ownerOf = 'npcNet'). Refused quietly
onRejectnonefunction(source, reason, rawArgs), run when WHIP refuses before the handler. rawArgs are unchecked
sheet'full''light': player holds only source, session, userId, charId, firstName, lastName, fullName, dateOfBirth, gender, isDead
Value typeWrittenAccepts
amount{name, 'amount', max?}A whole number from 1 to max (no limit without one). Else refused
id{name, 'id', min?, max?}A whole number from min (default 1) to max. Else refused, never clamped
key{name, 'key', maxLen?}Letters, digits, _ and -, at most maxLen (default 60). Else refused, never cleaned
enum{name, 'enum', {values}, default?}One of the values, matched exactly ("1" is not 1)
bool{name, 'bool', default?}true, 1, "true", "1"; false, 0, "false", "0", "". Nothing sent is default (or false)
string{name, 'string', maxLen, default?}Text cut to maxLen, control characters but tab and newline removed. Empty is invalid
number{name, 'number', min, max, default?}Any number, pulled into min–max
int{name, 'int', min, max, default?}As number, rounded down. Never for a count, money or an id
slot{name, 'slot', opts?}A slot in the caller's pockets, as { addr, item, amount, metadata }. opts: item (a key or list), allowEmpty (slot)
vehicle{name, 'vehicle', opts?}A car the caller owns, as a GetVehicle snapshot. opts: anyOwner, session
addr{name, 'addr', opts?}A store address the caller may name, as for slot. opts.slotOptional accepts a whole store (Addresses)
list{name, 'list', entry, max?}Up to max entries (default 50), each checked against entry: one definition, or several for table entries ({ {'slot', 'id', 1, 50}, {'index', 'int', -1, 99} }). Refusals name the entry (basket[2].slot). No addr inside
player{name, 'player', { range?, notSelf? }}Another loaded player's server id, not in the creator, in the caller's routing bucket, within range m (default 3); not the caller unless notSelf = false. Passes their light sheet (source, charId, names, isDead …). "They are not here" and "They are too far away" are shown
record{name, 'record', fields}One table (a form), each field checked as a list entry's; only those fields are passed
any{name, 'any'}Anything, unchecked. Try record, list or slot first

With a default, enum, bool, string, number and int turn an invalid value into it; without one, they refuse it.

Returns: true, or false, reason (also printed; examples in Secure Events): the name is another resource's, starts whip_core: or cb:, or is a server lifecycle event such as playerDropped; or the schema is wrong (a rateLimit of 0, an unknown type, an enum with no values)
SecureCallback(name, schema, handler)SERVER#

Registers a callback the client asks with Callback. Same checks as SecureEvent; the handler's return values are the answer.

ParamTypeDescription
namestringStarts with your resource's name
schematableAs SecureEvent's, without onReject
handlerfunctionfunction(source, player, ...values), returning the answer (up to its first nil). Refuse with return false, 'why'
Returns: true, or false, reason, as SecureEvent. Example: Asking the server

Inside a handler

RecordEventRejection(eventName, src, reason?)SERVER#

Records the call your handler is answering as refused in the Monitor. For a SecureCallback saying no (its false is an answer, recorded as accepted), or a SecureEvent refusing without a message on screen.

ParamTypeDescription
eventNamestringThe event or callback, as you registered it
srcnumberThe player whose request was refused
reasonstring?Why, as the Monitor shows it
Returns: nothing
exports.whip_core:RecordEventRejection('mycafe:getPrice', source, 'Not sold here')
return false, 'Not sold here'
TrackInvocationLock(releaseFn, eventName?, src?)SERVER#

Calls releaseFn if your handler errors, so a lock it took isn't stuck until a restart. On a normal return, release it yourself.

ParamTypeDescription
releaseFnfunctionReleases the lock
eventNamestring?The event or callback your handler is answering
srcnumber?The source your handler was given
Returns: true, or false, reason outside a SecureEvent or SecureCallback handler
local release = acquireSafeLock(safeId)      -- yours: a release function, or nil if taken
if not release then return false, 'Someone is already at that safe' end
exports.whip_core:TrackInvocationLock(release, 'myheist:crackSafe', source)
crackSafe(safeId, source)                    -- if this errors, WHIP calls release
release()
Pass the event name and source, and keep burst at 1 (declare a rateLimit): two overlapping calls from one player can't be told apart.

Client: Callback#

Callback(name, ...)CLIENTWAITS#

Asks a server SecureCallback and waits for the answer. Commands and event handlers can wait; anywhere else (a RegisterNUICallback handler, say), call it inside CreateThread.

ParamTypeDescription
namestringThe callback's name
...anyThe values, in its params order
Returns: what the server's handler returned, or false, reason (the reasons, including 'No answer from the server' after 10 seconds)
local stock, why = exports.whip_core:Callback('myshop:getStock', 'corner')
if not stock then return exports.whip_core:Notify(why, 'error') end