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.
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 ) -- Output the ban.
end
--
end
--
end
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.
Example 2:
This example shows you how you can make a commandHandler that can return data about bans on record.
In this example there are several ways to get the info you want.
You can find the ban you are looking for by providing one or more of the following arguments:
- IP (The IP that has been banned)
- Serial (The Serial that has been banned)
- Nick (The Nick that has been banned)
*You only have to provide ONE argument to find what you are looking for.*
In this example there is also TWO ways of returning the info you want to see.
Notice in the example that the FORTH argument is called showOutput .
If showOutput is ' 1 ' then the server will return all the data on ONE line.
If showOutput is anything else than ' 1 ' the server will return all data on seperate lines.
An example of what the command could look like:
/bans 192.168.0.10 0 0 1 This example would look for the IP.
/bans 0 NAME 0 1 This example would look for the NAME.
/bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 This example would look for the Serial.
*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*
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 )