How to make text in lowercase?
$message = $mod->strtolower($message);
here is the complete code
Spoiler anzeigen
<?php
/*
PLUGIN: Badwords
================
Kicks player when they use bad words defined in config/plugins/badwords.lst more
that X-Times
Добавления от jTommy:
1. В причине бана/кика указывается плохое слово (удобно при просмотре логов, особенно при использовании плагина logkickbans) .
2. Теперь плагин не ищет плохие слова внутри слов. Например, выражение "4 рубля" теперь не будет считаться плохим.
CONFIG:
-------
[badwords]
enabled = 1 ;Enable plugin
warnstokick = 3 ;Uses of badwords until kick
mode = "kick" ;kick/ban/tempban
kickreason = "Use of bad words (<WORD>)" ;Reason of a kick
NAMESPACE: badwords
Functions:
badwords_main
badwords_read
badwords_playerInit
Vars:
$badwords_list
*/
$mod->setDefaultCV("badwords", "enabled", 0);
$mod->setDefaultCV("badwords", "warnstokick", 3);
$mod->setDefaultCV("badwords", "mode", "tempban");
$mod->setDefaultCV("badwords", "kickreason", "Use of bad words (<WORD>)");
$mod->registerEvent("playerSay", "badwords_main");
$mod->registerEvent("playerJoined", "badwords_playerInit");
$mod->registerEvent("parseConfig", "badwords_read");
badwords_read();
//Init Players because playerJoined isn't called at startup
array_map("badwords_playerInit", array_keys($players));
function badwords_main($args) {
list($guid, $message, $executed) = $args;
global $players;
global $mod;
global $badwords_list;
$delimiters = array('!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~');
if (!$mod->getCV("badwords", "enabled")) return;
if ($executed) return;
if (!$badwords_list) return;
if ($players[$guid]->isProtected()) {
return;
}
// Убираем информацию о цвете текста
$message = $mod->removecolor($message);
// Убираем из строки все знаки препинания
foreach($delimiters as $symb) {
$message = str_replace($symb, '', $message);
}
//Слова преобразуем в нижний регистр
$message = $mod->strtolower($message);
// В целях отладки: Показываем игроку его же сообщение (уже после обработки)
$players[$guid]->say($message);
// Разбиваем строку на слова
$mess_exp = explode(' ', $message);
$bad = false;
foreach($mess_exp as $word) {
foreach($badwords_list["normal"] as $value) {
if (!strcasecmp($word, $value)) {
$bad = true;
$badword = $value;
break;
}
}
}
// foreach ($badwords_list["normal"] as $value) {
// if (stripos($message, $value) !== false) {
// $bad = true;
// $badword = $value;
// break;
// }
// }
/*
if (!$bad) {
foreach ($badwords_list["regexp"] as $value) {
if (preg_match("ґ".str_replace("ґ", "\\xB4", $value)."ґi", $message, $subpatterns)) {
$bad = true;
$badword = $subpatterns[0];
break;
}
}
}
*/
if ($bad) {
$players[$guid]->badwords_used ++;
$GLOBALS['logging']->write(MOD_NOTICE, "Badwords: Player '".$players[$guid]->getName()."' used the bad word '$badword', PID: ".$players[$guid]->getPID().", GUID: $guid");
if ($players[$guid]->badwords_used >= $mod->getCV("badwords", "warnstokick")) {
switch ($mod->getCV("badwords", "mode")) {
case "tempban":
//$players[$guid]->tempBan($mod->getCV("badwords", "kickreason"));
$players[$guid]->tempBan(str_replace("<WORD>", $badword, $mod->getCV("badwords", "kickreason")));
break;
case "kick":
//$players[$guid]->kick($mod->getCV("badwords", "kickreason"));
$players[$guid]->kick(str_replace("<WORD>", $badword, $mod->getCV("badwords", "kickreason")));
break;
case "ban":
//$players[$guid]->ban($mod->getCV("badwords", "kickreason"));
$players[$guid]->ban(str_replace("<WORD>", $badword, $mod->getCV("badwords", "kickreason")));
break;
}
}
else {
$players[$guid]->say($mod->getLngString("usedBadWord", array("<WORD>"), array($badword)));
}
}
}
function badwords_read() {
if (!$GLOBALS['mod']->getCV("badwords", "enabled")) {
return;
}
$configdir = $GLOBALS['mod']->getConfigDir();
global $badwords_list;
$list = file($configdir . "/plugins/badwords.lst");
if ($list === false) {
$GLOBALS['logging']->write(MOD_WARNING, "Badwords: File $configdir/plugins/badwords.lst could not be opened, badwords will be disabled");
$badwords_list = false;
return;
}
$normal = array();
$regexp = array();
foreach ($list as $value) {
$value = trim($value);
if (stripos($value, "regexp:") === 0) {
$regexp[] = substr($value, 7);
}
else {
$normal[] = $value;
}
}
$badwords_list = array("normal" => $normal, "regexp" => $regexp);
}
function badwords_playerInit($guid) {
$GLOBALS['players'][$guid]->badwords_used = 0;
}