HasObjectPermissionTo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}<!-- Change this to "Client function" or "Server function" appropriately-->
{{Server function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function returns whether or not the given object has access to perform the given action.  
This function returns whether or not the given object has access to perform the given action.  


==Syntax==  
==Syntax==  
<!-- 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">
bool hasObjectPermissionTo ( string / element theObject, string theAction [, bool defaultPermission = true ] )
bool hasObjectPermissionTo ( string / element theObject, string theAction [, bool defaultPermission = true ] )
Line 11: Line 9:


===Required Arguments===  
===Required Arguments===  
<!-- 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 -->
*'''theObject:''' The object to test if has permission to. This can be a client element (ie. a player), a resource or a string in the form "user.<name>" or "resource.<name>".
*'''theObject:''' The object to test if has permission to. This can be a client element (ie. a player), a resource or a string in the form "user.<name>" or "resource.<name>".
*'''theAction:''' The action to test if the given object has access to. Ie. "function.kickPlayer".
*'''theAction:''' The action to test if the given object has access to. Ie. "function.kickPlayer".


<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
Line 21: Line 17:


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
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.
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==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example does ban a player
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- ChrML: Please test this example
-- Ban command
-- Ban command
function onKickCommandHandler ( playerSource, commandName, playerToKick, stringReason )
function onKickCommandHandler ( playerSource, commandName, playerToKick, stringReason )
Line 41: Line 31:
         -- 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 ) ) then
             -- Kick him
             -- Kick him
             kickPlayer ( playerToKick, playerSource, stringReason )
             kickPlayer ( playerToKick, playerSource, stringReason )
Line 53: Line 43:
     end
     end
end
end
addCommandHandler ( "ban", onKickCommandHandler )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{ACL_functions}}
{{ACL_functions}}
[[Category:Needs_Example]] <!-- leave this until the example is completed. -->

Revision as of 15:27, 5 January 2008

This function returns whether or not the given object has access to perform the given action.

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), a resource or a string in the form "user.<name>" or "resource.<name>".
  • 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 ban a player

-- 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 ) ) then
            -- Kick him
            kickPlayer ( playerToKick, playerSource, stringReason )
        else
            -- Resource doesn't have any permissions, sorry
            outputChatBox ( "kick: The admin resource is not able to kick players. 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
addCommandHandler ( "ban", onKickCommandHandler )


See Also