PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Metaphase on 04 October, 2004, 05:39:15

Title: Special Redirect Array Script Needed...
Post by: Metaphase on 04 October, 2004, 05:39:15
Hi all.

I am in need of a special redirect array script. I am looking for a script that can redirect all non-registered users to one of my other hubs according to how much they are sharing... For example;

Users with 1GB or less shares get redirected to Hub1.no-ip.org.
Users with 1GB to 7GB shares get redirected to Hub2.no-ip.org.
Users with 7GB to 40GB shares get redirected to Hub3.no-ip.org.

Any assistance on this script would be appriciated.
Title:
Post by: Metaphase on 04 October, 2004, 06:04:07
I have found this script on the forum but it needs a little altering in order for it to be useful for my setup. It seems this script is designed for 2 hubs but my network has 5 hubs, including the one it will be redirecting from. Here is the script....

Quote--Requested by 3lancer
--Made by nErBoS
--Corrected by NightLitch

Bot = "Share-Redirecter"

redshare1 = "1.1.1.1"
redshare2 = "1.1.1.2"
share1 = 5 --GB
share2 = 10 --GB

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)

local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
share = share / (1024*1024*1024)
if(tonumber(share) ~= nil) then
if(tonumber(share) > tonumber(share1) and tonumber(share) < share2) then
user:SendData("$ForceMove "..redshare1.."|")
elseif(tonumber(share) >= tonumber(share2)) then
user:SendData("$ForceMove "..redshare2.."|")
else
end
else
end

end

If anyone is able to modify this script to be used with 5 hubs then please help  :)
Title:
Post by: plop on 04 October, 2004, 06:59:48
try this 1.
--Requested by 3lancer
--Made by nErBoS
--Corrected by NightLitch
-- added endless amount of hubs by plop

Bot = "Share-Redirecter"

-- biggest hub 1st, share size in GB
tHubs = {
   { share = 10,  ip = "1.1.1.1", name = "hubname1" },
   { share = 5, ip = "1.1.1.2", name = "hubname2" }
}

function Main()
   frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
   local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
   if(tonumber(share)) then
share = tonumber(share) / (1024*1024*1024)
for i=1,getn(tHubs) do
  if share > tHubs[i][share] then
user:SendData(Bot, "You are being redirected to "..tHubs[i][name].."|$ForceMove "..tHubs[i][ip].."|")
  end
end
   end
end

plop
Title:
Post by: Metaphase on 04 October, 2004, 17:16:13
Thanks alot Plop. I will give it a try. Am I right in thinking that when I want to add more hubs to the redirect list I only have to add an extra one of these lines per hub???

Quote{ share = 10,  ip = "1.1.1.1", name = "hubname1" },

Also, is it possible to change the IP address to the DNS of the hub as most hubs in the network have dynamic IP's?
Title:
Post by: nErBoS on 04 October, 2004, 22:05:03
Hi,

Offcourse you can put a IP or an addy.

Best regards, nErBoS
Title:
Post by: Metaphase on 05 October, 2004, 04:03:34
Thanks nErBoS.

One thing I have noticed about this script by looking at it is that it doesn't seem to redirect un-registered users only. Any ideas on what needs adding to achieve this?
Title:
Post by: bastya_elvtars on 05 October, 2004, 04:13:01
I hope we think the same :D

--Requested by 3lancer
--Made by nErBoS
--Corrected by NightLitch
-- added endless amount of hubs by plop
-- modded for setting user levels to be redirected by bastya_elvtars (nice crew in here)
-- CheckUserLevel originally by Nathanos


-- who can be redirected?
level=2 -- 5:all users
-- 4 ops & below
-- 3 vips & below
-- 2 registered users & below
-- 1 guests only


Bot = "Share-Redirecter"


-- biggest hub 1st, share size in GB
tHubs = {
   { share = 10,  ip = "1.1.1.1", name = "hubname1" },
   { share = 5, ip = "1.1.1.2", name = "hubname2" }
}


function Main()
   frmHub:RegBot(Bot)
end


function NewUserConnected(user, data)
if CheckUserLevel(user) < level then
  local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
  if(tonumber(share)) then
share = tonumber(share) / (1024*1024*1024)
for i=1,getn(tHubs) do
  if share > tHubs[i][share] then
user:SendData(Bot, "You are being redirected to "..tHubs[i][name].."|$ForceMove "..tHubs[i][ip].."|")
  end
end
  end
end
end

function CheckUserLevel(user)
if user.iProfile==0 then
return 5
elseif user.iProfile==1 then
return 4
elseif user.iProfile==3 then
return 2
elseif user.iProfile==2 then
return 3
else
return 1
end
end
:D  :D  :D
Title:
Post by: Metaphase on 05 October, 2004, 04:38:00
Thanks for your quick reply bastya_elvtars.

I tried the script and I am getting the following error..

Syntax error: attempt to compare number with nil
stack traceback:
   1:  function `NewUserConnected' at line 38 [file `...\PtokaX 0.330 Debug Build 15.25\scripts\121.lua']

I only get this error when a user connects to the hub.
Title:
Post by: Herodes on 05 October, 2004, 08:45:32
well in fact better try this one ....
--Requested by 3lancer
--Made by nErBoS
--Corrected by NightLitch
-- added endless amount of hubs by plop
-- modded for setting user levels to be redirected by bastya_elvtars (nice crew in here)
-- CheckUserLevel originally by Nathanos


-- who can be redirected?
level=2 -- 5:all users
-- 4 ops & below
-- 3 vips & below
-- 2 registered users & below
-- 1 guests only


Bot = "Share-Redirecter"


-- biggest hub 1st, share size in GB
tHubs = {
   { ["share"] = 10,  ["ip"] = "1.1.1.1", ["name"] = "hubname1" },
   { ["share"] = 5, ["ip"] = "1.1.1.2", ["name"] = "hubname2" }
}


function Main()
   frmHub:RegBot(Bot)
end


function NewUserConnected(user, data)
if CheckUserLevel(user) < level then
  local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)"
  if(tonumber(share)) then
share = tonumber(share) / (1024*1024*1024)
for i=1,getn(tHubs) do
  if share > tHubs[i]["share"] then
user:SendData(Bot, "You are being redirected to "..tHubs[i]["name"].."|$ForceMove "..tHubs[i]["ip"].."|"
  end
end
  end
end
end

function CheckUserLevel(user)
if user.iProfile==0 then
return 5
elseif user.iProfile==1 then
return 4
elseif user.iProfile==3 then
return 2
elseif user.iProfile==2 then
return 3
else
return 1
end
end

the error above was cause because of these lines ...
share = tonumber(share) / (1024*1024*1024) --- declaring the value of ' share ' variable  
for i=1,getn(tHubs) do
  if share > tHubs[i][share] then --- if the value of 'share' variable is more than the value of 'share' index in table ' i ' of table ' tHubs ' then ...

so infact if share = 23 then tHubs[23] is really true .. :)
Title:
Post by: Metaphase on 05 October, 2004, 17:01:32
Thanks Herodes.

The script now seems to be working fine. Its another script for Plops Archive. :)
Title:
Post by: bastya_elvtars on 05 October, 2004, 17:47:46
QuoteOriginally posted by Metaphase
Thanks Herodes.

The script now seems to be working fine. Its another script for Plops Archive. :)

but who is the author?  :D  :D  :D
Title:
Post by: plop on 06 October, 2004, 00:25:35
-- Requested by 3lancer
-- Made by nErBoS
-- Corrected by NightLitch
-- added endless amount of hubs by plop
-- modded for setting user levels to be redirected by bastya_elvtars (nice crew in here)
-- CheckUserLevel originally by Nathanos
-- rewritennen CheckUserLevel by plop


-- who can be redirected?
level=2 -- 5:all users
-- 4 ops & below
-- 3 vips & below
-- 2 registered users & below
-- 1 guests only

Bot = "Share-Redirecter"

-- biggest hub 1st, share size in GB
tHubs = {
{ ["share"] = 10,  ["ip"] = "1.1.1.1", ["name"] = "hubname1" },
{ ["share"] = 5, ["ip"] = "1.1.1.2", ["name"] = "hubname2" }
}

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
if CheckUserLevel(user) < level then
local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)"
if(tonumber(share)) then
share = tonumber(share) / (1024*1024*1024)
for i=1,getn(tHubs) do
if share > tHubs[i]["share"] then
user:SendData(Bot, "You are being redirected to "..tHubs[i]["name"].."|$ForceMove "..tHubs[i]["ip"].."|"
end
end
end
end
end

tLevels = {
[0]=5,
[1]=4,
[2]=3,
[3]=2,
}

function CheckUserLevel(user)
if tLevels[(user.iProfile}]then
return tLevels[(user.iProfile}]
else
return 1
end
end

plop
Title:
Post by: Herodes on 06 October, 2004, 01:12:00
Uhm ... Shouldn't this function CheckUserLevel(user)
if tLevels[(user.iProfile}]then
return tLevels[(user.iProfile}]
else
return 1
end
end
be like this? function CheckUserLevel(user)
if tLevels[(user.iProfile[b])[/b]]then
return tLevels[(user.iProfile[b])[/b]]
else
return 1
end
end
Title:
Post by: plop on 06 October, 2004, 01:35:10
more like this actualy.
damn mistyped a bit there.
function CheckUserLevel(user)
return tLevels[(user.iProfile)] or 1
end

plop
Title:
Post by: plop on 06 October, 2004, 01:43:08
which you can shorten a bit more.
-- Requested by 3lancer
-- Made by nErBoS
-- Corrected by NightLitch
-- added endless amount of hubs by plop
-- modded for setting user levels to be redirected by bastya_elvtars (nice crew in here)
-- CheckUserLevel originally by Nathanos
-- CheckUserLevel eliminated by plop


-- who can be redirected?
iLevel=2 -- 5:all users
-- 4 ops & below
-- 3 vips & below
-- 2 registered users & below
-- 1 guests only

Bot = "Share-Redirecter"

-- biggest hub 1st, share size in GB
tHubs = {
{ ["share"] = 10,  ["ip"] = "1.1.1.1", ["name"] = "hubname1" },
{ ["share"] = 5, ["ip"] = "1.1.1.2", ["name"] = "hubname2" }
}

function Main()
frmHub:RegBot(Bot)
end

tLevels = {
[0]=5,
[1]=4,
[2]=3,
[3]=2,
}

function NewUserConnected(user, data)
if (tLevels[(user.iProfile)] or 1) < iLevel then
local s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
if(tonumber(share)) then
share = tonumber(share) / (1024*1024*1024)
for i=1,getn(tHubs) do
if share > tHubs[i]["share"] then
user:SendData(Bot, "You are being redirected to "..tHubs[i]["name"].."|$ForceMove "..tHubs[i]["ip"].."|")
end
end
end
end
end

plop
Title:
Post by: Metaphase on 07 October, 2004, 04:50:05
Well all I can say is thanks alot guys. The script is working great and we havn't had one single user get passed it and into the hub. Our hubs are now starting to fill up according to share sizes.  :D

Without people like you lot, DC would just be a protocol.  ;)