### Get Online Players with Specific Access using CAMI Source: https://context7.com/glua/cami/llms.txt Retrieves a list of all currently online players who possess a specified access privilege. The function takes the privilege name as input and returns a callback with a list of player objects. This is useful for finding administrators or moderators with specific permissions. ```lua -- Get all online players with a privilege CAMI.GetPlayersWithAccess("Kick Player", function(players) print("Players with kick access: " .. #players) for _, ply in ipairs(players) do print(" - " .. ply:Nick()) end end) ``` -------------------------------- ### Register and Retrieve CAMI Usergroups and Privileges Source: https://context7.com/glua/cami/llms.txt Demonstrates how to define, register, and retrieve usergroup and privilege structures within CAMI. Usergroups can inherit from other groups, and privileges can have custom access logic. This allows for a flexible and hierarchical permission system. ```lua -- Creating usergroup structures local vipGroup = { Name = "vip", Inherits = "user" } local seniorModGroup = { Name = "senior_mod", Inherits = "moderator" -- Inherits from custom group } CAMI.RegisterUsergroup(vipGroup, "MyAdminMod") CAMI.RegisterUsergroup(seniorModGroup, "MyAdminMod") -- Retrieving registered usergroups local usergroup = CAMI.GetUsergroup("vip") if usergroup then print("VIP group inherits: " .. usergroup.Inherits) print("Registered by: " .. usergroup.CAMI_Source) end -- Creating privilege structures local teleportPriv = { Name = "Teleport", MinAccess = "admin", Description = "Allows teleporting to other players", HasAccess = function(self, actor, target) -- Custom logic: can't teleport to higher ranking players if target and target:IsSuperAdmin() and not actor:IsSuperAdmin() then return false, "Cannot teleport to superadmins" end return true end } CAMI.RegisterPrivilege(teleportPriv) -- Retrieving privilege information local priv = CAMI.GetPrivilege("Teleport") if priv then print("Teleport privilege - MinAccess: " .. priv.MinAccess) print("Description: " .. (priv.Description or "None")) end ``` -------------------------------- ### Register Custom Privileges with CAMI (Lua) Source: https://context7.com/glua/cami/llms.txt This code shows a third-party addon registering a custom privilege ('PlayX Spawn Screen') with CAMI, including optional custom access logic. It also demonstrates how an admin mod can listen for newly registered privileges using the 'CAMI.OnPrivilegeRegistered' hook and how to unregister a privilege. ```lua -- Third-party addon registering a privilege local spawnScreenPrivilege = { Name = "PlayX Spawn Screen", MinAccess = "admin", -- Default minimum access level Description = "Allows spawning PlayX screen entities", HasAccess = function(self, actor, target) -- Optional custom access logic if actor:GetNWBool("PlayX_Banned") then return false, "You are banned from using PlayX" end return true end } CAMI.RegisterPrivilege(spawnScreenPrivilege) -- Admin mod listening for privilege registrations hook.Add("CAMI.OnPrivilegeRegistered", "MyAdminMod_PrivilegeListener", function(privilege) print("New privilege: " .. privilege.Name) print("Default access: " .. privilege.MinAccess) print("Description: " .. (privilege.Description or "None")) -- Add to your admin mod's permission system MyAdminMod.AddPermission(privilege.Name, privilege.MinAccess) end) -- Check existing privileges on startup for name, priv in pairs(CAMI.GetPrivileges()) do print(name .. " - Min Access: " .. priv.MinAccess) end -- Unregister a privilege when no longer needed CAMI.UnregisterPrivilege("PlayX Spawn Screen") ``` -------------------------------- ### Registering Custom Privileges (Lua) Source: https://github.com/glua/cami/blob/master/README.md Third-party addons can register their own custom privileges using `CAMI.RegisterPrivilege`. This allows other modules to reference and manage these specific permissions. Optionally, privileges can be unregistered with `CAMI.UnregisterPrivilege` if they become obsolete. ```lua -- Example of registering a custom privilege CAMI.RegisterPrivilege("can_use_special_feature") -- Example of unregistering a custom privilege CAMI.UnregisterPrivilege("can_use_special_feature") ``` -------------------------------- ### CAMI API Functions Source: https://github.com/glua/cami/blob/master/README.md This section lists the core functions provided by the CAMI API for managing usergroups and privileges. These functions allow for registration, unregistration, retrieval, and access checking. Detailed descriptions can be found in the `sh_cami.lua` source file. ```lua CAMI.UsergroupInherits(usergroupName1 :: string, usergroupName2 :: string) :: bool CAMI.InheritanceRoot(usergroupName) :: string CAMI.RegisterUsergroup(usergroup :: CAMI_USERGROUP, source :: any) :: CAMI_USERGROUP CAMI.UnregisterUsergroup(name :: string, source :: any) :: bool CAMI.GetUsergroup(usergroupName :: string) :: CAMI_USERGROUP CAMI.RegisterPrivilege(privilege :: CAMI_PRIVILEGE) :: CAMI_PRIVILEGE CAMI.UnregisterPrivilege(name :: string) :: bool CAMI.GetPrivilege(name :: string) :: CAMI_PRIVILEGE CAMI.PlayerHasAccess(actor :: Player, privilege :: string, callback :: function(bool, string)[, target :: Player, extraInfo :: table]) :: nil CAMI.GetPlayersWithAccess(privilege :: string, callback :: function(table)[, target :: Player, extraInfo :: Table]) :: nil CAMI.SteamIDHasAccess(actor :: SteamID, privilege :: string, callback :: function(bool, string)[, target :: SteamID, extraInfo :: table]) :: nil CAMI.GetUsergroups() :: [CAMI_USERGROUP] CAMI.GetPrivileges() :: [CAMI_PRIVILEGE] CAMI.SignalUserGroupChanged(ply :: Player, old :: string, new :: string, source :: any) CAMI.SignalSteamIDUserGroupChanged(steamId :: string , old :: string, new :: string, source :: any) ``` -------------------------------- ### Third-Party Addon Integration with CAMI (Lua) Source: https://context7.com/glua/cami/llms.txt This Lua code demonstrates how a third-party addon uses CAMI to register its own privileges and check player access. It registers a privilege during initialization and uses CAMI's asynchronous access check to determine if a player can use a specific feature, providing feedback or executing the feature accordingly. ```lua -- Third-Party Addon Implementation hook.Add("Initialize", "MyAddon_RegisterPrivileges", function() CAMI.RegisterPrivilege({ Name = "MyAddon.UseFeature", MinAccess = "admin", Description = "Can use MyAddon features" }) end) -- Check access before executing function MyAddon.DoSomething(ply) CAMI.PlayerHasAccess(ply, "MyAddon.UseFeature", function(hasAccess, reason) if hasAccess then MyAddon.ExecuteFeature(ply) else ply:ChatPrint("Access denied: " .. (reason or "Unknown")) end end) end ``` -------------------------------- ### CAMI System Hooks (Lua) Source: https://github.com/glua/cami/blob/master/README.md This snippet lists the core hooks provided by the CAMI system. These hooks are designed to notify other modules about significant events, such as usergroup or privilege registration/unregistration, and changes to player access or usergroups. Some hooks require a return value to influence decision-making. ```lua CAMI.OnUsergroupRegistered(CAMI_USERGROUP) CAMI.OnUsergroupUnregistered(CAMI_USERGROUP) CAMI.OnPrivilegeRegistered(CAMI_PRIVILEGE) CAMI.OnPrivilegeUnregistered(CAMI_PRIVILEGE) CAMI.PlayerHasAccess(actor :: Player, privilege :: string, callback :: function(bool, string), target :: Player, extraInfo :: table) :: bool/nil CAMI.SteamIDHasAccess(actor :: SteamID, privilege :: string, callback :: function(bool, string), target :: Player, extraInfo :: table) :: bool/nil CAMI.PlayerUsergroupChanged(ply :: Player, from :: string, to :: string, source :: any) CAMI.SteamIDUsergroupChanged(steamId :: string, from :: string, to :: string, source :: any) ``` -------------------------------- ### Checking Player Access (Lua) Source: https://github.com/glua/cami/blob/master/README.md Both admin mods and third-party addons can check if a player has a specific privilege using `CAMI.PlayerHasAccess`. This function is vital for enforcing permission checks within your module. For offline access queries, `CAMI.SteamIDHasAccess` can be utilized. ```lua -- Example of checking player access local player = Player(1) local hasAccess = CAMI.PlayerHasAccess(player, "can_use_special_feature") if hasAccess then print("Player has access.") else print("Player does not have access.") end ``` -------------------------------- ### Handling Usergroup Changes (Lua) Source: https://github.com/glua/cami/blob/master/README.md When a player's usergroup is modified by your admin mod, it's essential to notify CAMI using `CAMI.SignalUserGroupChanged`. This ensures consistency across all admin mods. Hooking into `CAMI.PlayerUsergroupChanged` is also recommended to stay synchronized with changes made by other modules. ```lua -- Example of signaling a usergroup change local player = Player(1) CAMI.SignalUserGroupChanged(player, "old_group", "new_group", "MyAdminMod") -- Example of hooking into usergroup changes CAMI.PlayerUsergroupChanged(function(ply, from, to, source) print(string.format("%s changed from %s to %s (source: %s)", ply:Nick(), from, to, tostring(source))) end) ``` -------------------------------- ### Check Player Access to Privileges with CAMI (Lua) Source: https://context7.com/glua/cami/llms.txt This snippet illustrates how to check if a player has access to a specific privilege using CAMI. It covers asynchronous checks with callbacks, checks involving a target player, checks with additional parameters like fallback and command arguments, and synchronous checks where supported. ```lua -- Asynchronous access check (recommended) CAMI.PlayerHasAccess(ply, "PlayX Spawn Screen", function(hasAccess, reason) if hasAccess then print(ply:Nick() .. " can spawn screens") SpawnPlayXScreen(ply) else print("Access denied: " .. (reason or "Unknown")) ply:ChatPrint("You don't have permission to spawn screens") end end) -- With target player (for commands affecting others) CAMI.PlayerHasAccess(admin, "Ban Player", function(hasAccess, reason) if hasAccess then target:Ban() else admin:ChatPrint("Cannot ban: " .. reason) end end, target) -- With extra information CAMI.PlayerHasAccess(ply, "Custom Command", function(hasAccess, reason) if hasAccess then ExecuteCommand(ply) end end, nil, { Fallback = "superadmin", -- Fallback if privilege doesn't exist IgnoreImmunity = false, CommandArguments = {arg1, arg2} }) -- Synchronous check (only works if admin mod supports it) local hasAccess, reason = CAMI.PlayerHasAccess(ply, "PlayX Spawn Screen") if hasAccess then SpawnPlayXScreen(ply) end ``` -------------------------------- ### Implement Admin Mod Privilege Checking with CAMI Hooks Source: https://context7.com/glua/cami/llms.txt Allows admin mods to hook into CAMI's privilege checking system to handle access requests. This includes implementing custom logic for online players via `CAMI.PlayerHasAccess` and offline players via `CAMI.SteamIDHasAccess`. The hooks should return true if handled to prevent further processing. ```lua -- Hook to handle privilege queries in your admin mod hook.Add("CAMI.PlayerHasAccess", "MyAdminMod_PrivilegeHandler", function(actor, privilegeName, callback, target, extraInfo) -- Server always has access if not IsValid(actor) then callback(true, "Server entity") return true -- Return true to indicate we handled it end -- Check against your admin mod's permission system local hasPermission = MyAdminMod.PlayerHasPermission(actor, privilegeName) -- Check immunity if target is specified if hasPermission and target and not extraInfo.IgnoreImmunity then if not MyAdminMod.CanTarget(actor, target) then callback(false, "Target is immune") return true end end callback(hasPermission, "MyAdminMod") return true -- We made a decision, don't let other handlers process end) -- Handle SteamID privilege queries hook.Add("CAMI.SteamIDHasAccess", "MyAdminMod_SteamIDHandler", function(steamId, privilegeName, callback, targetSteamId, extraInfo) -- Query your database for offline player permissions MyAdminMod.Database.GetPermissions(steamId, function(permissions) local hasAccess = table.HasValue(permissions, privilegeName) callback(hasAccess, "MyAdminMod Database") end) return true -- We handled it end) ``` -------------------------------- ### Registering Custom Usergroups (Lua) Source: https://github.com/glua/cami/blob/master/README.md Admin mods should use `CAMI.RegisterUsergroup` to define custom usergroups. This function is crucial for extending the CAMI system beyond default groups like 'user' or 'admin'. Ensure to also register the removal of these custom usergroups using `CAMI.UnregisterUsergroup`. ```lua -- Example of registering a custom usergroup CAMI.RegisterUsergroup("my_custom_group") -- Example of unregistering a custom usergroup CAMI.UnregisterUsergroup("my_custom_group") ``` -------------------------------- ### Check Player Access by SteamID with CAMI Source: https://context7.com/glua/cami/llms.txt Checks if a player, identified by their SteamID, has specific access or privileges. This function can handle both online and offline players and supports checking for specific bans or general access. It allows specifying a target SteamID and additional options like ignoring immunity. ```lua -- Check if an offline player has access CAMI.SteamIDHasAccess("STEAM_0:1:12345678", "Permanent Ban", function(hasAccess, reason) if hasAccess then print("This SteamID has ban privileges") else print("Access denied: " .. (reason or "No information available")) end end) -- With target SteamID CAMI.SteamIDHasAccess( "STEAM_0:1:12345678", "Ban Player", function(hasAccess, reason) if hasAccess then BanSteamID(targetSteamID) end end, "STEAM_0:1:87654321", -- Target SteamID {IgnoreImmunity = false} ) ``` -------------------------------- ### Register Custom Usergroups with CAMI (Lua) Source: https://context7.com/glua/cami/llms.txt This snippet demonstrates how an admin mod registers a custom usergroup ('moderator') with CAMI. It also shows how to listen for usergroups registered by other mods using the 'CAMI.OnUsergroupRegistered' hook, retrieve existing usergroups, and check inheritance relationships. ```lua -- Admin mod registering a custom "moderator" usergroup local moderatorGroup = { Name = "moderator", Inherits = "user", -- Must inherit from user, admin, superadmin, or another custom group } CAMI.RegisterUsergroup(moderatorGroup, "MyAdminMod") -- Listen for usergroups registered by other admin mods hook.Add("CAMI.OnUsergroupRegistered", "MyAdminMod_UsergroupListener", function(usergroup, source) print("New usergroup registered: " .. usergroup.Name) print("Inherits from: " .. usergroup.Inherits) print("Registered by: " .. tostring(source)) -- Sync this usergroup with your admin mod's database MyAdminMod.SaveUsergroup(usergroup) end) -- Check if usergroups exist on startup for name, usergroup in pairs(CAMI.GetUsergroups()) do print(name .. " inherits " .. usergroup.Inherits) end -- Check inheritance relationships if CAMI.UsergroupInherits("moderator", "user") then print("Moderators inherit user permissions") end -- Find the root group local root = CAMI.InheritanceRoot("moderator") -- Returns "user" ``` -------------------------------- ### Admin Mod Integration with CAMI (Lua) Source: https://context7.com/glua/cami/llms.txt This Lua code implements an admin mod that integrates with CAMI. It registers custom usergroups, imports existing CAMI groups and privileges, and listens for changes to synchronize data. It also handles player privilege checks by defining custom access logic. ```lua -- Admin Mod Implementation MyAdminMod = {} -- Register custom usergroups on load hook.Add("Initialize", "MyAdminMod_RegisterGroups", function() -- Register custom groups CAMI.RegisterUsergroup({Name = "moderator", Inherits = "user"}, "MyAdminMod") CAMI.RegisterUsergroup({Name = "trialmoderator", Inherits = "user"}, "MyAdminMod") -- Load existing CAMI usergroups for name, group in pairs(CAMI.GetUsergroups()) do if group.CAMI_Source ~= "MyAdminMod" then MyAdminMod.ImportUsergroup(group) end end -- Load existing CAMI privileges for name, priv in pairs(CAMI.GetPrivileges()) do MyAdminMod.ImportPrivilege(priv) endend{) -- Listen for new usergroups hook.Add("CAMI.OnUsergroupRegistered", "MyAdminMod", function(usergroup, source) if source == "MyAdminMod" then return end MyAdminMod.ImportUsergroup(usergroup) end) -- Listen for new privileges hook.Add("CAMI.OnPrivilegeRegistered", "MyAdminMod", function(privilege) MyAdminMod.ImportPrivilege(privilege) end) -- Handle usergroup changes hook.Add("CAMI.PlayerUsergroupChanged", "MyAdminMod", function(ply, old, new, source) if source == "MyAdminMod" then return end MyAdminMod.Database.SaveUsergroup(ply:SteamID(), new) end) -- Handle privilege checks hook.Add("CAMI.PlayerHasAccess", "MyAdminMod", function(actor, privilegeName, callback, target, extraInfo) if not IsValid(actor) then callback(true, "Server") return true end local hasAccess = MyAdminMod.CheckPermission(actor, privilegeName) callback(hasAccess, "MyAdminMod") return true end) ``` -------------------------------- ### Signal and Sync Usergroup Changes with CAMI Source: https://context7.com/glua/cami/llms.txt Enables admin mods to signal and synchronize usergroup changes. This involves notifying other admin mods when a player's usergroup is modified and listening for changes originating from other mods to maintain consistency. It supports both online and offline player updates. ```lua -- Signal when your admin mod changes a player's usergroup function MyAdminMod.SetUsergroup(ply, newGroup) local oldGroup = ply:GetUserGroup() ply:SetUserGroup(newGroup) -- Notify other admin mods CAMI.SignalUserGroupChanged(ply, oldGroup, newGroup, "MyAdminMod") end -- Listen for usergroup changes from other admin mods hook.Add("CAMI.PlayerUsergroupChanged", "MyAdminMod_UsergroupSync", function(ply, old, new, source) -- Don't process changes from our own mod to avoid loops if source == "MyAdminMod" then return end print(ply:Nick() .. " changed from " .. old .. " to " .. new) print("Changed by: " .. tostring(source)) -- Sync with your admin mod's storage MyAdminMod.SyncUsergroup(ply, new) end) -- Signal usergroup change for offline player CAMI.SignalSteamIDUsergroupChanged( "STEAM_0:1:12345678", "user", "admin", "MyAdminMod" ) -- Listen for offline usergroup changes hook.Add("CAMI.SteamIDUsergroupChanged", "MyAdminMod_OfflineSync", function(steamId, old, new, source) if source == "MyAdminMod" then return end MyAdminMod.SaveOfflineUsergroup(steamId, new) end) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.