Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chat Swear Filter
#1
Author: Obsidian
Difficulty: 1/5

This is a very basic swear filter.

:: SERVER SIDE ::
First, we need to setup the checks for the swears. Open modHandleData and find:
Code:
If LCase(Parse(0)) = "saymsg" Then
In this packet, after you see:
Code:
' Prevent hacking
        For i = 1 To Len(Msg)
              If Asc(Mid$(Msg, i, 1)) < 32 Or Asc(Mid$(Msg, i, 1)) > 126 Then
                  Call HackingAttempt(Index, "Say Text Modification")
                  Exit Sub
              End If
        Next i
Add:
Code:
Call CheckMessage(Index, Msg)

All you have to do is add that in the same exact spot for every type of chat that you want censored. (Admin, Global, Broadcast, Emote, etc.)

Now, at the bottom of modDatabase (or wherever, I just use Database) add this function:
Code:
Public Function CheckMessage(Index As Long, Msg As String)
Dim kArray() As String
Dim Swears As String
Dim i As Integer
Dim SwearChar As String
  
    Swears = "ass,fuck,shit,bitch,damn,"
    kArray = Split(Swears, ",")
    
    SwearChar = "*"
    
    ' Thanks to Classified For Help with the Full Word Replacement
    For i = 0 To UBound(kArray)
        If InStr(LCase(Msg$), LCase(kArray(i))) Then
              'Msg = Replace(Msg, kArray(i), SwearChar)
              Msg$ = Replace$(LCase(Msg$), LCase(kArray(i)), LCase(String(Len(kArray(i)), SwearChar)))
        End If
    Next i
End Function
Now, all you have to do is change the swear char (if you'd like) and then add to the swear list.

Note: The forum censors certain words, so be sure to replace whatever has been caught by the filter.

That's all!
Reply
#2
Well, I changed it a bit, and I thought I could share


Code:
Public Function CheckMessage(Msg As String)
Dim SwearSplit() As String
Dim SwearReplaceSplit() As String
Dim Swears As String
Dim SwearReplace As String
Dim i As Integer
    
    Swears = "ass,fuck,shit,bitch,"
    SwearReplace = "***,f**k,s**t, b****,"
    
    SwearSplit = Split(Swears, ",")
    SwearReplaceSplit = Split(SwearReplace, ",")
      
    For i = 0 To UBound(SwearSplit)
        If InStr(LCase(Msg$), LCase(SwearSplit(i))) Then
              Msg$ = Replace$(LCase(Msg$), LCase(SwearSplit(i)), LCase(SwearReplaceSplit(i)), 1)
        End If
    Next i
    
End Function

What I did is removing the Useless Byval Index as long and exept of remplacing whole insult by ***, you can change to whatever you want
Reply
#3
that's not a bad little addition Smile

i originally wrote this code for an engine, so it wouldn't make much sense having two different (or even and extra set of info) for a txt or ini file. The engine just allows you to add different swears, and select the swear character, which by default is *
Reply
#4
Thanks for sharing it and damn.. I was looking for the command to split a bunch of stuff divided by ,'s so this also helped me with that.
Reply
#5
pretty nice tutorial that, thanks

p.s. Tosuxo is back at Mirage Source!! WOOO!!!
Reply
#6
Im not really sure, but wouldn't that change the entire thing into lowercase?
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#7
^ Just checked, it does..

whata crap
Reply
#8
yeh, but there are few cases when upper-case is needed... i can't think of any right now...

but all the same, it would be good if someone could fix this problem... if that's possible... :S
Reply
#9
I think this might work:

Msg = Replace(Msg, kArray(i), String(Len(kArray(i))), SwearChar)

(might need to change the syntax, the '(' etc. i don't have visual basic with me.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)