Skip to content

Admin

Shared administration helpers for usergroup management, privilege registration, permission checks, CAMI synchronization, and admin UI support.


Overview

This module powers Lilia's admin permission system under `lia.admin`. It manages built-in and custom usergroups, resolves privilege inheritance, integrates with CAMI, synchronizes permission data to clients, provides usergroup editing UI, and executes or routes admin commands depending on realm.

lia.admin.isValidGroup(groupName)View Source

Purpose

Checks whether a usergroup name exists in the loaded admin groups or in the built-in default groups.

Realm

Shared

Parameters

string|any groupName The usergroup name to validate.

Returns

boolean True if the group name resolves to a known group. False otherwise.

Example Usage

  local isValid = lia.admin.isValidGroup("admin")

lia.admin.getDefaultUserGroup()View Source

Purpose

Returns the configured default usergroup, falling back to `user` when the configured value is invalid.

Realm

Shared

Returns

string The valid default usergroup name to assign to players without an explicit rank.

Example Usage

  local defaultGroup = lia.admin.getDefaultUserGroup()

lia.admin.shouldShowUsergroupIcons()View Source

Purpose

Reads the configuration that controls whether usergroup icons should be shown in the UI.

Realm

Shared

Returns

boolean True when usergroup icons should be displayed.

Example Usage

  if lia.admin.shouldShowUsergroupIcons() then
      -- draw icons
  end

lia.admin.getUsergroupIcon(groupOrPlayer)View Source

Purpose

Resolves the icon path for a usergroup name or player using configured group metadata and hooks.

Realm

Shared

Parameters

string|Player groupOrPlayer A usergroup name or a player whose current usergroup should be inspected.

Returns

string|nil The icon material path to use, or nil when icons are disabled.

Example Usage

  local icon = lia.admin.getUsergroupIcon(LocalPlayer())

lia.admin.isProtectedStaffTarget(cmd, target)View Source

Purpose

Checks whether a command target is an on-duty staff member protected from targeted moderation actions.

Realm

Shared

Parameters

string cmd The admin command being attempted.

Entity|Player target optional The entity being targeted by the command.

Returns

boolean True when the target is protected from the requested action.

Example Usage

  if lia.admin.isProtectedStaffTarget("kick", target) then return end

lia.admin.notifyProtectedStaffTarget(admin)View Source

Purpose

Sends the localized protected-staff warning to the acting administrator.

Realm

Shared

Parameters

Player admin optional The player who attempted the blocked action.

Example Usage

  lia.admin.notifyProtectedStaffTarget(client)

lia.admin.getExternalPrivilegeName(id)View Source

Purpose

Builds a display-safe external privilege name and caches alias mappings for integrations like CAMI.

Realm

Shared

Parameters

string|any id The internal privilege ID.

Returns

string The external display name for the privilege.

Example Usage

  local name = lia.admin.getExternalPrivilegeName("command_plykick")

lia.admin.normalizePrivilege(privilege)View Source

Purpose

Normalizes a privilege identifier by resolving stored aliases back to the canonical privilege ID.

Realm

Shared

Parameters

string|any privilege The privilege name or alias to normalize.

Returns

string The canonical privilege ID, or the original string when no alias exists.

Example Usage

  local id = lia.admin.normalizePrivilege(privilege)

lia.admin.getCommandPrivilegeID(cmd)View Source

Purpose

Converts an admin command name into the privilege ID used to authorize that command.

Realm

Shared

Parameters

string|any cmd The command name to translate.

Returns

string|nil The matching privilege ID, or nil when the command name is empty.

Example Usage

  local privilegeID = lia.admin.getCommandPrivilegeID("kick")

lia.admin.applyPunishment(client, infraction, kick, ban, time, kickKey, banKey)View Source

Purpose

Applies a standardized kick and/or ban punishment for a named infraction using localized reason strings.

Realm

Shared

Parameters

Player client The player receiving the punishment.

string infraction The infraction label inserted into the localized reason text.

boolean kick Whether the player should be kicked.

boolean ban Whether the player should be banned.

number time optional The ban duration in minutes, or 0 for permanent/default behavior.

string kickKey optional The localization key used to build the kick reason.

string banKey optional The localization key used to build the ban reason.

Example Usage

  lia.admin.applyPunishment(client, "cheating", true, true, 60)

lia.admin.hasAccess(ply, privilege)View Source

Purpose

Determines whether a player or usergroup has access to a specific privilege, creating dynamic tool and property privileges when needed.

Realm

Shared

Parameters

Player|string ply The player to check, or a usergroup name.

string privilege The privilege ID to authorize.

Returns

boolean True if the player or group has the requested privilege.

Example Usage

  if lia.admin.hasAccess(client, "manageUsergroups") then
      -- allow action
  end

lia.admin.save(noNetwork)View Source

Purpose

Persists the current admin group configuration to the database and optionally re-syncs it to connected clients.

Realm

Shared

Parameters

boolean noNetwork optional When true, skips the client synchronization step after saving.

Example Usage

  lia.admin.save()

lia.admin.registerPrivilege(priv)View Source

Purpose

Registers a new privilege, stores its metadata, seeds inherited group access, and notifies integrations.

Realm

Shared

Parameters

table priv The privilege definition containing fields such as `ID`, `Name`, `MinAccess`, and `Category`.

Example Usage

  lia.admin.registerPrivilege({
      ID = "examplePrivilege",
      Name = "Example Privilege",
      MinAccess = "admin"
  })

lia.admin.unregisterPrivilege(id)View Source

Purpose

Removes a privilege from Lilia's caches, usergroups, and CAMI registrations.

Realm

Shared

Parameters

string|any id The privilege ID to unregister.

Example Usage

  lia.admin.unregisterPrivilege("examplePrivilege")

lia.admin.applyInheritance(groupName)View Source

Purpose

Applies inherited permissions and default minimum-access grants to a usergroup.

Realm

Shared

Parameters

string groupName The group whose effective permissions should be rebuilt.

Example Usage

  lia.admin.applyInheritance("moderator")

lia.admin.load()View Source

Purpose

Loads admin groups from the database, normalizes them, rebuilds privileges, and finishes CAMI synchronization.

Realm

Shared

Example Usage

  lia.admin.load()

lia.admin.createGroup(groupName, info)View Source

Purpose

Creates a new custom usergroup, applies inheritance, and registers it with hooks and CAMI.

Realm

Shared

Parameters

string groupName The name of the new usergroup.

table info optional Optional group data including `_info` metadata.

Example Usage

  lia.admin.createGroup("moderator", {
      _info = {
          inheritance = "admin",
          types = {"Staff"}
      }
  })

lia.admin.removeGroup(groupName)View Source

Purpose

Removes a custom usergroup and unregisters it from CAMI.

Realm

Shared

Parameters

string groupName The name of the group to remove.

Example Usage

  lia.admin.removeGroup("moderator")

lia.admin.renameGroup(oldName, newName)View Source

Purpose

Renames a custom usergroup while preserving its permissions and inheritance data.

Realm

Shared

Parameters

string oldName The existing group name.

string newName The new group name to assign.

Example Usage

  lia.admin.renameGroup("helper", "moderator")

lia.admin.notifyAdmin(notification)View Source

Purpose

Sends an admin-only localized notification to every player with permission to view alting-related alerts.

Realm

Server

Parameters

string notification The localization key to send to eligible staff members.

Example Usage

  lia.admin.notifyAdmin("playerAltDetected")

lia.admin.addPermission(groupName, permission, silent)View Source

Purpose

Grants or explicitly enables a privilege for a custom usergroup and saves the change.

Realm

Server

Parameters

string groupName The usergroup receiving the permission.

string permission The privilege ID or alias to enable.

boolean silent optional When true, skips immediate network synchronization during the save call.

Example Usage

  lia.admin.addPermission("moderator", "manageUsergroups")

lia.admin.removePermission(groupName, permission, silent)View Source

Purpose

Revokes or explicitly disables a privilege for a custom usergroup and saves the change.

Realm

Server

Parameters

string groupName The usergroup losing the permission.

string permission The privilege ID or alias to disable.

boolean silent optional When true, skips immediate network synchronization during the save call.

Example Usage

  lia.admin.removePermission("moderator", "manageUsergroups")

lia.admin.sync(c)View Source

Purpose

Sends the latest admin privilege and group tables to one client or to all ready human clients in batches.

Realm

Server

Parameters

Player c optional An optional player to sync individually. When nil, all ready human clients are synced.

Example Usage

  lia.admin.sync()

lia.admin.hasChanges()View Source

Purpose

Compares current privilege and group counts against the last broadcast snapshot to detect unsynced changes.

Realm

Server

Returns

boolean True when the cached sync counts no longer match the current admin data.

Example Usage

  local dirty = lia.admin.hasChanges()

lia.admin.setPlayerUsergroup(ply, newGroup, source)View Source

Purpose

Updates a live player's usergroup by SteamID through the shared SteamID assignment helper.

Realm

Server

Parameters

Player ply The player whose rank should change.

string newGroup optional The target group name, or nil to fall back to the configured default group.

string source optional A source label passed into CAMI and hooks.

Example Usage

  lia.admin.setPlayerUsergroup(client, "admin", "Console")

lia.admin.setSteamIDUsergroup(steamId, newGroup, source)View Source

Purpose

Assigns a usergroup to a SteamID, updates the live player if connected, and signals CAMI and hooks.

Realm

Server

Parameters

string steamId The SteamID to update.

string newGroup optional The target group name, or nil to use the configured default group.

string source optional A label describing who or what initiated the change.

Example Usage

  lia.admin.setSteamIDUsergroup("STEAM_0:1:12345", "admin", "Lilia")

lia.admin.serverExecCommand(cmd, victim, dur, reason, admin)View Source

Purpose

Executes a server-side admin action against a target player after validating privileges and special protections.

Realm

Server

Parameters

string cmd The admin command to execute.

Player|string victim The target player entity or a lookup string.

number dur optional An optional duration used by timed commands.

string reason optional An optional reason string for punishments.

Player admin optional The acting administrator, or nil when the server console initiated the action.

Returns

boolean True when the command completed successfully. False otherwise.

Example Usage

  lia.admin.serverExecCommand("kick", target, nil, "Rule violation", client)

lia.admin.execCommand(cmd, victim, dur, reason)View Source

Purpose

Executes a clientside admin command by routing it through hooks or chat command fallbacks.

Realm

Client

Parameters

string cmd The admin command to execute.

Player|string victim The target player or identifier.

number dur optional An optional duration argument for timed actions.

string reason optional An optional reason string to forward with the command.

Returns

boolean|nil True when a command handler ran successfully, false when blocked, or nil when no handler exists.

Example Usage

  lia.admin.execCommand("kick", target, nil, "Rule violation")

Hooks

Library-specific hooks documented for this library.


GetUsergroupIcon(groupName, groupData, groupOrPlayer)View Source

Purpose

Allows plugins or modules to override the icon path used for a usergroup in admin-related UI.

Realm

Shared

Parameters

string groupName The normalized usergroup name being resolved.

table groupData optional The stored group data for the usergroup, if available.

string|Player groupOrPlayer The original argument passed into `lia.admin.getUsergroupIcon`.

Returns

string|nil Return a string icon path to override the default icon resolution. Return nil to continue normal behavior.


OnAdminSystemLoaded(groups, privileges)View Source

Purpose

Runs after the admin system finishes loading groups and privileges from storage.

Realm

Shared

Parameters

table groups The normalized admin usergroup table.

table privileges The rebuilt privilege minimum-access table.


PopulateAdminTabs(pages)View Source

Purpose

Allows modules to add pages to the admin menu, including the usergroup management panel defined in this file.

Realm

Client

Parameters

table pages The mutable page definition array used to build the admin interface.