UnbanIP: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Deprecated}}
Please use [[removeBan]]
This function will unban the specified IP.
This function will unban the specified IP.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool unbanIP ( string ipToUnban, [player unbanningPlayer = null] )         
bool unbanIP ( string ipToUnban, [player unbanningPlayer = nil] )         
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===
*'''unbanningPlayer:''' The who is unbanning the ip
*'''ipToUnban:''' The IP that should be unbanned.
*'''ipToUnban:''' The IP that should be unbanned
===Optional Arguments===
 
{{OptionalArg}}
===Optional Arguments===  
*'''unbanningPlayer:''' The player who is unbanning the IP. Defaults to nil, meaning no one.
{{OptionalArg}}  
(none)


===Returns===
===Returns===
Returns ''true'' if the unban was successful, ''false'' otherwise.
Returns ''true'' if the unban was successful, ''false'' otherwise.


==Example==  
==Example==
This example adds a unbanip command for only admins to use (uses a ACL permission check).
<syntaxhighlight lang="lua">
addCommandHandler( "unbanip", -- add a command handler to command 'unbanip'
  function ( thePlayer, command, ip )
      if ( hasObjectPermissionTo ( thePlayer, "command.unbanip", false ) ) then -- check if the player has access to the command (specified in ACL)
        if not ip then outputChatBox( "No IP specified.", thePlayer ) return end -- if no IP was specified, abort command
        if not findpattern( ip, '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', 1 ) then outputChatBox( "Given IP is not valid.", thePlayer ) return end -- if IP is not in correct format, abort command
        local success = unbanIP( ip, thePlayer ) -- see whether the function was a success
        if success then
            outputChatBox( "IP " .. ip .. " succesfully unbanned!", thePlayer ) -- if it was, tell that to player
        else
            outputChatBox( "Unbanning IP " .. ip .. " failed!", thePlayer ) -- if it wasn't, tell that to player
        end
      else
        outputChatBox( "You have no permission to use this command.", thePlayer ) -- tell player that he hasn't got right permission
      end
  end
)


-- specify the findpattern function used in the command handler
function findpattern(text, pattern, start)
local found = string.find(text, pattern, start)
if found ~= nil then
return string.gsub(text, found)
else return nil end
end
</syntaxhighlight>
==See Also==
==See Also==
{{Admin_functions}}
{{Admin_functions}}

Latest revision as of 21:39, 20 April 2011

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions, but there should be a more generic way to perform what it does.


Please use removeBan

This function will unban the specified IP.

Syntax

bool unbanIP ( string ipToUnban, [player unbanningPlayer = nil] )         

Required Arguments

  • ipToUnban: The IP that should be unbanned.

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.

  • unbanningPlayer: The player who is unbanning the IP. Defaults to nil, meaning no one.

Returns

Returns true if the unban was successful, false otherwise.

Example

This example adds a unbanip command for only admins to use (uses a ACL permission check).

addCommandHandler( "unbanip", -- add a command handler to command 'unbanip'
   function ( thePlayer, command, ip )
      if ( hasObjectPermissionTo ( thePlayer, "command.unbanip", false ) ) then -- check if the player has access to the command (specified in ACL)
         if not ip then outputChatBox( "No IP specified.", thePlayer ) return end -- if no IP was specified, abort command
         if not findpattern( ip, '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', 1 ) then outputChatBox( "Given IP is not valid.", thePlayer ) return end -- if IP is not in correct format, abort command
         local success = unbanIP( ip, thePlayer ) -- see whether the function was a success
         if success then
            outputChatBox( "IP " .. ip .. " succesfully unbanned!", thePlayer ) -- if it was, tell that to player
         else
            outputChatBox( "Unbanning IP " .. ip .. " failed!", thePlayer ) -- if it wasn't, tell that to player
         end
      else
         outputChatBox( "You have no permission to use this command.", thePlayer ) -- tell player that he hasn't got right permission
      end
   end
)

-- specify the findpattern function used in the command handler
function findpattern(text, pattern, start)
	local found = string.find(text, pattern, start)
	if found ~= nil then
		return string.gsub(text, found)
	else return nil end
end

See Also