problem with Signs in my script
 

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

problem with Signs in my script

Started by blackwings, 19 February, 2005, 12:01:38

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

blackwings

I'm making my own anti advertise script just for fun.

It all work except for the thing that I want my script to detect all kinds of signs that might be used in advertise.

As you see in the code below, I have tried several things, but I can't get it to work anyway. So could anyone please help me?
--Advertise Crusher by blackwings
--v0.4

Bot = "#Anti-Advertise"

function Main() 
end

antiAdver = {
{"bummer","com"},
{"super","net"},
}

tMSigns = {
{"?"},
{"?"},
{"?"},
{"?"},
{"#"},
{"!"},
{"@"},
{"$"},
{"%"},
{"^"},
{"&"},
{"*"},
{"_"},
{"-"},
{"="},
{"+"},
{"?"},
}

--tMSigns = {
--	"?","?","?","?","#","!","@","$","%","^","&","*","_","-","=","+","?"
--}

function DataArrival(user,data,sData)
	for i=1,getn(antiAdver) do
	--	for b=1,getn(tMSigns) do
			antiAdver[i][1] = gsub(antiAdver[i][1], "<" , "")
			local tPart01 = antiAdver[i][1]
			local tPart02 = (%p)
			-- local tPart02 = tMSigns[b][1]
			local tPart03 = antiAdver[i][2]

			-- local advDetect = tPart01..tPart03
			-- local advDetect = tPart01..tPart02..tPart03
			local advDetect = tPart01.."%S"..tPart03



			local word2nd = ardkngadrngarkjgdar

			if( strfind(data, advDetect,1,1))  then
					-- if not user.bOperator then
						SendToAll(Bot, "Dont advertise")	
					-- end
			end

			if(strsub(data, 1, 4) == "$To:") then
				if( strfind(data, advDetect,1,1) ) then
					-- if not user.bOperator then
						SendToAll(Bot, "Dont advertise")	
					-- end
				end
			end
			collectgarbage()
	--	end
	end
end


bastya_elvtars

You are using magic chars without escape. If you use those standalone, they will act as "regular expressions." Use them with % before them.  See how:

tMSigns = {

"%?","%?","%?","%?","%#","%!","%@","%$","%%","%^","%&","%*","%_","%-","%=","%+","%?"

}

OK, it's unnecessary to put it before all, but it's recommended to use an escape before any non-alphanumeric character. This is from LUA4 book:

QuoteSome characters, called magic characters, have special meanings when used
in a pattern. The magic characters are
( ) . % + - * ? [ ^ $
The character % works as an escape for those magic characters. So, %. matches
a dot, and %% matches the % itself. You can use the escape % not only for the
magic characters, but for any non alphanumeric character. When in doubt, play
safe and put an escape.
Everything could have been anything else and it would have just as much meaning.

blackwings

#2
My script works now :D  Now I shall just fix a safe advertise function :)

btw bastya_elvtars, % infront of a non-alphanumeric character in my script doesn't work.

--Advertise Crusher by blackwings
--v1.0

Bot = "#Anti-Advertise"

function Main() 
end

-- Check the bottom of the script to find different dns that this script can detect

adverKill = 3

tMSigns = {
{"?"},
{"?"},
{"?"},
{"?"},
{"#"},
{"!"},
{"@"},
{"$"},
{"%"},
{"^"},
{"&"},
{"*"},
{"_"},
{"-"},
{"="},
{"+"},
{"."},
{"?"},
}

adverCounter = 0

function adverSmashing(user)
	if not user.bOperator then
		adverCounter = adverCounter + 1
		tmpBanLeft = adverKill - adverCounter
		if adverCounter < adverKill then
			user:SendData(Bot, "You are tempbanned because of advertiseing.")
			user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
			user:TempBan()
		elseif adverKill == adverKill then
			user:SendData(Bot, "You are PERMBANNED because of advertiseing")
			user:Ban()
			adverCounter = 0
		end
	end
	collectgarbage()
end


function DataArrival(user,data)
	for i=1,getn(antiAdver) do
		antiAdver[i][1] = gsub(antiAdver[i][1], "<" , "")
			tPart01 = antiAdver[i][1]
			tPart03 = antiAdver[i][2]
		for b=1,getn(tMSigns) do
			tMSigns[b][1] = gsub(tMSigns[b][1], "<" , "")
			tPart02 = tMSigns[b][1]
				local advDetect = tPart01..tPart02..tPart03
			if( strfind(data, advDetect,1,1))  then
				return adverSmashing(user)
			end
			if(strsub(data, 1, 4) == "$To:") then
				if( strfind(data, advDetect,1,1) ) then
					return adverSmashing(user)
				end
			end

		end
	end
	collectgarbage()
end

antiAdver = {
{"no-ip","com"},
{"no-ip","org"},
{"no-ip","info"},
{"no-ip","biz"},
{"no-ip","co.uk"},
{"mine","nu"},
{"sytes","net"},
{"dynip","com"},  -- not sure if it should be .com or .org etc	
{"dyndns","org"},
{"dyndns","info"},
{"dyndns","biz"},
{"gotdns","com"},
{"gotdns","org"},
{"kicks-ass","net"},
{"kicks-ass","org"},
{"d2g","org"},    -- not sure if it should be .com or .org etc
{"serveftp","com"},
{"serveftp","org"},
{"serveftp","net"},
{"servehttp","com"},
{"servehalflife","com"},
{"servequake","com"},
{"servecounterstrike","com"},
{"xs4all","com"}, -- not sure if it should be .com or .org etc
{"myftp","biz"}, 
{"myftp","org"},  
{"servebeer","com"}, 
{"zapto","org"},
{"tropico","com"}, -- not sure if it should be .com or .org etc
{"lysekil","net"}, -- not sure if it should be .com or .org etc
{"udgnet","com"}, -- not sure if it should be .com or .org etc
{"dnsalias","net"},
{"dnsalias","com"},
{"dnsalias","org"},
{"dynalias","net"},
{"dynalias","com"},
{"dynalias","org"},
{"ath","cx"},
{"homeip","net"},
{"servemp3","com"}, 
{"hopto","org"}, 
{"servegame","org"},
{"staticip","com"}, -- not sure if it should be .com or .org etc
{"orgdns","com"}, -- not sure if it should be .com or .org etc
{"myftpsite","com"}, -- not sure if it should be .com or .org etc
{"ipactive","com"}, -- not sure if it should be .com or .org etc
{"idlegames","com"}, -- not sure if it should be .com or .org etc
{"homeunix","com"},
{"homeunix","net"},
{"homeunix","org"},
{"homelinux","com"},
{"homelinux","net"},
{"homelinux","org"},
{"flamenap","com"}, -- not sure if it should be .com or .org etc
{"dns2go","org"}, -- not sure if it should be .com or .org etc
{"clanpimp","com"}, -- not sure if it should be .com or .org etc
{"bounceme","net"}, 
{"ip","biz"},
{"uni","cc"},
{"is-a-geek","com"},
{"is-a-geek","org"},
{"is-a-geek","net"},
{"isa-geek","com"},
{"isa-geek","org"},
{"isa-geek","net"},
}


blackwings

#3
Added a safe advertisment function.

I will be happy to get any comments on how to make it better :)

EDIT: lol, I tested to advertise in my testhub with both my script and RoboCop 0.9g, my script was faster on detecting and take action.
--Advertise Crusher by blackwings
--v1.5
--functions: 
--	anti-advertise - detect and tempban 
--	safe advertise - so you can type the hubs own adress
--	Counter	       - aka adverKill, in default it bans after 3 tempbans
--	Many Signs     - can detect advertisment that use different signs then "."
--      Tempban left   - how many tempbans a user has before permban
-----------
--added: safe advertisment
-----------

Bot = "#Anti-Advertise"

function Main() 
end

-- Check the bottom of the script to see what it can detect
-- Do also check the bottom of the script for the safe advertising settings

adverKill = 3

tMSigns = {
{"?"},
{"?"},
{"?"},
{"?"},
{"#"},
{"!"},
{"@"},
{"$"},
{"%"},
{"^"},
{"&"},
{"*"},
{"_"},
{"-"},
{"="},
{"+"},
{"."},
{"?"},
}

adverCounter = 0

function adverSmashing(user)
	if not user.bOperator then
		adverCounter = adverCounter + 1
		tmpBanLeft = adverKill - adverCounter
		if adverCounter < adverKill then
			user:SendData(Bot, "You are tempbanned because of advertiseing.")
			user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
			user:TempBan()
		elseif adverKill == adverKill then
			user:SendData(Bot, "You are PERMBANNED because of advertiseing")
			user:Ban()
			adverCounter = 0
		end
	end
	collectgarbage()
end


function DataArrival(user,data)
	for i=1,getn(antiAdver) do
		antiAdver[i][1] = gsub(antiAdver[i][1], "<" , "")
			tPart01 = antiAdver[i][2]
			tPart03 = antiAdver[i][3]
			safeAdv = antiAdver[i][1]
		for b=1,getn(tMSigns) do
			tMSigns[b][1] = gsub(tMSigns[b][1], "<" , "")
			tPart02 = tMSigns[b][1]
				local advDetect = tPart01..tPart02..tPart03
			if( strfind(data, advDetect,1,1))  then
				if( strfind(data, safeAdv,1,1))  then
					return nil
				end
				return adverSmashing(user)
			end
			if(strsub(data, 1, 4) == "$To:") then
				if( strfind(data, advDetect,1,1) ) then
					if( strfind(data, safeAdv,1,1))  then
						return nil
					end
					return adverSmashing(user)
				end
			end

		end
	end
	collectgarbage()
end

-- To add a safe advertise adress, add the first part of your adress 
-- to the first field infront of the correct DNS.
-- Example: your adress is test.no-ip.org, then replace "xxxxxxx" with "test" 
-- in {"xxxxxxx","no-ip","org"},

antiAdver = {
{"test","no-ip","com"},
{"xxxxxxx","no-ip","org"},
{"xxxxxxx","no-ip","info"},
{"xxxxxxx","no-ip","biz"},
{"xxxxxxx","no-ip","co.uk"},
{"xxxxxxx","mine","nu"},
{"xxxxxxx","sytes","net"},
{"xxxxxxx","dynip","com"},  -- not sure if it should be .com or .org etc	
{"xxxxxxx","dyndns","org"},
{"xxxxxxx","dyndns","info"},
{"xxxxxxx","dyndns","biz"},
{"xxxxxxx","gotdns","com"},
{"xxxxxxx","gotdns","org"},
{"xxxxxxx","kicks-ass","net"},
{"xxxxxxx","kicks-ass","org"},
{"xxxxxxx","d2g","org"},    -- not sure if it should be .com or .org etc
{"xxxxxxx","serveftp","com"},
{"xxxxxxx","serveftp","org"},
{"xxxxxxx","serveftp","net"},
{"xxxxxxx","servehttp","com"},
{"xxxxxxx","servehalflife","com"},
{"xxxxxxx","servequake","com"},
{"xxxxxxx","servecounterstrike","com"},
{"xxxxxxx","xs4all","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","myftp","biz"}, 
{"xxxxxxx","myftp","org"},  
{"xxxxxxx","servebeer","com"}, 
{"xxxxxxx","zapto","org"},
{"xxxxxxx","tropico","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","lysekil","net"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","udgnet","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","dnsalias","net"},
{"xxxxxxx","dnsalias","com"},
{"xxxxxxx","dnsalias","org"},
{"xxxxxxx","dynalias","net"},
{"xxxxxxx","dynalias","com"},
{"xxxxxxx","dynalias","org"},
{"xxxxxxx","ath","cx"},
{"xxxxxxx","homeip","net"},
{"xxxxxxx","servemp3","com"}, 
{"xxxxxxx","hopto","org"}, 
{"xxxxxxx","servegame","org"},
{"xxxxxxx","staticip","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","orgdns","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","myftpsite","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","ipactive","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","idlegames","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","homeunix","com"},
{"xxxxxxx","homeunix","net"},
{"xxxxxxx","homeunix","org"},
{"xxxxxxx","homelinux","com"},
{"xxxxxxx","homelinux","net"},
{"xxxxxxx","homelinux","org"},
{"xxxxxxx","flamenap","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","dns2go","org"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","clanpimp","com"}, -- not sure if it should be .com or .org etc
{"xxxxxxx","bounceme","net"}, 
{"xxxxxxx","ip","biz"},
{"xxxxxxx","uni","cc"},
{"xxxxxxx","is-a-geek","com"},
{"xxxxxxx","is-a-geek","org"},
{"xxxxxxx","is-a-geek","net"},
{"xxxxxxx","isa-geek","com"},
{"xxxxxxx","isa-geek","org"},
{"xxxxxxx","isa-geek","net"},
}


Optimus

QuoteI will be happy to get any comments on how to make it better :)

EDIT: lol, I tested to advertise in my testhub with both my script and RoboCop 0.9g, my script was faster on detecting and take action.
There we go again, i though we had this conversation allready with a other script of you lol

Do you really think things are that easy hehe

It has nothing todo with speed (check other thread about allowed clients script you made), and second mine is faster cause yours uses loops and mine is hashed. (without loops)

Your way to fast making your conclusiens

LOOOLlllllll :D

blackwings

QuoteOriginally posted by Optimus
QuoteI will be happy to get any comments on how to make it better :)

EDIT: lol, I tested to advertise in my testhub with both my script and RoboCop 0.9g, my script was faster on detecting and take action.
There we go again, i though we had this conversation allready with a other script of you lol

Do you really think things are that easy hehe

It has nothing todo with speed (check other thread about allowed clients script you made), and second mine is faster cause yours uses loops and mine is hashed. (without loops)

Your way to fast making your conclusiens

LOOOLlllllll :D
ok, sorry for makeing such comment :P

Why is hashed better then loop, if loop works faster??
Just curious, because you said that your faster even if my detects och take action faster.

And if you have time, could you show a code example on the difference between loop and hash?

I'm always intresting to learn, even if I'm  not so often program in lua :)


Optimus

well m8 i have tested your script and i have found the reason why yours seems tobe faster.

Call your script z.lua and yours will take action
Call your script 1.lua and mine will take action

So simple is it.

- Optimus

bastya_elvtars

#7
QuoteOriginally posted by blackwings

btw bastya_elvtars, % infront of a non-alphanumeric character in my script doesn't work.

OK, i see. I thought you are using strfind or something like it. Nice work btw, just 1 question: why do you use the
tMSigns = {

{"?"},

{"?"},

{"?"},

{"?"},

{"#"},

{"!"},

{"@"},

{"$"},

{"%"},

{"^"},

{"&"},

{"*"},

{"_"},

{"-"},

{"="},

{"+"},

{"."},

{"?"},

}

such a way, when
tMSigns = {"a","b","c", --etc.
}

would be enough?

BTW i really like the solution you made for it. Keep up the good work!

-- // edit

btw opti is right: hashing is faster and less resource consumant, your script is only faster because it processes the data before RoboCop, this has nothing to do with speed, this depends on the order of the scripts.
Everything could have been anything else and it would have just as much meaning.

blackwings

#8
QuoteOriginally posted by bastya_elvtars
OK, i see. I thought you are using strfind or something like it. Nice work btw, just 1 question: why do you use the
tMSigns = {
{"?"},
{"?"},
}
such a way, when
tMSigns = {"a","b","c", --etc.
}
would be enough?
well, after the time I started this thread and asked for help,  this method was the one I used when I made it work. I didn't really think about that other types of tables might be faster/better. Is the one you showed faster?
QuoteOriginally posted by bastya_elvtars
hashing is faster and less resource consumant
Could you show a code example of how hashing works bastya_elvtars? Maybe then I could modify my script to use hashing instead of loops.


bastya_elvtars

-- this is an example

table={

["a"]=1, -- [key]=value 

["b"]=1,

["c"]=1,

-- etc.
}

-- now lets see hashing

function WeHaveAStringValue(val)

if table[val] then --if the string is in the table
-- dothingshere
end

end

You are using an array. Array is:

arr={"a","b"}


which is considered by lua as if it were

arr={[1]="a", [2]="b"}

thus in an array you only list the values, but in tables you do hashing using the [keys] and it's a pity keys are always ascending numbers in arrays. What i recommend is to run a loop on the array(s) you use and insert its elements into a table. Thus your script remains well-configurable still fast on the cost of a little more ram usage.

array={"a","b","c","d"} --declare aray elements
table={} --create empty table
for a=1,getn(array) do -- do a loop consisting of  repeats
table[array[a]]=1 -- a-th element of array becomes a key in the table with value 1
end
Everything could have been anything else and it would have just as much meaning.

blackwings

#10
QuoteOriginally posted by bastya_elvtars
array={"a","b","c","d"} --declare aray elements
table={} --create empty table
for a=1,getn(array) do -- do a loop consisting of  repeats
table[array[a]]=1 -- a-th element of array becomes a key in the table with value 1
end
I must have misundertood your example, because this doesn't work =>
--Advertise Crusher by blackwings
--v2.0
--functions: 
--	anti-advertise - detect and tempban 
--	safe advertise - so you can type the hubs own adress
--	Counter	       - aka adverKill, in default it bans after 3 tempbans
--	Many Signs     - can detect advertisment that use different signs then "."
--      Tempban left   - how many tempbans a user has before permban
-----------
--added: safe advertisment
--added: pm to ops
--added: improved what the script detects
--added: profiles that the script should take action against
--fixed: a copy mistake
--changed: from typical loops to hashing = faster
-----------

Bot = "#Anti-Advertise"

function Main() 
end

--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Check the bottom of the script to see what it can detect
-- Do also check the bottom of the script for the safe advertising settings
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- (1)Shall be tempbanned/banned / (0) this profile shouldn't be effected.
SetToWho = {
[0] = 0, -- Masters
[1] = 0, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
[-1] = 1, -- Users
}

adverKill = 3

DNS01={"super","mega","nova","hellfire"}
MSigns={".","-","?","+"}
DNS02={"com","net","org","nu"}

tDNS01={}
tMSigns={}
tDNS02={}


adverCounter = 0

function adverSmashing(user)
	if SetToWho[user.iProfile]==1 then
		adverCounter = adverCounter + 1
		tmpBanLeft = adverKill - adverCounter
		if adverCounter < adverKill then
			user:SendData(Bot, "You are tempbanned because of advertiseing.")
			user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
		--	user:TempBan()
			SendPmToOps(Bot, "User <"..user.sName.."> was tempbanned for advertising, wrote = "..advDetect)
		elseif adverCounter == adverKill then
			user:SendData(Bot, "You are PERMBANNED because of advertiseing")
		--	user:Ban()
			SendPmToOps(Bot, "User <"..user.sName.."> was PERMBANNED for advertising, wrote = "..advDetect)
			adverCounter = 0
		end
	end
	collectgarbage()
end


function DataArrival(user,data)
	for a=1,getn(DNS01) do
		tDNS01[DNS01[a]]=1
			tPart02 = tDNS01[DNS01[a]]==1
		for b=1,getn(MSigns) do
			tMSigns[MSigns[b]]=1
				tPart01 = tMSigns[MSigns[b]]==1
				tPart03 = tMSigns[MSigns[b]]==1
			for c=1,getn(DNS02) do
				tDNS02[DNS02[c]]=1
					tPart04 = tDNS02[DNS02[c]]==1
					user:SendData(Bot, "this was typed = "..tPart04)
				advDetect = tPart01..tPart02..tPart03..tPart04
				if( strfind(data, advDetect,1,1))  then
				
					return adverSmashing(user)
				end
				if(strsub(data, 1, 4) == "$To:") then
					if( strfind(data, advDetect,1,1) ) then
						return adverSmashing(user)
					end
				end
			end
		end
	end
	collectgarbage()
end


Optimus

Quotearray={"a","b","c","d"} --declare aray elements
table={} --create empty table
for a=1,getn(array) do -- do a loop consisting of repeats
table[array[a]]=1 -- a-th element of array becomes a key in the table with value 1
end
i think he ment you should put it in function main()

bastya_elvtars

QuoteOriginally posted by Optimus
Quotearray={"a","b","c","d"} --declare aray elements
table={} --create empty table
for a=1,getn(array) do -- do a loop consisting of repeats
table[array[a]]=1 -- a-th element of array becomes a key in the table with value 1
end
i think he ment you should put it in function main()

No, this was a general lua tutorial. :)
And yes, it should be in Main() - sorry if I forgot to mention - and thx, Opti.
Everything could have been anything else and it would have just as much meaning.

blackwings

QuoteOriginally posted by bastya_elvtars
QuoteOriginally posted by Optimus
Quotearray={"a","b","c","d"} --declare aray elements
table={} --create empty table
for a=1,getn(array) do -- do a loop consisting of repeats
table[array[a]]=1 -- a-th element of array becomes a key in the table with value 1
end
i think he ment you should put it in function main()
No, this was a general lua tutorial. :)
And yes, it should be in Main() - sorry if I forgot to mention - and thx, Opti.
All of it, or just some of it?


bastya_elvtars

#14
This is the whole method to insert array intems into a table for further usage.

-- // edit

see this thread, i exactly made the way i explained.
Everything could have been anything else and it would have just as much meaning.

blackwings

#15
Hmm, still doesn't work. I get this error message =
Syntax error: table index is nil
stack traceback:
   1:  function `DataArrival' at line 82 [file `C:\ptokax\scripts\AdvertiseCrusher2_0.lua']
Either something is missing in the script or this is wrong =
tPart01 = tMSigns[MSigns[b]]==1
	tPart02 = tDNS01[DNS01[a]]==1
	tPart03 = tMSigns[MSigns[b]]==1
	tPart04 = tDNS02[DNS02[c]]==1
Here is the rest of the code =
--Advertise Crusher by blackwings
--v2.0
--functions: 
--	anti-advertise - detect and tempban 
--	safe advertise - so you can type the hubs own adress
--	Counter	       - aka adverKill, in default it bans after 3 tempbans
--	Many Signs     - can detect advertisment that use different signs then "."
--      Tempban left   - how many tempbans a user has before permban
-----------
--added: safe advertisment
--added: pm to ops
--added: improved what the script detects
--added: profiles that the script should take action against
--fixed: a copy mistake
--changed: from typical loops to hashing = faster
-----------

Bot = "#Anti-Advertise"

--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Check the bottom of the script to see what it can detect
-- Do also check the bottom of the script for the safe advertising settings
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- (1)Shall be tempbanned/banned / (0) this profile shouldn't be effected.
SetToWho = {
[0] = 0, -- Masters
[1] = 0, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
[-1] = 1, -- Users
}

adverKill = 3

DNS01={"super","mega","nova","hellfire"}
MSigns={".","-","?","+"}
DNS02={"com","net","org","nu"}

tDNS01={}
tMSigns={}
tDNS02={}


adverCounter = 0

function Main() 
	for a=1,getn(DNS01) do
		tDNS01[DNS01[a]]=1
	end
	for b=1,getn(MSigns) do
		tMSigns[MSigns[b]]=1
	end
	for c=1,getn(DNS02) do
		tDNS02[DNS02[c]]=1
	end
end

function adverSmashing(user)
	if SetToWho[user.iProfile]==1 then
		adverCounter = adverCounter + 1
		tmpBanLeft = adverKill - adverCounter
		if adverCounter < adverKill then
			user:SendData(Bot, "You are tempbanned because of advertiseing.")
			user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
		--	user:TempBan()
			SendPmToOps(Bot, "User <"..user.sName.."> was tempbanned for advertising, wrote = "..advDetect)
		elseif adverCounter == adverKill then
			user:SendData(Bot, "You are PERMBANNED because of advertiseing")
		--	user:Ban()
			SendPmToOps(Bot, "User <"..user.sName.."> was PERMBANNED for advertising, wrote = "..advDetect)
			adverCounter = 0
		end
	end
	collectgarbage()
end


function DataArrival(user,data)
	tPart01 = tMSigns[MSigns[b]]==1
	tPart02 = tDNS01[DNS01[a]]==1
	tPart03 = tMSigns[MSigns[b]]==1
	tPart04 = tDNS02[DNS02[c]]==1
		advDetect = tPart01..tPart02..tPart03..tPart04
			if( strfind(data, advDetect,1,1))  then
				return adverSmashing(user)
			end
			if(strsub(data, 1, 4) == "$To:") then
				if( strfind(data, advDetect,1,1) ) then
					return adverSmashing(user)
				end
			end
			collectgarbage()
end


bastya_elvtars

I do not understand your way of declaring those things. Please explain. :)


function DataArrival(user,data)
--     ||	         				       ||
----  \/ ==== what the hell is this for? :P \/ ==== -----

	tPart01 = tMSigns[MSigns[b]]==1
	tPart02 = tDNS01[DNS01[a]]==1
	tPart03 = tMSigns[MSigns[b]]==1
	tPart04 = tDNS02[DNS02[c]]==1

---- /\ ==== what the hell is this for? :P /\ ==== -----
----  ||                                                      ||
 		advDetect = tPart01..tPart02..tPart03..tPart04
			if( strfind(data, advDetect,1,1))  then
				return adverSmashing(user)
			end
			if(strsub(data, 1, 4) == "$To:") then
				if( strfind(data, advDetect,1,1) ) then
					return adverSmashing(user)
				end
			end
			collectgarbage()
end
Everything could have been anything else and it would have just as much meaning.

blackwings

#17
QuoteOriginally posted by bastya_elvtars
I do not understand your way of declaring those things. Please explain. :)
well, my script search for "advDetect" =>
if( strfind(data, advDetect,1,1))  then
which is this =>
advDetect = tPart01..tPart02..tPart03..tPart04
tPart01-04 is the different part of DNS the script looks for
tPart01 = dot/sign
tPart02 = the middle part of a DNS
tPart03 = dot/sign
tPart04 = the extensions, you now, .com and .org
Thats why I try to declare each array to tPart01-04.


bastya_elvtars

But where do a, b and c come from?
Everything could have been anything else and it would have just as much meaning.

blackwings

QuoteOriginally posted by bastya_elvtars
But where do a, b and c come from?
from here =>
function Main() 
	for a=1,getn(DNS01) do
		tDNS01[DNS01[a]]=1
	end
	for b=1,getn(MSigns) do
		tMSigns[MSigns[b]]=1
	end
	for c=1,getn(DNS02) do
		tDNS02[DNS02[c]]=1
	end
end


bastya_elvtars

You have to do the loop again in DataArrival as the lifetime of a, b, and c is only inside Main()
Everything could have been anything else and it would have just as much meaning.

blackwings

#21
QuoteOriginally posted by bastya_elvtars
You have to do the loop again in DataArrival as the lifetime of a, b, and c is only inside Main()
ok, now my script do the thing in main() and I have loops in DataArrival. The script works, but I don't think it's hashing, so something is still missing =
--Advertise Crusher by blackwings
--v2.0
--functions: 
--	anti-advertise - detect and tempban 
--	safe advertise - so you can type the hubs own adress
--	Counter	       - aka adverKill, in default it bans after 3 tempbans
--	Many Signs     - can detect advertisment that use different signs then "."
--      Tempban left   - how many tempbans a user has before permban
-----------
--added: safe advertisment
--added: pm to ops
--added: improved what the script detects
--added: profiles that the script should take action against
--fixed: a copy mistake
--changed: from typical loops to hashing = faster
-----------

Bot = "#Anti-Advertise"

--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Check the bottom of the script to see what it can detect
-- Do also check the bottom of the script for the safe advertising settings
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- (1)Shall be tempbanned/banned / (0) this profile shouldn't be effected.
SetToWho = {
[0] = 0, -- Masters
[1] = 0, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
[-1] = 1, -- Users
}

adverKill = 3

DNS01={"super","mega","nova","hellfire"}
MSigns={".","-","?","+"}
DNS02={"com","net","org","nu"}

tDNS01={}
tMSigns={}
tDNS02={}


adverCounter = 0

function Main() 
	for a=1,getn(DNS01) do
		tDNS01[DNS01[a]]=1
	end
	for b=1,getn(MSigns) do
		tMSigns[MSigns[b]]=1
	end
	for c=1,getn(DNS02) do
		tDNS02[DNS02[c]]=1
	end
end

function adverSmashing(user)
	if SetToWho[user.iProfile]==1 then
		adverCounter = adverCounter + 1
		tmpBanLeft = adverKill - adverCounter
		if adverCounter < adverKill then
			user:SendData(Bot, "You are tempbanned because of advertiseing.")
			user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
		--	user:TempBan()
			SendPmToOps(Bot, "User <"..user.sName.."> was tempbanned for advertising, wrote = "..advDetect)
		elseif adverCounter == adverKill then
			user:SendData(Bot, "You are PERMBANNED because of advertiseing")
		--	user:Ban()
			SendPmToOps(Bot, "User <"..user.sName.."> was PERMBANNED for advertising, wrote = "..advDetect)
			adverCounter = 0
		end
	end
	collectgarbage()
end


function DataArrival(user,data)
	for d=1,getn(MSigns) do
			tPart01 = (strlower(MSigns[d]))
			tPart03 = (strlower(MSigns[d]))
		for e=1,getn(DNS01) do
				tPart02 = (strlower(DNS01[e]))
			for f=1,getn(DNS02) do
				tPart04 = (strlower(DNS02[f]))
				advDetect = tPart01..tPart02..tPart03..tPart04
					if( strfind(data, advDetect,1,1))  then
						return adverSmashing(user)
					end
					if(strsub(data, 1, 4) == "$To:") then
						if( strfind(data, advDetect,1,1) ) then
							return adverSmashing(user)
						end
					end
			end
		end				
	end
	collectgarbage()
end


bastya_elvtars

1) you are doing loops inside loops

2) you are redeclaring the same value d times.

3) why use those arrays once you declared tables?

4) please comment what that chunk should do
Everything could have been anything else and it would have just as much meaning.

blackwings

#23
QuoteOriginally posted by bastya_elvtars
1) you are doing loops inside loops

2) you are redeclaring the same value d times.

3) why use those arrays once you declared tables?

4) please comment what that chunk should do
1)if you mean what I'm doing in DataArrival, well, the script doesn't work if they are separeted

2) I only declare "d" one time, or have I missed something.
in main I use = a,b,c
in dataarrival = d,e,f

3) because you said so = You have to do the loop again in DataArrival as the lifetime of a, b, and c is only inside Main()

4) What is this "chunk" your are talking about??

Maybe you should post the code that your questioning + describe whatever you are wondering better.


bastya_elvtars

Commented what I dislike. Sorry for being brief (and thus rude), but hate typing... :P

for d=1,getn(MSigns) do
			tPart01 = (strlower(MSigns[d]))
			tPart03 = (strlower(MSigns[d])) -- declaring 2 variables w/ same value
	-- why no end HERE?
		for e=1,getn(DNS01) do
				tPart02 = (strlower(DNS01[e]))
				-- and here?
			for f=1,getn(DNS02) do
				tPart04 = (strlower(DNS02[f]))
			-- and here?
				advDetect = tPart01..tPart02..tPart03..tPart04
					if( strfind(data, advDetect,1,1))  then
						return adverSmashing(user)
					end
					if(strsub(data, 1, 4) == "$To:") then -- so this check is done several times until adving is really found
						if( strfind(data, advDetect,1,1) ) then
							return adverSmashing(user)
						end
					end
			end
		end				
	end

-- IMHO better use 
-- dnsarray={{no,ip,com},{myftp,org},{kicks,ass,org}}
-- this is easier to handle
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk