need help
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

need help

Started by urpoxi, 24 March, 2004, 10:38:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

urpoxi

i need help with a script. Users with oDC version 5.3 and higher cant get into my hub anymore :(


script
Quotekb = 1024
mb = kb*kb
gb = kb*kb*kb

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

checkSets = {
   op = {
      minShare = 0 * gb,
      minShareFormatted = "0 Gb",
      minVersion = nil,
      maxHubs = nil,
      minSlotsPerHub = nil,
      minSlots = nil,
      maxSlots = nil,
      allowNmdc = 1,
      disallowPassive = nil,
   },
   vip = {
      minShare = 1 * gb,
      minShareFormatted = "1 Gb",
      minVersion = 0.23,
      maxHubs = 8,
      minSlotsPerHub = 1,
      minSlots = nil,
      maxSlots = nil,
      allowNmdc = nil,
      disallowPassive = nil,
   },
   user = {
      minShare = 1 * gb,
      minShareFormatted = "1 Gb",
      minVersion = 0.23,
      maxHubs = 8,
      minSlotsPerHub = 1,
      minSlots = 1,
      maxSlots = 21,
      allowNmdc = nil,
      disallowPassive = nil,
   },
}
      
msg = {
   ["bad myinfo"] = "1",
   ["no nmdc"] = "2",
   ["low version"] = "3 [V]",
   ["no pasv"] = "4",
   ["many hubs"] = "5 [H]",
   ["slots and hubs"] = "6 [mS] [MS]"..
                   " [mSpH]",
   ["low share"] = "7 [share]",
   ["you are not a vip"] = "8",
   ["redirected"] = "9 [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 "..addy.."|")
         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


plop

replace this next part for the 1 in your script and every client with a tag should be able 2 enter.
--// 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
"<%S+%sV:([^,]+),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
"<%S+%sV:([^,]+),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
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

urpoxi

Thank you plop, it works! Now i have those dc-gui users do deal with :/

plop

QuoteOriginally posted by urpoxi
Thank you plop, it works! Now i have those dc-gui users do deal with :/
there is nothing wrong with dcgui-qt users.
i'm still on a crusade for them so i won't fix the script 2 kick them, sorry.
i got a couple friends who are only using linux/bsd and they deserve 2 enjoy dc 2.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk