PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Smulf on 12 July, 2004, 00:47:27

Title: Profile Share
Post by: Smulf on 12 July, 2004, 00:47:27
Is it posible making a script that will check min share for different profiles. So all REG user has to share 50GB, VIPs 20... Also slot checking if thats posible

Thx for your time
Title:
Post by: Madman on 12 July, 2004, 01:50:37
Get Robocop 8, it is already in there...

Sorry, for any spelling misstakes.... tierd, and not so good at english..... =)
Title:
Post by: plop on 12 July, 2004, 10:06:18
QuoteOriginally posted by madman
Get Robocop 8, it is already in there...

Sorry, for any spelling misstakes.... tierd, and not so good at english..... =)
not only RC has that option, same goes for channelbot, a.i. and a bunch more.

plop
Title: Thx for replay
Post by: Smulf on 12 July, 2004, 13:22:02
Thx guess, but I realy need it as a single script...Isn't that posible...

THX
Title:
Post by: Typhoon on 12 July, 2004, 13:54:44
found a script from Sedulus that does what you want ..


-- vim:ts=4:sw=4:noet
-- VIPpp.lua 1.3
-- share/vip/hubs/slots/etc checker for PtokaX (tested on 0.3.2.4 IceCube III-fix3)
--
-- created by Sedulus / 20030218,20030308, no rights reserved,
-- but that doesn't mean you can edit it and don't give me credit! ;)
--
-- based on VIPShare.lua by Sedulus (20030130)
--
-- since the hub doesn't have any isReggedUser() function,
-- we'll do the following:
--
--   * at DataArrival, we'll store the user if it has [VIP] in the name, upon recieval of MyPass
--   then, at userexit, we'll remove the user.
--   this seems secure, because:
--   1. when the pass is incorrect, the userdisconnected is still called, so we can clear mem
--   2. when pass is sent without GetPass, the dataarrival never gets the MyPass
--
--   * at newuserconnected, we'll check if the user is in the vip-has-sent-pwds-list,
--   if not, he gets disconnected with a message that he is not a vip
--
   

kb = 1024
mb = kb*kb
gb = kb*kb*kb

bot_name = "-ShareChecker-"
redirect_on_failed = 1 -- nil or 1 to redirect on when user fails to meet the criteria
hubCheckMethod = 3 -- DC++0.24 Hubs notation 1=x, 2=x/y, 3=x/y/z

checkSets = {
op = {
minShare = 5 * gb,
minShareFormatted = "5 GB",
minVersion = nil,
maxHubs = 4,
minSlotsPerHub = nil,
minSlots = nil,
maxSlots = 10,
allowNmdc = 1,
disallowPassive = nil,
},
vip = {
minShare = 100 * gb,
minShareFormatted = "100 GB",
minVersion = 0.181,
maxHubs = 5,
minSlotsPerHub = 1,
minSlots = 1,
maxSlots = nil,
allowNmdc = 1,
disallowPassive = nil,
},
user = {
minShare = 300 * gb,
minShareFormatted = "300 GB",
minVersion = 0.233,
maxHubs = 2,
minSlotsPerHub = 2,
minSlots = 3,
maxSlots = 10,
allowNmdc = 1,
disallowPassive = nil,
},
}

msg = {
["bad myinfo"] = "We couldn't parse your MyINFO string. Get the steppin'",
["no nmdc"] = "We don't like crappy old software, go download DC++",
["low version"] = "The ++ version you are using is too old. Minimum is [V]",
["no pasv"] = "We don't allow passive users in here. You people put too much load on the hub.",
["many hubs"] = "You are in too many hubs. Max hubs allowed is [H]. Disconnect from some and try again.",
["slots and hubs"] = "You do not meet the slots/hubs requirements. MinSlots = [mS], MaxSlots = [MS], Min slots "..
"per hub = [mSpH]",
["low share"] = "The minimum share here is [share].",
["you are not a vip"] = "You are not a VIP here. Get lost!",
["redirected"] = "You are being redirected to [H]",
}

function has_a_vip_name( name ) return strlower( strsub( name, 1, 5 ) ) == "[vip]" end

--// start //--

vipusers = {}

--// This function is fired at the serving start
function Main()
guardGlobals()
end

--// This function is fired when a new data arrives
function DataArrival( curUser, data )
--// a mypass is a sign that the user is registered
if strsub( data, 1, 8 ) == "$MyPass " then
--// if it's a vip, we save his name
if has_a_vip_name( curUser.sName ) then
vipusers[curUser.sName] = 1
end
--// whenever myinfo is sent, we check the user
elseif strsub( data, 1, 8 ) == "$MyINFO " then
CheckMyInfo( curUser, strsub( data, 1, strlen( data ) - 1 ) )
end
end

--// This function is fired when a new user finishes the login
function CheckMyInfo( curUser, myinfo )

--// the set of rules we want to test the user against
local checkSet

--// what action do we want on criteria mismatch?
if redirect_on_failed then
curUser.FailedLogin = function( o )
local addr = frmHub:GetRedirectAddress()
local warning = gsub( msg["redirected"], "%[H%]", addr, 1 )
o:SendData( bot_name, warning )
o:SendData( "$ForceMove "..addr )
o:Disconnect()
end
else
curUser.FailedLogin = curUser.Disconnect
end

--// define rules for usergroups
if curUser.bOperator then
checkSet = checkSets["op"]
elseif vipusers[curUser.sName] then
checkSet = checkSets["vip"]
elseif has_a_vip_name( curUser.sName ) then
curUser:SendData( bot_name, msg["you are not a vip"] )
curUser:FailedLogin()
return
else
checkSet = checkSets["user"]
end

--// get needed info from string
local ret,c,V,M,H,S,O,share = strfind( myinfo,
-- V:0123  M:P|A H:0-99    S:0-99    O:0-99                        share
"<%+%+ V:([^,]+),M:(.),H:([^,]+),S:([^,]+),O:([^,>]+).*>$ $[^$]*%$[^$]*%$(%d+)%$$" ) -- dc++, with O
if not ret then
ret,c,V,M,H,S,share = strfind( myinfo,
-- V:0123  M:P|A H:0-99    S:0-99                        share
"<%+%+ V:([^,]+),M:(.),H:([^,]+),S:([^,>]+).*>$ $[^$]*%$[^$]*%$(%d+)%$$" ) -- dc++, without O
end
if not ret then
ret,c,share = strfind( myinfo,
-- share
"%$(%d+)%$$" ) -- nmdc/other, non <++ V:
end
if not ret then
-- info seems to be messed up, disconnect the bastard
curUser:SendData( bot_name, msg["bad myinfo"] )
curUser:FailedLogin()
return
end

--// do we allow nmdc?
if not V and not checkSet.allowNmdc then
curUser:SendData( bot_name, msg["no nmdc"] )
curUser:FailedLogin()
return
end
--// check ++version
if V and checkSet.minVersion then
local n = tonumber( V )
if not n then -- we can't parse the version number, let the OPs handle it
SendPmToOps( bot_name, "warning, couldn't parse version V:"..V.." for user "..curUser.sName.." -- "..
  "skipping version check" )
elseif n < checkSet.minVersion then
local warning = gsub( msg["low version"], "%[V%]", tostring( checkSet.minVersion ), 1 )
curUser:SendData( bot_name, warning )
curUser:FailedLogin()
return
end
end
--// check active/passive
if M == "P" and checkSet.disallowPassive then
curUser:SendData( bot_name, msg["no pasv"] )
curUser:FailedLogin()
return
end
--// fix new DC024 H:x/y/z notation
if H then
local Hn = {0} -- crappy-ass lua4 workaround
gsub( H, "(%d+)", function( x ) %Hn[1] = %Hn[1] + tonumber( x ) end, hubCheckMethod )
H = Hn[1]
end
--// fix slots while we're at it, no need for multiple tonumber()'s
if S then
S = tonumber( S )
end
--// check hubs
if H and checkSet.maxHubs then
if H > checkSet.maxHubs then
local warning = gsub( msg["many hubs"], "%[H%]", tostring( checkSet.maxHubs ), 1 )
curUser:SendData( bot_name, warning )
curUser:FailedLogin()
return
end
end
--// check slots / slots/hub
if H and S then
local dis = nil
if checkSet.minSlots and S < checkSet.minSlots then dis = 1
elseif checkSet.maxSlots and S > checkSet.maxSlots then dis = 1
elseif checkSet.minSlotsPerHub and S < ( H * checkSet.minSlotsPerHub ) then dis = 1
end
if dis then
local minSlots = checkSet.minSlots or "(void)"
local maxSlots = checkSet.maxSlots or "(void)"
local minSlotsPerHub = checkSet.minSlotsPerHub or "(void)"
local warning = gsub( gsub( gsub( msg["slots and hubs"], "%[mS%]", minSlots ), "%[MS%]", maxSlots ),
"%[mSpH%]", minSlotsPerHub )
curUser:SendData( bot_name, warning )
curUser:FailedLogin()
return
end
end
--// finally check the share and kick the user if lower
if tonumber( share ) < checkSet.minShare then
local warning = gsub( msg["low share"], "%[share%]", checkSet.minShareFormatted )
curUser:SendData( bot_name, warning )
curUser:FailedLogin()
return
end
end

function UserDisconnected( curUser )
--// clean up
vipusers[curUser.sName] = nil
end
function OpDisconnected( curUser )
--// clean up
vipusers[curUser.sName] = nil
end

--// debug functions

function _assign_undef_global( varname, newvalue )
error( "assignment to undefined global `"..varname.."'" )
end
--function _safe_get_global( varname )
-- -- access the table of globals
-- local value = rawgetglobal( varname )
-- if not value then error( "requesting undefined global variable `"..varname.."'" ) return end
-- local tm = gettagmethod( tag( value ), "getglobal")
-- if not tm then
--     if ret then return ret else error( "requesting undefined global variable `"..varname.."'" ) end
-- return value
-- else
-- return tm( varname, value )
-- end
--end

function guardGlobals()
settagmethod( tag(nil), "setglobal", _assign_undef_global )
-- settagmethod( tag(nil), "getglobal", _safe_get_global )
end


enjoy ;o)
Title:
Post by: Braindead on 12 July, 2004, 14:27:14
This is basicly what you need.. Got it from NightLitch ...


-----------------------------------------------------------
-- Multi Share/Slot Bot v.3
-- By: NightLitch  2003
-----------------------------------------------------------
kb = 1024
mb = kb*kb
gb = kb*kb*kb
tb = kb*kb*kb*kb
-----------------------------------------------------------
-- All Share values are in GB
-- Need to Set correct Level/Profile
-- on those levels that are nil.
-----------------------------------------------------------
-- Start of Editable Data --

BotName = "-Link-"

-- Master --
MstrLvl = 0
MSR = {
MinShare = 0,
MaxShare = 10000,
MinSlots = 0,
MaxSlots = 100,   
}

-- Operator 1 --
Op1Lvl = 1
OP1 = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Operator 2 --
Op2Lvl = nil
OP2 = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Vip User --
VipLvl = 2
VIP = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Reg User 1 --
Reg1Lvl = 3
REG1 = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Reg User 2 --
Reg2Lvl = nil
REG2 = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Reg User 3 --
Reg3Lvl = nil
REG3 = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- Regular Users --
UsrLvl = -1
USR = {
MinShare = 10,
MaxShare = 500,
MinSlots = 3,
MaxSlots = 15,
}

-- End of Editable Data --
-------------------------------------------------------------------------------------------------------------
function Main()
   frmHub:RegBot(BotName)
end
-------------------------------------------------------------------------------------------------------------
function DataArrival(curUser,data)
   if (strsub(data,1,7) == "$MyINFO") then
      local _,_, Slots = strfind(data,".*S:(%d+)")
-- Master Check Slots ---------------------------------------------------------------------------------------
      if curUser.iProfile == MstrLvl then
         CheckSlots(curUser,MSR.MinSlots,MSR.MaxSlots,Slots)
-- Operator 1 Check Slots -----------------------------------------------------------------------------------
      elseif curUser.iProfile == Op1Lvl then
         CheckSlots(curUser,OP1.MinSlots,OP1.MaxSlots,Slots)
-- Operator 2 Check Slots -----------------------------------------------------------------------------------
      elseif curUser.iProfile == Op2Lvl then
         CheckSlots(curUser,OP2.MinSlots,OP2.MaxSlots,Slots)
-- Vip User Check Slots -------------------------------------------------------------------------------------
      elseif curUser.iProfile == VipLvl then
         CheckSlots(curUser,VIP.MinSlots,VIP.MaxSlots,Slots)
-- Reg User  1 Check Slots ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg1Lvl then
         CheckSlots(curUser,REG1.MinSlots,REG1.MaxSlots,Slots)
-- Reg User  2 Check Slots ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg2Lvl then
         CheckSlots(curUser,REG2.MinSlots,REG2.MaxSlots,Slots)
-- Reg User  3 Check Slots ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg3Lvl then
         CheckSlots(curUser,REG3.MinSlots,REG3.MaxSlots,Slots)
-- Regular Users Check Slots --------------------------------------------------------------------------------
      elseif curUser.iProfile == UsrLvl then
         CheckSlots(curUser,USR.MinSlots,USR.MaxSlots,Slots)
      end
-------------------------------------------------------------------------------------------------------------
      CheckShare(curUser,data)
-------------------------------------------------------------------------------------------------------------
   end
end
-------------------------------------------------------------------------------------------------------------
function CheckSlots(curUser,mnSlots,mxSlots,Slots)
   if Slots==nil then
      curUser:SendData(BotName,"You are hidding your Tag for checking your slots.")
      curUser:Disconnect()
   elseif (tonumber(Slots) < mnSlots) then
      curUser:SendData(BotName,"You have too few slots open ( "..Slots.." ) Minimum slots is ( "..mnSlots.." ). ")
      curUser:Disconnect()
   elseif (tonumber(Slots) > mxSlots) then
      curUser:SendData(BotName,"You have too many slots open ( "..Slots.." ) Maximum slots is ( "..mxSlots.." ). ")
      curUser:Disconnect()
   end
end
-------------------------------------------------------------------------------------------------------------
function CheckShare(curUser,data)
   s,e, vShare = strfind(data,"$+(%d+)$+|+")
   if vShare ~= nil then
-- Master Check Share ---------------------------------------------------------------------------------------
      if curUser.iProfile == MstrLvl then
         if (tonumber(vShare) < MSR.MinShare * gb) then
            curUser:SendPM(BotName," With the profile Master you have to share atleast "..MSR.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Operator 1 Check Share -----------------------------------------------------------------------------------
      elseif curUser.iProfile == Op1Lvl then
         if (tonumber(vShare) < OP1.MinShare * gb) then
            curUser:SendPM(BotName," With the profile OP1 you have to share atleast "..OP1.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Operator 2 Check Share -----------------------------------------------------------------------------------
      elseif curUser.iProfile == Op2Lvl then
         if (tonumber(vShare) < OP2.MinShare * gb) then
            curUser:SendPM(BotName," With the profile OP2 you have to share atleast "..OP2.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Vip User Check Share -------------------------------------------------------------------------------------
      elseif curUser.iProfile == VipLvl then
         if (tonumber(vShare) < VIP.MinShare * gb) then
            curUser:SendPM(BotName," With the profile VIP you have to share atleast "..VIP.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Reg User  1 Check Share ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg1Lvl then
         if (tonumber(vShare) < REG1.MinShare * gb) then
            curUser:SendPM(BotName," With the profile Reg1 you have to share atleast "..REG1.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Reg User  2 Check Share ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg2Lvl then
         if (tonumber(vShare) < REG2.MinShare * gb) then
            curUser:SendPM(BotName," With the profile Reg2 you have to share atleast "..REG2.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Reg User  3 Check Share ----------------------------------------------------------------------------------
      elseif curUser.iProfile == Reg3Lvl then
         if (tonumber(vShare) < REG3.MinShare * gb) then
            curUser:SendPM(BotName," With the profile Reg3 you have to share atleast "..REG3.MinShare.." Gb")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
-- Regular Users Check Share --------------------------------------------------------------------------------
      elseif curUser.iProfile == UsrLvl then
         if (tonumber(vShare) < USR.MinShare * gb) then
            curUser:SendPM(BotName," You have to share atleast "..USR.MinShare.." Gb to enter this hub.")
            curUser:SendPM(BotName," Disconnecting...")
            curUser:Disconnect()
         end
      end
   end
end
Title: You better can use Robocap at one
Post by: [NL]Portal on 12 July, 2004, 19:07:18
Use robocop and ask him to put some scripts inside and he will have soon the best security script ever mde in history.
Title: Thanks
Post by: Smulf on 12 July, 2004, 22:40:44
Thx guess! Just what I needed... ;)