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

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.

blackwings

Hi
I need help to make this script work.
I tried to convert an old dl blocker script I used with the old ptokax.
Unfortunely it doesn't go so well, can anyone help me please???
sBot = "DLBlocker"

arrRC = {}

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"

function ConnectToMeArrival(curUser, Data)
	local _,_,towho = string.find(data, "$ConnectToMe%s+(%S+)%s+.*|")
	if curUser.iProfile == -1 then
		if (arrRC[curUser.sName] ~= nil) then
			arrRC[curUser.sName] = nil
		elseif (GetItemByName(towho) ~= nil and GetItemByName(towho).iProfile ~= -1) then 
			curUser:SendData(sBot,msg1)
			curUser:SendPM(sBot, msg1) 
			return 1
		end 
	end
end
        
function MultiConnectToMeArrival(curUser, Data)
--dunno what to do here.
end        

function RevConnectToMeArrival(curUser, Data)
	local _,_,towho = string.find(data, "$RevConnectToMe%s+%S+%s+(%S+)|") 
	if (curUser.iProfile == -1 and GetItemByName(towho) ~= nil and GetItemByName(towho).iProfile ~= -1) then 
		curUser:SendData(sBot,msg1)
		curUser:SendPM(sBot, msg1) 
		return 1
	elseif (towho ~= nil) then 
		arrRC[towho] = 1
	end
end


Dessamator

there are so many download blockers around, what's so special about that one??
Ignorance is Bliss.

jiten

Took this from a Upload blocker I made, that may help you:
function ConnectToMeArrival(curUser, data)
	data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+(%S+)");
	nick = GetItemByName(nick);
	if (nick == nil) then return 1; end
	if BlockedNicks[string.lower(nick.sName)] then
		if not curUser.bRegistered then
			curUser:SendData("*** The user "..nick.sName.." you are trying to download from is not authorized to upload to Unreg Users.")
			return 1
		end
	end
end

function RevConnectToMeArrival(curUser,data)
	data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+%S+%s+(%S+)");
	nick = GetItemByName(nick);
	if (curUser == nil) then return 1; end
	if BlockedNicks[string.lower(nick.sName)] then
		if not curUser.bRegistered then
			curUser:SendData("*** The user "..nick.sName.." you are trying to download from is not authorized to upload to Unreg Users.")
			return 1
		end
	end
end
Best regards

blackwings

QuoteOriginally posted by Dessamator
there are so many download blockers around, what's so special about that one??
because I haven't found any that does the same thing, but maybe I have missed one. I want a dl blocker that allows unregged users to download from other unregged users, but gets blocked when the unregged user tries to download from other profiles.


kepp

Get Guarding or get someone to strip download blocker out of it or use Chillas download blocker which i think does the same ;)
Guarding    

blackwings

#5
thanx to jiten, it almost works to 100%. one thing that isn't working is when a
passive mode unregged user tries to download from for example a OP,
they don't get the "block" msg, just gets disconnected. I think this error msg will help =  
[21:23] Syntax C:\ptokax\scripts\DLBlock.lua:31: bad argument #1 to `sub' (string expected, got nil)
Here is the new code =
sBot = "DLBlocker"

arrRC = {}

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"

function ConnectToMeArrival(curUser, data)
	data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+(%S+)");
	nick = GetItemByName(nick);
	if curUser.iProfile == -1 then
		if (arrRC[curUser.sName] ~= nil) then
			arrRC[curUser.sName] = nil
		elseif (nick~=nil and nick.iProfile ~= -1) then 
			curUser:SendData(sBot,msg1)
			curUser:SendPM(sBot, msg1) 
			return 1
		end 
	end
end

function RevConnectToMeArrival(curUser, Data)
	data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+%S+%s+(%S+)");
	nick = GetItemByName(nick);
	if (curUser.iProfile == -1 and nick~=nil and nick.iProfile ~= -1) then
		curUser:SendData(sBot,msg1)
		curUser:SendPM(sBot, msg1) 
		return 1
	elseif (nick ~= nil) then 
		arrRC[towho] = 1
	end
end


jiten

Replace this:
function RevConnectToMeArrival(curUser, Data)

with:
function RevConnectToMeArrival(curUser, data)
That should solve it ;)

Best regards

blackwings

#7
QuoteOriginally posted by jiten
Replace this:
function RevConnectToMeArrival(curUser, Data)

with:
function RevConnectToMeArrival(curUser, data)
That should solve it ;)

Best regards
thanx jiten, I didn't see that ;) + I missed this to =
arrRC[towho] = 1
should be this =
arrRC[nick] = 1
anyway it seems to work now :D


jiten

Nice to know that you sorted it out.

Best regards

Cid

uhm. what can i do so that the above script doesnt eat up my memory? after running it a day my ptokax uses like 200MB memory... very weird never had that with other scripts.

blackwings

#10
QuoteOriginally posted by Cid
uhm. what can i do so that the above script doesnt eat up my memory? after running it a day my ptokax uses like 200MB memory... very weird never had that with other scripts.
Try this =
--Simple DL blocker by nerbos
--Converted to LUA 5 by blackwings
--modding made by blackwings
--- ADDED: memory garbage collector = fixes memory problem - by blackwings

sBot = "DLBlocker"

arrRC = {}

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"

function Main() 
	SetTimer(20000) -- empty garbage memory every 20 seconds
	StartTimer()
end

function OnTimer(user)
	collectgarbage(); io.flush();
end

function ConnectToMeArrival(curUser, data)
	local data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+(%S+)");
	local nick = GetItemByName(nick);
	if curUser.iProfile == -1 then
		if (arrRC[curUser.sName] ~= nil) then
			arrRC[curUser.sName] = nil
		elseif (nick~=nil and nick.iProfile ~= -1) then 
			curUser:SendData(sBot,msg1)
			curUser:SendPM(sBot, msg1) 
			return 1
		end 
	end
end



function RevConnectToMeArrival(curUser, data)
	local data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+%S+%s+(%S+)");
	local nick = GetItemByName(nick);
	if (curUser.iProfile == -1 and nick~=nil and nick.iProfile ~= -1) then
		curUser:SendData(sBot,msg1)
		curUser:SendPM(sBot, msg1) 
		return 1
	elseif (nick ~= nil) then 
		arrRC[nick] = 1
	end
end


Cid

its eating up slower now. but still 10MB already after an hour.
the garbage collector threshold doesnt get cleaned. its setting itself higher as soon as the memory usage reaches the threshold amount...

Dessamator

data = string.sub(data,1,-2);
nick = GetItemByName(nick);


This two variables should be local, and another thing some of the code in ur ConnectToMeArrival, is the same as the code in ur RevconnectToMeArrival, maybe u should use a function to decrease the repition.
Ignorance is Bliss.

blackwings

#13
QuoteOriginally posted by Dessamator
data = string.sub(data,1,-2);
nick = GetItemByName(nick);


This two variables should be local, and another thing some of the code in ur ConnectToMeArrival, is the same as the code in ur RevconnectToMeArrival, maybe u should use a function to decrease the repition.
I haven't tested this, but I did what you said ;) =
--Simple DL blocker by nerbos
--Converted to LUA 5 by blackwings
--modding made by blackwings
--- ADDED: memory garbage collector = fixes memory problem - by blackwings
-- CHANGED: made the script more compact = less repition

sBot = "DLBlocker"

arrRC = {}

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"

function Main() 
	SetTimer(20000) -- empty garbage memory every 20 seconds
	StartTimer()
end

function OnTimer(user)
	collectgarbage(); io.flush();
end

function ConnectToMeArrival(curUser, data)
	local ConnectType = 1
	return Dlblocking(curUser,data,ConnectType)
end

function RevConnectToMeArrival(curUser, data)
	local ConnectType = 2
	return Dlblocking(curUser,data,ConnectType)
end

function Dlblocking(curUser,data,ConnectType)
	local data = string.sub(data,1,-2);
	local s,e,nick = string.find(data,"%S+%s+%S+%s+(%S+)");
	local nick = GetItemByName(nick);
	if ConnectType = 1 then
		if curUser.iProfile == -1 then
			if (arrRC[curUser.sName] ~= nil) then
				arrRC[curUser.sName] = nil
			elseif (nick~=nil and nick.iProfile ~= -1) then 
				curUser:SendData(sBot,msg1)
				curUser:SendPM(sBot, msg1) 
				return 1
			end 
		end	
	else
		if (curUser.iProfile == -1 and nick~=nil and nick.iProfile ~= -1) then
			curUser:SendData(sBot,msg1)
			curUser:SendPM(sBot, msg1) 
			return 1
		elseif (nick ~= nil) then 
			arrRC[nick] = 1
		end
	end
end


bastya_elvtars

#14
QuoteOriginally posted by Dessamator
data = string.sub(data,1,-2);
nick = GetItemByName(nick);


This two variables should be local

Function arguments (here: user and data) are always local, also nick has already been declared as local, and local variables have always higher precedence over globals of the same name, so this is not a problem.

The garbage collection is automatic in LUA.

--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)


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(curUser, data)
  data = string.sub(data,1,-2);
  local _,_,nick = string.find(data,"%S+%s+(%S+)");
  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

ConnectToMeArrival=RevConnectToMeArrival

-- // edit

I just do not get why you don't look at the wiki, there are pages describing tables and the LUA API either.
Everything could have been anything else and it would have just as much meaning.

blackwings

QuoteOriginally posted by bastya_elvtars
What is arrRC for?
I dunno, I wasn't the one that origianlly made this script, but I guess it has it purpose
QuoteOriginally posted by bastya_elvtars
-- // edit

I just do not get why you don't look at the wiki, there are pages describing tables and the LUA API either.
what do you mean? that I didn't use locals and the script wasn't compact?
the script is just an conversion + some modding and I did this a long time ago,
just made more changes now when Cid complained about the memory usage.


Anyway, I see your compact version is very different, are you sure it completly works??
Just asking this because you use the code from the ConnectToMeArrival for the both arrivals.
If you check the script above, the code in the two arrivals works differently.
Which I believe serve a certain purpose, or maybe Im wrong, Nerbos is a skilled lua programmer.


bastya_elvtars

It did the following: it added the users who had a passive connection request to a table and removed when they had an active one. Which does not seem to make sense for me. The above code I posted should work, and the memory leak has been fixed. Edited the above.
Everything could have been anything else and it would have just as much meaning.

Cid

DLBlocker.lua:50: attempt to index global `arrRC' (a nil value)

except for that it all works great. mem leak fixed. so if anyone would be so kind to think about a way to remove that script error i would be very greatful
:D

bastya_elvtars

QuoteOriginally posted by Cid
DLBlocker.lua:50: attempt to index global `arrRC' (a nil value)

except for that it all works great. mem leak fixed. so if anyone would be so kind to think about a way to remove that script error i would be very greatful
:D

Sorry, fixed, now it checks passive users too. :D
Everything could have been anything else and it would have just as much meaning.

[UK]Madman

As Jiten's example earlier shows, you cant use one string.find for both Connect and RevConnect.

The username you are trying to connect to are in different positions:

$RevConnectToMe  
$ConnectToMe  :

bastya_elvtars

#20
--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

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(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+)");
  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

Haven't tested this, too. Thx for pointing that out.
Everything could have been anything else and it would have just as much meaning.

Cid

DLBlocker.lua:38: attempt to index global `curUser' (a nil value)

almost there :)

Cid

#22
if i change it like below it seems to work:

-- do not edit below

function Main()
  frmHub:RegBot(sBot)
end

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

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

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

blackwings

QuoteOriginally posted by [UK]Madman
As Jiten's example earlier shows, you cant use one string.find for both Connect and RevConnect.

The username you are trying to connect to are in different positions:

$RevConnectToMe  
$ConnectToMe  :
I haven't still tested bastys version of the dlblocker, but when it comes to the string.find problem, its easily fixed like this =

Change this line =
 local _,_,nick = string.find(data,"%S+%s+(%S+)");
To this =
 local _,_,nick = string.find(data,"%S+%s*(%S*)");


Cid

okay. tested it as normal user and with regged user account. works fine now. thanks to all you kind people who helped out.
i really appreciate this.
:)

SMF spam blocked by CleanTalk