AclCreate: 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}}
{{Server function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function creates an ACL entry in the Access Control List system with the specified name.
This function creates an ACL entry in the Access Control List system with the specified name.


==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">
acl aclCreate ( string aclName )
acl aclCreate ( string aclName )
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 -->
*'''aclName:''' The name of the ACL entry to add.
*'''aclName:''' The name of the ACL entry to add.


===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 the created ACL object if successful. Returns false if an ACL of the given name could not be created.
Returns the created ACL object if successful. Returns false if an ACL of the given name could not be created.


==Example==  
==Example==
<!-- Explain what the example is in a single sentance -->
This example adds a command ''setaclright'' with which you can easily add new rights to specified access control lists.
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">
--TODO
function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    local ourACL = aclGet ( aclName )
    -- if there is no previous ACL with this name, we need to create one
    if not ourACL then
        ourACL = aclCreate ( aclName )
    end
 
    -- turn the boolean string to lower case
    access = string.lower ( access )
    -- access has to be either true or false (booleans)
    if not (access == "true" or access == "false") then
        -- print out error message to debug window
        outputDebugString ( "Invalid access; true and false are only accepted", 1 )
        -- exit function
        return
    end
 
    -- change the access to boolean
    if access == "true" then
        access = true
    else
        access = false
 
    -- and finally let's set the right
    aclSetRight ( ourACL, rightName, access )
    -- don't forget to save the ACL after it has been modified
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )
</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 -->
{{ACL_functions}}
{{ACL_functions}}
[[Category:Needs_Example]]

Revision as of 18:21, 22 June 2009

This function creates an ACL entry in the Access Control List system with the specified name.

Syntax

acl aclCreate ( string aclName )

Required Arguments

  • aclName: The name of the ACL entry to add.

Returns

Returns the created ACL object if successful. Returns false if an ACL of the given name could not be created.

Example

This example adds a command setaclright with which you can easily add new rights to specified access control lists.

function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    local ourACL = aclGet ( aclName )
    -- if there is no previous ACL with this name, we need to create one
    if not ourACL then
        ourACL = aclCreate ( aclName )
    end

    -- turn the boolean string to lower case
    access = string.lower ( access )
    -- access has to be either true or false (booleans)
    if not (access == "true" or access == "false") then
        -- print out error message to debug window
        outputDebugString ( "Invalid access; true and false are only accepted", 1 )
        -- exit function
        return
    end

    -- change the access to boolean
    if access == "true" then
        access = true
    else 
        access = false

    -- and finally let's set the right
    aclSetRight ( ourACL, rightName, access )
    -- don't forget to save the ACL after it has been modified
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )

See Also