-- IP block lua 5
-- created by -RICK- and Amsterdambulldogs
-- make a ipblocker.tbl in your script folder
----------------------------------------------------------------------------
sBot ="IPblocker" --frmHub:GetHubBotName()
File = "ipblocker.tbl"
ipallowed = {}
-- 1=on / 0=off -- who can add a ip
SendTo = {
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 0, -- Vips
[3] = 0, -- Regs
[4] = 1, -- Moderator
[5] = 1, -- NetFounder
[-1] = 0, -- Users
}
function Main()
dofile(File)
end
function UserIPArrival(user, data)
if (IspChecker(user.sIP) == 0) then
SendToOps(sBot, "found a user with a wrong ip and removed him/her.")
user:SendData(sBot, "Your IP is NOT allowed in this hub.")
user:Ban()
end
end
function IspChecker(IP)
local accept = 1
local s,e,ip1,ip2,ip3,ip4 = string.find(IP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
local userIP = Addzero(ip1)..Addzero(ip2)..Addzero(ip3)..Addzero(ip4)
userIP = (userIP)
for i=1, table.getn(ipallowed) do
local s,e,a1,a2,a3,a4 = string.find(ipallowed[i], "(%d+)%.(%d+)%.(%d+)%.(%d+)")
local aIP = Addzero(a1)..Addzero(a2)..Addzero(a3)..Addzero(a4)
aIP = (aIP)
if (userIP == aIP) then
accept = 0
break
end
end
return accept
end
function Addzero(number)
iAux = tonumber(number)
if (iAux < 10) then
number = "00"..number
elseif (iAux < 100) then
number = "0"..number
else
number = number
end
return number
end
function ChatArrival(user, data)
local data = string.sub(data,1,-2)
if (string.sub(data,1,1) == "<" or string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!addiptolist" then
if SendTo[user.iProfile] == 1 then
s,e,ip = string.find(data, "%b<>%s+%S+%s(.*)")
if ip == nil then
local dsp0
dsp0 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-<>=-=\r\n"
dsp0 = dsp0.."\t u didn't fill in a ip\r\n"
dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=<>=-=\r\n"
user:SendData(sBot,dsp0)
return 1
else
table.insert(ipallowed, ip)
SaveToFile(File , ipallowed , "ipallowed")
dsp0 = "\t Done: "..ip.." added to ban list"
user:SendData(sBot,dsp0)
dsp0 = nil
return 1
end
end
end
end
end
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
function SaveToFile(file , table , tablename)
local ipfile = io.open(file, "w+")
ipfile:write(Serialize(table, tablename))
ipfile:close()
end
___________________________
ipblocker.tbl (in your scripts folder)
-------------------------------------------
ipallowed = {
}
------------------------------------------------
Hum, u posted in the wrong Section. It should be Lua 5 Finished Scripts.
Btw, try using the [ CODE] [ /CODE] thingy (without the spaces between the "[", "C" and "/".
Best regards.