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
there are so many download blockers around, what's so special about that one??
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
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.
Get Guarding or get someone to strip download blocker out of it or use Chillas download blocker which i think does the same ;)
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
Replace this:
function RevConnectToMeArrival(curUser, Data)
with:
function RevConnectToMeArrival(curUser, data)
That should solve it ;)
Best regards
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
Nice to know that you sorted it out.
Best regards
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.
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
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...
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.
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
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.
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.
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.
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
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
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 :
--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.
DLBlocker.lua:38: attempt to index global `curUser' (a nil value)
almost there :)
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
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*)");
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.
:)
QuoteOriginally posted by Cid
if i change it like below it seems to work:
Cool! A new scripter! :D
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)
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 ;)
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
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