Bolt is the admin mod of Flux: roles, permissions, bans, and the commands and menus that
manage them.
Every player has a role (user, assistant, gamemaster or admin out of the box): a
Role with an immunity level and a set of allowed permissions. A permission is an ID
registered with Bolt:register_permission, normally from a RegisterPermissions hook;
every command also gets a permission named after its ID. Which roles have a permission by
default is up to the role files: each one lists the permissions it allows with can. A
command may name a role in its permission field instead, which allows it to that role
and the roles based on it unless a role file decides the command itself; a command that
neither a role file nor its permission field allows is denied to every player.
Code asks whether a player may do something with actor:can(id), which Bolt answers from
the permissions set on the player individually and those set on their active character
(PERM_ALLOW or PERM_NEVER, each lasting or temporary), then from their role, see
Bolt:get_permission_layer. A PERM_NEVER in either of them denies the permission, and
otherwise a PERM_ALLOW in either of them allows it. So one character of a player can be
allowed something that the role lacks, or denied something, while the player's other
characters are not, but no character undoes what the player is denied. The permissions of
a character belong to the character and apply to whoever has it loaded, such as a
gamemaster who plays a character that several players share. The SteamIDs listed in the
root_steamid config are root players, who may do anything.
Each role is based on the one below it and has every permission that role allows. Assistants have the basic staff tools: kicking, banning, vanishing, observer mode, the physics and tool guns and spawning props, and other addons see them as admins. Gamemasters also get the tools that run the game world, such as spawning NPCs, vehicles and weapons, handing out items and money, and managing areas, map scenes and spawn points, and other addons see them as super admins. Administrators may do anything, including editing the configuration, permissions and plugins, managing roles and restarting the server.
Bans are stored in the database and checked whenever a player connects. Staff manage
players with the plugin's commands, such as /ban add|remove, /role set|remove,
/permission grant|revoke|reset|list, /charpermission grant|revoke|reset|list,
/freeze on|off, /kick and /tp, whose 'permission', 'role', 'map' and 'duration'
arguments are completed while they are typed. They also have the Admin entry of the tab
menu, which holds the player management page (role and permission editor, for players and
their active characters), the staff page (everybody with a role above user, connected or
not), the ban list, the config editor and the plugin manager.
Other plugins extend Bolt by registering permissions, by shipping role files in a roles
folder, and by adding pages to the admin panel from the AddAdminMenuItems hook. A role
file whose ID is already registered adds its permissions to that role, which is how a
plugin or schema with several commands gives the existing roles their permissions. A
plugin with a single command sets the command's permission field instead.
Summary
Hooks
permission field to that role.Methods
permission field to that role and to the roles based on it, except where a role file decided the command itself: a cannot for the command in a role file keeps it from that role and the roles based on it.PlayerPermissionChanged hook for every permission whose character value has changed.user, whether they are on the server or not, on behalf of a player.grant and revoke subcommands of the permission and charpermission commands names, as Bolt:find_permission does, and tells the caller if there is none.Bolt.max_temp_duration.permission_id if it sets one, built from the command's name, description and category, and one for every subcommand that names its own permission_id, built from the subcommand's full name and description.grant and revoke subcommands of the permission and charpermission commands, which makes the permission they set a temporary one.user: the stored users with such a role, up to 256 of them, together with the players on the server who have one.Hooks
Implements hook ActiveRecordReady
Loads all bans from the database into the ban cache.
Implements hook AddAdminMenuItems
Adds the pages of the admin plugin to the admin panel: player management, the staff
list, the ban list, the config editor and the plugin manager. Each one asks for the
permission that the server checks for what the page does; for the config editor that is
the permission named by Config.permission.
Parameters
- panel Panel the admin panel
- _sidebar Panel the admin panel's sidebar
Implements hook AddTabMenuItems
Adds the Admin entry to the tab menu.
Parameters
- menu Panel the tab menu
Keeps players without the 'context_menu' permission from driving entities, which is started from the context menu. The decision is left to the gamemode for everybody else.
Parameters
- actor Player the player trying to drive
- _entity Entity the entity to be driven
Returns
- Boolean false if the player lacks the permission, nothing otherwise
Keeps players without the 'context_menu' permission from using the properties of entities. The gamemode only keeps them from opening the context menu, which is done on the client; this is the same check where it counts, since the server asks this hook before it runs a property. The decision is left to the gamemode for everybody else.
Parameters
- actor Player the player using the property
- _property String ID of the property, e.g. 'remover'
- _entity Entity the entity the property is used on
Returns
- Boolean false if the player lacks the permission, nothing otherwise
Blocks tools that require a permission the player does not have.
Parameters
- actor Player
- _trace Map trace result of the tool use
- tool_name String tool ID
Returns
- Boolean false to block the tool, nothing otherwise
Implements hook ChatboxGetPlayerIcon
Supplies the icon of the player's role for their chat messages.
Parameters
- speaker Player the sender
- _text String message text
- _team_chat Boolean
Returns
- Map icon data for the chatbox (icon, size, margin, is_data), or nothing if the player is invalid
Bolt:CheckPassword(steam_id64, ip, _sv_pass, _cl_pass, name)
server plugins/admin/plugin/sv_hooks.lua:20Checks connecting players against the ban cache. A timed ban that has expired is lifted and the connection left to the other checks, such as the server password; any other ban rejects the connection with the message of Bolt:get_ban_message, which names its reason and the time it has left, including a ban whose end time cannot be read.
Parameters
- steam_id64 String 64-bit SteamID of the connecting player
- ip String
- _sv_pass String server password
- _cl_pass String password entered by the client
- name String player name
Returns
- Boolean false to reject (nothing otherwise)
- String rejection message (only when rejecting)
Implements hook CommandCheckImmunity
Checks role immunity for commands that target players, by way of Bolt:check_immunity: the caller's role must have a higher immunity than the target's, except that callers may always target themselves and root players may target anyone.
Parameters
- actor Player the caller
- target Player the player being targeted
- can_equal Boolean optional, defaults to
falsealso pass when both roles have the same immunity
Returns
- Boolean false if the caller may not target that player
Draws the vanish indicator in the bottom right corner while the local player is hidden from other players.
Bolt:NetVarChanged(entity, key, _old_value, _new_value)
client plugins/admin/plugin/cl_hooks.lua:104Implements hook NetVarChanged
Lets the permission editor, if it is open, follow the changes to the role, the permissions and the active character of the player it edits.
Parameters
- entity Entity the entity whose networked variable has changed
- key String name of the variable
- _old_value Any previous value
- _new_value Any new value
Implements hook OnActiveCharacterCleared
Takes the permissions of a character away from the player who is dropping it.
Parameters
- owner Player
- _character Character the character that is being dropped
Implements hook OnActiveCharacterSet
Applies the permissions of a character that has become the active character of a player. Expired temporary permissions of the character are deleted first.
Parameters
- owner Player
- character Character
Implements hook OnBanAdded
Lets open ban list pages know that a ban has been added.
Parameters
- _steam_id String SteamID that has been banned
- _ban Ban the ban record
Implements hook OnBanRemoved
Lets open ban list pages know that a ban has been lifted.
Parameters
- _steam_id String SteamID that is no longer banned
- _data Map column values of the deleted ban record
Implements hook OnCharacterDelete
Deletes the permissions of a character that a player is about to delete, from the character and from the database. The foreign keys of the tables delete the rows with the character as well, but they only exist where the Characters plugin was present when the migrations ran.
Parameters
- _actor Player the player who deletes the character
- id Number ID of the character
- character Character the character that is about to be deleted
Implements hook OnCommandCreated
Registers a permission for every newly created command.
Parameters
- _id String command ID
- data Command command table
Implements hook OnConfigPendingReceived
Updates the line of a config in the config editor, if it is open, when the server reports that the config has got a pending value or no longer has one.
Parameters
- key String config key
- _is_pending Boolean whether the config has a pending value now
- _value Any value the config takes on the next start of the server
Implements hook OnConfigReceived
Updates the line of a config in the config editor, if it is open, when the value of the config has arrived from the server.
Parameters
- key String config key
- _old_value Any value the client had before
- _new_value Any value that has been received
Queues every new entity to be checked on the next tick, once it has been attached to whatever it belongs to.
Parameters
- entity Entity
Registers 'roles' as a plugin folder type and loads the admin plugin's own roles.
Implements hook OnPluginsLoaded
Runs the RegisterPermissions hook, then allows the commands that name a role in their
permission field to that role. Also ties the character permission models to the
Character model.
Implements hook OnPluginStateChanged
Rebuilds the list of the plugin manager, if it is open, when the server reports that a plugin has been disabled or enabled.
Parameters
- _id String normalized ID of the plugin
- _disabled Boolean true if the plugin will be disabled after the restart
Implements hook OnThemeLoaded
Registers the constructors of the admin panel's pages with the loaded theme.
Parameters
- current_theme ThemeBase
Mutes talkers that lack the 'voice' permission.
Parameters
- _listener Player the listener
- talker Player
Returns
- Boolean false if the talker may not be heard, nothing otherwise
Keeps hidden players (vanished or observing) from picking up weapons that lie in the world. Weapons that they are given are let through: those are created in the same tick.
Parameters
- actor Player
- weapon Weapon
Returns
- Boolean false for a hidden player and a weapon that lies in the world
Implements hook PlayerCreated
Defaults the banned flag of a newly created user record to false.
Parameters
- _actor Player
- record User the player's database record
Networks a weapon dropped by a hidden player to everyone again: it no longer belongs to the player.
Parameters
- _actor Player
- weapon Weapon
Implements hook PlayerHasPermission
Answers the permission checks made through actor:can by delegating to Bolt:can.
Parameters
- actor Player
- action String permission ID
- object String optional, defaults to
nilobject name the permission was allowed for
Returns
- Boolean
Implements hook PlayerInitialized
Remembers whether the player could edit configs when the config was first sent to them, which the gamemode does right before this hook. Bolt:update_config_access compares against it to tell when the config has to be sent again. Also applies once more which hidden players the player may see, now that their client is in the game and their role is known.
Parameters
- actor Player the player whose client has finished loading
Implements hook PlayerInitialSpawn
Hides hidden players (vanished or observing) from a newly connected player. The player's role is not known yet at this point; Bolt:PlayerRestored and Bolt:PlayerInitialized show them again if the player turns out to have the 'moderate' permission.
Parameters
- actor Player the player that just connected
Implements hook PlayerIsRoot
Reports whether the player was flagged as root, which happens when their SteamID is listed in the root_steamid config.
Parameters
- target Player
Returns
- Boolean true for root players, nil otherwise
Implements hook PlayerOneMinute
Removes the expired temporary permissions of the player and of their active character.
Parameters
- actor Player
Implements hook PlayerPermissionChanged
Gives or strips the tool gun or the physgun when the matching individual permission, or the value that the active character sets for it, changes, going by what the player may do now (character, individual and temporary permissions and role together): unsetting the permission leaves the tool with a player whose role allows it, and PERM_NEVER takes it away. Does nothing while the player is dead; they get the tools they are allowed when they spawn. Any permission change also sends the config to the player again if it has changed their right to edit configs.
Parameters
- target Player
- perm_id String permission ID
- _value Number new PERM_ value
Implements hook PlayerPickupObject
Keeps hidden players (vanished or observing) from carrying objects in their hands, which would show other players an object floating in the air.
Parameters
- actor Player
- _entity Entity
- _drag Boolean
Returns
- Boolean false for a hidden player
Implements hook PlayerRestored
Applies a loaded user record to the player: sets their role, makes the SteamIDs from the root_steamid config root admins, networks stored permissions, sends the config again if the player turns out to be allowed to edit it, shows hidden players (vanished or observing) to players with the 'moderate' permission and logs the connection.
Parameters
- actor Player
- record User the player's database record
Decides whether a player may spawn a chair: a seat of the vehicle list, which is a 'prop_vehicle_prisoner_pod'. Chairs take the 'spawn_chairs' permission instead of the 'spawn_vehicles' permission that the gamemode asks of every other vehicle. A player who has both is left to the gamemode and to the other handlers of this hook. For a player who may only spawn chairs the gamemode has to be overruled, which also skips the handlers that come after this one; the chair is passed on to the FLPlayerSpawnVehicle hook the way the gamemode passes vehicles on.
Parameters
- actor Player
- model String model of the vehicle
- name String name of the vehicle in the vehicle list
- tab Map vehicle table from the vehicle list
Returns
- Boolean false if the player may not spawn chairs, true if they may spawn chairs but no other vehicles; nothing if it is not a chair or the player may spawn vehicles as well, which leaves the decision to the gamemode
Returns false for speakers that lack the 'voice' permission.
Parameters
- speaker Player the player that started talking
Returns
- Boolean false if the player lacks the permission, nothing otherwise
Bolt:PlayerUserGroupChanged(target, _group, _old_group)
server plugins/admin/plugin/sv_hooks.lua:365Implements hook PlayerUserGroupChanged
Gives or strips the tool gun and the physgun after the player's role has changed, going by the 'toolgun' and 'physgun' permissions the player has now (role, individual, temporary and character permissions together). Does nothing while the player is dead; they get the tools they are allowed when they spawn. Also sends the config to the player again if the new role has changed their right to edit configs.
Parameters
- target Player
- _group Role the player's new role, nil if its ID is not registered
- _old_group Role the player's previous role
Implements hook PluginIncludeFolder
Loads the role files of a plugin when its 'roles' folder is being included.
Parameters
- extra String name of the extra folder being included
- folder String path of the plugin folder
Returns
- Boolean true if the folder was handled here, nothing otherwise
Implements hook PostPlayerSpawn
Makes a vanished player invisible again after a respawn, which has made them visible.
Parameters
- actor Player
Switches to fullbright lighting when the local player's 'should_fullbright' net var is set.
Restores normal lighting before the HUD is drawn if fullbright was switched on.
Implements hook RegisterConditions
Registers the 'bolt_role' condition, which compares a player's role with a chosen one.
Implements hook RegisterPermissions
Registers the built-in permissions: tools, spawning, voice, context menu, management of permissions, configs and plugins, and the staff / admin / super admin compatibility levels.
Queues a weapon that a player picks up to be checked on the next tick, as it is not a new entity.
Parameters
- weapon Weapon
- _actor Player
Methods
Bolt:add_ban(steam_id, name, unban_time, duration, reason, admin)
server internal plugins/admin/plugin/lib/sh_admin.lua:696Internal
This function is internal. It is not part of the public API and may change without notice.
Use Bolt:ban to ban somebody.
Creates or updates the ban record for a SteamID, saves it to the database and caches it. Runs the OnBanAdded hook afterwards.
Parameters
- steam_id String SteamID of the banned player
- name String name stored with the ban
- unban_time Number unix timestamp at which the ban ends
- duration Number ban length in seconds, 0 for a permanent ban
- reason String
- admin Player optional, defaults to
nilthe player who issued the ban; nothing is stored for the server console or for a ban made by code
Returns
- Ban the saved ban record
Stores a permission data table under a category. A permission that already exists there is kept unless force is set.
Parameters
- id String permission ID; nothing happens without one
- category String optional, defaults to
'general'category name or language phrase - data Map permission data (name, description, category); id is written into it
- force Boolean optional, defaults to
falsereplace an existing permission with the same ID
See also
Allows every command that names a role in its permission field to that role and to the
roles based on it, except where a role file decided the command itself: a cannot for
the command in a role file keeps it from that role and the roles based on it. The same goes
for a subcommand with a permission of its own (permission_id), which is allowed under
that permission; the permission field of a subcommand without one is ignored. A command
whose role is not registered is reported in the console and stays unallowed.
See also
Bolt:apply_character_permissions(target, character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:349Networks the permissions of the character that a player has loaded, or takes them away
when character is nil, and runs the PlayerPermissionChanged hook for every permission
whose character value has changed. Called when a character is loaded, switched or dropped,
and whenever the permissions of a loaded character change.
Parameters
- target Player
- character Character optional, defaults to
nilthe active character of the player, nil when the player is left without one
Bolt:ban(target, duration, reason, prevent_kick, admin, name)
server plugins/admin/plugin/lib/sh_admin.lua:743Bans a player or a SteamID and saves the ban to the database. The banned player is kicked if they are on the server, whether they were given as a player or as a SteamID, unless prevent_kick is set. The owner of the SteamID does not have to be on the server, or to have ever joined it.
-- Ban an online player for a day.
Bolt:ban(target, 60 * 60 * 24, 'Prop spam')
-- Permanently ban somebody by SteamID, on behalf of an admin.
Bolt:ban('STEAM_0:1:12345', 0, 'Cheating', false, actor)
Parameters
- target Player/String the player to ban, or a SteamID
- duration Number optional, defaults to
0ban length in seconds, 0 for a permanent ban - reason String optional, defaults to
'N/A'text or language phrase - prevent_kick Boolean optional, defaults to
falsedo not kick the banned player - admin Player optional, defaults to
nilthe player who issues the ban, stored with it - name String optional, defaults to
nilname to store with the ban of a SteamID whose owner is not on the server; the name of an earlier ban of that SteamID or else the SteamID itself by default
Returns
- Ban the ban record, or nil if target is neither a valid player nor a string
Checks whether a player may perform an action. This is what Player:can answers with, on
both realms; see Bolt:get_permission_layer for how it is decided.
Parameters
- actor Player
- action String permission ID; an empty string is always allowed
- object String optional, defaults to
nilobject name the permission was allowed for, passed on to Role#can
Returns
- Boolean whether the action is allowed (a role permission callback's return value is passed through as is)
Checks whether a player may act on somebody who is not on the server. The server console and root players may act on anyone; nobody else may act on a SteamID from the root_steamid config, or on a holder of a role whose immunity is not lower than their own.
Parameters
- actor Player the player performing the action, an invalid entity for the server console
- steam_id String SteamID of whoever is acted on
- role_id String optional, defaults to
'user'ID of the role stored for that SteamID
Returns
- Boolean
Checks whether a player's role has enough immunity to act on another player. A player may always act on themselves, and a root player on anyone. Also passes when either player is invalid or a registered role has no numeric immunity. A role ID that is not registered counts as lower than every registered role.
Parameters
- actor Player the player performing the action
- target Player the player being acted on
- can_equal Boolean optional, defaults to
falsealso pass when both roles have the same immunity
Returns
- Boolean true if the player may act on the target
Bolt:check_role_immunity(actor, role_id, can_equal)
shared plugins/admin/plugin/lib/sh_admin.lua:525Checks whether a player's role has enough immunity to act on the holder of a role. This
is Bolt:check_immunity for a target who is not on the server and is only known by the
role stored for them. An invalid player (the server console) and a root player always
pass, and so does everybody when a registered role has no numeric immunity. A role ID that
is not registered counts as lower than every registered role.
Parameters
- actor Player the player performing the action
- role_id String ID of the role of whoever is acted on
- can_equal Boolean optional, defaults to
falsealso pass when both roles have the same immunity
Returns
- Boolean true if the player may act on the holder of that role
See also
Stores a role under the given ID, inheriting the permissions and unset fields of the role
named in data.base if that role is already registered. Roles registered earlier that are
based on the new role get its permissions too, except for the actions they set themselves.
A role file whose ID is already registered adds its permissions to that role instead: the
allowed and denied actions of data, with their callbacks, replace what the registered role
had for the same actions and count as its own, allow_anything carries over, and the
entries are copied into every role based on it, recursively, except where a role decided
the same action itself. The other fields of data are ignored then, and an existing role is
never replaced. Does nothing unless id is a string.
-- A schema plugin's roles/sh_user.lua: lets every player run the plugin's Report command.
function ROLE:define_permissions()
can 'report'
end
Parameters
- id String role ID
- data Role role object (a plain table of role fields also works), modified in place
See also
Bolt:delete_character_temp_permission(character, perm_id)
server plugins/admin/plugin/lib/sv_character_permissions.lua:282Removes a temporary permission from a character, deleting its database record. If the character is the active character of a connected player, that player's permissions are brought up to date.
Parameters
- character Character
- perm_id String permission ID
Returns
- Boolean true if the character had the temporary permission
Removes a temporary permission from a player, destroying its database record, taking it off the player's record and updating the networked table. The config is sent to the player again if that has changed their right to edit configs.
Parameters
- target Player
- perm_id String permission ID
Sets the role of the owner of a SteamID back to user, whether they are on the server
or not, on behalf of a player. The player needs a higher immunity than the target's (root
players and the server console do not) and is notified when the target is immune, has
never joined or is a user already. A target who is on the server is notified as well.
Does not check permissions.
Parameters
- actor Player the player who demotes, an invalid entity for the server console
- steam_id String SteamID of the player to demote
- callback Function optional, defaults to
nilcalled with the name of the demoted player and the ID of the role they had, once they have been demoted
Bolt:expire_character_permissions(actor)
server plugins/admin/plugin/lib/sv_character_permissions.lua:391Takes the expired temporary permissions off a player's active character once a minute.
Parameters
- actor Player
Finds the permission that an argument of the grant and revoke subcommands of the
permission and charpermission commands names, as Bolt:find_permission does, and tells
the caller if there is none.
Parameters
- actor Player the caller, or an invalid entity for the server console
- text String permission ID, command ID or command alias
Returns
- Map permission data, or nil if there is no such permission
Bolt:find_command_targets(actor, argument, can_equal)
server plugins/admin/plugin/lib/sv_staff.lua:126Finds whom a command argument targets, for the commands that work on players who are
not on the server as well. Players are found and checked for immunity the way the command
interpreter does it for a command with immunity set: by their exact name or SteamID, or
by one of the selectors of Flux.Command:str_to_player; a name that several players have
targets nobody. A SteamID, in any case and with any universe digit, is read as
Bolt:normalize_steam_id writes it; if it matches nobody it is handed back as such, and the
caller then checks immunity with Bolt:with_offline_target. The caller of the command is
notified when nothing comes of it.
Parameters
- actor Player the player who runs the command, an invalid entity for the server console
- argument String exact player name, target selector or SteamID
- can_equal Boolean optional, defaults to
falselet the command affect players of the same immunity
Returns
- List<Player> the targets, or nil if there are none or one of them is immune
- String the SteamID if the argument is the SteamID of somebody who is not on the server
Returns the role registered under the given ID.
Parameters
- id String role ID
Returns
- Role the role, or nil if there is none
Finds a map by its name without the .bsp extension, matched exactly but in any case.
Parameters
- name String map name
Returns
- String the name of the map as its file has it, or nil if there is no such map
See also
Finds a registered permission by what a person would type for it: its ID, or the ID or an alias of the command the permission belongs to, matched exactly but in any case.
Bolt:find_permission('spawn_props') -- the 'spawn_props' permission
Bolt:find_permission('perms') -- the permission of the Permission command
Parameters
- id String permission ID, command ID or command alias
Returns
- Map permission data (id, name, description, category), or nil if there is no such permission
Finds a role by what a person would type for it: its ID or its name, matched exactly but in any case.
Bolt:find_role('Admin') -- the 'admin' role
Bolt:find_role('Administrator') -- the 'admin' role, by its name
Parameters
- text String role ID or role name
Returns
- Role the role, or nil if no role has this ID or name
Looks up the stored user of a SteamID. The query is asynchronous on most databases: the callback runs once the answer has arrived, and not at all if the query fails.
Parameters
- steam_id String
- callback Function called with a table that has the id, steam_id, name and role fields of the user, or with nil if nobody with that SteamID has ever joined
Returns the active character of a player, if it is a saved character record.
Parameters
- target Player
Returns
- Character the active character, nil if none is loaded
Returns every registered permission in one flat table, ignoring categories.
Returns
- Map permission data tables keyed by permission ID
Builds the message a banned player reads when they are kicked or turned away: the reason of the ban and, unless it is permanent, the time it has left. The text comes from the 'error.banned.temporary' and 'error.banned.permanent' phrases.
Parameters
- ban Ban ban record, or a table with its reason, duration and unban_time fields
- lang String optional, defaults to
nillanguage code to write the message in; the language set by the ban_message_language config by default, since the language of a player who is still connecting is not known
Returns
- String
Returns how long a ban still lasts.
Parameters
- ban Ban ban record, or a table with its duration and unban_time fields
Returns
- Number/Boolean seconds until the ban ends, 0 if it has already run out; false for a permanent ban and for a ban whose end time cannot be read
Returns the ban cache. It is only filled on the server, once the database is ready.
Returns
- Map Ban records keyed by SteamID
Bolt:get_character_holder(character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:102Returns the connected player whose active character a character is.
Parameters
- character Character
Returns
- Player the player, nil if nobody has the character loaded
Bolt:get_character_label(target, character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:95Returns the name of a player's character followed by the player's Steam name, as the notifications of character permissions name it.
Parameters
- target Player
- character Character
Returns
- String
Bolt:get_character_permissions(character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:122Returns the lasting permissions of a character.
Parameters
- character Character
Returns
- Map PERM_ALLOW or PERM_NEVER keyed by permission ID; empty for anything that is not a saved character
Bolt:get_character_temp_permissions(character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:143Returns the temporary permissions of a character, expired ones included until they are
removed. Bolt:get_permission_layer ignores the expired ones.
Parameters
- character Character
Returns
- Map tables with value (PERM_ value) and expires (unix timestamp) fields, keyed by permission ID; empty for anything that is not a saved character
Reads the value that one layer of a player's own permissions (the player's, or their
active character's) sets for an action: an unexpired temporary value comes first, then the
lasting one. Only PERM_ALLOW and PERM_NEVER decide anything; PERM_NO, a missing value
and an expired temporary value leave the action to the next layer.
Parameters
- temp_entry Map temporary permission with value and expires (unix timestamp) fields, or nil
- value Number lasting PERM_ value, or nil
- now Number optional, defaults to
os.time()unix timestamp to compare the expiry with
Returns
- Number PERM_ALLOW or PERM_NEVER, nil if the layer does not decide the action
- Boolean true if the temporary value decides it
Returns the names of the maps that can be loaded, without the .bsp extension and sorted. Only names made of letters, digits, underscores, dashes and dots are listed, since a map name ends up in a file path and in a console command. The list is read once and kept; on the client it holds the maps the client has.
Returns
- List<String> map names
Decides whether a player may perform an action and names the layer that decides it.
A player's own permissions come in two layers, those of the player ('user') and those of
the active character ('character'), and in each of them an unexpired temporary value
comes before the lasting one ('user_temporary', 'character_temporary'). They are
consulted in this order:
'root': root players are always allowed.- If either layer says
PERM_NEVER, the action is denied, the character's denial being named first. A character cannot undo what the player is denied. - Otherwise, if either layer says
PERM_ALLOW, the action is allowed, the character's permission being named first. A character can be allowed what the role does not allow. 'role': the player's role, together with the roles it is based on.
The character layer only applies while the character is loaded. Invalid players (such as
the server console) and an empty action are always allowed, with no layer. Immunity is not
a permission: Bolt:check_immunity only compares roles, so character permissions never
change whom a player may act on.
local allowed, layer = Bolt:get_permission_layer(target, 'physgun')
-- true, 'character' when the active character was granted the physgun
Parameters
- actor Player
- action String permission ID
- object String optional, defaults to
nilobject name the permission was allowed for, passed on to Role#can
Returns
- Boolean whether the action is allowed (a role permission callback's return value is passed through as is)
- String the deciding layer, nil when no layer applies
Returns every registered permission, grouped by category.
Returns
- Map permission data tables keyed by category, then by permission ID
Returns the admin system's player table. Nothing in this plugin writes to it.
Returns
- Map
Returns every registered role.
Returns
- Map Role objects keyed by role ID
Returns the players on the server who have the 'staff' permission.
Returns
- List<Player>
Checks whether a role with the given ID is registered. The role itself is returned rather than a strict boolean.
Parameters
- id String role ID
Returns
- Role the role (truthy), or nil if it does not exist
Loads every role file in a folder through the 'role' pipeline. Each file fills in the ROLE
global and is registered under its file name without the sh_/cl_/sv_ prefix. A role file
whose ID is already registered adds its permissions to that role, see Bolt:create_role.
Parameters
- directory String folder path, as taken by Pipeline.include_folder
See also
Converts a human-readable duration into seconds. Bare numbers are taken as minutes, and words such as 'perma' or 'forever' (as well as text with no recognizable duration) give 0, which bans treat as permanent.
Bolt:interpret_ban_time(30) -- 1800
Bolt:interpret_ban_time('15') -- 900
Bolt:interpret_ban_time('2 hours') -- 7200
Bolt:interpret_ban_time('1 week 3 days') -- 864000
Bolt:interpret_ban_time('couple of minutes') -- 120
Bolt:interpret_ban_time('perma') -- 0
Parameters
- str String/Number duration text, or a number of minutes
Returns
- Number/Boolean duration in seconds, or false if str is neither a string nor a number
Checks whether a duration is one of the words that stand for a permanent one, such as 'perma', 'permanently' or 'forever'.
Parameters
- str String duration text
Returns
- Boolean
Checks whether a SteamID is listed in the root_steamid config, which makes its owner a root player when they join.
Parameters
- steam_id String
Returns
- Boolean
Checks whether a value has the form of a SteamID, such as 'STEAM_0:1:12345'.
Parameters
- text Any
Returns
- Boolean
Checks whether a value can be the duration of a temporary character permission: a number
of seconds above 0 and at most Bolt.max_temp_duration.
Parameters
- duration Any
Returns
- Boolean
Copies permission entries (allowed or denied actions, with their callbacks) into a role
and, through it, into every registered role based on it. An entry is skipped for a role
whose own role files decided the same action (see Role:set_own), and is then not passed
on to the roles based on that role either, since they take after it.
Parameters
- role Role
- perms Map permission entries (allowed, callback) keyed by object name, then by action, as in Role#get_permissions
- as_own Boolean optional, defaults to
falsetake the entries as decided by the role itself: they replace what it had for the same actions and are recorded in its own_permissions
Brings a SteamID into the form the engine gives it, upper case and with the universe digit 0, so that 'steam_1:1:12345' becomes 'STEAM_0:1:12345'. Anything that is not a SteamID in any case is returned as it is.
Parameters
- text Any
Returns
- Any the SteamID in the engine's form, or text
Registers the permissions of a command: one named after the command's ID, or after its
permission_id if it sets one, built from the command's name, description and category,
and one for every subcommand that names its own permission_id, built from the subcommand's
full name and description. A permission_id that is registered already is kept as it is.
Role files allow these permissions under their IDs.
Parameters
- cmd Command command table; nothing happens if it is nil
Reads the optional duration of the grant and revoke subcommands of the permission
and charpermission commands, which makes the permission they set a temporary one. An
empty text or a word for a permanent duration, such as 'perma', sets it for good. The
caller is told if the text is not a duration.
Parameters
- actor Player the caller, or an invalid entity for the server console
- text String duration as read by Bolt:interpret_ban_time, or an empty string
Returns
- Boolean false if the text is neither empty nor a duration, true otherwise
- Number duration in seconds; nil if the permission is set for good
Puts a ban record into the ban cache without touching the database.
Parameters
- id String SteamID the ban belongs to
- obj Ban
Bolt:register_permission(id, name, description, category)
shared plugins/admin/plugin/lib/sh_admin.lua:270Registers a permission that can then be checked with actor:can(id), and that the
permission editor lists under its category. Registering a permission does not allow it for
anybody: the role files allow it to roles with can, and roles based on those inherit it.
function Doors:RegisterPermissions()
Bolt:register_permission('manage_doors', 'Doors settings access',
'Grants access to customize doors.', 'permission.categories.level_design')
end
-- roles/sh_assistant.lua
function ROLE:define_permissions()
can 'manage_doors'
end
Parameters
- id String permission ID; nothing happens if it is empty or not a string
- name String optional, defaults to
iddisplay name - description String optional, defaults to
'No description provided.' - category String optional, defaults to
'general'category name or language phrase
Deletes the ban record of a SteamID from the database and from the ban cache, so that the player can connect again right away and a later ban gets a record of its own. Runs the OnBanRemoved hook if there was a ban.
Parameters
- steam_id String
Returns
- Boolean whether a ban record was found and deleted
- Map the deleted record's column values (only when found)
Bolt:remove_expired_character_permissions(character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:308Deletes the expired temporary permissions of a character.
Parameters
- character Character
Returns
- Boolean true if anything was deleted
Sends a page of the ban list to a player: the bans sorted by name, 25 to a page, with the time each has left at this moment. Does not check permissions.
Parameters
- target Player player to send the page to
- page Number optional, defaults to
1page to send; brought into the range of existing pages - search_text String optional, defaults to
nilonly list the bans that have this text in their name, SteamID or reason, in any case
Tells the players who may see the ban list that it has changed, so that a ban list page that is open asks for its bans again.
Sends a player the list of everybody whose role is not user: the stored users with such
a role, up to 256 of them, together with the players on the server who have one. Each
entry has the steam_id, name, role and online fields. Does not check permissions.
Parameters
- target Player player to send the list to
Bolt:set_character_permission(character, perm_id, value)
server plugins/admin/plugin/lib/sv_character_permissions.lua:172Sets one of the lasting permissions of a character and writes it to the database. The
character does not have to be loaded. If it is the active character of a connected player,
that player's permissions are brought up to date, see Bolt:update_character_permissions.
-- Lets the active character of a player use the tool gun, whatever the player's role says.
Bolt:set_character_permission(Bolt:get_active_character(target), 'toolgun', PERM_ALLOW)
Parameters
- character Character
- perm_id String permission ID
- value Number PERM_ALLOW or PERM_NEVER, or PERM_NO to remove the permission
Returns
- Boolean false if the character is not a saved character, the permission ID is empty or the value is not a PERM_ value; true otherwise
Bolt:set_character_temp_permission(character, perm_id, value, duration)
server plugins/admin/plugin/lib/sv_character_permissions.lua:225Gives a character a temporary permission value that takes precedence over its lasting
permissions until it expires, and writes it to the database. Giving the value the character
already has temporarily adds the duration to the time that is left; any other value starts
counting from now. A permission never lasts longer than Bolt.max_temp_duration from now.
If the character is the active character of a connected player, that player's permissions
are brought up to date.
Parameters
- character Character
- perm_id String permission ID
- value Number PERM_ALLOW or PERM_NEVER
- duration Number seconds until the permission expires, see Bolt#is_temp_duration
Returns
- Boolean false if any of the arguments is not valid, true otherwise
Changes the role that is stored for a SteamID, which its owner gets the next time they
join. Use Player:SetUserGroup for a player who is on the server. Does not check
permissions or immunity.
Parameters
- steam_id String
- role_id String role ID
- callback Function optional, defaults to
nilcalled without arguments once the role has been stored
Bolt:update_character_permissions(character)
server plugins/admin/plugin/lib/sv_character_permissions.lua:334Brings the permissions of the player who has a character loaded up to date with the character's records. Does nothing when nobody has the character loaded.
Parameters
- character Character
See also
Brings what a player knows about the configs in line with what they may see: sends them the config again if their right to edit configs has changed since it was last sent, so that private and pending values reach a new editor and are forgotten by a former one. Called whenever the role or a permission of a player changes. Does nothing before the player has received the config for the first time.
Parameters
- target Player
Looks up the stored user of a SteamID on behalf of a player and runs the callback if the player may act on them. A player who may not is told that the target has a higher immunity. Nothing happens if the player has left by the time the answer arrives.
Parameters
- actor Player the player performing the action, an invalid entity for the server console
- steam_id String SteamID of whoever is acted on
- callback Function called with the user table of Bolt:find_user, or with nil if nobody with that SteamID has ever joined