Skip to content

Administrator

Comprehensive user group and privilege management system for the Lilia framework.


Overview

The administrator library provides comprehensive functionality for managing user groups, privileges, and administrative permissions in the Lilia framework. It handles the creation, modification, and deletion of user groups with inheritance-based privilege systems. The library operates on both server and client sides, with the server managing privilege storage and validation while the client provides user interface elements for administrative management. It includes integration with CAMI (Comprehensive Administration Management Interface) for compatibility with other administrative systems. The library ensures proper privilege inheritance, automatic privilege registration for tools and properties, and comprehensive logging of administrative actions. It supports both console-based and GUI-based administrative command execution with proper permission checking and validation. Setting Superadmin: To set yourself as superadmin in the console, use: plysetgroup "STEAMID" superadmin The system has three default user groups with inheritance levels: user (level 1), admin (level 2), and superadmin (level 3). Superadmin automatically has all privileges and cannot be restricted by any permission checks.

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

Purpose

Applies kick or ban punishments to a player based on the provided parameters.

When Called

Called when an automated system or admin action needs to punish a player with a kick or ban.

Parameters

Player client The player to punish.

string infraction Description of the infraction that caused the punishment.

boolean kick Whether to kick the player.

boolean ban Whether to ban the player.

number time Ban duration in minutes (only used if ban is true).

string kickKey Localization key for kick message (defaults to "kickedForInfraction").

string banKey Localization key for ban message (defaults to "bannedForInfraction").

Example Usage

  -- Kick a player for spamming
  lia.admin.applyPunishment(player, "Spamming in chat", true, false, nil, nil, nil)
  -- Ban a player for griefing for 24 hours
  lia.admin.applyPunishment(player, "Griefing", false, true, 1440, nil, nil)
  -- Both kick and ban with custom messages
  lia.admin.applyPunishment(player, "Hacking", true, true, 10080, "kickedForHacking", "bannedForHacking")

lia.admin.hasAccess(ply, privilege)

Purpose

Checks if a player has access to a specific privilege based on their usergroup and privilege requirements.

When Called

Called when verifying if a player can perform an action that requires specific permissions.

Parameters

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

string privilege The privilege ID to check access for (e.g., "command_kick", "property_door", "tool_remover").

Returns

boolean true if the player has access to the privilege, false otherwise.

Example Usage

  -- Check if player can use kick command
  if lia.admin.hasAccess(player, "command_kick") then
      -- Allow kicking
  end
  -- Check if player has access to a tool
  if lia.admin.hasAccess(player, "tool_remover") then
      -- Give tool access
  end
  -- Check usergroup access directly
  if lia.admin.hasAccess("admin", "command_ban") then
      -- Admin group has ban access
  end

lia.admin.save(noNetwork)

Purpose

Saves administrator group configurations and privileges to the database.

When Called

Called when administrator settings are modified and need to be persisted, or when syncing with clients.

Parameters

boolean noNetwork If true, skips network synchronization with clients after saving.

Example Usage

  -- Save admin groups without network sync
  lia.admin.save(true)
  -- Save and sync with all clients
  lia.admin.save(false)
  -- or simply:
  lia.admin.save()

lia.admin.registerPrivilege(priv, ID, Name, MinAccess, Category)

Purpose

Registers a new privilege in the administrator system with specified access levels and categories.

When Called

Called when defining new administrative permissions that can be granted to user groups.

Parameters

table priv Privilege configuration table with the following fields:

string ID Unique identifier for the privilege (required)

string Name Display name for the privilege (optional, defaults to ID)

string MinAccess Minimum usergroup required ("user", "admin", "superadmin")

string Category Category for organizing privileges in menus

Example Usage

  -- Register a custom admin command privilege
  lia.admin.registerPrivilege({
      ID = "command_customban",
      Name = "Custom Ban Command",
      MinAccess = "admin",
      Category = "staffCommands"
  })
  -- Register a property privilege
  lia.admin.registerPrivilege({
      ID = "property_teleport",
      Name = "Teleport Property",
      MinAccess = "admin",
      Category = "staffPermissions"
  })

lia.admin.unregisterPrivilege(id)

Purpose

Removes a privilege from the administrator system and cleans up all associated data.

When Called

Called when a privilege is no longer needed or when cleaning up removed permissions.

Parameters

string id The privilege ID to unregister.

Example Usage

  -- Unregister a custom privilege
  lia.admin.unregisterPrivilege("command_customban")
  -- Clean up a tool privilege
  lia.admin.unregisterPrivilege("tool_remover")

lia.admin.applyInheritance(groupName)

Purpose

Applies privilege inheritance to a usergroup, copying permissions from parent groups and ensuring appropriate access levels.

When Called

Called when setting up or updating usergroup permissions to ensure inheritance rules are properly applied.

Parameters

string groupName The name of the usergroup to apply inheritance to.

Example Usage

  -- Apply inheritance to a moderator group
  lia.admin.applyInheritance("moderator")
  -- Apply inheritance after creating a new usergroup
  lia.admin.applyInheritance("customadmin")

lia.admin.load()

Purpose

Loads administrator group configurations from the database and initializes the admin system.

When Called

Called during server startup to restore saved administrator settings and permissions.

Example Usage

  -- Load admin system (called automatically during server initialization)
  lia.admin.load()

lia.admin.createGroup(groupName, info)

Purpose

Creates a new administrator usergroup with specified configuration and inheritance.

When Called

Called when setting up new administrator roles or permission levels in the system.

Parameters

string groupName The name of the usergroup to create.

table info Optional configuration table for the group (privileges, inheritance, etc.).

Example Usage

  -- Create a moderator group
  lia.admin.createGroup("moderator", {
      _info = {
          inheritance = "user",
          types = {}
      },
      command_kick = true,
      command_mute = true
  })
  -- Create a custom admin group
  lia.admin.createGroup("customadmin")

lia.admin.removeGroup(groupName)

Purpose

Removes an administrator usergroup from the system.

When Called

Called when cleaning up or removing unused administrator roles.

Parameters

string groupName The name of the usergroup to remove.

Example Usage

  -- Remove a custom moderator group
  lia.admin.removeGroup("moderator")
  -- Remove a custom admin group
  lia.admin.removeGroup("customadmin")

lia.admin.renameGroup(oldName, newName)

Purpose

Renames an existing administrator usergroup to a new name.

When Called

Called when reorganizing or rebranding administrator roles.

Parameters

string oldName The current name of the usergroup to rename.

string newName The new name for the usergroup.

Example Usage

  -- Rename moderator group to staff
  lia.admin.renameGroup("moderator", "staff")
  -- Rename admin group to administrator
  lia.admin.renameGroup("admin", "administrator")

lia.admin.notifyAdmin(notification)

Purpose

Sends a notification to all administrators who have permission to see admin notifications.

When Called

Called when important administrative events need to be communicated to staff.

Parameters

string notification The notification message key to send.

Example Usage

  -- Notify admins of a potential exploit
  lia.admin.notifyAdmin("exploitDetected")
  -- Notify admins of a player report
  lia.admin.notifyAdmin("playerReportReceived")

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

Purpose

Grants a specific permission to an administrator usergroup.

When Called

Called when configuring permissions for administrator roles.

Parameters

string groupName The name of the usergroup to grant the permission to.

string permission The permission ID to grant.

boolean silent If true, skips network synchronization.

Example Usage

  -- Grant kick permission to moderators
  lia.admin.addPermission("moderator", "command_kick", false)
  -- Grant ban permission to admins silently
  lia.admin.addPermission("admin", "command_ban", true)

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

Purpose

Removes a specific permission from an administrator usergroup.

When Called

Called when revoking permissions from administrator roles.

Parameters

string groupName The name of the usergroup to remove the permission from.

string permission The permission ID to remove.

boolean silent If true, skips network synchronization.

Example Usage

  -- Remove kick permission from moderators
  lia.admin.removePermission("moderator", "command_kick", false)
  -- Remove ban permission from admins silently
  lia.admin.removePermission("admin", "command_ban", true)

lia.admin.sync(c)

Purpose

Synchronizes administrator privileges and usergroups with clients.

When Called

Called when administrator data changes and needs to be updated on clients, or when a player joins.

Parameters

Player c Optional specific client to sync with. If not provided, syncs with all clients in batches.

Example Usage

  -- Sync admin data with all clients
  lia.admin.sync()
  -- Sync admin data with a specific player
  lia.admin.sync(specificPlayer)

lia.admin.hasChanges()

Purpose

Checks if administrator privileges or groups have changed since the last sync.

When Called

Called to determine if a sync operation is needed.

Returns

boolean true if there are unsynced changes, false otherwise.

Example Usage

  -- Check if admin data needs syncing
  if lia.admin.hasChanges() then
      lia.admin.sync()
  end

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

Purpose

Sets the usergroup of a player entity.

When Called

Called when promoting, demoting, or changing a player's administrative role.

Parameters

Player ply The player to change the usergroup for.

string newGroup The new usergroup name to assign.

string source Optional source identifier for logging.

Example Usage

  -- Promote player to admin
  lia.admin.setPlayerUsergroup(player, "admin", "promotion")
  -- Demote player to user
  lia.admin.setPlayerUsergroup(player, "user", "demotion")

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

Purpose

Sets the usergroup of a player by their SteamID.

When Called

Called when changing a player's usergroup using their SteamID, useful for offline players.

Parameters

string steamId The SteamID of the player to change the usergroup for.

string newGroup The new usergroup name to assign.

string source Optional source identifier for logging.

Example Usage

  -- Set offline player's usergroup to admin
  lia.admin.setSteamIDUsergroup("STEAM_0:1:12345678", "admin", "promotion")
  -- Demote player by SteamID
  lia.admin.setSteamIDUsergroup("STEAM_0:1:12345678", "user", "demotion")

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

Purpose

Executes administrative commands on players with proper permission checking and logging.

When Called

Called when an administrator uses commands like kick, ban, mute, gag, freeze, slay, bring, goto, etc.

Parameters

string cmd The command to execute (e.g., "kick", "ban", "mute", "gag", "freeze", "slay", "bring", "goto", "return", "jail", "cloak", "god", "ignite", "strip", "respawn", "blind").

Player|string victim The target player entity or SteamID string.

number|string dur Duration for commands that support time limits (ban, freeze, blind, ignite).

string reason Reason for the action (used in kick, ban, etc.).

Player admin The administrator executing the command.

Returns

boolean true if the command was executed successfully, false otherwise.

Example Usage

  -- Kick a player for spamming
  lia.admin.serverExecCommand("kick", targetPlayer, nil, "Spamming in chat", adminPlayer)
  -- Ban a player for 24 hours
  lia.admin.serverExecCommand("ban", targetPlayer, 1440, "Griefing", adminPlayer)
  -- Mute a player
  lia.admin.serverExecCommand("mute", targetPlayer, nil, nil, adminPlayer)
  -- Bring a player to admin's position
  lia.admin.serverExecCommand("bring", targetPlayer, nil, nil, adminPlayer)

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

Purpose

Executes an administrative command using the client-side command system.

When Called

Called when running admin commands through console commands or automated systems.

Parameters

string cmd The command to execute (e.g., "kick", "ban", "mute", "freeze", etc.).

Player|string victim The target player or identifier.

number dur Duration for time-based commands.

string reason Reason for the administrative action.

Returns

boolean true if the command was executed successfully, false otherwise.

Example Usage

  -- Kick a player via console command
  lia.admin.execCommand("kick", targetPlayer, nil, "Rule violation")
  -- Ban a player for 24 hours
  lia.admin.execCommand("ban", targetPlayer, 1440, "Griefing")