ID:141592
 
Code:
var/list/BannedWords = list("<font","<b")//etc, all the word to bann >_<

mob/Player/proc
CheckSpam(msg as text)
if(length(msg)>=101)
var/M=copytext(msg,1,100)
msg=M // i also tried msg=copytext(msg,1,100)
for(var/A in BannedWords)
if(findtext(msg,A,1)==1)
alert("Dont use HTML")
return 0
else
return 1



mob/Player
verb
say(msg as text)
set hidden=1
if(CheckSpam(msg)==0)
return
world<<"[usr:nombre]: [msg]"


Problem description: well... im trying to make an spam-check system for the messages and i dont want users to use html or to write a too long message, the html one works fine, if i write the html tag at the start of the message (like
"Hi"// THIS IS BANNED
) but it doesnt work if i write it later (like
 "Hi!  this is red and your anti-spam system wont stop me" // THIS ISNT O_o
:P )

and the text lenght code just doesn't work, i can write thousands of lines and nothing...
so id like someone to help me a little...


oh and english isn't my main language so sorry if i say something without sense...

Frolik wrote:
Code:
> var/list/BannedWords = list("<font","<b")//etc, all the word to bann >_<
>
> mob/Player/proc
> CheckSpam(msg as text)
> if(length(msg)>=101)
> var/M=copytext(msg,1,100)
> msg=M // i also tried msg=copytext(msg,1,100)
> for(var/A in BannedWords)
> if(findtext(msg,A,1)==1)
> alert("Dont use HTML")
> return 0
> else
> return 1
>
>
>
> mob/Player
> verb
> say(msg as text)
> set hidden=1
> if(CheckSpam(msg)==0)
> return
> world<<"[usr:nombre]: [msg]"
>

Problem description: well... im trying to make an spam-check system for the messages and i dont want users to use html or to write a too long message, the html one works fine, if i write the html tag at the start of the message (like
"<font,color=red>Hi"// THIS IS BANNED
) but it doesnt work if i write it later (like
 "Hi! <font color=red> this is red and your anti-spam system wont stop me" // THIS ISNT O_o
:P )
and the text lenght code just doesn't work, i can write thousands of lines and nothing...
so id like someone to help me a little...


oh and english isn't my main language so sorry if i say something without sense...


mob
verb
Say(msg as text)
world << "[src]: [html_encode(msg)]"//one way to stop HTML from being used
for(var/s in HtmlWords)//another way
if(findtext(msg,s))
src << "HTML WAS ENTERED!"

var
list
HtmlWords = list("<font","<b")
In response to Haywire
Haywire wrote:
Frolik wrote:
Code:
> > var/list/BannedWords = list("<font","<b")//etc, all the word to bann >_<
> >
> > mob/Player/proc
> > CheckSpam(msg as text)
> > if(length(msg)>=101)
> > var/M=copytext(msg,1,100)
> > msg=M // i also tried msg=copytext(msg,1,100)
> > for(var/A in BannedWords)
> > if(findtext(msg,A,1)==1)
> > alert("Dont use HTML")
> > return 0
> > else
> > return 1
> >
> >
> >
> > mob/Player
> > verb
> > say(msg as text)
> > set hidden=1
> > if(CheckSpam(msg)==0)
> > return
> > world<<"[usr:nombre]: [msg]"
> >

Problem description: well... im trying to make an spam-check system for the messages and i dont want users to use html or to write a too long message, the html one works fine, if i write the html tag at the start of the message (like
"<font,color=red>Hi"// THIS IS BANNED
) but it doesnt work if i write it later (like
 "Hi! <font color=red> this is red and your anti-spam system wont stop me" // THIS ISNT O_o
:P )
and the text lenght code just doesn't work, i can write thousands of lines and nothing...
so id like someone to help me a little...


oh and english isn't my main language so sorry if i say something without sense...


> mob
> verb
> Say(msg as text)
> world << "[src]: [html_encode(msg)]"//one way to stop HTML from being used
> for(var/s in HtmlWords)//another way
> if(findtext(msg,s))
> src << "HTML WAS ENTERED!"
>
> var
> list
> HtmlWords = list("<font","<b")
>
>




i dont wanna use html_encode cause if you write things like ">_>" it show "<_<" and people get confused...

and about the list thing.. isnt that exactly the same than the code im using right now?


>           
for(var/s in HtmlWords)//another way
if(findtext(msg,s))
src << "HTML"

for(var/A in BannedWords)
if(findtext(msg,A,1))
alert("Dont use HTML")
return 0

I mean isn't that exactly the same?
In response to Frolik
Look at my findtext third parameter, and look at yours...
In response to Haywire
it's the same anyway
findtext(Haystack,Needle,Start=1,End=0)

the default is 1 so setting it to 1 isn't gonna make anything, i just setted it to see if it worked that way... even when i knew it wasnt going to do anything
look up html_encode() In the DM Refrence(which can be done by pressing F1 in Dream Maker)

As for your copytext problem.

var/max_character_length = 300 // maximum chharacter length

mob/Player/proc
CheckSpam(var/msg)
if(length(msg) > max_character_length)
// cuts off the remaining characters while encoding the message to remove any HTML
return html_encode(copytext(msg, 1, max_character_length))
// if we aren't over the character limit, then return the HTML Encoded Message.
else return html_encode(msg)

mob/Player/verb
WorldSay(msg as text)
world << "[usr.name]: [usr.CheckSpam(msg)]"
In response to Axerob
Your CheckSpam() verb is redundant, it could just be:
return html_encode(copytext(msg, 1, max_character_length)

Instead of the checks. He also stated earlier he didn't want html_encode.
var/list/legal_tags = list("b", "i", "u")

proc/sanitize_html(string)
. = ""
var
previous = 1
start
end

do
start = findtext(string, "<", end + 1)
end = start && findtext(string, ">", start)

if(start && end)
var/tag = copytext(string, start + 1, end)
if(!(ckey(tag) in legal_tags))
. += copytext(string, previous, start) + "&lt;[tag]&gt;"
previous = end + 1

while(start && end)

. += copytext(string, previous)


That'll do what you want. Just pass the message though the sanitize_html() proc.
In response to Axerob
oh look like im confused...
because before, when i used html_encode(), "<" turned into
"<"
and ">" into
">"
, that's why i didn't wanted to use it, but now the text just shows the "<" and ">", why it could be?


(when i say before i mean months ago, when i started coding, i left it for a while ;) )

if it's just gonna show the < and > simbols i can use html_encode sorry for the problem xD anyway i should use the system to bann another words

so this is my final code

var/list/PalabrasBanneadas = list("Word1","Word2","Word3")
mob/Player/proc
CheckSpam(var/msg)
var/start=1
var/end=100
do
for(var/A in PalabrasBanneadas)
if(findtext(msg,A,start))
alert("La palabra [A] no puede ser usada en el chat") // it means "The word [A] can't be used in chat" :P
return
else
start+=1
while(start<end)
if(length(msg) > end)
return html_encode(copytext(msg, 1, end))
else return html_encode(msg)

mob/Player/verb
WorldSay(msg as text)
world << "[usr.name]: [usr:CheckSpam(msg)]"



i used the Axe code for a base and the idea from the Popis code and modifyed a little, and it works perfectly till now ^^
i ended using the html_encode because it works different than i remembered for some reason... maybe a byond update?


ok thx for everything, i still not pretty of why my original text-cutting thing did't work, cause the one im using now is almos the same than the other one, but i fixed the word-bann one and got a solution for html so thnx =)