PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Request for scripts => Topic started by: LeBleu on 16 November, 2008, 17:38:41

Title: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 16 November, 2008, 17:38:41
Hi everyone,
I'd like to reqest 2 scripts:

1. Nick prefix for selected IP ranges:
I have LAN DC++HUB in dorm that has 4 buldings, each bulding has diffrent IP range.
I'd like to force users to have tag [X]before nicknamename, example:

[X] - IP range

[N] - 192.168.100.0 - 192.168.119.255
(B) - 192.168.120.0 - 192.168.139.255 <--- i mean here B in '[]' as in other places, but forum changes it to bolder font
[P] - 192.168.140.0 - 192.168.159.255
[Z] - 192.168.160.0 - 192.168.179.255
[?] - all other

that means that if someone has IP 192.168.101.10 then he should set his nickname to [N]SomeName, etc.
if he won't set it like that, then each time he connects or search he should get PM saing
'Please insert [N] tag before nickname in your DC++ settings.'

Also, it would be good to have possibility for kicking people that are not in any selected range or have false prefix.



2. Advenced limiter

let's say user connects to hub and has X slots, Y Mb shared and Z MBits/s.

If user has X equal 3 or less he gets kicked with PM 'Minimum slots number on this server is 5, and your is X. Please raise it in your DC++ settings.'
if user has 3<X<5 he doesn't get kicked, but each time he connects or search he should get PM as above
(where 3 is minX and 5 is goodX, set by HUB master)

if user has Y equal 5000 or less he gets kicked with PM 'Minimum share on this server is 7 Gb, and your is Y. Please share more.'
if user has 5000<Y<7000 he doesn't get kicked, but each time he connects or search he should get PM as above
(where 5000 is minY and 7000 is goodY, set by HUB master)

if user has Z less than 0.1 each time he connects or search he should get PM 'Minimum upload speed limit on this server is 1 Mbits/s, and your is Z. Please raise it in your DC++ settings.'
(where 1 (in MBit/s) is goodZ, set by HUB master)


X<minX --->  user gets PM and kick,
minX<X<goodX  --->  User gets PM
Y<minY  --->  user gets PM and kick,
minY<Y<goodY  --->  User gets PM
Z<goodZ  --->  User gets PM


Please, can anyone help?
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 16 November, 2008, 21:52:28
OK, i just found in another topic something close to my first request,
script was writen by Mutor and i did some changes..
please tell me if it's correct:
Code (lua) Select

-- Is the third octet of the user's I.P. required
local req_ip = true

MyINFOArrival = function(user,data)
if user.iProfile == -1 then
local _,_,oct3 = user.sIP:find("^%d+%.%d+%.(%d+)%.%d+$")
local literka = "?"
if ( tonumber(oct3) > 99 and tonumber(oct3) < 120) then
literka="N"
end
if ( tonumber(oct3) > 119 and tonumber(oct3) < 140) then
literka="B"
end
if ( tonumber(oct3) > 139 and tonumber(oct3) < 160) then
literka="P"
end
if ( tonumber(oct3) > 159 and tonumber(oct3) < 180) then
literka="Z"
end
local _,_,tag = user.sNick:find("^(%["..literka.."%][^%s]+)")
if req_ip then
if oct3 and tonumber(oct3) > 99 and tonumber(oct3) < 180 and tag then return end
else
if tag then return end
end
local Bot,Msg = SetMan.GetString(21),"Invalid nick prefix, your nick should be ["..literka.."]"..user.sNick
return Core.SendPmToUser(user,Bot,Msg.."|"),true
-- return Core.SendToUser(user,"<"..Bot.."> "..Msg.."|"),Core.Disconnect(user),true
end
end
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 17 November, 2008, 01:23:18
Thanx a lot, it's waaaay cleaner now :)

how about second request?
i managed to handle min shares by Px limit and simple

RegConnected = function(User)
if Core.GetUserValue(User,16) < (7*1024*1024*1024) then
Core.SendPmToUser(User,SetMan.GetString(21),"Please share at least 7 Gb.|")
end
end


so the same thing should also work for slots, i guess-but what Core.GetUserValue(User,????) should i use?

for upload, i tried to use UpLimit from finished scripts section- but it always said that i have 0 B/s.
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 17 November, 2008, 02:16:45
Sorry, I now realized that i didn't mean upload limit, but that value in 'connection' column on user list.. since we all are on the same LAN, i wanted to ask all users choose medium or max connection speed, instead of standard '0.005 Mb/s'.. is it possible?

And what about slots?

Also, i get bunch of same errors with your script in post 2:

[02:05] Składnia G:\0.4.1.1\scripts\akademik2.lua:2: attempt to index global 'Profiles' (a nil value)
[02:08] Składnia G:\0.4.1.1\scripts\akademik2.lua:2: attempt to index global 'Profiles' (a nil value)

Składnia means Syntax in polish, so it would be syntax error, I guess?
what's the diffrence between
if Profiles[user.iProfile] then
and
if user.iProfile == -1 then
because second one works, and first does that error..
i have clean PotkaX 0.4.1.1
Only I'm registred user, others do not register themselves.
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 17 November, 2008, 03:00:09
works great now, thanks.
but agin, can you help me with slots or connection setting?
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 17 November, 2008, 03:39:49
Ok, so connection topic closed.
As for slots, i know there are several scripts that do what i need, but they all have some fancy features such as context menu, slot ratio per share or hub, per profile, bot etc.
but for now i want just plain and simple function PMing users at connect when they have less slots than required, such as few posts up was for min share.
I mean something like this:

RegConnected = function(User)
   if Core.GetUserValue(User, ??? ) < 5 then
      Core.SendPmToUser(User,SetMan.GetString(21),"Please open at least 5 slots.|")
   end
end
Title: Re: 2 requests: Nick prefix per ip range and advenced limiter
Post by: LeBleu on 17 November, 2008, 19:27:59
Ok, that would be all..
local Profiles = {
[-1] = true, --Unregistered User
[0] = false, --Master
[1] = true, --Operator
[2] = true, --Vip
[3] = true, --Registered User
}
local minShare = (7*1024*1024*1024)
local minSlots = 5
MyINFOArrival = function(user,data)
if Profiles[user.iProfile] then
Core.GetUserAllData(user)
if ( Core.GetUserValue(user,16) < minShare ) then
Core.SendPmToUser(user,SetMan.GetString(21),"Please share at least 7 Gb.|")
end
if ( Core.GetUserValue(user,21) < minSlots ) then
Core.SendPmToUser(user,SetMan.GetString(21),"Please open 5 slots.|")
end
local Msg,_,_,oct = "",user.sIP:find("^192%.168%.(%d+)%.%d+$")
oct = tonumber(oct) or 0
local Pfxs = {
["N"] = {99,120},
["B"] = {119,140},
["P"] = {139,160},
["Z"] = {159,180},
}
local Loop = function(oct)
for k,v in pairs(Pfxs) do if oct > v[1] and oct < v[2] then return k end end
end
local ltr = "?"
ltr = Loop(oct)
if ltr and user.sNick:find("^%["..ltr.."%][^%s]+$") then return end
local Bot = SetMan.GetString(21)
if not ltr then
Msg = "Your IP is wrong. You'll be disconnected."
return Core.SendToUser(user,"<"..Bot..">"..Msg.."|"),Core.SendPmToUser(user,Bot,Msg.."|"),Core.Disconnect(user),true
end
Msg = "Please add proper prefix before nick, like ["..ltr.."]"..user.sNick.." ."
Core.SendPmToUser(user,Bot,Msg.."|")
end
end

Works like a charm, thanx a lot :)