PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: user on 18 June, 2005, 18:37:09

Title: Nick exception on IPBot
Post by: user on 18 June, 2005, 18:37:09
Hello everyone!

Thanks in advance for anyone who could help me with this:

Since some ISP charge heavy download costs from internacional IPs, i can only allow a certain range of IPs to get in.

This script is working fine, but now i need a nick exception - That is, add a line in the code just to prevent certain nicknames from being disconnected, so they could join no matter their IP.

Bot = "Bot-name"
oAllow={}
function splittip(IP)
r,g,a,b,c,d = strfind(IP, "(%d*).(%d*).(%d*).(%d*)")
d=a.."."..b.."."..c.."."..d
c=a.."."..b.."."..c..".*"
b=a.."."..b..".*"
a=a..".*"
return a,b,c,d
end
function Main()
frmHub:RegBot(Bot)
oAllow["127.0.0.1"] =1
oAllow["192.168.0.*"] =1
oAllow["62.48.128.*"] =1
oAllow["62.48.134.*"] =1
oAllow["62.48.135.*"] =1
oAllow["62.48.136.*"] =1

and goes.. and goes....

oAllow["217.112.207.*"] =1
oAllow["217.129.*"] =1
end
function NewUserConnected(curUser)
theIP=curUser.sIP
local a,b,c,d=splittip(theIP)
if ((oAllow[a]==1)or(oAllow[b]==1)or(oAllow[c]==1)or(oAllow[d]==1)) then
else
curUser:SendPM(Bot,"MESSAGE TO SEND")
curUser:Disconnect()
end
end


Thank you all!
Title:
Post by: jiten on 18 June, 2005, 19:05:05
Give this a try (Lua 4 one):
Bot = "Bot-name"

oAllow={}
oAllow["127.0.0.1"] =1
oAllow["192.168.0.*"] =1
oAllow["62.48.128.*"] =1
oAllow["62.48.134.*"] =1
oAllow["62.48.135.*"] =1
oAllow["62.48.136.*"] =1
oAllow["217.112.207.*"] =1
oAllow["217.129.*"] =1

tImmune = { ["nick1"] = 1, ["nick2"] = 1, } -- Immune nicks. Ex: ["nick"] = 1,

Main = function()
frmHub:RegBot(Bot)
end

NewUserConnected = function(curUser)
theIP=curUser.sIP
local a,b,c,d=splittip(theIP)
if not tImmune[curUser.sName] then
if not ((oAllow[a] == 1) or (oAllow[b] == 1) or (oAllow[c] == 1) or (oAllow[d] == 1)) then
curUser:SendPM(Bot,"MESSAGE TO SEND")
curUser:Disconnect()
end
end
end

splittip = function(IP)
r,g,a,b,c,d = strfind(IP, "(%d*).(%d*).(%d*).(%d*)")
d=a.."."..b.."."..c.."."..d
c=a.."."..b.."."..c..".*"
b=a.."."..b..".*"
a=a..".*"
return a,b,c,d
end
Title:
Post by: Dessamator on 18 June, 2005, 22:39:06
hmm, indeed but that script is messsy, even i cant make heads or tails of it, hehe, no tabs no nothing,

its always better to separate functions from constant variables(in my opinion)

 :)
Title:
Post by: user on 25 June, 2005, 13:43:31
Thank you very much for your useful reply!
I'm using this script and there is no problems at all :)
I just want to change the following:

QuoteOriginally posted by Mutor
I'm not thrilled with populating the table in function Main() but it's easier to see the difference if I leave the script as it was so...

A quick edit...

Bot = "Bot-name"
oAllow={}
nAllow={}
function splittip(IP)
r,g,a,b,c,d = strfind(IP, "(%d*).(%d*).(%d*).(%d*)")
d=a.."."..b.."."..c.."."..d
c=a.."."..b.."."..c..".*"
b=a.."."..b..".*"
a=a..".*"
return a,b,c,d
end
function Main()
frmHub:RegBot(Bot)
oAllow["127.0.0.1"] =1
oAllow["192.168.0.*"] =1
oAllow["62.48.128.*"] =1
oAllow["62.48.134.*"] =1
oAllow["62.48.135.*"] =1
oAllow["62.48.136.*"] =1
oAllow["217.112.207.*"] =1
oAllow["217.129.*"] =1
--Add Nicks here
nAllow["UserNick1"] =1
nAllow["UserNick2"] =1
end
function NewUserConnected(curUser)
if nAllow[curUser.sName] ==1 then return 1 end
theIP=curUser.sIP
local a,b,c,d=splittip(theIP)
if ((oAllow[a]==1)or(oAllow[b]==1)or(oAllow[c]==1)or(oAllow[d]==1)) then
else
curUser:SendPM(Bot,"MESSAGE TO SEND")
[COLOR=red]curUser:Disconnect()[/COLOR]
end
end
How can i make this script REDIRECT or TEMPBAN instead of disconnect ?

My thanks in advance!
Title:
Post by: Madman on 25 June, 2005, 14:12:47
QuoteOriginally posted by user
How can i make this script REDIRECT or TEMPBAN instead of disconnect ?

My thanks in advance!

Relpace the disconnect line with one of thesee

curUser:TempBan() -- The time user gets timebanned for is specified in PtokaX.
curUser:TimeBan(TimeInMinutes) -- The time user gets timebanned for is specified here.
curUser:Redirect(Address, Reason) -- Redirect user to Address, with Reason. Reason is optional.
Title:
Post by: user on 25 June, 2005, 14:52:57
QuoteOriginally posted by madman

Relpace the disconnect line with one of thesee

curUser:TempBan() -- The time user gets timebanned for is specified in PtokaX.
curUser:TimeBan(TimeInMinutes) -- The time user gets timebanned for is specified here.
curUser:Redirect(Address, Reason) -- Redirect user to Address, with Reason. Reason is optional.

Can i use both?

Example, i replace the disconnect line with curUser:TempBan() and in the next line curUser:Redirect(Address, Reason)  so the user would get temporary banned AND  redirected.

And if i also want to have a message sent to main chat like "The user NICKNAME  using IP  has been redirected" (replacing Underlined terms by the right ones) how should i do?


Thank you.
Title:
Post by: Dessamator on 25 June, 2005, 15:57:49
hmm, using both im unsure, if u redirect first, there will be no user to ban, and if u ban first there will be no user to redirect(in theory), but u could store the ip and ban it.

for the message thingy write something like this :
SendToOps("bot","The user "..curUser.sName.." using IP : "..curUser.sIP.." has been redirected!")