ChatBlade SDK Documentation

Class   CBReplacementFilter
Header   CBReplacementFilter.h

Data    Member Summary    Member Details


Information 

CBReplacementFilter is a class designed to support Replacement Filtering of Chat Messages.  The Replacement Filter is also known as the RolePlay Filter. The RP filter allows Players to specify a string and its replacement value. When the Replacement Filter is enabled, any Chat Messages containing strings found in the Replacement Filter are altered and have those strings replaced with their replacement values.  
 
CBReplacementFilter allows users to do the following:
  /replace OMG, By the Heavens!
  /replace movies, plays
After issuing these commands any Chat Messages originally containing the strings 'OMG' or 'movies' shall have those strings replaced with their specified values on the Players client.
The RP Filter is designed to be conducive to Role Playing.
 
Players can typically enable and disable the Replacement Filter by using the /EnableRPFilter and /DisableRPFilter Slash Commands.  
Players can add or remove phrases from their local Replacement Filter by using the /Replace and /Unreplace commands.  
 
Replacement Filtering is Non Case-Sensitive in its search for strings to Replace.  The Replacement values retain whatever case they were set as.  Replacement Filtering is performed if the Replacement string is found anywhere in the Chat Text, including being a substring of a longer word.   
 
Any strings can be loaded into the Replacement Filter, spaces are allowed.   
 
An instance of CBReplacementFilter is created by ChatBlade and stored in CBChatHandler as CBChatHandler::m_ReplacementFilter.  
 
Certain Chat Channels (such as Customer Service Channels) are exempt from Replacement Filtering.  

Game Developer Implementation:  

CBReplacementFilter should be loaded up with Replacement Strings via the AddString() function (CBData::pChatHandler->m_ReplacementFilter.AddString()).  
CBClientImplementation::LoadReplacementFilter() is the location where the Replacement Filter should be filled via AddString().  
CBSampleImplementation::LoadReplacementFilter() displays how to do this.
A Players Replacement phrases and values should be persisted and reloaded upon logon.  
CBReplacementFilter does not need to be instantiated.  CBChatHandler contains an internal instance of this class that is used by ChatBlade.  

Source File Comments:  

// Represents a set of strings that should be replaced with alternate strings in Chat Messages if the Replacement Filter is enabled
// The Replacement Filter allows Players to modify incoming Chat and replace any phrases they desire with alternate ones of their own specification
// The Replacement Filter (RP Filter) might also be known as the RolePlay Filter and is conducive to RolePlaying for Players who want to take advantage of it
 
// On startup of the chat system this class should be loaded up with strings to be replaced and their replacements

// Generally Players can use the Replacement Filter like so:
//   /replace OMG, By the Heavens!
//   /enablereplacementfilter
 
// Players can add words to the Replacement Filter by using the /replace and /unreplace Slash Commands (by default)
 
// The check is not Case Sensitive and entire phrases can be Replaced and are not limited to single words
 
// Strings to be replaced are stored in the Replacement Filter in all UPPERCASE though their Replacement strings retain whatever case they were specified in

Data:  

int m_nReplacementFilterEnabledFlag
        Flag to tell if we should Replacement Filter or not - CB_TRUE = Replace text    CB_FALSE = don't Replace
std::map<CBSTRING, CBSTRING> m_ReplacementStringMap
        A list of all the strings to Replace and their Replacement values (keyed by the UPPERCASE string to Replace)

Member Function Summary:  

     CBReplacementFilter()
        Constructor.
int  ClearFilter()
        Function which removes all words from the Replacement Filter.
int  EnableReplacementFilter(int bEnableFlag = CB_TRUE)
        Function which turns on the Replacement (RP) Filter.
int  DisableReplacementFilter()
        Function which disables the RP Filter.
int  AddString(CBSTRING sOriginalString, CBSTRING sReplacementString)
        Function which adds a string to the Replacement Filter and specifies its Replacement text.
int  RemoveString(CBSTRING sString)
        Function which removes a string from the Replacement Filter.
int  ReplaceStringsFromLine(CBSTRING & sString /*IN OUT*/)
        Function which does an inplace Replacement of any strings found which are in the Replacement Filter with their Replacement text.  

Member Function Detail:  

       CBReplacementFilter::CBReplacementFilter()
Comments:
Constructor.  
Sets the initial state of the Replacement Filter.   
Parameters:
None
Returns:
None
 
int  CBReplacementFilter::ClearFilter()
Comments:
Removes all entries from the Replacement Filter.  
Parameters:
None
Returns:
CB_SUCCESS
 
int  CBReplacementFilter::EnableReplacementFilter( int bEnableFlag = CB_TRUE)
Comments:
Enables or Disables the Replacement Filter depending on if TRUE or FALSE is passed in.  
No Parameters means to Enable the filter.  
When the Replacement Filter is enabled, Chat Messages containing strings found in the Replacement Filter have those strings Replaced with their Replacement values.    
Parameters:
bEnableFlag 
    TRUE or FALSE flag to specify if the Filter should be Enabled or Disabled.  Defaults to CB_TRUE.   
Returns:
CB_SUCCESS regardless of if the Filter is Enabled or Disabled.  
 
int  CBReplacementFilter::DisableReplacementFilter()
Comments:
Turns off the Replacement Filter.  
With the Replacement Filter disabled, Chat text is displayed in its original form.  
Parameters:
None
Returns:
CB_SUCCESS
 
int  CBReplacementFilter::AddString( CBSTRING sOriginalString,
    CBSTRING sReplacementString)
Comments:
Adds a string to the Replacement Filter and specifies its Replacement value.  
Any Chat Messages containing strings found in the Replacement Filter would have those strings Replaced by the appropriate Replacement text (provided the Replacement Filter is enabled).   
Phrases (strings containing spaces) may be added.   
Original strings are converted to UPPERCASE before storage as the Map key, while the Replacement text retains its case.  Replacement Filtering is not Case Sensitive.  
The function can also be used to Update an existing Replacement string value.   
Parameters:
sOriginalString
    A String representing a word or phrase to add to the Replacement Filter which should be Replaced in Chat Messages with the specified Replacement text.  
sReplacementString
    A String representing the text which should Replace the original string in each Chat Message.  
Returns:
CB_ERROR_EMPTY_STRING if sOriginalString is empty.
CB_SUCCESS if the phrase was added to the Replacement Filter
 
int  CBReplacementFilter::RemoveString( CBSTRING sString)
Comments:
Removes a string from the Replacement Filter.
All string Keys are stored in the Replacement Filter in UPPERCASE.  sString is converted to UPPERCASE before searching for it for removal.  
Parameters:
sString
    The String to remove from the Replacement Filter
Returns:
CB_SUCCESS regardless of if the string was already in the Replacement Filter or not.  
 
int  CBReplacementFilter::ReplaceStringsFromLine( CBSTRING & sString /*IN OUT*/)
Comments:
Applies the Replacement Filter to the string.  If the Replacement Filter is enabled and sString contains any phrases found in the Replacement Filter (m_ReplacementStringMap), then this function shall perform an in-place Replacement of strings from the Replacement Filter with their Replacement values.  
If the Replacement Filter is disabled and/or sString does not contain any phrases found in the Replacement Filter, then sString is not modified.  
Replacement Filtering is not Case Sensitive.  
The Replacement is string based, and not word based, meaning that if a substring is found which matches any string in the Replacement Filter (even if it is a portion of a larger word) then this function shall Replace those strings with their Replacement text as long as the RP Filter is enabled.  
sString typically represents the text of a Chat Message which should potentially be subject to RP Filtering.  
This function calls CBUtils::CBStringIgnoreReplace() to perform the text Replacements.  
Called by CBChatMessage::GetConfigurableChatString().  
Parameters:
sString
    A Reference to a CBString which may contain phrases to be Replaced by the RP Filter. Upon function return this string shall have its text altered if any phrases specified by the Replacement Filter were located within it and the RP Filter is enabled 
 
Returns:
Upon return sString shall have any occurances of phrases found in the RP Filter Replaced with their specified text.   
CB_TRUE regardless of whether or not any Replacement was performed.   
 
 

 

 

 

ChatBlade Copyright © Flex Dolphynn