Team036-KeywordChatFilter icon

KeywordChatFilter

KeywordChatFilter.

By Team036
Last updated 3 months ago
Total downloads 363
Total rating 0 
Categories Mods Client-side
Dependency string Team036-KeywordChatFilter-1.0.2
Dependants 0 other packages depend on this package

README

Caution

I only test this mod in local. But in theory it should run on server also.

If you install only on client yourself, this only works locally.

If you install it on server, it should influence the whole chat. I guess?

What this mod brings

Filter chat with keywords

Now those words you don’t like will be replaced with a “*”.(You can change the “*” into anything you like.)

Block players you don’t like away from Chats

Add their names in the mod.json.

If you use this with a server, may you can add their UIDs. (I don’t know how to get the UID in Client, so this feature not works in local user.)

Modes

It offers 3 modes: Replace| Block| Both

  • Replace Replace the dirty words with placeholder.

  • Block Block players away from your char.(Their messages are still shown in other players’ chats.)

  • Both Replace and Block

Convars

Use [Space] to separate the keywords like: "dirty1 dirty2 dirty3"

	// use [Space] to sep
	"ConVars": [
		{
			"Name": "l1nexus_keyword_chatfilter_keywords",
			"DefaultValue": ""
		},
		{
			"Name": "l1nexus_keyword_chatfilter_blacklistPlayername",
			"DefaultValue": ""
		},
		{
			"Name": "l1nexus_keyword_chatfilter_blacklistPlayerUID",
			"DefaultValue": ""
		},
		{
			"Name": "l1nexus_keyword_chatfilter_mode",
			// Replace | Block | Both
			"DefaultValue": "Both"
		},
		{
			"Name": "l1nexus_keyword_chatfilter_replaceHolder",
			"DefaultValue": "*"
		}
	]

Some String function

​ I noticed that there is a StringReplace function existed. But I failed to figure out the parameters, so I did mine.

// return start index of a substring in the string
// -1, means not found.
int function SearchString(string targetString, string search)
{
    int index = -1
    int flag = 1
    if (targetString.len() < search.len())  return -1
    if (targetString == search)  return 0

    for(int i; i < targetString.len() - search.len() + 1; i++)
    {
        if (targetString[i] != search[0]) continue
        for(int j = 0; j < search.len(); j++)
        {
            if (targetString[i+j] != search[j])
            {
                flag = 0
            }
        }
        if (flag)
            index = i
    }

    return index
}


string function ReplaceString(string targetString, string oldString, string newString, bool replaceAll, bool ignoreCaps)
{
    if (targetString.len() < oldString.len()) return targetString
    if (targetString == oldString) return newString

    int index = -1
    string searchString = targetString

    if (ignoreCaps)
    {
        searchString = targetString.toupper()
        oldString = oldString.toupper()
    }

    index = SearchString(searchString, oldString)

    print(searchString + " " + oldString + " " + newString + " index "+ index)
    while(index != -1)
    {
        if (index == 0)
        {
            targetString = newString + targetString.slice(oldString.len(), targetString.len())
        }
        else
        {
            targetString = targetString.slice(0, index) + newString + targetString.slice(index + oldString.len(), targetString.len())
        }

        // replace once
        if (!replaceAll)
            break

        // prepare next search
        searchString = targetString.toupper()
        index = SearchString(searchString, oldString)
    }

    return targetString
}

These 2 functions are globalized. You can use them with this mod, or just copy the code.

Further updates

  • Once I find the way to get the UIDs, I will update this mod.
  • Add commands allow to modify the list dynamically.

Update log

v0.0.1

  • Upload

v0.0.2

  • Fix .zip file structure.

v1.0.1

  • Update ConVars.

v1.0.2

  • Update readme.