PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: bastya_elvtars on 24 May, 2005, 14:24:55

Title: RangeFucker by bastya_elvtars
Post by: bastya_elvtars on 24 May, 2005, 14:24:55
Many requests arrived to me... So fiant voluntates tuae (plural!!!) and here you go.

(Also, I was told that I am just jawing here but doing nothing productive... :D)

 Basically you have to do nothing, set the commands and play with OP protection. More things are in the comments.

-- range fucker by bastya_elvtars (the rock n' roll doctor)
-- it was standalone, but got into lawmaker as well.
-- some code from easyranger by tezlo
-- checks if ips are valid and if ranges are really ranges :D
-- thx go out to Herodes for IP validation, Typhoon for paying attention, and plop for finding the bug i couldn't
-- also thx to NightLitch, i always wanna make same scripts as him but much bettter ones :D
-- and to nerbos for his ranger ;)
-- at the moment ONLY Masters with profile 0 can use this. Will change l8r on. :)
-- enjoy

--v1.0:released
--v1.1: fixed some shit ;)
--v1.2: converted to lua5
--v 1.3RC: small fixes and optimizations

-- TODO: optimize command parsing and make user rights management as I usually do :P

-- prefixes:!+#

cmd1="banrange"

cmd2="showranges"

cmd3="unbanrange"

cmd4="rangehelp"

Bot="---===Ranger===---"

opsips=1 -- set 0 to protect OPs

function ChatArrival(user,data)
data=string.sub(data,1,string.len(data)-1)
local _,_,cmd=string.find(data,"%b<>%s+[%!%+%#](%S+)")
if cmd==cmd1 and user.iProfile==0 then
checknban(user,data) return 1
elseif cmd==cmd2 and user.iProfile==0 then
user:SendPM(Bot,showipranges()) return 1
elseif cmd==cmd3 and user.iProfile==0 then
unbanrange(user,data) return 1
elseif cmd==cmd4 and user.iProfile==0 then
help(user) return 1
elseif cmd==cmd1 or cmd==cmd2 or cmd==cmd3 or cmd==cmd4 and user.iProfile~=0 then
user:SendData(Bot,"You dont have suficiebt rights to use this command.")
return 1
end
end

function checknban(user,data)
local _,_,ip1,ip2=string.find(data,"%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
if ip1 and ip2 then
if ipchk(ip1)~="shit" then
if ipchk(ip2)~="shit" then
if calculate(ip1) if ipranges[ip1]~=ip2 then
ipranges[ip1]=ip2
save(ipranges)
ipranges=loadipranges()
user:SendData(Bot,"Range "..ip1.."-"..ip2.." banned.")
else
user:SendData(Bot,"Already banned range!")
end
collectgarbage()
io.flush()
else
user:SendData(Bot,"Invalid range! "..ip1.."-"..ip2)
end
else
user:SendData(Bot,"Invalid IP #2! Please check and retry! ;)")
end
else
user:SendData(Bot,"Invalid IP #1! Please check and retry! ;)")
end
else
user:SendData(Bot,"Bad usage! Usage: !"..cmd1.." xxx.xxx.xxx.xxx-yyy.yyy.yyy.yyy")
end
end

function calculate(ip)
local _,_,pt1,pt2,pt3,pt4=string.find(ip,"(%d+)%.(%d+)%.(%d+)%.(%d+)")
return (tonumber(pt1)*16777216+tonumber(pt2)*65536+tonumber(pt3)*256+tonumber(pt4))
end

function loadipranges()
local tbl={}
local f=io.open("banned_ranges.dat","r")
if f then
for line in f:lines() do
local _,_,a,b=string.find(line,"([^|]+)|(.+)")
tbl[a]=b
end
f:close()
end
return tbl
end

function save(tbl)
io.output("banned_ranges.dat")
for a,b in tbl do
io.write(a.."|"..b.."\n")
end
io.output()
end

function NewUserConnected(user)
for a,b in ipranges do
if calculate(user.sIP)>=calculate(a) and calculate(user.sIP)<=calculate(b) then
user:SendData(Bot,"Your IP range ("..a.."-"..b..") is banned in here...")
user:Disconnect()
return 1
end
end
collectgarbage()
io.flush()
end

-- old function, left 4 experimenting
--function ipchk(ip)
-- gsub(ip,"(%d+)",function(ipp)
-- if tonumber(ipp)>255 then
-- return "shit"
-- end
-- end)
--end

function ipchk(ip)
local tIP = {}
_,_,tIP.a,tIP.b,tIP.c,tIP.d= string.find(ip, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
for a,b in tIP do
if tonumber(b)<0 or tonumber(b)> 255 then
return "shit"
end
end
tIP=nil
collectgarbage()
io.flush()
end

function unbanrange(user,data)
local _,_,ip1,ip2=string.find(data,"%b<>%s+%S+%s+(%d+%.%d+%.%d+%.%d+)%-(%d+%.%d+%.%d+%.%d+)")
if ip1 and ip2 then
if ipranges[ip1]==ip2 then
user:SendData(Bot,"Range "..ip1.."-"..ip2.." unbanned.")
ipranges[ip1]=nil
save(ipranges)
ipranges=loadipranges()
else
user:SendData(Bot,"Range was not banned...")
end
else
user:SendData(Bot,"Bad usage! Usage: !"..cmd3.." xxx.xxx.xxx.xxx-yyy.yyy.yyy.yyy")
end
end

function showipranges()
local msg="All banned IP ranges:\r\n=============================\r\n"
for a,b in ipranges do
msg=msg..a.." - "..b.."\r\n"
end
msg=msg.."=============================\r\n"
return msg
end


function Main()
frmHub:RegBot(Bot)
ipranges=loadipranges()
if opsips==1 then
OpConnected=NewUserConnected
end
end

function help(user)
local msg="Bot usage:\r\n\r\n"..
cmd1.." \t\tAdd an IP range to banlist.\r\n"..
cmd2.."\t\tShow a list of currently banned IP ranges.\r\n"..
cmd3.." \tUnbans an IP range.\r\n"..
cmd4.."\t\t\tThis help screen ;)\r\n"
user:SendPM(Bot,msg)
end
Title:
Post by: TTB on 24 May, 2005, 14:38:59
Nice one... Maybe ppl like also to add a reason why the range is banned... just an idea.
Title:
Post by: bastya_elvtars on 24 May, 2005, 16:49:02
QuoteOriginally posted by TTB
Nice one... Maybe ppl like also to add a reason why the range is banned... just an idea.

Yes, and banned nick too...
Title:
Post by: witch on 11 September, 2005, 12:19:59
QuoteOriginally posted by bastya_elvtars
Many requests arrived to me... So fiant voluntates tuae (plural!!!) and here you go.

(Also, I was told that I am just jawing here but doing nothing productive... :D)

 Basically you have to do nothing, set the commands and play with OP protection. More things are in the comments.
hola, sorry me not a scripter. i would like to run this script, but i can't understend how i should set up the cmds, please can u show the example?

i tryed to add perflexes on cmd, but still nothing works  ?(

please help  :P
Title:
Post by: bastya_elvtars on 11 September, 2005, 12:29:38
QuoteOriginally posted by witch
hola, sorry me not a scripter. i would like to run this script, but i can't understend how i should set up the cmds, please can u show the example?

i tryed to add perflexes on cmd, but still nothing works  ?(

please help  :P

Do not use it, I will post a much les reource demanding version when the appropriate library gets released by bluebear.