|
In my opinion censoring should be done clientside with the option to turn it on or off. Therefor it should be applied to OTHER player chat rather than your own(using I think it's onRemotePlayerChats() {}). This is because it discourages swear evasion. Those who feel comfortable with cursing can see/do it without feeling censored, so no need to evade it. Thus those who don't like cursing can have other chat censored and since they don't need to evade it remains far more accurate.
Also it'd probably be better to just load them from the serveroptions rather than a file.
|
I've never used onRemotePlayerChats before, so I'll look into it. I'll also add an option to enable/disable it. I'll also work on adding functionality to use the serveroptions to store words too. Thanks for the feedback (and your replaceText() function)
|
also if you are going to make it so there is no option make it so the word is replaced or censored, not the entire pm or text.
|
I pointed out that it removes the word from the chat, and doesn't replace the whole chat text (unless the ERASE rule is defined next to it in the text document)
Update
I've added onRemotePlayerChats() and the ability to turn it on and off (thanks Dusty for the feedback)
I don't currently have access to anywhere where I can play around with the server options (other than Delteria, but that's a no-go) so I'll have to find somewhere so I can add filter via server ops. I've also removed sending a message to RC and loggin vulgar language, since there's really no need for it in my opinion.
PHP Code:
const RULES_PATH = "storage/filter/rules.txt";
function onActionServerside() {
switch(params[0]) {
case "loadFilterRules": {
temp.path = RULES_PATH;
if (fileExists(temp.path) != true) {
echo("[Filter]: Could not find chat filter file!");
} else {
temp.filter.loadLines(temp.path);
for (f : temp.filter) {
temp.word = f.tokenize(":")[0];
temp.rule = f.tokenize(":")[1];
if (!({temp.word, temp.rule} in temp.rules)) {
temp.rules.add({temp.word, temp.rule});
}
}
triggerClient("gui", name, "loadedFilterRules", temp.rules);
}
break;
}
}
}
//#CLIENTSIDE
const REPLACEMENT_TEXT = "Don't use this kind of language!";
function onCreated() {
loadFilterRules();
}
function onActionClientside() {
switch(params[0]) {
case "loadedFilterRules": {
this.filterRule = params[1];
break;
}
}
}
function ChatBar.onAction() {
if (ChatBar.text == "/filter") {
client.swearFilter = !client.swearFilter;
if (client.swearFilter) {
ChatBar.text = "Swear filter has been enabled!";
} else {
ChatBar.text = "Swear filter has been disabled!";
}
}
}
function onPlayerChats() {
// Also notifies the player that they've used
// bad words when their filter is on.
onRemotePlayerChats(player, player.chat);
}
function onRemotePlayerChats(obj, chat) {
if (client.swearFilter != true) return;
for (temp.i = 0; temp.i < this.filterRule.size(); temp.i ++) {
if (obj.chat.pos(this.filterRule[temp.i][0]) >= 0) {
if (this.filterRule[temp.i][1] == "ERASE") {
obj.chat = REPLACEMENT_TEXT;
} else {
obj.chat = replaceText(obj.chat, this.filterRule[temp.i][0], this.filterRule[temp.i][1]);
}
}
}
}
//FUNCTIONS
function loadFilterRules() {
triggerServer("gui", name, "loadFilterRules");
}
//Dusty's replace text function
function replaceText(txt, a, b) {
if (txt.pos(a) < 0) return txt;
temp.txtpos = txt.positions(a);
temp.newtxt = txt.substring(0, txtpos[0]);
for (temp.i = 0; i < txtpos.size(); i++) {
newtxt @= b;
newtxt @= txt.substring(txtpos[i] + a.length(), txt.substring(txtpos[i] + a.length()).pos(a));
}
return newtxt;
}
Bugs, errors or improvements, let me know.