PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Pieltre on 26 January, 2004, 22:47:21

Title: Upload limit checker
Post by: Pieltre on 26 January, 2004, 22:47:21
Hi,

I've got this bot that I generated on some web tool a while ago.  I recall there was an option to reject non DC++, oDC or NMDC client (hacked clients) and an option that would check upload limits and kick users who would have it set below that.   In my bot, I can see there is such an upload limit checker, but it doesn't work.  So, either I get this bot edited or I get a new script altogether.  I'd appreciate any of the two solutions.

Here's my bot:

BotName="Bot"
allowConnSpeed={}
allowConnSpeed["28.8Kbps"]=0
allowConnSpeed["33.6Kbps"]=0
allowConnSpeed["56Kbps"]=1
allowConnSpeed["ISDN"]=1
allowConnSpeed["DSL"]=1
allowConnSpeed["Cable"]=1
allowConnSpeed["LAN(T1)"]=1
allowConnSpeed["LAN(T3)"]=1
allowConnSpeed["Satellite"]=1
SlotspPerConnSpeed={}
SlotspPerConnSpeed["28.8Kbps"]=1
SlotspPerConnSpeed["33.6Kbps"]=1
SlotspPerConnSpeed["56Kbps"]=1
SlotspPerConnSpeed["ISDN"]=2
SlotspPerConnSpeed["DSL"]=3
SlotspPerConnSpeed["Cable"]=3
SlotspPerConnSpeed["LAN(T1)"]=6
SlotspPerConnSpeed["LAN(T3)"]=14
SlotspPerConnSpeed["Satellite"]=3
AllowNeoModus=1
AllowDCPP=1
AllowMLDonkey=0
AllowReplika=0
AllowPePeK=0
trigs={}
awayArray={}
seenArray={}
CommandFlood="+flood"
CommandMassMessage="+mm"
CommandMassMessageOps="+mmops"
ComandAway="+afk"
ComandBack="+re"
CommandMyIP="+myip"
CommandSetMaxUsers="+setmaxusers"
CommandRedirectAllNow="+rdall"
CommandOpenBotDialog="##"
--intern constants
cKB=1024
cMB=1024*cKB
cGB=1024*cMB
--helper functions
function isMCM(data)
if( strsub(data, 1, 1) == "<" ) then
return 1
else
return 0
end
end
function isPM(data)
if( strsub(data, 1, 3) == "$To" ) then
return 1
else
return 0
end
end

function ParsePM(data)
   s,e,whoTo,from,message = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")
   --remove pipe
   message = strsub(message,1,strlen(message)-1)
   return whoTo,from,message
end
function ParseMCM(data)
   s,e,message = strfind(data, "%b<> (.*)")
   --remove pipe
   message = strsub(message,1,strlen(message)-1)
   return message
end

function ParseMyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
--remove speed identifier
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

function ParseDCPPDescription(description)
_,b, slots = strfind(description,"S:(%d+)")
_,b, dcver = strfind(description,"V:(%x.%x+)")
_,b, slots = strfind(description,"S:(%d+)")
_,b, hubs = strfind(description,"H:(%d+)")
_,b, bs = strfind(description,"B:(%x+)")
slots=tonumber(slots)
hubs=tonumber(hubs)


return dcver, slots, hubs, bs
end

function GetCommand(message)
s,e,command=strfind(message,"(%S+)")
return command
end

function GetOneParam(message)
s,e,param1=strfind(message,"%S+%s(.+)")
return param1
end

function GetTwoParam(message)
s,e,param1,param2=strfind(message,"%S+%s(%S+)%s(.+)")
return param1,param2
end


function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
--checker functions
function MaxSlotsCheck(slots, connectiontype)
if (SlotspPerConnSpeed[connectiontype]>=slots)then
return 1
else
return 0
end
end

function IsDCPPCLient(description)
if strfind(description,"<++") then
return 1
else
return 0
end
end

function IsConnAllowed(speed)
if (allowConnSpeed[speed]==1)then
return 1
else
return 0
end
end

function CheckClientType(description)
local result=1

if (AllowDCPP==0) then
   if (IsDCPPCLient(description)) then
      result=0
   end
end
if (AllowMLDonkey==0) then
   if (strfind(description,"mldonkey")) then
      result=0
   end
end

if (AllowReplika==0) then
   if (strfind(description,"REPLIKA")) then
      result=0
   end
end
if (AllowPePeK==0) then
   if (strfind(description,"Pepek")) then
      result=0
   end
end


return result
end
function DoFlood(victim)
user=GetItemByName(victim)
for a=1,600000 do
   user:SendPM(BotName..a,"you are flooded ....")
end
end
function HandleComand(curUser,message)
command=GetCommand(message)
if (curUser.bOperator) then
if (command==CommandFlood) then
   victim=GetOneParam(message)
   if (victim~=nil) then
      DoFlood(victim)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandFlood.." username")
   end
end
if (command==CommandMassMessage) then
   masstext=GetOneParam(message)
   if (masstext~=nil) then
      SendPmToAll(BotName,masstext)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandMassMessage.." text")
   end
end
if (command==CommandMassMessageOps) then
   masstext=GetOneParam(message)
   if (masstext~=nil) then
      SendPmToOps(BotName,masstext)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandMassMessageOps.." text")
   end
end
if (command==CommandSetMaxUsers) then
   newamount=GetOneParam(message)
   frmHub:SetMaxUsers(newamount)
   curUser:SendPM(BotName,"Max users has been changed to: "..newamount)
end
if (command==CommandRedirectAllNow) then
SendToOps(Bot, curUser.sName.." is redirecting all users to: "..frmHub:GetRedirectAddress())
SendToAll(BotName, "Redirecting... |$ForceMove "..frmHub:GetRedirectAddress().."|")
end
if (command==CommandOpenBotDialog) then
   curUser:SendPM(BotName,"How may i help?")
end
if (command=="+cleartemp") then
   ClearTempBan()
end
if (command=="+drop") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      tempuser=GetItemByName(victim)
      tempuser:Disconnect()
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: +drop username")
   end
end
if (command=="+ban") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      tempuser=GetItemByName(victim)
      tempuser:NickBan()
      tempuser:Ban()
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: +ban username")
   end
end
if (command=="+unban") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      Unban(victim)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: +unban username")
   end
end
if (command=="+chred") then
   arg=GetOneParam(message)
   frmHub:SetRedirectAddress(arg)
end
if (command=="+addvip") then
   vipname,vippass=GetTwoParam(message)
   if (vippass~=nil) then
      frmHub:AddRegUser(vipname,vippass,0)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: +addvip username password")
   end
end
if (command=="+removevip") then
   vipname=GetOneParam(message)
   if (vipname~=nil) then
      frmHub:DelRegUser(vipname)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: +removevip username")
   end
end
end
if (command==CommandMyIP) then
   curUser:SendPM(BotName, "Your IP is "..curUser.sIP)
end
if (command==CommandHelp) then
   ShowHelp(curUser)
end
if (command==ComandAway) then
   arg=GetOneParam(message)
SendToAll(BotName,date("User "..curUser.sName.." told us at %T that he is away, because of:")..arg.." ")
awayArray[curUser.sName]=arg
end
if (command==ComandBack) then
if (awayArray[curUser.sName]~=nil) then
awayArray[curUser.sName]=nil
SendToAll(BotName,date("User "..curUser.sName.." told us at %T that he is back"))
end
end
if (command=="+seen") then
   target=GetOneParam(message)
   if (seenArray[target]~=nil) then
      curUser:SendPM(BotName,seenArray[target])
   else
      curUser:SendPM(BotName,"The user "..target.." wasnt seen here .... ")
   end
end
if (command=="+time") then
   SendToAll(BotName, date("Today is %A the %D. Time is %T"))
end
--triggers
for key, value in trigs do
if( strfind( strlower(message), key) ) then
   SendToAll( BotName, value )
   break
   end
end
end


function Main()
frmHub:RegBot(BotName)
end
--[off]function OpConnected(curUser)
--[off]   ShowHelp(curUser)
--[off]end
function OpDisconnected(curUser)
seenArray[curUser.sName]=date(curUser.sName.." last seen at %d/%m/%Y %T .")
end
function NewUserConnected(curUser)
description,speed,email,share=ParseMyInfoString(curUser.sMyInfoString)
if (IsConnAllowed(speed)~=1) then
   curUser:SendPM(BotName,"Your connection-speed is not allowed in here -> disconnected"..IsConnAllowed(speed))
   curUser:Disconnect()
end
if (strfind(strlower(curUser.sName),"search")) then
   curUser:Disconnect()
end
CheckClientType(description)
if (IsDCPPCLient(description)==1)then
dcver, slots, hubs, bs=ParseDCPPDescription(description)
if (bs~=nil) then
if (tonumber(bs)<10) then
   curUser:SendPM(BotName,"You have a too less upload limit ....")
   curUser:Disconnect()
end
end
end
end
function UserDisconnected(curUser)
seenArray[curUser.sName]=date(curUser.sName.." last seen at %d/%m/%Y %T .")
end


function DataArrival(curUser,data)
local MessageRecognized = 0
if (isPM(data)==1) then
   whoto,from,message=ParsePM(data)
   MessageRecognized=1
if (awayArray[whoto]~= nil) then
curUser:SendPM(whoto,"I am currently away, because of: "..awayArray[whoTo])
end
end
if (isMCM(data)==1) then
   message=ParseMCM(data)
   from=curUser.sName
   whoto=BotName
   MessageRecognized=1
end
if ((MessageRecognized==1)and(whoto==BotName)) then
   HandleComand(curUser,message)
end
end



thanks,
pieltre
Title:
Post by: NoiZe on 11 March, 2004, 09:13:23
Hmmn.. I would like to have an upload limiter checker too  :(
Title:
Post by: Stravides on 11 March, 2004, 09:16:58
please try to remember to use the [ code ] and [ / code ] tags (no spaces)

Then the code retains its formatting :)
Many thanks - will take a look at the code once I can read it

please edit your post to include the tags and I will see what I can do...