PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: BAlexandrov on 29 December, 2004, 13:10:51

Title: Script to force that upload/download limits are set
Post by: BAlexandrov on 29 December, 2004, 13:10:51
Hello guys!

Our hub is in serious trouble and it is possible to be closed...
It is situated in internal network of an ISP. The network is 100mbit ethernet one, and have more than 1000 users.
The hub is internally accessible only but gives very good speeds of 300 kb - 2 mb/sec depending on distance between users.
Our ISP insist that the hub overload their network will take steps to disable it.

That I am thinking of is to force all users to use bcdc and to set limits on upload and download speed to say...300-500 kb/sec this way there will be no load on the network.

I need script to enforce this policy. I
 already use Xsthetic that have limit of user agents. But for the limits - can't they be checked from the TAG?

I need that users have set limits bellow (or between) some values, if they are not - display them a message and either prevent them to download or disconnected (not banned).
Only unregistered and regular users must be checked.

What is your opinion?

PS. I failed to find forum for BCDC issues. The last version have problem with cyrillic characters but only on main chat, not in PM. Where can I ask for?
Title:
Post by: bastya_elvtars on 29 December, 2004, 13:39:12
a) bcdc formatting.lua cant handle cyrillic

b) your script:

-- Have2Limit by bastya_elvtars
-- if no limit set or client has a too high limit it disconnects
-- supports DCPRO and DCGUI
-- please no buuuuuuuuuuuuuugs

-- // editable settings

-- set user levels here if you do not have the default profiles
-- [profileindex]=rank
-- the higher the rank is, the less likely user will be checked.


userlevels={

[-1]=1,

[0]=5,

[1]=4,

[2]=3,

[3]=2
}

checklevel=2 -- checks regs & nonregs now

upload_limit=300 -- same dimension as in BCDC++

-- // end of editable settings

function NewUserConnected(user)
investigate(user)
end

function DataArrival(user,data)
if strsub(data, 1, 7) == "$MyINFO" then
if user.sMyInfoString and strlen (user.sMyInfoString) > (strlen(user.sName)+13) then
investigate(user)
end
end
end

function checklimit(user)
if strfind(user.sMyInfoString,"[BLU]") then
local upstream
local _,_,Slots = strfind(user.sMyInfoString, "H:[^,]+,S:(%d+).*>")
local _,_,limit1=strfind(user.sMyInfoString,"[BLU]:(%d+)")
local _,_,limit2 = strfind(user.sMyInfoString,"F:%d+/(%d+)")
if Slots and Slots~="0" then
if limit1 then
upstream=calclimit(user,limit1,Slots)
elseif limit2 then
upstream=calclimit(user,limit2,Slots)
end
else
user:SendData("SlotChk","You have a stupid client, it cannot show slots.")
user:Disconnect()
end
return upstream
end
end

function calclimit(user,limit,s)
if strfind(user.sMyInfoString," return tonumber(limit)*tonumber(s)
else
return tonumber(limit)
end
end

function investigate(user)
if checklevel > userlevels[user.iProfile] then
local limit=checklimit(user)
if not limit or limit > upload_limit then
user:SendData("LimitChk","Please set your upload limit to a maximum of "..upload_limit.." kB/s in your client. If you do not have a client capable of limiting, look at [URL]http://utrum.dyndns.org:8000/[/URL]")
end
end
end
Title:
Post by: BAlexandrov on 29 December, 2004, 14:29:34
Thanks!


I test it in clear environment with PtokaX testdrive 4.99 (alternatives are acceptable)

It gives in scripts screen "Syntax Error: bad argument #1 to `strfind' (string expected, got nil)" when user connects.
Title:
Post by: plop on 29 December, 2004, 17:56:58
QuoteOriginally posted by BAlexandrov PS. I failed to find forum for BCDC issues. The last version have problem with cyrillic characters but only on main chat, not in PM. Where can I ask for?
you won't find it because it doesn't excist.
but you can try 2 ask in the dcdev hub.

plop
Title:
Post by: bastya_elvtars on 29 December, 2004, 19:29:02
QuoteOriginally posted by plop
but you can try 2 ask in the dcdev hub.

plop

you must be kidding  :D

btw edited the script above.
Title:
Post by: BAlexandrov on 30 December, 2004, 06:17:44
Hi, thanks for the fast response.

I've done little debugging with SendData's -

"local upstream" must be declared before the "if" in order to be in-scope when is returned.

Now it works well, bu there is another problem when after client is connected, user change his limits, the script is triggered with old value of the limit. (i've put "user:SendData("SlotChk","limit "..limit)" before "if not limit or limit > upload_limit then")
Why is that, can something be done?

Is there an easy way when user does not conform the limits to be prevented from downloading. If not then disconnect is enough.
Title:
Post by: bastya_elvtars on 30 December, 2004, 06:22:37
local upstream: thx missed ;)

hmm every myinfo gets checked. maybe if you fix the local upstream then it works

about dl blockling: not hard, but i do not like it and disagree with it so i won't make it. sorry
Title:
Post by: [NL]Pur on 30 December, 2004, 12:01:04
Quotebut you can try 2 ask in the dcdev hub.

suicidal mission ?
Title:
Post by: bastya_elvtars on 30 December, 2004, 14:13:20
QuoteOriginally posted by [NL]Pur
Quotebut you can try 2 ask in the dcdev hub.

suicidal mission ?

they will say: ask in the forum
you ask in the forum: they say google it
you google it: find nothing
you ask again in the forum: they say ask in the hub
you ask in the hub: if you are lucky, you will get that answer, which is one simple sentence.  :rolleyes:
Title:
Post by: plop on 30 December, 2004, 22:33:41
QuoteOriginally posted by bastya_elvtars
QuoteOriginally posted by [NL]Pur
Quotebut you can try 2 ask in the dcdev hub.

suicidal mission ?

they will say: ask in the forum
you ask in the forum: they say google it
you google it: find nothing
you ask again in the forum: they say ask in the hub
you ask in the hub: if you are lucky, you will get that answer, which is one simple sentence.  :rolleyes:
the way you ask is the key factor.
show in your question that you allready tryed all way's you could think of.
then you get a normal answer.
but i do agree, they can give very rude/stupid answers.

plop
Title:
Post by: bastya_elvtars on 30 December, 2004, 23:08:28
IMHO the key factor is the ? in the end of the line.

all other main chat post are welcome in dcdev.

 :D
Title:
Post by: plop on 31 December, 2004, 17:51:30
QuoteOriginally posted by bastya_elvtars
IMHO the key factor is the ? in the end of the line.

all other main chat post are welcome in dcdev.

 :D
where did you found that weird char.

plop
Title:
Post by: bastya_elvtars on 31 December, 2004, 17:53:45
http://www.btinternet.com/~andrew.murphy/html_character_set.html
Title:
Post by: BAlexandrov on 02 January, 2005, 14:51:45
QuoteOriginally posted by bastya_elvtars
local upstream: thx missed ;)

hmm every myinfo gets checked. maybe if you fix the local upstream then it works

about dl blockling: not hard, but i do not like it and disagree with it so i won't make it. sorry

After I've moved "local upstream" it began to work, but when limit is changed after connect - the check is triggered with the previous value of the limit.

Here is example.
In function "function investigate(user)"

Ive added user:SendData above the if like:
"
      user:SendData("SlotChk","limit "..limit)
      
      if not limit or limit > upload_limit then
"
I've connected with limit 200
then changed it to 400,500,100,150
Watch messages and the warning - they are for the previous value of the limit. Very strange...

[15:43] limit 200 <-- initial connnect
[15:43] limit 200 <-- after set 400
[15:43] limit 400 <-- after 500
[15:43] Please set your upload limit to a maximum of 300 kB/s in your client. If you do not have a client capable of limiting, look at http://utrum.dyndns.org:8000/
[15:43] limit 500 <--after 100
[15:43] Please set your upload limit to a maximum of 300 kB/s in your client. If you do not have a client capable of limiting, look at http://utrum.dyndns.org:8000/
[15:44] limit 100 <-- after 150
Title:
Post by: bastya_elvtars on 02 January, 2005, 15:10:38
i bet this is a client error. it sends myinfo badly.

it analyzes every myinfo, the check is fully objective.

enable CMDs in the ptokax users and chat screen and se what myinfos you send when setting limit.
Title:
Post by: BAlexandrov on 02 January, 2005, 16:47:53
nope... it comes correctly
I've connected with 150, then changed to 400, then 200

[17:40] 192.168.112.30:1775 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:150>$ $LAN(T3)$bojo@bojo$0$|
[17:40] 192.168.112.30:1775 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:400>$ $LAN(T3)$bojo@bojo$0$|
[17:41] 192.168.112.30:1775 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:200>$ $LAN(T3)$bojo@bojo$0$|
Title:
Post by: bastya_elvtars on 02 January, 2005, 16:51:36
edited the script above.
Title:
Post by: BAlexandrov on 02 January, 2005, 18:17:52
Sorry that I have to say it but it it works the same way:
I've started with 600
then changed it to 400,200,500
PtocaX log looks like:
[19:14] 192.168.112.30:1956 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:400>$ $LAN(T3)$bojo@developer.bg$0$|
[19:14] 192.168.112.30:1956 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:200>$ $LAN(T3)$bojo@developer.bg$0$|
[19:14] 192.168.112.30:1956 > $MyINFO $ALL Bojo3 <++ V:0.668,M:A,H:1/0/0,S:20,B:500>$ $LAN(T3)$bojo@developer.bg$0$|

bcdc main chat  (i've added
"
->      user:SendData("SlotChk","limit "..limit)

      if not limit or limit > upload_limit then
")


[19:14] limit 600
[19:14] Please set your upload limit to a maximum of 300 kB/s in your client. If you do not have a client capable of limiting, look at http://utrum.dyndns.org:8000/
[19:14] limit 400
[19:14] Please set your upload limit to a maximum of 300 kB/s in your client. If you do not have a client capable of limiting, look at http://utrum.dyndns.org:8000/
[19:14] limit 200
Title:
Post by: bastya_elvtars on 02 January, 2005, 18:53:03
heh, this is not a script error.

the script gets the number from after B:/L:/U:/F: and analyzes it, so dunno what can be wrong.
Title:
Post by: plop on 02 January, 2005, 19:22:26
dcgui can have a limiter set to 100.80.
also take this into count.

plop
Title:
Post by: BAlexandrov on 02 January, 2005, 19:41:34
QuoteOriginally posted by plop
dcgui can have a limiter set to 100.80.
also take this into count.

plop

We plan to use ptocax with bcdc, dcgui is another client with function to set limits?

What is your suggestion, plop, where is the problem with previous values?
It really looks like problem in the hub server and scripting engine...

Must I try another hub server (I use now PtocaX 0.3.2.6 testdrive 4.99), or another client (bcdc 0.668 latest)
Title:
Post by: bastya_elvtars on 02 January, 2005, 22:08:36
@plop: d'uh then it will be a bit miscounted ;)

@BAlexandrov: TD4 is downloadable from plop's site: http://www.plop.nl/ptokax/PtokaX-0.326.TestDrive4.zip

(my sig does not work atm)
Title: ole
Post by: lyte on 02 August, 2005, 11:03:04
hello, can sum1 change this script to check only reg users
" checkin if reg ppl have dl and upl limited to 50KB on bcdc"

may sum1 do dat?