HasObjectPermissionTo: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{Server function}}<!-- Change this to "Client function" or "Server function" appropriately--> <!-- Describe in plain english what this function does. Don't go into details, jus...) |
|||
Line 34: | Line 34: | ||
-- Ban command | -- Ban command | ||
function onKickCommandHandler ( playerSource, commandName, playerToKick, stringReason ) | function onKickCommandHandler ( playerSource, commandName, playerToKick, stringReason ) | ||
-- Does the calling user have permission to kick the player? Default | -- Does the calling user have permission to kick the player? Default | ||
-- to false for safety reasons. We do this so any user can't use us to | -- to false for safety reasons. We do this so any user can't use us to | ||
-- kick players. | -- kick players. | ||
if ( hasObjectPermissionTo ( playerSource, "function.kickPlayer", false ) ) then | if ( hasObjectPermissionTo ( playerSource, "function.kickPlayer", false ) ) then | ||
-- Do we have permission to kick the player? We do this so we can fail | -- Do we have permission to kick the player? We do this so we can fail | ||
-- nicely if this resource doesn't have access to call that function. | -- nicely if this resource doesn't have access to call that function. | ||
if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) | if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) | ||
-- Kick him | -- Kick him | ||
kickPlayer ( playerToKick, playerSource, stringReason ) | kickPlayer ( playerToKick, playerSource, stringReason ) | ||
else | else | ||
-- Resource doesn't have any permissions, sorry | -- Resource doesn't have any permissions, sorry | ||
outputChatBox ( "kick: The admin resource does not have permission to kick the given player. Please give this resource access to 'function.kickPlayer' in the ACL to use this function.", playerSource ) | outputChatBox ( "kick: The admin resource does not have permission to kick the given player. Please give this resource access to 'function.kickPlayer' in the ACL to use this function.", playerSource ) | ||
end | end | ||
else | else | ||
-- User doesn't have any permissions | -- User doesn't have any permissions | ||
outputChatBox ( "kick: You don't have permissions to use this command.", playerSource ) | outputChatBox ( "kick: You don't have permissions to use this command.", playerSource ) | ||
end | end | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 22:46, 19 December 2007
This function returns whether or not the given object has access to perform the given action. The object can be given as a resource or a client element (ie. a player), or a string formatted like "user.<name>" or "resource.<name>".
Syntax
bool hasObjectPermissionTo ( string / element theObject, string theAction [, bool defaultPermission = true ] )
Required Arguments
- theObject: The object to test if has permission to. This can be a client element (ie. a player) or a string.
- theAction: The action to test if the given object has access to. Ie. "function.kickPlayer".
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- defaultPermission: The default permission if none is specified in either of the groups the given object is a member of. If this is left to true, the given object will have permissions to perform the action unless the opposite is explicitly specified in the ACL. If false, the action will be denied by default unless explicitly approved by the ACL.
Returns
Returns true if the given object has permission to perform the given action, false otherwise. Returns nil if the function failed because of bad arguments.
Example
This example does...
-- ChrML: Please test this example -- Ban command function onKickCommandHandler ( playerSource, commandName, playerToKick, stringReason ) -- Does the calling user have permission to kick the player? Default -- to false for safety reasons. We do this so any user can't use us to -- kick players. if ( hasObjectPermissionTo ( playerSource, "function.kickPlayer", false ) ) then -- Do we have permission to kick the player? We do this so we can fail -- nicely if this resource doesn't have access to call that function. if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) -- Kick him kickPlayer ( playerToKick, playerSource, stringReason ) else -- Resource doesn't have any permissions, sorry outputChatBox ( "kick: The admin resource does not have permission to kick the given player. Please give this resource access to 'function.kickPlayer' in the ACL to use this function.", playerSource ) end else -- User doesn't have any permissions outputChatBox ( "kick: You don't have permissions to use this command.", playerSource ) end end
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