GetBans: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (fix oop)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Server function}}
This function will return a table over all the [[ban]] values in the server.
This function will return a table containing all the [[ban]]s present in the server's banlist.xml.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getBans ()
table getBans ( )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[Ban]].getList}}


===Returns===
===Returns===
Returns a [[table]] of all the [[ban]]s.
Returns a [[table]] containing all the [[ban]]s.


==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Example 1: Server" class="server" show="true">
'''Example 1:''' This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.
This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function listBans ( playerSource )
function listBans ( playerSource )
Line 23: Line 25:
--
--
if nick then
if nick then
outputChatBox ( "Ban #" .. banID .. ": " .. nick, playerSource , 255, 0, 0 ) -- Output the ban.
outputChatBox ( "Ban #" .. banID .. ": " .. nick, playerSource , 255, 0, 0, true ) -- Output the ban.
end
end
--
--
Line 32: Line 34:
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
<section name="Server" class="server" show="false">
'''Example 2:''' <br>
This example shows you how you can make a commandHandler that can return data about bans on record.<br>
In this example there are several ways to get the info you want.<br>
You can find the ban you are looking for by providing one or more of the following arguments: <br>
- IP (The IP that has been banned)<br>
- Serial (The Serial that has been banned)<br>
- Nick (The Nick that has been banned)<br>
'''*You only have to provide ONE argument to find what you are looking for.*'''<br><br>
In this example there is also TWO ways of returning the info you want to see.<br>
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .<br>
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.<br>
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.<br><br>
An example of what the command could look like:<br>
''' /bans 192.168.0.10 0 0 1 ''' This example would look for the IP.<br>
''' /bans 0 NAME 0 1 ''' This example would look for the NAME.<br>
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 ''' This example would look for the Serial.<br>
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''<br><br>
<syntaxhighlight lang="lua">
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )
local allBans = getBans() -- Returns a table of all bans on record.
--
for banID, ban in ipairs ( allBans ) do -- Loop through all the bans to find our target.
--
local nick = getBanNick ( ban )
local ip = getBanIP ( ban )
local serial = getBanSerial( ban )
local banTime = getBanTime( ban )
local banReason = getBanReason ( ban )
--
if not nick then -- if ' nick ' doesn't exist, we will use "N/A"
nick = "N/A"
end
--
if not ip then -- if ' ip ' doesn't exist, we will use "N/A"
ip = "N/A"
end
--
if not serial then -- if ' serial ' doesn't exist, we will use "N/A"
serial = "N/A"
end
--
if not banReason then -- if ' banReason ' doesn't exist, we will use "N/A"
banReason = "N/A"
end
--
if nick == iNick or ip == iIp or serial == iSerial then -- If any of our input arguments match any bans.
--
if tonumber(showOutput) == 1 then -- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.
outputChatBox ( "Ban #" .. banID .. " | Nick: " .. nick .. " | IP: " .. ip .. " | Serial: " .. serial .. " | BanTime: " .. banTime .. " | BanReason: " .. banReason, playerSource, 0, 153, 0, true )
else -- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.
outputChatBox ( "Ban #" .. banID, playerSource, 0, 153, 0, true )
outputChatBox ( "Nick: " .. nick, playerSource, 0, 153, 0, true )
outputChatBox ( "IP: " .. ip, playerSource, 0, 153, 0, true )
outputChatBox ( "Serial: " .. serial, playerSource, 0, 153, 0, true )
outputChatBox ( "BanTime: " .. banTime, playerSource, 0, 153, 0, true )
outputChatBox ( "BanReason: " .. banReason, playerSource, 0, 153, 0, true )
end
--
break -- Break the loop when we have found our target.
--
end
--
end
--
end
addCommandHandler ( "bans", listBans )
</syntaxhighlight>
</section>
==See Also==
==See Also==
{{Admin functions}}
{{Admin functions}}
[[ru:getBans]]
[[ru:getBans]]

Latest revision as of 14:39, 7 August 2016

This function will return a table containing all the bans present in the server's banlist.xml.

Syntax

table getBans ( )


OOP Syntax Help! I don't understand this!

Method: Ban.getList(...)


Returns

Returns a table containing all the bans.

Example

Click to collapse [-]
Example 1: Server

This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.

function listBans ( playerSource )
local banList = getBans() -- Return a table of all the bans.
	--
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	
		--
		local nick = getBanNick ( ban ) -- Get the IP of the ban
		--
		if nick then
			outputChatBox ( "Ban #" .. banID .. ": " .. nick, playerSource , 255, 0, 0, true ) -- Output the ban.
		end
		--
	end
	--
end
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.

See Also