Command Palette

Search for a command to run...

Server exports

Every supported server-side export of AstroShield, with parameters, return values and examples.

These exports are available to server scripts. See Developer overview for how to call them from Lua, JavaScript and C#. In the signatures below, ? marks an optional parameter.

ExportPurpose
punishPlayerRaise your own detection and punish through AstroShield.
allowPlayerAllow a legitimate action of one player for a short time.
whitelistEntity / removeWhitelistAllow spawning a model on purpose.
getConfigRead the configuration that AstroShield received from the dashboard.
getStatusRead the connection and license state.
shouldDetect, isPlayerAdmin, isTxAdminWhitelistEnabledAsk who is exempt from detections.
isPlayerAcReady / waitForPlayerAcReadyWait until a player is fully checked.
isEventProtectedAsk whether the event protection covers an event.
checkPlayerNameReject players whose name contains a blacklisted word.
getPlayers, getPlayer, getPlayerCount, getPlayerPositions, getPlayerFrameworkStatusPlayer data as the dashboard shows it.
getLocalRecords, getRecordsRead bans.
getHeartbeatStatus, getServerResourcesDiagnostics.

Punish and allow#

punishPlayer#

Punishes a player through the normal AstroShield flow, exactly like a built-in detection would. Use it for your own detections, for example an exploit in one of your scripts.

Lua
exports.AstroShield:punishPlayer(playerId, detection, data?, action?) --> boolean
ParameterTypeDescription
playerIdnumberServer ID of the player. The player must be connected.
detectionstringA name for your detection, for example myShop:priceExploit. It is stored with the ban and shown as the Detection. Use a name that is easy to recognize.
datastring or tableA string is used as the reason. A table can carry a reason key, and the whole table is stored with the ban as detection data. Reasons are cut to 250 characters.
actionstringban, kick, warn, log or none. Without it the detection's configured action is used, and ban if there is none.

Returns true when a punishment was started, and false when it was not. That happens when:

  • the player is not connected, or is already being banned,
  • the player is an admin excluded by the txAdmin whitelist,
  • Dev Mode is on, in which case the detection is only logged,
  • the action is log or none, or the detection is configured as no-punishment.

What happens next depends on the action. A ban isolates the player, requests a video clip, stores the ban and drops the player with your ban message. See Punishments. AstroShield also fires astroshield:player:punished.

Lua
RegisterNetEvent('myShop:buy', function(item, price)
    local src = source
    if price < 0 then
        exports.AstroShield:punishPlayer(src, 'myShop:priceExploit', {
            reason = 'Sent a negative price to the shop',
            item = item,
            price = price,
        })
        return
    end
    -- ...
end)

Another resource can also trigger the detection with the local server event astroshield:detection:trigger, which calls punishPlayer for it. See Events.

allowPlayer#

Tells AstroShield that something about a player is about to change legitimately, so neither the server nor the client checks punish it.

Lua
exports.AstroShield:allowPlayer(playerId, kind, ms?) --> boolean
ParameterTypeDescription
playerIdnumberServer ID of the player.
kindstringOne of the server-side kinds below.
msnumberHow long the allowance lasts. Default 5000, maximum 60000.

The allowed kind values are teleport, revive, fade, attach, warpVehicle, superJump, playerSwitch, screenFade, camera, health and armour. Any other value makes the call return false.

Returns true when the allowance was applied. The player's client is told as well, so its own checks stay quiet.

Lua
-- Teleport a player to a hospital, legitimately
exports.AstroShield:allowPlayer(src, 'teleport', 5000)
SetEntityCoords(GetPlayerPed(src), 340.0, -1396.0, 32.5)

The full list of kinds, including the ones that only exist on the client, is in Allowances.

whitelistEntity#

Allows a model to be spawned on purpose, so AstroShield does not treat it as a spoofed or spam spawn.

Lua
exports.AstroShield:whitelistEntity(modelHash, playerId?) --> boolean
ParameterTypeDescription
modelHashnumber or stringThe model hash or the model name, like 'adder'.
playerIdnumberOptional. Allow it only for this player. Without it the model is allowed for everyone.

Returns true when added and false when the model is not valid. A model that is on a blacklist is still blocked, whitelisting does not override a blacklist.

removeWhitelist#

Removes an entry added with whitelistEntity. Use the same arguments.

Lua
exports.AstroShield:removeWhitelist(modelHash, playerId?) --> boolean

State and configuration#

getConfig#

Returns the configuration table that AstroShield received from the dashboard, or nil while it has not arrived yet. getAnticheatConfig is the same function under its older name.

Lua
local config = exports.AstroShield:getConfig()
if config and config.Settings and config.Settings.general.devMode then
    print('AstroShield is in Dev Mode')
end

The server-side configuration contains your webhook URLs. Never send it to a client and never print it to a shared log.

getStatus#

Returns the connection and license state of the resource.

Lua
local status = exports.AstroShield:getStatus()
FieldTypeMeaning
connectedbooleanA WebSocket connection to the backend is open.
authenticatedbooleanThe license was accepted.
serverIdstring or nilThe license ID of this server.
serverNamestringYour sv_hostname.
players, maxPlayersnumberCurrent players and sv_maxclients.
versionstringThe installed version of the resource.
configLoadedbooleanThe configuration from the dashboard has arrived.
activeModulesnumberNumber of JavaScript modules running.
recordstableCounts of bans, warns and kicks the resource knows about.
uptimenumberSeconds since the server started.
resourceNamestringNormally AstroShield.
licenseKeybooleantrue when a .key file was found. The key itself is never returned.
expiresOn, planstring or nilExpiry date and plan of the license.

Use it to check that protection is live, for example to show a warning in your admin tools when authenticated is false.

shouldDetect#

Lua
exports.AstroShield:shouldDetect(playerId) --> boolean

Returns false when the player is exempt from detections because the txAdmin Whitelist is on and the player counts as an admin, and true otherwise. Use it before you run your own punishments, so you treat admins the same way AstroShield does.

isPlayerAdmin#

Lua
exports.AstroShield:isPlayerAdmin(playerId) --> boolean

Returns true when AstroShield counts the player as an admin. See Permissions and whitelisting for what that means. The answer does not depend on the whitelist setting.

isTxAdminWhitelistEnabled#

Lua
exports.AstroShield:isTxAdminWhitelistEnabled() --> boolean

Returns whether txAdmin Whitelist is switched on.

isPlayerAcReady#

Lua
exports.AstroShield:isPlayerAcReady(playerId) --> boolean

Returns true once the player has spawned and a short grace period is over. Until then AstroShield does not run its checks on them.

waitForPlayerAcReady#

Lua
exports.AstroShield:waitForPlayerAcReady(playerId, timeoutMs?) --> boolean

Waits, in the calling thread, until the player is ready and then returns true. It returns false if the player leaves or the time runs out. timeoutMs defaults to 60000 and is limited to 300000. Call it from a thread or an event handler, because it yields.

Lua
CreateThread(function()
    if exports.AstroShield:waitForPlayerAcReady(src, 30000) then
        -- safe to run actions that look suspicious during loading
    end
end)

isEventProtected#

Lua
exports.AstroShield:isEventProtected(eventName) --> boolean

Returns false when the event protection is switched off, or when eventName is on the ignore list, and true otherwise. Useful to find out why an event of yours is or is not guarded.

checkPlayerName#

Rejects players whose name contains a word from the Anti Blacklisted Names list. Call it when a player connects.

Lua
exports.AstroShield:checkPlayerName(source, playerName, deferrals) --> boolean

It returns true when the name is fine. Otherwise it ends the connection with a message that names the word, through deferrals.done, and returns false. AstroShield already applies this check to every connection, so you only need this export if you handle the connection yourself.

Players#

These return the same data the dashboard shows.

Lua
exports.AstroShield:getPlayers()                    --> { { id, name, ping, role, vehicle, identifiers }, ... }
exports.AstroShield:getPlayer(playerId)             --> { id, name, ping, identifiers } or nil
exports.AstroShield:getPlayerCount()                --> number
exports.AstroShield:getPlayerPositions()            --> { { id, name, coords = { x, y, z } }, ... }
exports.AstroShield:getPlayerFrameworkStatus(id)    --> { success, data } or { success = false, error }
  • identifiers is a table with license, license2, steam, discord, fivem, xbl, live and ip, as far as the player has them.
  • vehicle is true while the player is in a vehicle.
  • getPlayerFrameworkStatus reads health, armor and, when ESX, QBCore, Qbox or ox_core is running, hunger, thirst, job, money and inventory. See Frameworks.

Bans#

getLocalRecords#

Returns the bans that this server currently knows, as last sent by the backend. Expired timed bans are left out.

Lua
local bans = exports.AstroShield:getLocalRecords('bans')
for _, ban in ipairs(bans) do
    print(ban.id, ban.username, ban.detection)
end

Only 'bans' is stored by the backend. 'warns' and 'kicks' return empty lists.

getRecords#

Asks the backend for the current bans. It waits for the answer, so call it from a thread or an event handler.

Lua
local result = exports.AstroShield:getRecords('bans', nil, 5000)
if result.success then
    print(#result.data .. ' bans')
else
    -- the backend did not answer, `result.data` is the last known list
    print('using cached list:', result.cached, result.error)
end
ParameterDescription
kind'bans'.
serverIdLeave it nil. The backend uses your license.
timeoutMsHow long to wait. Default 5000.

See Ban records for the fields of a ban and the events that tell you when it changes.

Heartbeat and diagnostics#

Lua
exports.AstroShield:getHeartbeatStatus(playerId?)   --> table
exports.AstroShield:getServerResources()            --> { [resourceName] = started }
exports.AstroShield:validateExecution()             --> true
  • getHeartbeatStatus(playerId) returns { lastSeen, seq, started, alerted } for one player: when AstroShield's client part last reported in, how many reports it sent, which monitored resources it saw running and whether an alert was already raised. Without an argument it returns a table of all players keyed by server ID, and nil for an unknown player.
  • getServerResources() returns every resource and whether it is started.
  • validateExecution() always returns true. It exists so that older resources that call it keep working.
Other exports you may see

These exist because the dashboard bridge and AstroShield's own scripts use them. They are not supported for your own use and can change without notice:

getRulesCatalog, getRulesSummary, setRules, inspectResource, sendCommand, reportGameEvent, reportRuleTriggered, reportReplayResult, sendStreamOffer, sendStreamIce, createRecord, deleteRecord, checkAdminPermission, getEmbedUrl, updateAnticheatConfig, registerModule, startModule, stopModule, forceHeartbeatCheck.

To remove a ban from a script, run the console command astroshield unban <id> through ExecuteCommand. See the recipes.