PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: belea on 02 October, 2004, 11:34:28

Title: 2 Scripts, 1 for nick, 1 for ban
Post by: belea on 02 October, 2004, 11:34:28
Aloha to all,

I want 2 good scripts for PtokaX 0.330 dbg 15:25..

First i want a script to block users that come with those symbols in the nickname: ( ) : ; - =
...and if its possible to block users with nombers in the first part of the nickname like 1980nick is not allowed and nick1980 its allowed.

Second i want to find a good permemanet ban script that work with commands.. and i want on IP not on IP ranges..


Thx.. Ptokax rulez !
Title:
Post by: enema on 02 October, 2004, 16:26:45
both of those things are inbuild in ptokaX

1) see - rules and bots -> nickname rules (you have to enable this function of course and make some adjusments

2) When you use !ban it bans only IP not IP range
Title:
Post by: Herodes on 02 October, 2004, 16:37:59
enema is right but I wouldnt recomend using the nick rules of debug or TD versions ... there have been many many problems reported ... pls look in the forum a bit more ..

that script for the numbers in the nick i think was requested again in the forum last week .. I dont remember if someone responded though...

as for the range ban you'll definately be able to find something like that in the Forum ... ;)
Title:
Post by: enema on 02 October, 2004, 19:13:35
here u go! Of course, u have to edit it a little bit --## BLCOK ILLEGAL CHAR
--## Requested by jiten
--## Made by nErBoS

sBot = "BIC-BOT"

arrIllegalChar = {
"?",
} --<<<---- Type all your unwanted Characters here

function Main(user)
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
for i=1, getn(arrIllegalChar) do
if (strfind(user.sName, arrIllegalChar[i])) then
user:SendData(sBot, "Your nick has a illegal char: "..arrIllegalChar[i])
user:SendData(sBot, "Please remove it.")
user:Disconnect()
break
end
end
end
Title:
Post by: belea on 02 October, 2004, 20:54:30
Hi there,

1)
i putted:
-----------
arrIllegalChar = {

"@",
"(",
")",
} --<<<---- Type all your unwanted Characters here
-----------

and its not work.. and beside that its an incomplet script..  if i can have one that exclude the vips, owners and  reg users..  

2) i want another bot for permban :) that was the idea.. i know what commands i have..  but i have also iprange..  and there in permban.dat i have all the ips that are not in my ip range.. so i want another permanent ban..  where to put manually the ips..  i hope u understand me :)

Thx again
Title:
Post by: nErBoS on 02 October, 2004, 23:42:36
Hi,

1) Done, about the "(" and ")" some chars need % in because of the function string find, here you have...

--## BLCOK ILLEGAL CHAR 1.0
--## Requested by jiten
--## Not Check Regged Users (requested by belea)
--## Made by nErBoS

sBot = "BIC-BOT"

arrIllegalChar = {
"@",
"%(",
"%)",
} --<<<---- Type all your unwanted Characters here

function Main(user)
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
if (user.iProfile == -1) then
for i=1, getn(arrIllegalChar) do
if (strfind(user.sName, arrIllegalChar[i]) ~= nil) then
local char = arrIllegalChar[i]
if (strsub(arrIllegalChar[i],1,1) == "%") then
char = strsub(arrIllegalChar[i],2,strlen(arrIllegalChar[i]))
end
user:SendData(sBot, "Your nick has a illegal char: "..char)
user:SendData(sBot, "Please remove it.")
user:Disconnect()
return 0
end
end
end
end

2) Like herodes said, you have a script that bans IP-Ranges that you want, or else, it doesn't bans it stops it from enter your HUB (same thing). Search in the "Finished Scripts" section.

Best regards, nErBoS
Title:
Post by: belea on 03 October, 2004, 08:52:35
Hi there,

1) Yes its work perfectlly, thx nErBoS.

2) I think i was not clear enough,  I want to have 2 permban.dat..  because  in one permban.dat its where not allowed ips range goes.. and in the second permban.dat i want to be only with manually ip bans...  

Thx again
Title:
Post by: enema on 03 October, 2004, 10:34:28
Hope this is what u are looking for! You have to create ranges.dat in your scripts folder and put there all your unwanted IP ranges like this:
 111.111.000.00|222.222.202.333

All IPs between will be blocked

Here it goes:

--//RangeBlaster v2.07 by Phatty
--//IP Keys written by John, and Phatty

Bot = "RangeBlaster"

Ranges = {}

function Main()
--frmHub:RegBot(Bot)
LoadIps()
end

function LoadIps()
local tmp = 0
local handle = openfile("ranges.dat","r")
line = read(handle)
while line do
tmp = tmp + 1
local s,e,ipr1,ipr2 = strfind(line,"(%S+)|(%S+)")
if ipr2 == nil then
SendToAll(Bot,"Error on line "..line)
end
local s,e,ipa1,ipb1,ipc1,ipd1 = strfind(ipr1, "(%d*).(%d*).(%d*).(%d*)")
local s,e,ipa2,ipb2,ipc2,ipd2 = strfind(ipr2, "(%d*).(%d*).(%d*).(%d*)")
si1 = CheckNumber(ipa1)..CheckNumber(ipb1)..CheckNumber(ipc1)..CheckNumber(ipd1)
si2 = CheckNumber(ipa2)..CheckNumber(ipb2)..CheckNumber(ipc2)..CheckNumber(ipd2)
Ranges[si1] = si2
line = read(handle)
end

end

function Blocked(userip)
local s,e,range1,range2,range3,range4 = strfind(userip,"(%d+).(%d+).(%d+).(%d+)")
checker = CheckNumber(range1)..CheckNumber(range2)..CheckNumber(range3)..CheckNumber(range4)

--SendToAll(Bot,"IP-Test..."..checker)

for i,p in Ranges do
local s,e,xstart = strfind(i, "(%d*)")
local s,e,xend = strfind(p, "(%d*)")

if checker > xstart and checker < xend then
collectgarbage()
flush()
return 1
else
end
end
end

function CheckNumber(number)
numbera = tonumber(number)
if numbera < 10 then
numbera = "00"..number
elseif numbera < 100 then
numbera = "0"..number
else
numbera = number
end
return numbera
end

function DataArrival(user,data)
if strsub(data, 1, 8) == "$Version" then
if Blocked(user.sIP) == 1 then
user:SendData(Bot, "You have been banned")
SendToOps(Bot, "User: "..user.sName..", with IP: ["..user.sIP.."] was disconnected from Hub by "..bot..".")
user:PermBan()
user:Disconnect()
end
end
end
 


Havent tested it though, but I think it should work. Maybe nErBoS could add some commands for IP range adding and removing? It would be great :)
Title:
Post by: belea on 03 October, 2004, 18:09:58
Hi there,

Thx enema but i have already one "ipRanges" and its work great.. no reason to change it..  

Right now im looking for a bot or for something that hold manually permamnet ban.. and put them in differnet location not in permban.dat..

Thx again :p
Title:
Post by: nErBoS on 03 October, 2004, 21:30:43
Hi,

Here you have then...

--## MANUALY IP-RANGE BAN BOT
--## Requested by belea
--## Will ban ip-ranges by a command (only for Masters)
--## Made by nErBoS
--## Commands:
--## !banipr -- It bans an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !unbanipr -- It unbas an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !bannedipr -- Shows All the IP-Range banned

sBot = "MIRB-Bot"

arrIpRange = {}
fIpRange = "iprange.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if you are using Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using Ptokax Version lower then 0.3.3.0

--## END ##--


function Main()
frmHub:RegBot(sBot)
LoadFromFile(fIpRange)
end

function OnExit()
SaveToFile(fIpRange , arrIpRange , "arrIpRange")
end

function NewUserConnected(user)
if (CheckIP(user.sIP) == 1) then
user:SendData(sBot, "Your IP is banned.")
user:Disconnect()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!banipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
user:SendPM(sBot, "Syntax Error, !banipr , you must write a IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
elseif (arrIpRange[ip1.."-"..ip2] ~= nil) then
user:SendPM(sBot, "The IP-Range "..ip1.."-"..ip2.." is already banned.")
else
arrIpRange[ip1.."-"..ip2] = user.sName
user:SendPM(sBot, "The IP-Range "..ip1.."-"..ip2.." is now banned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!unbanipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
user:SendPM(sBot, "Syntax Error, !unbanipr , you must write a IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
elseif (arrIpRange[ip1.."-"..ip2] == nil) then
user:SendPM(sBot, "The IP-Range "..ip1.."-"..ip2.." is not banned.")
else
arrIpRange[ip1.."-"..ip2] = nil
user:SendPM(sBot, "The IP-Range "..ip1.."-"..ip2.." is now unbanned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!bannedipr" and user.iProfile == 0) then
local sTmp,ipr,who = "The IP-Range banned in the HUB:\r\n\r\n"
for ipr, who in arrIpRange do
sTmp = sTmp.."IP-Range: "..ipr.." Banned by: "..who.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
end
end

function CheckIP(sIP)
local s,e,a,b,c,d,ipr,aux,ip1,ip2 = strfind(sIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
sIP = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
for ipr, aux in arrIpRange do
local s,e,a,b,c,d,x,w,y,z = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)%-(%d+)%.(%d+)%.(%d+)%.(%d+)")
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
ip2 = tonumber(Zero(x)..Zero(w)..Zero(y)..Zero(z))
if (sIP >= ip1 and sIP <= ip2) then
return 1
end
end
return 0
end

function Zero(iNum)
iNum = tonumber(iNum)
if (iNum < 10) then
return "00"..iNum
elseif(iNum < 100) then
return "0"..iNum
else
return iNum
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 format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: belea on 04 October, 2004, 10:08:58
Hi there,

Thx again nErBoS, its work great..  but if u can modify it to give ban only on one IP not a range..  just on single IP or when the users its there to ban using his Nick..   ?

like !banipx 198.0.0.1
or !bannick Belea         (when the users its on the hub)

I mean without a range just on single IP or on the Nick when its possible..  when the nick its there on the hub..

Thx again man :)
Title:
Post by: nErBoS on 04 October, 2004, 13:37:04
Hi,

Here you have, the commands will ban and unban single IPs.

--## MANUALY IP-RANGE BAN BOT 1.0
--## Requested by belea
--## Will ban ip-ranges by a command (only for Masters)
--## Added to ban single IPs as also
--## Made by nErBoS
--## Commands:
--## !banipr -- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !unbanipr -- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !bannedipr -- Shows All the IP-Range and single IP banned

sBot = "MIRB-Bot"

arrIpRange = {}
fIpRange = "iprange.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if you are using Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using Ptokax Version lower then 0.3.3.0

--## END ##--


function Main()
frmHub:RegBot(sBot)
LoadFromFile(fIpRange)
end

function OnExit()
SaveToFile(fIpRange , arrIpRange , "arrIpRange")
end

function NewUserConnected(user)
if (CheckIP(user.sIP) == 1) then
user:SendData(sBot, "Your IP is banned.")
user:Disconnect()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!banipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !banipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] ~= nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is already banned.")
else
arrIpRange[ip1] = user.sName
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now banned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!unbanipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !unbanipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] == nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is not banned.")
else
arrIpRange[ip1] = nil
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now unbanned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!bannedipr" and user.iProfile == 0) then
local sTmp,ipr,who = "The IP-Range and IPs banned in the HUB:\r\n\r\n"
for ipr, who in arrIpRange do
sTmp = sTmp.."IP-Range or IP: "..ipr.." Banned by: "..who.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
end
end

function CheckIP(sIP)
local s,e,a,b,c,d,ipr,aux,ip1,ip2 = strfind(sIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
sIP = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
for ipr, aux in arrIpRange do
local s,e,a,b,c,d,x,w,y,z = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)%-(%d+)%.(%d+)%.(%d+)%.(%d+)")
if (x == nil) then
local s,e,a,b,c,d = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
if (ip1 == sIP) then
return 1
end
else
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
ip2 = tonumber(Zero(x)..Zero(w)..Zero(y)..Zero(z))
if (sIP >= ip1 and sIP <= ip2) then
return 1
end
end
end
return 0
end

function Zero(iNum)
iNum = tonumber(iNum)
if (iNum < 10) then
return "00"..iNum
elseif(iNum < 100) then
return "0"..iNum
else
return iNum
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 format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: belea on 04 October, 2004, 19:39:42
Thx man..

1) work perfectlly
2) same :)

but if i want to make a special !help for masters.. with all those commands ? how can i do that ?  

Thx again :p
Title: here u go
Post by: enema on 04 October, 2004, 21:12:39
if theres some command ive missed, give me a shout!
command for help is - !iphelp
here goes:

--## MANUALY IP-RANGE BAN BOT 1.0
--## Requested by belea
--## Will ban ip-ranges by a command (only for Masters)
--## Added to ban single IPs as also
--## Made by nErBoS
--## Help thing added by enema   <<--- you have rights to erase this part :)
--## Commands:
--## !banipr -- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !unbanipr -- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !bannedipr -- Shows All the IP-Range and single IP banned
--## !iphelp -- Shows help

prefix = "!"

sBot = "MIRB-Bot"

arrIpRange = {}
fIpRange = "iprange.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if you are using Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using Ptokax Version lower then 0.3.3.0

--## END ##--


function Main()
frmHub:RegBot(sBot)
LoadFromFile(fIpRange)
end

function OnExit()
SaveToFile(fIpRange , arrIpRange , "arrIpRange")
end

function NewUserConnected(user)
if (CheckIP(user.sIP) == 1) then
user:SendData(sBot, "Your IP is banned.")
user:Disconnect()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!banipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !banipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] ~= nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is already banned.")
else
arrIpRange[ip1] = user.sName
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now banned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!unbanipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !unbanipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] == nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is not banned.")
else
arrIpRange[ip1] = nil
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now unbanned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!bannedipr" and user.iProfile == 0) then
local sTmp,ipr,who = "The IP-Range and IPs banned in the HUB:\r\n\r\n"
for ipr, who in arrIpRange do
sTmp = sTmp.."IP-Range or IP: "..ipr.." Banned by: "..who.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
end
end

function CheckIP(sIP)
local s,e,a,b,c,d,ipr,aux,ip1,ip2 = strfind(sIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
sIP = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
for ipr, aux in arrIpRange do
local s,e,a,b,c,d,x,w,y,z = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)%-(%d+)%.(%d+)%.(%d+)%.(%d+)")
if (x == nil) then
local s,e,a,b,c,d = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
if (ip1 == sIP) then
return 1
end
else
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
ip2 = tonumber(Zero(x)..Zero(w)..Zero(y)..Zero(z))
if (sIP >= ip1 and sIP <= ip2) then
return 1
end
end
end
return 0
end

function Zero(iNum)
iNum = tonumber(iNum)
if (iNum < 10) then
return "00"..iNum
elseif(iNum < 100) then
return "0"..iNum
else
return iNum
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 format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")


if cmd == prefix.."iphelp"
 then
user:SendData(sBot,"--## IP-RANGE BAN BOT 1.0 commands:")
user:SendData(sBot,"--## !banipr -- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)")
user:SendData(sBot,"--## !unbanipr -- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)")
user:SendData(sBot,"--## !bannedipr -- Shows All the IP-Range and single IP banned")

end
end
end
Title:
Post by: enema on 04 October, 2004, 21:18:02
... just realised, that command !iphelp can be used by everyone :( ... no big deal, rest of the commands can be used only by masters anyway :D
Title:
Post by: nErBoS on 04 October, 2004, 22:14:42
Hi,

Here you have the help command only for Masters...

--## MANUALY IP-RANGE BAN BOT 1.1
--## Requested by belea
--## Will ban ip-ranges by a command (only for Masters)
--## Added to ban single IPs as also
--## Added the help command
--## Made by nErBoS
--## Commands:
--## !banipr -- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !unbanipr -- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !bannedipr -- Shows All the IP-Range and single IP banned
--## !iprhelp -- Shows all this commands

sBot = "MIRB-Bot"

arrIpRange = {}
fIpRange = "iprange.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if you are using Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using Ptokax Version lower then 0.3.3.0

--## END ##--


function Main()
frmHub:RegBot(sBot)
LoadFromFile(fIpRange)
end

function OnExit()
SaveToFile(fIpRange , arrIpRange , "arrIpRange")
end

function NewUserConnected(user)
if (CheckIP(user.sIP) == 1) then
user:SendData(sBot, "Your IP is banned.")
user:Disconnect()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!banipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !banipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] ~= nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is already banned.")
else
arrIpRange[ip1] = user.sName
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now banned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!unbanipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !unbanipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] == nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is not banned.")
else
arrIpRange[ip1] = nil
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now unbanned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!bannedipr" and user.iProfile == 0) then
local sTmp,ipr,who = "The IP-Range and IPs banned in the HUB:\r\n\r\n"
for ipr, who in arrIpRange do
sTmp = sTmp.."IP-Range or IP: "..ipr.." Banned by: "..who.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
elseif (cmd == "!iprhelp" and user.iProfile == 0) then
local sTmp = "\t\t --## IP/IP-Range Ban Commands ##--\r\n\r\n"
sTmp = sTmp.."!banipr \t-- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)\r\n"
sTmp = sTmp.."!unbanipr \t-- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)\r\n"
sTmp = sTmp.."!bannedipr\t\t-- Shows All the IP-Range and single IP banned\r\n"
sTmp = sTmp.."!iprhelp\t\n-- Shows all this commands\r\n"
user:SendPM(sBot, sTmp)
return 1
end
end
end

function CheckIP(sIP)
local s,e,a,b,c,d,ipr,aux,ip1,ip2 = strfind(sIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
sIP = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
for ipr, aux in arrIpRange do
local s,e,a,b,c,d,x,w,y,z = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)%-(%d+)%.(%d+)%.(%d+)%.(%d+)")
if (x == nil) then
local s,e,a,b,c,d = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
if (ip1 == sIP) then
return 1
end
else
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
ip2 = tonumber(Zero(x)..Zero(w)..Zero(y)..Zero(z))
if (sIP >= ip1 and sIP <= ip2) then
return 1
end
end
end
return 0
end

function Zero(iNum)
iNum = tonumber(iNum)
if (iNum < 10) then
return "00"..iNum
elseif(iNum < 100) then
return "0"..iNum
else
return iNum
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 format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: belea on 05 October, 2004, 03:10:35
Hi there,

Thx enema and of course thx nErBoS :)

The last thing that i want to have it from this beautiful script :p  is to have the possibility to use the nicknames.. beside the IPs.. but of course in the iprange.dat to be as a IP not a nick..

and if its possible.. the same command to be used for single ip, for ip range and for a nickname..
...and to have this form stored in iprange.dat: IP - (nick)..  when the nickname its know
..  that will be really cool

i hope u understood me again.. thx again guys..  and if its too hard or impossible do what u can..  10x :p

Title:
Post by: nErBoS on 05 October, 2004, 12:22:30
Hi,

Here you have...

--## MANUALY IP-RANGE BAN BOT 1.2
--## Requested by belea
--## Will ban ip-ranges by a command (only for Masters)
--## Added to ban single IPs as also
--## Added the help command
--## Add a ban to IP on an online nick
--## Made by nErBoS
--## Commands:
--## !banipr -- It bans a single IP, a Nick (will ban the Nick IP, if is online) or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !unbanipr -- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)
--## !bannedipr -- Shows All the IP-Range and single IP banned
--## !iprhelp -- Shows all this commands

sBot = "MIRB-Bot"

arrIpRange = {}
fIpRange = "iprange.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if you are using Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using Ptokax Version lower then 0.3.3.0

--## END ##--


function Main()
frmHub:RegBot(sBot)
LoadFromFile(fIpRange)
end

function OnExit()
SaveToFile(fIpRange , arrIpRange , "arrIpRange")
end

function NewUserConnected(user)
if (CheckIP(user.sIP) == 1) then
user:SendData(sBot, "Your IP is banned.")
user:Disconnect()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!banipr" and user.iProfile == 0) then
local s,e,nick,ip1,ip2,ip3 = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Error, !banipr , you must write an IP, a Nick or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
if (GetItemByName(nick) == nil) then
user:SendPM(sBot, "The user "..nick.." is not online.")
else
ip = GetItemByName(nick).sIP
end
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
end
if (arrIpRange[ip1] ~= nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is already banned.")
else
arrIpRange[ip1] = user.sName
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now banned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!unbanipr" and user.iProfile == 0) then
local s,e,ip1,ip2 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
local s,e,ip3 = strfind(data, "%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)")
if (ip1 == nil or ip2 == nil) then
if (ip3 == nil) then
user:SendPM(sBot, "Syntax Error, !unbanipr , you must write an IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2).")
return 1
else
ip1 = ip3
end
else
ip1 = ip1.."-"..ip2
end
if (arrIpRange[ip1] == nil) then
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is not banned.")
else
arrIpRange[ip1] = nil
user:SendPM(sBot, "The IP-Range or IP "..ip1.." is now unbanned.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "!bannedipr" and user.iProfile == 0) then
local sTmp,ipr,who = "The IP-Range and IPs banned in the HUB:\r\n\r\n"
for ipr, who in arrIpRange do
sTmp = sTmp.."IP-Range or IP: "..ipr.." Banned by: "..who.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
elseif (cmd == "!iprhelp" and user.iProfile == 0) then
local sTmp = "\t\t --## IP/IP-Range Ban Commands ##--\r\n\r\n"
sTmp = sTmp.."!banipr \t-- It bans a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)\r\n"
sTmp = sTmp.."!unbanipr \t-- It unbas a single IP or an IP-Range (the IP-Range should be like this: 1.1.1.1-1.1.1.2)\r\n"
sTmp = sTmp.."!bannedipr\t\t-- Shows All the IP-Range and single IP banned\r\n"
sTmp = sTmp.."!iprhelp\t\n-- Shows all this commands\r\n"
user:SendPM(sBot, sTmp)
return 1
end
end
end

function CheckIP(sIP)
local s,e,a,b,c,d,ipr,aux,ip1,ip2 = strfind(sIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
sIP = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
for ipr, aux in arrIpRange do
local s,e,a,b,c,d,x,w,y,z = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)%-(%d+)%.(%d+)%.(%d+)%.(%d+)")
if (x == nil) then
local s,e,a,b,c,d = strfind(ipr, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
if (ip1 == sIP) then
return 1
end
else
ip1 = tonumber(Zero(a)..Zero(b)..Zero(c)..Zero(d))
ip2 = tonumber(Zero(x)..Zero(w)..Zero(y)..Zero(z))
if (sIP >= ip1 and sIP <= ip2) then
return 1
end
end
end
return 0
end

function Zero(iNum)
iNum = tonumber(iNum)
if (iNum < 10) then
return "00"..iNum
elseif(iNum < 100) then
return "0"..iNum
else
return iNum
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 format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: belea on 05 October, 2004, 17:54:57
Hi there,

Thx nErBoS..

when i banned a nickname.. i got this message..
[18:49:13] User [Toldi] has been banned. IP: 213.154.155.142
[18:49:13] User [Toldi] has been banned because: No reason specified.

and the ban was putted in permban.dat.. not in iprange.dat..

Can u fix ? to be in iprange.dat and also to have with the nickname the IP and the reason..  ? all that in iprange.dat ?

Best Regards,
Title:
Post by: belea on 09 October, 2004, 14:14:52
Hi there,

Plz someone cand modify the nErBoS`s script (because i guess he its on vacantion :D ) and putted the reasone in iprange.dat ?

There i have: the banned IP and who banned the IP..

arrIpRange = {
   ["22.22.22.22"] = "Belea",
}

but i want to be with reason as well


Thx again :)
Title:
Post by: nErBoS on 09 October, 2004, 17:43:20
Hi,

I am not in vacations (unfortinaly), but i am having a lot of work this days. When i arrange some free time i will do it.

Best regards, nErBoS
Title:
Post by: belea on 15 October, 2004, 13:15:07
HI there,


okay nErBoS.. take it easy its not a rush..  

Regards