ZH-CN/aclGroupListObjects: Difference between revisions
Jump to navigation
Jump to search
Qwe7769611 (talk | contribs) No edit summary |
Qwe7769611 (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象. | 此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象. | ||
== | ==语法== | ||
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | <!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
table aclGroupListObjects ( aclgroup theGroup ) | table aclGroupListObjects ( aclgroup theGroup ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{ | {{OOP_ZH-CN||[[aclgroup]]:listObjects|objects|}} | ||
=== | ===必填参数=== | ||
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | <!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | ||
*'''theGroup:''' 要从中获取对象的ACL组 | *'''theGroup:''' 要从中获取对象的ACL组 | ||
=== | ===返回值=== | ||
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
返回给定ACL组中的字符串表。这张表子可能是空的。如果组无效或由于其他原因失败,则返回“false”或“nil”. | |||
== | ==示例== | ||
如果给定了ACL组,本例将输出对象列表.(已测试!) | |||
<section name="Example 1: Server" class="server" show="true"> | <section name="Example 1: Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua">addCommandHandler("aclObjectList",function(player,command,aclGroup) | <syntaxhighlight lang="lua">addCommandHandler("aclObjectList",function(player,command,aclGroup) | ||
Line 42: | Line 42: | ||
<section name="Example 2: Server" class="server" show="true"> | <section name="Example 2: Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua" >function outputAdminGroupAccounts( player ) | <syntaxhighlight lang="lua" >function outputAdminGroupAccounts( player ) | ||
local admins = {} -- | local admins = {} -- 创建将在其中添加“Admin”组帐户的表 | ||
local group = aclGetGroup( "Admin" ) | local group = aclGetGroup( "Admin" ) | ||
-- | -- 如果在ACL中找到“Admin”组,则应返回“aclgroup” | ||
if (group) then | if (group) then | ||
for _, object in ipairs(aclGroupListObjects(group) or {}) do | for _, object in ipairs(aclGroupListObjects(group) or {}) do | ||
local objType = gettok( object, 1, string.byte('.') ) | local objType = gettok( object, 1, string.byte('.') ) | ||
-- | -- objType:只获取对象类型,可以是“user”或“resource” | ||
if (objType == "user") then -- | if (objType == "user") then -- 检查是否是玩家帐户 | ||
local _name = gettok( object, 2, string.byte('.') ) -- | local _name = gettok( object, 2, string.byte('.') ) -- 忽略“user.”,将其与帐户名分开 | ||
table.insert( admins, _name ) -- | table.insert( admins, _name ) -- 将帐户名添加到“admins”表中 | ||
end | end | ||
end | end | ||
end | end | ||
for i, name in ipairs(admins) do -- | for i, name in ipairs(admins) do -- 在“admins”表中循环 | ||
outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140) | outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140) | ||
-- | -- 输出如下:“1:John” | ||
end | end | ||
end | end | ||
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts) | addCommandHandler("getAdminAccounts", outputAdminGroupAccounts) | ||
-- | -- 添加命令“getAdminAccounts”并将其附加到函数“outputAdminGroupAccounts” | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Revision as of 06:46, 6 February 2021
此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象.
语法
table aclGroupListObjects ( aclgroup theGroup )
OOP 语法 什么是OOP?
- 方法: aclgroup:listObjects(...)
- 变量: .objects
必填参数
- theGroup: 要从中获取对象的ACL组
返回值
返回给定ACL组中的字符串表。这张表子可能是空的。如果组无效或由于其他原因失败,则返回“false”或“nil”.
示例
如果给定了ACL组,本例将输出对象列表.(已测试!)
Click to collapse [-]
Example 1: ServeraddCommandHandler("aclObjectList",function(player,command,aclGroup) if(aclGroup~="")then table = aclGroupListObjects(aclGetGroup(aclGroup)) count = 0 for objects,name in pairs(table)do outputChatBox("ACL LIST: "..aclGroup.." #"..tostring(count).." Object: "..name..".",player) count = count + 1 end else outputChatBox("Please add the aclGroup you want the list of.",player) outputChatBox("Syntax: /aclObjectList aclGroup",player) end end)
This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.
Click to collapse [-]
Example 2: Serverfunction outputAdminGroupAccounts( player ) local admins = {} -- 创建将在其中添加“Admin”组帐户的表 local group = aclGetGroup( "Admin" ) -- 如果在ACL中找到“Admin”组,则应返回“aclgroup” if (group) then for _, object in ipairs(aclGroupListObjects(group) or {}) do local objType = gettok( object, 1, string.byte('.') ) -- objType:只获取对象类型,可以是“user”或“resource” if (objType == "user") then -- 检查是否是玩家帐户 local _name = gettok( object, 2, string.byte('.') ) -- 忽略“user.”,将其与帐户名分开 table.insert( admins, _name ) -- 将帐户名添加到“admins”表中 end end end for i, name in ipairs(admins) do -- 在“admins”表中循环 outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140) -- 输出如下:“1:John” end end addCommandHandler("getAdminAccounts", outputAdminGroupAccounts) -- 添加命令“getAdminAccounts”并将其附加到函数“outputAdminGroupAccounts”
See Also
- aclCreate
- aclCreateGroup
- aclDestroy
- aclDestroyGroup
- aclGet
- aclGetGroup
- aclGetName
- aclGetRight
- aclGroupAddACL
- aclGroupAddObject
- aclGroupGetName
- aclGroupList
- aclGroupListACL
- aclGroupListObjects
- aclGroupRemoveACL
- aclGroupRemoveObject
- aclList
- aclListRights
- aclReload
- aclRemoveRight
- aclSave
- aclSetRight
- hasObjectPermissionTo
- isObjectInACLGroup