failed to convert a dl blocker, need help to fix it please - Page 2
 

failed to convert a dl blocker, need help to fix it please

Started by blackwings, 04 June, 2005, 18:33:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bastya_elvtars

QuoteOriginally posted by Cid
if i change it like below it seems to work:

Cool! A new scripter! :D
Everything could have been anything else and it would have just as much meaning.

[UK]Madman

Without being able to test it, I cant see how
local _,_,nick = string.find(data,"%S+%s*(%S*)");
would work with the 2 different arrivals.


%s* = 0 or more occurances of a space

so this would still match the space after the command (connect or revconnect) so you would still capture the first occurance of non space characters (ok for connect, wrong with revconnect)

blackwings

#27
QuoteOriginally posted by [UK]Madman
Without being able to test it, I cant see how
local _,_,nick = string.find(data,"%S+%s*(%S*)")
would work with the 2 different arrivals.


%s* = 0 or more occurances of a space

so this would still match the space after the command (connect or revconnect) so you would still capture the first occurance of non space characters (ok for connect, wrong with revconnect)
lol, I did it on the wrong string.find, this is what I meant =
local _,_,nick = string.find(data,"%S+%s+%S+%s*(%S*)")
this should work :P

oh basty, change sBot to Bot if you want the bot regged properly ;)


bastya_elvtars

This abuses the fact that there can NOT be a : in a nick. However it will eat more CPU, because it does 2 pattern matchings, but it is safer on the other hand, because it will disconnect users sending corrupted connection requests. Untested.


--Simple DL blocker by nerbos
--Converted to LUA 5 by blackwings
--modding made by blackwings
--- ADDED: memory garbage collector = fixes memory problem - by blackwings
-- memleak fixed, bot data extended, script made smaller by bastya_elvtars (the rock n' roll doctor)
-- forgot the difference between CTM and RCTM, thx [UK]Madman
-- added an experimental new matcher

sBot =
  {
    Name="DLBlocker",
    Desc="Blocks connections to registered users from non-registered",
    Email="dlblocker@ptokax.exe",
  }
  
msg1 = "\r\n\r\n"
msg1 = msg1.."\t *** ----------------------------------------------- \r\n"
msg1 = msg1.."\t *** You can only download from Normal users (non-regged). You need to get registered to be able to download from others then normal users \r\n"
msg1 = msg1.."\t *** To become a registerd, you need to: \r\n"
msg1 = msg1.."\t *** %[1%] Share either 15 GB and the share should not break any rules \r\n"
msg1 = msg1.."\t *** %[2%] Only then you can ask a OP for registration \r\n"

-- do not edit below

function Main() 
  frmHub:RegBot(Bot.Name,1,Bot.Desc,Bot.Email)
end

function ConnectToMeArrival(user, data)
  data = string.sub(data,1,-2);
  local nick
  local _,_,arg1,arg2=string.find(data,"%S+%s+(%S+)%s+(%S+)")
  if arg1 then
    if string.find(arg2,":") then -- there is never : in a nick
      nick=arg1
    else
      nick=arg2
    end
    return ChkIfCanDL(user,nick)
  else
    user:SendData(sBot.Name,"You have a stupid client.")
    user:Disconnect()
    return 1
  end
end

RevConnectToMeArrival=ConnectToMeArrival

ChkIfCanDL=function (user,nick)
  nick = GetItemByName(nick);
  if not user.bRegistered then
    if nick and nick.bRegistered then 
      curUser:SendData(sBot,msg1)
      curUser:SendPM(sBot, msg1) 
      return 1
    end 
  end
end
Everything could have been anything else and it would have just as much meaning.

blackwings

#29
bastya, I think its better if there are 2 string.find, use something like this for the
accurate revconnect string.find(do you see what I changed?) =
local _,_,nick = string.find(data,"%S+%s+(%S+)%s+(%S+%:%d+)")
I changed this =
frmHub:RegBot(Bot.Name,1,Bot.Desc,Bot.Email)
to this (you had forgotten to change it) =
frmHub:RegBot(sBot.Name,1,sBot.Desc,sBot.Email)
Here is the code with the change + my revconnect string.find =
--Simple DL blocker by nerbos
--Converted to LUA 5 by blackwings
--modding made by blackwings
--- ADDED: memory garbage collector = fixes memory problem - by blackwings
-- memleak fixed, bot data extended, script made smaller by bastya_elvtars (the rock n' roll doctor)
-- forgot the difference between CTM and RCTM, thx [UK]Madman
--- CHANGED: fixed typos and improved the revconnect detection accuracy.

sBot =
  {
    Name="DLBlocker",
    Desc="Blocks connections to registered users from non-registered",
    Email="dlblocker@ptokax.exe",
  }
  
msg1 = "\r\n\r\n"
msg1 = msg1.."\t *** ----------------------------------------------- \r\n"
msg1 = msg1.."\t *** You can only download from Normal users (non-regged). You need to get registered to be able to download from others then normal users \r\n"
msg1 = msg1.."\t *** To become a registerd, you need to: \r\n"
msg1 = msg1.."\t *** %[1%] Share either 15 GB and the share should not break any rules \r\n"
msg1 = msg1.."\t *** %[2%] Only then you can ask a OP for registration \r\n"

-- do not edit below

function Main() 
	frmHub:RegBot(sBot.Name,1,sBot.Desc,sBot.Email)
end

function ConnectToMeArrival(curUser, data)
	data = string.sub(data,1,-2);
	local _,_,nick = string.find(data,"%S+%s+(%S+)");
	return ChkIfCanDL(curUser,nick)
end

function RevConnectToMeArrival(user,data)
	data = string.sub(data,1,-2);
	local _,_,nick = string.find(data,"%S+%s+(%S+)%s+(%S+%:%d+)");
	return ChkIfCanDL(curUser,nick)
end

ChkIfCanDL=function (user,nick)
	nick = GetItemByName(nick);
	if not curUser.bRegistered then
		if nick and nick.bRegistered then 
			curUser:SendData(sBot,msg1)
			curUser:SendPM(sBot, msg1) 
			return 1
		end 
	end
end


SMF spam blocked by CleanTalk