PtokaX forum

Development Section => Your Developing Problems => Topic started by: enema on 20 December, 2004, 07:48:11

Title: IP range from $MyINFO
Post by: enema on 20 December, 2004, 07:48:11
Hello!

How can I get (and is it possible?) IP range from $MyInfo? How will it look in script?

For example, If I want to get users mode from his $MyInfo, it would look like this:
function DataArrival(user,data)
if strsub(data, 1, 7) == "$MyINFO" then
if strfind(data,"M:P") then

I need it to look somehow like this:
function DataArrival(user,data)
if strsub(data, 1, 7) == "$MyINFO" then
if strfind(data,"[B]IPrange:61.22, 81.198, 195.95[/B] ") then
Title:
Post by: blackwings on 20 December, 2004, 09:27:41
that isn't possible I think. I think you need to check what I a User has and compair in with a range in a table.
Title:
Post by: enema on 20 December, 2004, 09:41:43
how about $ConnectToMe then? Can I rip somehow those  IP ranges out from $ConnectToMe??
Title:
Post by: [NL]Pur on 20 December, 2004, 09:52:05
The $MyINFO string doesn't contain any IP
Title:
Post by: blackwings on 20 December, 2004, 10:24:40
QuoteOriginally posted by [NL]Pur
The $MyINFO string doesn't contain any IP
ya, that was what I thought too, so enema, you need a script that check like user.sIP and compairs it with a ip range in a table. Take a existing IP blocker and modify it to your need.
Title:
Post by: enema on 20 December, 2004, 10:57:46
**offtopic

which string contains users IP?

**ontopic
Title:
Post by: blackwings on 20 December, 2004, 11:00:11
QuoteOriginally posted by enema
**offtopic

which string contains users IP?

**ontopic
you can see users IP with "user.sIP", which isn't a string, more like a variable.
Title:
Post by: enema on 20 December, 2004, 11:08:59
Ok, heres what I came up with:

RC_MinShare = "10 GB"
-------------------------------------------------
sUnit = {}
sUnit["KB"]= 1024
sUnit["MB"]= 1048576
sUnit["GB"]= 1073741824
sUnit["TB"]= 1099511627776

tRanges = {
["81.198.(%d*).(%d*)"]=1
}

function Main()
   if tonumber(RC_MinShare) == nil then s,e,num,cur = strfind(RC_MinShare, "(%d+)%s+(%S+)") RC_MinShare = num * sUnit[cur] end
end

function DataArrival(user,data)
if tRanges[user.sIP] == tRanges[user.sIP] + 1 then
local _,_,share = strfind(data, "(%d+)%$%|$")
if tonumber(share) < tonumber(RC_MinShare / 5) then
user:SendData(" You do not meet the minimum share for passive users. You are being disconnected.")
user:Disconnect()
return 1
end
end
end

As you can see, It is totally in mess.. gives me this error: Syntax Error: attempt to perform arithmetic on a nil value

Im stuck... HELP!
Title:
Post by: blackwings on 20 December, 2004, 11:24:19
no line number in the error message :P Anyway I think its the line in Main() it complains about.
I 'm a newbie in lua, so I can't really tell you how to fix it :P
Title:
Post by: enema on 20 December, 2004, 11:47:17
QuoteOriginally posted by blackwings
no line number in the error message :P Anyway I think its the line in Main() it complains about.
I 'm a newbie in lua, so I can't really tell you how to fix it :P

hmm... the Main() line should be ok... I took it from difrient script where it worked fine...
Title:
Post by: enema on 22 December, 2004, 18:52:45
cmon guys, please help me! Im stuck!  PX says: No syntax errors in script file.... BUT IT DOESNT WORK! :'(

This is how far I am:

RC_MinShare = "10 GB"
-------------------------------------------------
sUnit = {}
sUnit["KB"]= 1024
sUnit["MB"]= 1048576
sUnit["GB"]= 1073741824
sUnit["TB"]= 1099511627776

tRanges = {
["62.84.(%d*).(%d*)"] = 1
}

bot = "share_man"

function Main()
   if tonumber(RC_MinShare) == nil then s,e,num,cur = strfind(RC_MinShare, "(%d+)%s+(%S+)") RC_MinShare = num * sUnit[cur] end
end

function DataArrival(user,data)
if tRanges[user.sIP] then
local _,_,share = strfind(data, "(%d+)%$%|$")
if tonumber(share) < tonumber(RC_MinShare / 2) then
user:SendData(bot, "You do not meet the minimum share for passive users. You are being disconnected.")
user:Disconnect()
return 1
end
end
end

Can u find my mistake?
Title:
Post by: Madman on 22 December, 2004, 20:18:04
The Problem is in the
tRanges = {
["62.84.(%d*).(%d*)"] = 1,
["192.168.0.2"] = 1,
}

I added My Lan IP and that works...
So, the problem is this (%d*).(%d*)
but i dont know how to fix that...
I'm not that good...
I added some lines, beacuse i got syntax error without them...

RC_MinShare = "10 GB"
-------------------------------------------------
sUnit = {}
sUnit["KB"]= 1024
sUnit["MB"]= 1048576
sUnit["GB"]= 1073741824
sUnit["TB"]= 1099511627776

tRanges = {
["62.84.(%d*).(%d*)"] = 1,
["192.168.0.2"] = 1,
}

bot = "share_man"

function Main()
if tonumber(RC_MinShare) == nil then s,e,num,cur = strfind(RC_MinShare, "(%d+)%s+(%S+)") RC_MinShare = num * sUnit[cur] end
end

function DataArrival(user,data)
if tRanges[user.sIP]==1 then
if strsub(data, 1, 7) == "$MyINFO" then
if strfind(data,"M:P") then
local _,_,share = strfind(data, "(%d+)%$%|$")
if tonumber(share) < tonumber(RC_MinShare) then
user:SendData(bot, "You do not meet the minimum share for passive users. You are being disconnected.")
user:Disconnect()
return 1
end
end
end
end
end
Title:
Post by: enema on 23 December, 2004, 09:43:09
still doesnt give any errors and still doesnt work... im starting to feel depresed :(

--- Script Base is taken from NightLitch share bot and Ipbot lua script by aMutex
-------------------------------------------------
Scripted_share = "10 GB"
-------------------------------------------------
sUnit = {}
sUnit["KB"]= 1024
sUnit["MB"]= 1048576
sUnit["GB"]= 1073741824
sUnit["TB"]= 1099511627776

bot = "share_man"



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()
oAllow["127.*"]=1
oAllow["81.198.*"]=1
oAllow["62.84.16.*"]=1

if tonumber(Scripted_share) == nil then s,e,num,cur = strfind(Scripted_share, "(%d+)%s+(%S+)") Scripted_share = num * sUnit[cur]
end
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

local _,_,share = strfind(data, "(%d+)%$%|$")
if tonumber(share) < tonumber(Scripted_share / 2) then
user:SendData(bot, "You do not meet the minimum share for your IP range.")
user:Disconnect()
return 1
end
end
end
 
whats wrong with it???
Title:
Post by: enema on 26 December, 2004, 14:40:36
ok, changed few things, but now I recieve this error: Syntax Error: bad argument #1 to `strfind' (string expected, got nil)

here goes script:

--- Script Base is taken from NightLitch share bot and Ipbot lua script by aMutex
-------------------------------------------------
sharex = "5 GB"
-------------------------------------------------
sUnit = {}
sUnit["KB"]= 1024
sUnit["MB"]= 1048576
sUnit["GB"]= 1073741824
sUnit["TB"]= 1099511627776

bot = "shareman"

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()
oAllow["127.*"]=1
oAllow["81.198.*"]=1
oAllow["62.84.16.*"]=1

if tonumber(sharex) == nil then s,e,num,cur = strfind(sharex, "(%d+)%s+(%S+)") sharex = num * sUnit[cur]
end
end

function NewUserConnected(curUser)
theIP=curUser.sIP
local a,b,c,d=splittip(theIP)
if ((oAllow[a]==1)or(oAllow==1)or(oAllow[c]==1)or(oAllow[d]==1)) then

local _,_,share = strfind(data, "(%d+)%$%|$")
if tonumber(share) < tonumber(sharex * 2) then
user:SendData(bot, "You do not meet the minimum share for your IP range.")
user:Disconnect()
return 1
end
end
end

Plz help me! I know you guys can!  this one is very important to me!

To Moderators:  It would be nice, If you could change the name of this thread from "IP range from $Myinfo" to "Certain IP ranges has difrient min share" since we're not talking about any $MyInfos anymore
Title:
Post by: Herodes on 26 December, 2004, 17:34:01
function NewUserConnected(curUser)
theIP=curUser.sIP
local a,b,c,d=splittip(theIP)
if ((oAllow[a]==1)or(oAllow==1)or(oAllow[c]==1)or(oAllow[d]==1)) then

local _,_,share = strfind([b]data[/b], "(%d+)%$%|$")
if tonumber(share) < tonumber(sharex * 2) then
the "data" of the strfind is not defined or provided anywhere ...
maybe try it with "user.sMyInfoString"
Title:
Post by: enema on 26 December, 2004, 18:41:24
I start to think, that I dont need this line at all:
local _,_,share = strfind(data, "(%d+)%$%|$")Correct me if im wrong!!!

If I remove it I recieve this error - Syntax Error: attempt to compare nil with number

I recieve it very offten, when I try to build this script and in situations, where I think it should work but it doesnt...
I think problem is in this line:
if tonumber(sharex) == nil then s,e,num,cur = strfind(sharex, "(%d+)%s+(%S+)") sharex = num * sUnit[cur]
If so, im unable to find solution =(
Title:
Post by: Herodes on 26 December, 2004, 22:14:47
--- Script Base is taken from NightLitch share bot and Ipbot lua script by aMutex
-------------------------------------------------
sharex = "5 GB"
-------------------------------------------------
sUnit = {
["KB"]= 1024,
["MB"]= 1024^2,
["GB"]= 1024^3,
["TB"]= 1024^4,
}

bot = "shareman"

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()
oAllow["127.*"]=1
oAllow["81.198.*"]=1
oAllow["62.84.16.*"]=1
if tonumber(sharex) == nil then
s,e,num,cur = strfind(sharex, "(%d+)%s+(%S+)")
sharex = num * sUnit[cur]
end
end

function NewUserConnected(curUser)
--- theIP=curUser.sIP --- removed this variable It is totally uneccessary.
local a,b,c,d=splittip(curUser.sIP)
if ( (oAllow[a]==1) or (oAllow==1) or (oAllow[c]==1) or (oAllow[d]==1) ) then
local _,_,share = strfind(curUser.sMyInfoString, "(%d+)%$%|$")      --- changed "data" with curUser.sMyInfoString ...
if tonumber(share) < (sharex * 2) then --- removed the "tonumber(sharex * 2)" on this line .. it is a number already ;)
user:SendData(bot, "You do not meet the minimum share for your IP range.")
user:Disconnect()
return 1
end
end
end
try this .. watch the comments and compare to what u have ..
Title:
Post by: enema on 27 December, 2004, 08:46:09
same problem:

Syntax Error: attempt to compare nil with number

I recieve it when user with "62.84.16" IP range connects.

I guess, the problem is here:
if tonumber(sharex) == nil then
s,e,num,cur = strfind(sharex, "(%d+)%s+(%S+)")
sharex = num * sUnit[cur]
end

and here:
local _,_,share = strfind(user.sMyInfoString, "(%d+)%$%|$")
if tonumber(share) < (sharex * 2) then

How can I solve this and where is the mistake?
Title:
Post by: enema on 29 December, 2004, 08:54:33
A little bit more simplified version... Still doesnt work... All functions are taken from scripts, that work. That means I have made a mistake somewhere while putting them together

gives me this Syntax Error: attempt to compare string with number
--- Script Base is taken from Ipbot lua script by aMutex

Bot = "shareman"

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.*"]=1
oAllow["130.239.103.*"]=1
oAllow["212.217.193.*"]=1
end

function NewUserConnected(curUser)
local s,e,share = strfind(curUser.sMyInfoString, "%$%s*(%d+)%$")
share = format("%0.2f", tonumber(share)/(1024*1024*1024))
local a,b,c,d=splittip(curUser.sIP)
if ((oAllow[a]==1)or(oAllow[b]==1)or(oAllow[c]==1)or(oAllow[d]==1)) then
else
if (share < 10) then
curUser:SendData(Bot, "You do not meet the minimum share for your IP range.")
curUser:Disconnect()
return 1
end
end
end
Title:
Post by: Herodes on 29 December, 2004, 15:30:18
function NewUserConnected(curUser)
local s,e,share = strfind(curUser.sMyInfoString, "%$%s*(%d+)%$")
share = format("%0.2f", tonumber(share)/(1024*1024*1024)) --- this outputs a string
local a,b,c,d=splittip(curUser.sIP)
if ((oAllow[a]==1)or(oAllow[b]==1)or(oAllow[c]==1)or(oAllow[d]==1)) then
else
--- if (share < 10) then --- then you this ... :)
if (tonumber(share) > 10) then-- it is better to do smth like this  
curUser:SendData(Bot, "You do not meet the minimum share for your IP range.")
curUser:Disconnect()
return 1
end
end
end
watch the comments ...
Title:
Post by: enema on 29 December, 2004, 16:32:13
YES IT FINNALY WORKS!!!!! Thank you Herodes, you rock!!!

I will put this one in finished scripts section... I guess it is quite usefull!!!!

And thank you again!!!!
Title:
Post by: Herodes on 30 December, 2004, 01:30:30
you r welcome