SecureEvent & SecureCallback
Server exports for checked events and callbacks, and the client's Callback. New to them? Read Secure Events first.
Registering
Registers a net event whose every call is checked against schema before handler runs.
| Param | Type | Description |
|---|---|---|
| eventName | string | Starts with your resource's name ('myshop:buy'); up to 128 characters |
| schema | table | The rules, below. {} takes every default and passes no values |
| handler | function | function(source, player, ...values), values in params order; player lacks metadata. return false, 'why' refuses (Saying no) |
| Schema field | Default | Description |
|---|---|---|
| params | {} | One {name, type, …} per value (types below). Only these reach the handler |
| rateLimit | 10 in a row, then one per 100 ms | Least ms between calls, per player. false: no limit. 0 is refused (rate limits) |
| burst | 1 with a rateLimit, else 10 | Calls allowed back to back before rateLimit applies; a whole number, 1 or more |
| near | none | { at, range = 5.0, message?, allowUnknown? } (near) |
| ace | none | An ACE the player must have. A dead player with it is let through |
| permission | none | A WHIP permission, or a list (any one) |
| whileDead | false | true lets a dead player send it |
| requirePlayer | true | false accepts players with no character loaded |
| ownerOf | none | Names an id value holding a netId: only that entity's network owner may send it (ownerOf = 'npcNet'). Refused quietly |
| onReject | none | function(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 type | Written | Accepts |
|---|---|---|
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.
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)Registers a callback the client asks with Callback. Same checks as SecureEvent; the handler's return values are the answer.
| Param | Type | Description |
|---|---|---|
| name | string | Starts with your resource's name |
| schema | table | As SecureEvent's, without onReject |
| handler | function | function(source, player, ...values), returning the answer (up to its first nil). Refuse with return false, 'why' |
Inside a handler
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.
| Param | Type | Description |
|---|---|---|
| eventName | string | The event or callback, as you registered it |
| src | number | The player whose request was refused |
| reason | string? | Why, as the Monitor shows it |
exports.whip_core:RecordEventRejection('mycafe:getPrice', source, 'Not sold here')
return false, 'Not sold here'
Calls releaseFn if your handler errors, so a lock it took isn't stuck until a restart. On a normal return, release it yourself.
| Param | Type | Description |
|---|---|---|
| releaseFn | function | Releases the lock |
| eventName | string? | The event or callback your handler is answering |
| src | number? | The source your handler was given |
true, or false, reason outside a SecureEvent or SecureCallback handlerlocal 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()
burst at 1 (declare a rateLimit): two overlapping calls from one player can't be told apart.Client: Callback#
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.
| Param | Type | Description |
|---|---|---|
| name | string | The callback's name |
| ... | any | The values, in its params order |
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