Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optional Censoring
#1
Difficulty: ?/5 - It's not a direct C&P tutorial. I tried to explain things, but I don't have a copy of MS4 on my laptop currently so this will try to explain things as best as possible.

< CLIENT SIDE >

Make a new check box object on frmMirage. This will let players turn censoring on or off for themselves. Now double click the check box and add this:

Code:
Call SendData("censor" & END_CHAR)

Now where the packets are checked, add this:

Code:
If Parse$(0) = "censor" Then
        If Val(Parse$(1)) = 3 Then
            frmMirage.chkCensor.Enabled = False
            frmMirage.chkCensor.Value = 0
        Else
            If frmMirage.chkCensor.Enabled = False Then frmMirage.chkCensor.Enabled = True
            frmMirage.chkCensor.Value = Val(Parse$(1))
        End If
        Exit Sub
    End If

< SERVER SIDE >

Find where the player is logged in. It should be something like "LoadPlayer(Index, Name)". Add this to that section:

Code:
If CENSOR_ON = 1 Then
                        Call SendDataTo(Index, "censor" & SEP_CHAR & Player(Index).Censor & END_CHAR)
                    Else
                        Call SendDataTo(Index, "censor" & SEP_CHAR & 3 & END_CHAR)
                    End If

Now find where all the packets are handled in the server. Add this to the list of Case's:

Code:
Case "censor"
      
                If CENSOR_ON = 1 Then
                    Player(Index).Censor = Not Player(Index).Censor
                    Call SendDataTo(Index, "censor" & SEP_CHAR & Player(Index).Censor & END_CHAR)
                Else
                    Call SendDataTo(Index, "censor" & SEP_CHAR & 3 & END_CHAR)
                End If
                Exit Sub

Open the Data.ini file and under MAX add: CENSOR=1

Now here's the magic function, in modGeneral (or wherever) add this:

Code:
Public Function CensorShip(ByVal Index As Long, ByVal Sentence As String) As String
Dim I As Long

    CensorShip = Sentence

    If CENSOR_ON = 1 Then
        If Player(Index).Censor = 1 Then
            For I = 1 To TOTAL_CENSOR
                CensorShip = Replace$(Sentence, Censor(I).Find, Censor(I).Replace, , , vbTextCompare)
                If CensorShip  Sentence Then Sentence = CensorShip
            Next I
        End If
    End If

End Function

Add this at the top of a module:

Code:
' Censoring data
Public CENSOR_ON As Byte
Public TOTAL_CENSOR As Long

Type CensorRec
    Find As String
    Replace As String
End Type

Public Censor() As CensorRec

Find where the server is initialized (ServerInit?) and add this:

Code:
CENSOR_ON = GetVar(App.Path & "\Data.ini", "CONFIG", "CENSOR")
  
    If CENSOR_ON  0 Then
        I = 1
        Do
            If GetVar(App.Path & "\Censor.ini", "CENSOR" & I, "Find") = "" Then Exit Do
            I = I + 1
        Loop
      
        TOTAL_CENSOR = I - 1
      
        ReDim Censor(1 To TOTAL_CENSOR)
      
        For I = 1 To TOTAL_CENSOR
            Censor(I).Find = GetVar(App.Path & "\Censor.ini", "CENSOR" & I, "Find")
            Censor(I).Replace = GetVar(App.Path & "\Censor.ini", "CENSOR" & I, "Replace")
        Next I
    End If

This will be the piece of data in the player's collection that will tell if they want to see censors. In "PlayerRec" add this:

Code:
Censor As Byte

Now in SavePlayer, add this after it sets the player's password:

Code:
Call PutVar(FileName, "GENERAL", "Censor", Trim$(Player(Index).Censor))

Now in LoadPlayer, add this after it gets the player's password:

Code:
Player(Index).Censor = Val(GetVar(FileName, "GENERAL", "Censor"))

I'm not exactly sure where all the chat is handled, because this wasn't made for MS4. So wherever the server sends the chat to the client, you need to wrap the variable with the CensorShip function. Example: In MapMsg you'll see a loop and something like "Packet = "mapmsg" & SEP_CHAR & Msg ..." Change the Msg to: Censorship(I, Msg).

Since we have each player able to turn the censoring on or off, we have to go directly inside the subs that send out the message so that it can use the function in the loop.

Also make a new Censor.ini file where the Server.exe is and paste this inside the file:

Code:
[CENSOR1]
Find=fuck
Replace=****
[CENSOR2]
Find=bitch
Replace=*****
[CENSOR3]
Find=shit
Replace=****
[CENSOR4]
Find=cock
Replace=****
[CENSOR5]
Find=dick
Replace=****
[CENSOR6]
Find=pussy
Replace=*****
[CENSOR7]
Find=ass
Replace=***
[CENSOR8]
Find=cunt
Replace=****
[CENSOR9]
Find=twat
Replace=****
[CENSOR10]
Find=whore
Replace=*****
Reply
#2
Just saw a problem and fixed it Big Grin

I was looking it over and noticed that it would only censor one word. So I changed:

Code:
If CensorShip  Sentence Then Exit For

To:

Code:
If CensorShip  Sentence Then Sentence = CensorShip
Reply
#3
Faaail.
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
#4
Yeah that's true...I like to over complicating things :? I like everything to be in the server. Also this won't take away hardly any server power...
Reply
#5
Well I just tested the function against:

fuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckshitshitshitshitshitshitbitchbitchbitchbitchbitch

And turned censor on and off and both returned 0 ms.
Reply
#6
The actual function CensorShip (since that's all that the server requires extra work) from when it starts to when it ends. Time = GetTickCount, MsgBox GetTickCount - Time
Reply
#7
GIAKEN Wrote:The actual function CensorShip (since that's all that the server requires extra work) from when it starts to when it ends. Time = GetTickCount, MsgBox GetTickCount - Time

Awww, you already know your game is gonna fail so hard you think only one person is going to be talking at once?

Set up 80 connections, all spamming it Big Grin
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
#8
Well if each time they enter a message that takes the server less than a millisecond to process the censoring with then I doubt they would be able to even get the server to take a full second of processing unless they can send more than 1000 messages...
Reply
#9
wouldnt this be good
if you make it add 1 to the ini with thier name
and if it is over a certain number it mutes them"?"
Reply
#10
doomteam1 Wrote:wouldnt this be good
if you make it add 1 to the ini with thier name
and if it is over a certain number it mutes them"?"

No because the point is to let them choose if they want words to be censored or not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)