setMessage() публичный Метод

public setMessage ( string $message )
$message string
Пример #1
0
 public function onPreprocess(PlayerCommandPreprocessEvent $event)
 {
     //query basic information in event.
     $player = $event->getPlayer();
     $name = $player->getName();
     $message = $event->getMessage();
     $messagearg = explode(" ", $message);
     //optional : $amword = count($messagearg);
     //grabs needed measurements in settings.json
     $jsons = file_get_contents($this->getDataFolder() . "/settings.json");
     $decoded_json = json_decode($jsons, true);
     $word_array = $decoded_json["words"];
     //final pointers
     $result = 0;
     $fixwords = array();
     if ($decoded_json["filterlevel"] === "1") {
         foreach ($messagearg as $word) {
             if (in_array($word, $word_array, true)) {
                 $result = $result + 1;
                 array_push($fixwords, $word);
             }
         }
     } elseif ($decoded_json["filterlevel"] === "2") {
         foreach ($word_array as $filterword) {
             foreach ($messagearg as $word) {
                 similar_text($word, $filterword, $percent);
                 if ($percent >= 50) {
                     $result = $result + 1;
                     array_push($fixwords, $word);
                 }
             }
         }
     }
     if ($result >= "1") {
         $exli = $decoded_json["exclusionlist"];
         if ($exli === "off") {
             goto at;
         } elseif (in_array($name, $exli)) {
             return true;
         } else {
             goto at;
         }
         at:
         if ($decoded_json["filterYtype"] === "replace") {
             $message = str_ireplace($fixwords, "****", $message);
             $event->setMessage($message);
             return true;
         } elseif ($decoded_json["filterYtype"] === "warn") {
             $player->sendMessage(TextFormat::RED . "Please do not swear.");
             $event->setCancelled();
             return true;
         }
     } else {
         return true;
     }
 }
Пример #2
0
 public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
 {
     if ($this->getPlugin()->isConfused($event->getPlayer())) {
         $msg = $event->getMessage();
         if ($msg[0] != "/") {
             // lol md5
             $event->setMessage(md5(md5($event->getMessage())));
         }
     }
 }
 /**
  * @param PlayerCommandPreprocessEvent $event
  * @priority LOWEST
  */
 public function onCommandPreprocess(PlayerCommandPreprocessEvent $event)
 {
     $ses = $this->main->getSession($player = $event->getPlayer());
     if (!$ses instanceof Session) {
         $player->sendMessage(Phrases::VAR_wait . "Please wait. We are still preparing your account. You cannot type anything until your account is ready.");
         $event->setMessage("");
         return;
     }
     if ($ses->onCmd($event) === false) {
         $event->setCancelled();
     }
 }
Пример #4
0
 public function onCaps(PlayerCommandPreprocessEvent $event)
 {
     $message = $event->getMessage();
     if (strtoupper($message) == $message) {
         $isnum = false;
         foreach (explode(" ", $message) as $num) {
             $isnum = is_numeric($num);
         }
         $ischaronly = false;
         foreach (str_split($message) as $char) {
             $ischaronly = $this->getSpecialChar($char) !== false ? false : true;
         }
         if (!$isnum) {
             $event->getPlayer()->sendMessage(TextFormat::AQUA . "I think your CAPS-lock is on ;)");
         }
         $newmsg = $this->invertCase($event->getPlayer(), $message);
         if ($this->command) {
             $this->getServer()->dispatchCommand($event->getPlayer(), $newmsg);
             $event->setCancelled();
         } else {
             $event->setMessage($newmsg);
         }
     }
 }
 public function onPlayerCmdPreprocess(PlayerCommandPreprocessEvent $event)
 {
     $session = $this->getSession($event->getPlayer());
     if ($session->format !== null and substr($event->getMessage(), 0, 1) !== "/") {
         $event->setMessage($session->format($event->getMessage()));
     }
 }
Пример #6
0
 public function onMessage(PlayerCommandPreprocessEvent $event)
 {
     $message = $event->getMessage();
     $hash = HereAuth::hash($message, $this->getPlayer());
     if ($this->state === self::STATE_PENDING_LOGIN) {
         if ($this->accountInfo->testPassword($this->main, $message) and $this->callLogin(HereAuthLoginEvent::METHOD_PASSWORD)) {
             $this->main->getAuditLogger()->logLogin(strtolower($this->player->getName()), $this->player->getAddress(), "password");
             $this->onAuth();
         } else {
             $this->main->getAuditLogger()->logInvalid(strtolower($this->player->getName()), $this->player->getAddress());
             $this->loginAttempts++;
             $chances = $this->main->getConfig()->getNested("Login.MaxAttempts", 5);
             $left = $chances - $this->loginAttempts;
             if ($left <= 0) {
                 $this->getPlayer()->kick("Failed to login in {$chances} attempts", false);
                 $event->setCancelled();
                 $event->setMessage("");
                 $blockSecs = $this->main->getConfig()->getNested("Login.MaxAttemptsBlock", 600);
                 if ($blockSecs > 0) {
                     $this->main->getServer()->getNetwork()->blockAddress($this->player->getAddress(), $blockSecs);
                 }
                 return;
             }
             $msg = $this->getMain()->getMessages()->getNested("Login.WrongPass", "wrong pass");
             $msg = str_replace('$CHANCES', $left, $msg);
             $this->getPlayer()->sendMessage($msg);
         }
         $event->setCancelled();
         $event->setMessage("");
     } elseif ($this->state === self::STATE_PLAYING) {
         if ($hash === $this->accountInfo->passwordHash and $this->getMain()->getConfig()->getNested("BlockPasswordChat", true)) {
             $event->setCancelled();
             $event->setMessage("");
             $this->getPlayer()->sendMessage($this->getMain()->getMessages()->getNested("Chat.DirectPass", "Don't tell your password"));
         }
     } elseif ($this->state === self::STATE_REGISTERING) {
         $this->registration->handle($message);
         $event->setCancelled();
         $event->setMessage("");
     }
 }
Пример #7
0
 /**
  * @priority LOWEST
  */
 public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev->getPlayer()->hasPermission("gb.module.repeater")) {
         return;
     }
     $res = $this->processCmd($ev->getMessage(), $ev->getPlayer());
     if ($res === false) {
         return;
     }
     $ev->setMessage($res);
 }
Пример #8
0
 public function onCmd(PlayerCommandPreprocessEvent $event)
 {
     if ($this->isRegistering()) {
         $event->setCancelled();
         $len = strlen($event->getMessage());
         $event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
         if ($this->state === self::STATE_REGISTERING_FIRST) {
             $this->tmpHash = $hash;
             $this->sendCurlyLines();
             $this->send(Phrases::LOGIN_REGISTER_RETYPE);
             $this->state = self::STATE_REGISTERING_SECOND;
         } elseif ($this->state === self::STATE_REGISTERING_SECOND) {
             $this->sendCurlyLines();
             if ($this->tmpHash === $hash) {
                 $this->sendCurlyLines();
                 $this->setLoginDatum("hash", $hash);
                 $this->setLoginDatum("pwprefix", "~");
                 $this->setLoginDatum("pwlen", $len);
                 $this->state = self::STATE_PLAYING;
                 $this->sendFirstJoinMessages();
                 $this->login(self::AUTH_REG);
                 $this->send(Phrases::LOGIN_REGISTER_SUCCESS);
                 $this->saveData(Settings::STATUS_ONLINE);
             } else {
                 $this->send(Phrases::LOGIN_REGISTER_MISMATCH);
                 $this->tmpHash = null;
                 $this->state = self::STATE_REGISTERING_FIRST;
             }
         }
         return false;
     } elseif ($this->isLoggingIn()) {
         $msg = $event->getMessage();
         $hash = self::hash($msg, $this->getUid());
         $oldHash = self::oldHash($msg);
         $len = strlen($msg);
         $event->setMessage($hash);
         $this->sendCurlyLines();
         if ($hash === $this->getPasswordHash()) {
             $this->login(self::AUTH_PASS);
         } elseif ($this->isPortingOldPassword() and $oldHash === $this->getPasswordOldHash()) {
             $this->setLoginDatum("pwprefix", "~");
             $this->setLoginDatum("pwlen", $len);
             $this->setLoginDatum("hash", $hash);
             $this->setLoginDatum("oldhash", "");
             $this->login(self::AUTH_PASS);
             new UpdateHashesQuery($this->getMain(), $this->getUid(), $hash);
         } else {
             $this->state++;
             $chances = "chance";
             MUtils::word_quantitize($chances, 5 - $this->getStatePrecise());
             $this->send(Phrases::LOGIN_PASS_MISMATCH, ["chances" => $chances]);
             if ($this->getStatePrecise() === 5) {
                 $this->getPlayer()->kick("Failure to login within 5 attempts");
                 return false;
             }
         }
         return false;
     } else {
         $event->setMessage(TextFormat::clean($event->getMessage()));
         $msg = $event->getMessage();
         if (self::hash($msg, $this->getUid()) === $this->getPasswordHash()) {
             $this->send(Phrases::CHAT_BLOCKED_PASS);
             return false;
         }
         $len = $this->getLoginDatum("pwlen");
         $msgLen = strlen($msg);
         for ($i = 0; $i < $msgLen; $i++) {
             $substr = substr($msg, $i, $len);
             if (strlen($substr) < $len) {
                 break;
             }
             if ($this->getPasswordHash() === $this->hash($substr, $this->getUid())) {
                 $this->send(Phrases::CHAT_BLOCKED_PASS);
                 return false;
             }
         }
         $firstChar = substr($event->getMessage(), 0, 1);
         if ($firstChar === "\\") {
             $event->setMessage("/" . substr($event->getMessage(), 1));
         }
         if ($firstChar === "/") {
             $msg = $event->getMessage();
             if (strpos($msg, " ") === false) {
                 $cmd = $msg;
                 $postCmd = "";
             } else {
                 $cmd = strtolower(strstr($msg, " ", true));
                 $postCmd = strstr($msg, " ");
             }
             if ($cmd === "/w") {
                 $cmd = "/tell";
             }
             $event->setMessage($cmd . $postCmd);
             return true;
         }
         $target = $this->getQueryTarget();
         if ($target !== null) {
             fwrite($this->getMain()->pmLog, "|from:{$this->getPlayer()->getName()}|to:{$target->getPlayer()->getName()}|msg:{$msg}|" . PHP_EOL);
             $arrows = Phrases::VAR_info . "[" . $this->getPlayer()->getName() . " > " . $target->getPlayer()->getName() . "] " . Phrases::VAR_info . $msg;
             $target->getPlayer()->sendMessage($arrows);
             $this->getPlayer()->sendMessage($arrows);
             return false;
         }
         $this->setQueryTargetUid(null);
         $isLocal = $firstChar !== ".";
         if (!$isLocal) {
             $event->setMessage(substr($event->getMessage(), 1));
         }
         $message = trim($event->getMessage());
         if (!$this->spamDetector->censor($message)) {
             return false;
         }
         if ($this->currentChatState === self::CHANNEL_TEAM) {
             $data = ["tid" => $this->getTeamId(), "teamName" => $this->getTeamName(), "ign" => $this->getInGameName()];
             $type = Hormone::get($this->getMain(), Hormone::TEAM_CHAT, $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
             $type->release();
             return false;
         }
         if ($this->currentChatState !== self::CHANNEL_LOCAL) {
             $data = ["channel" => $this->currentChatState, "fromClass" => Settings::$LOCALIZE_CLASS, "ign" => $this->getInGameName()];
             $type = Hormone::get($this->getMain(), Hormone::CHANNEL_CHAT, $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
             $type->release();
             return false;
         }
         $this->onChat($message, $isLocal ? self::CHAT_NORMAL_LOCAL : self::CHAT_NORMAL_CLASS);
         return false;
     }
 }
Пример #9
0
 /**
  * @param PlayerCommandPreprocessEvent $event
  */
 public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
 {
     $command = $this->getPlugin()->colorMessage($event->getMessage(), $event->getPlayer());
     if ($command === false) {
         $event->setCancelled(true);
     }
     $event->setMessage($command);
 }
Пример #10
0
 public function onCmd(PlayerCommandPreprocessEvent $event)
 {
     if ($this->isRegistering()) {
         $event->setCancelled();
         $len = strlen($event->getMessage());
         $event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
         if ($this->state === self::STATE_REGISTERING_FIRST) {
             $this->tmpHash = $hash;
             $this->sendCurlyLines();
             $this->send(Phrases::LOGIN_REGISTER_RETYPE);
             $this->state = self::STATE_REGISTERING_SECOND;
         } elseif ($this->state === self::STATE_REGISTERING_SECOND) {
             $this->sendCurlyLines();
             if ($this->tmpHash === $hash) {
                 $this->sendCurlyLines();
                 $this->setLoginDatum("hash", $hash);
                 $this->setLoginDatum("pwprefix", "~");
                 $this->setLoginDatum("pwlen", $len);
                 $this->state = self::STATE_PLAYING;
                 $this->sendFirstJoinMessages();
                 $this->login(self::AUTH_REG);
                 $this->send(Phrases::LOGIN_REGISTER_SUCCESS);
             } else {
                 $this->send(Phrases::LOGIN_REGISTER_MISMATCH);
                 $this->tmpHash = null;
                 $this->state = self::STATE_REGISTERING_FIRST;
             }
         }
         return false;
     } elseif ($this->isLoggingIn()) {
         $event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
         $this->sendCurlyLines();
         if ($hash === $this->getPasswordHash()) {
             $this->login(self::AUTH_PASS);
         } else {
             $this->state++;
             $chances = "chance";
             MUtils::word_quantitize($chances, 5 - $this->getStatePrecise());
             $this->send(Phrases::LOGIN_PASS_MISMATCH, ["chances" => $chances]);
             if ($this->getStatePrecise() === 5) {
                 $this->getPlayer()->kick("Failure to login within 5 attempts");
                 return false;
             }
         }
         return false;
     } else {
         $msg = $event->getMessage();
         $len = $this->getLoginDatum("pwlen");
         $msgLen = strlen($msg);
         for ($i = 0; $i < $msgLen; $i++) {
             $substr = substr($msg, $i, $len);
             if (strlen($substr) < $len) {
                 break;
             }
             if ($this->getPasswordHash() === $this->hash($substr, $this->getUid())) {
                 $this->send(Phrases::CHAT_BLOCKED_PASS);
                 return false;
             }
         }
         $firstChar = substr($event->getMessage(), 0, 1);
         if ($firstChar === "/") {
             return true;
         } elseif ($firstChar === "\\") {
             $event->setMessage("/" . substr($event->getMessage(), 1));
         }
         $isLocal = $firstChar !== ".";
         if (!$isLocal) {
             $event->setMessage(substr($event->getMessage(), 1));
         }
         $message = trim($event->getMessage());
         if (!$this->spamDetector->censor($message)) {
             return false;
         }
         if ($this->currentChatState === self::CHANNEL_TEAM) {
             $data = ["tid" => $this->getTeamId(), "teamName" => $this->getTeamName(), "ign" => $this->getInGameName()];
             $type = new TeamChatType($this->getMain(), $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
             $type->push();
             return false;
         }
         if ($this->currentChatState !== self::CHANNEL_LOCAL) {
             $data = ["channel" => $this->currentChatState, "fromClass" => Settings::$LOCALIZE_CLASS, "ign" => $this->getInGameName()];
             $type = new ChannelChatType($this->getMain(), $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
             $type->push();
             return false;
         }
         $this->onChat($message, $isLocal ? self::CHAT_LOCAL : self::CHAT_STD);
         return false;
     }
 }
Пример #11
0
 public function onPlayerCmd(PlayerCommandPreprocessEvent $event)
 {
     if ($event instanceof PlayerCommandPreprocessEvent_sub) {
         return;
     }
     $line = $event->getMessage();
     if (substr($line, 0, 1) === "/") {
         $cmd = substr($line, 1);
         if ($this->proceedCommand($event->getPlayer(), $cmd)) {
             // if recursive; $cmd must be changed to array
             if (count($cmd) > 0) {
                 $event->setCancelled();
                 //$event->setMessage("/".array_shift($cmd));
                 foreach ($cmd as $c) {
                     $this->getServer()->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent_sub($event->getPlayer(), "." . $c));
                     if ($ev->isCancelled()) {
                         continue;
                     }
                     Timings::$playerCommandTimer->startTiming();
                     $this->getServer()->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
                     Timings::$playerCommandTimer->stopTiming();
                 }
             } else {
                 $event->setCancelled();
             }
         } else {
             $event->setMessage("/{$cmd}");
         }
     }
 }
 /**
  * @priority LOW
  */
 public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $pl = $ev->getPlayer();
     $n = $pl->getName();
     if ($this->auth->isPlayerAuthenticated($pl) && !isset($this->chpwd[$n])) {
         return;
     }
     if (!$this->auth->isPlayerRegistered($pl) || isset($this->chpwd[$n])) {
         if (!isset($this->pwds[$n])) {
             if (!$this->checkPwd($pl, $ev->getMessage())) {
                 $ev->setCancelled();
                 $ev->setMessage("~");
                 return;
             }
             $this->pwds[$n] = $ev->getMessage();
             $pl->sendMessage($this->cfg["messages"]["re-enter pwd"]);
             $ev->setCancelled();
             $ev->setMessage("~");
             return;
         }
         if ($this->pwds[$n] != $ev->getMessage()) {
             unset($this->pwds[$n]);
             $ev->setCancelled();
             $ev->setMessage("~");
             $pl->sendMessage($this->cfg["messages"]["passwords dont match"]);
             return;
         }
         if (isset($this->chpwd[$n])) {
             // User is changing password...
             unset($this->chpwd[$n]);
             $ev->setMessage("~");
             $ev->setCancelled();
             $pw = $this->pwds[$n];
             unset($this->pwds[$n]);
             if (!$this->auth->unregisterPlayer($pl)) {
                 $pl->sendMessage($this->cfg["messages"]["registration error"]);
                 return;
             }
             if (!$this->auth->registerPlayer($pl, $pw)) {
                 $pl->kick($this->cfg["messages"]["registration error"]);
                 return;
             }
             $pl->sendMessage($this->cfg["messages"]["chpwd ok"]);
             return;
         }
         // New user registration...
         if (!$this->auth->registerPlayer($pl, $this->pwds[$n])) {
             $pl->kick($this->cfg["messages"]["registration error"]);
             return;
         }
         if (!$this->auth->authenticatePlayer($pl)) {
             $pl->kick($this->cfg["messages"]["auth error"]);
             return;
         }
         unset($this->pwds[$n]);
         $ev->setMessage("~");
         $ev->setCancelled();
         $pl->sendMessage($this->cfg["messages"]["register ok"]);
         if (isset($this->cfg["nest-egg"]) && !$pl->isCreative()) {
             // Award a nest egg to player...
             foreach ($this->cfg["nest-egg"] as $i) {
                 $r = explode(":", $i);
                 if (count($r) != 3) {
                     continue;
                 }
                 $item = Item::fromString($r[0] . ":" . $r[1]);
                 $item->setCount(intval($r[2]));
                 $pl->getInventory()->addItem($item);
             }
         }
         return;
     }
     $ev->setMessage("/login " . $ev->getMessage());
     if ($this->cfg["max-attempts"] > 0) {
         if (isset($this->pwds[$n])) {
             ++$this->pwds[$n];
         } else {
             $this->pwds[$n] = 1;
         }
         $this->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this, [$this, "checkLoginCount"], [$n]), 5);
     }
     return;
 }
Пример #13
0
 public function onPlayerCommandPreprocess(PlayerCommandPreprocessEvent $event)
 {
     if (strpos($cmd = $event->getMessage(), "/") !== 0) {
         return;
     }
     $event->setMessage("/" . $this->alias(substr($cmd, 1)));
     if ($m = $this->eazyCommand($event)) {
         $event->setMessage("/" . $m);
     } else {
         $event->setCancelled();
     }
 }
Пример #14
0
 public function onChatCommand(PlayerCommandPreprocessEvent $event)
 {
     $message = $event->getMessage();
     $player = $event->getPlayer();
     $this->cfg = $this->plugin->getConfig()->getAll();
     //Check if message is not a command
     if ($message[0] != "/") {
         //Check if player is muted
         if ($this->plugin->isMuted(strtolower($player->getName()))) {
             if ($this->cfg["mute"]["log-to-player"]) {
                 $player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cYou can't send messages because you were muted"));
             }
             $event->setCancelled(true);
         } else {
             //if char-check finds an illegal char, the censor will be bypassed
             $status = 0;
             //Check if CharCheck is enabled
             if ($this->cfg["char-check"]["enabled"] == true) {
                 //Checking if bypass is allowed
                 if ($this->cfg["char-check"]["allow-bypassing"] == true) {
                     //Checking CharCheck bypass permission
                     if ($player->hasPermission("chatcensor.bypass.char-check") != true) {
                         //Char checker
                         $getchar = $this->plugin->getChars();
                         $getchar = $getchar . " ";
                         if ($this->cfg["char-check"]["allow-backslash"] == true) {
                             $getchar = $getchar . "\\";
                         }
                         $allowedchr = str_split($getchar);
                         $messagearray = str_split($message);
                         for ($i = 0; $i < count($messagearray); $i++) {
                             if (in_array($messagearray[$i], $allowedchr) == false) {
                                 if ($this->cfg["char-check"]["log-to-player"] == true) {
                                     $player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cYou can't send this message: it contains invalid characters."));
                                 }
                                 $status = 1;
                                 $event->setCancelled(true);
                             }
                         }
                     }
                 } else {
                     //No-bypassing
                     //Char checker
                     $getchar = $this->plugin->getChars();
                     $getchar = $getchar . " ";
                     if ($this->cfg["char-check"]["allow-backslash"] == true) {
                         $getchar = $getchar . "\\";
                     }
                     $allowedchr = str_split($getchar);
                     $messagearray = str_split($message);
                     for ($i = 0; $i < count($messagearray); $i++) {
                         if (in_array($messagearray[$i], $allowedchr) == false) {
                             if ($this->cfg["char-check"]["log-to-player"] == true) {
                                 $player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cYou can't send this message: it contains invalid characters."));
                             }
                             $status = 1;
                             $event->setCancelled(true);
                         }
                     }
                 }
             }
             //Check if Censor is enabled
             if ($this->cfg["censor"]["enabled"] == true && $status == 0) {
                 $iskicked = 0;
                 $isbanned = 0;
                 $result = 0;
                 //Checking if bypass is allowed
                 if ($this->cfg["censor"]["allow-bypassing"] == true) {
                     //Checking CharCheck bypass permission
                     if ($player->hasPermission("chatcensor.bypass.censor") != true) {
                         $tempmessage = $message;
                         $messagewords = str_word_count($message, 1);
                         for ($i = 0; $i < count($messagewords); $i++) {
                             if ($this->plugin->wordExists($messagewords[$i])) {
                                 //Check Word Config
                                 $tmp = $this->plugin->getWord($messagewords[$i]);
                                 if ($tmp["delete-message"] == true) {
                                     $event->setCancelled(true);
                                 }
                                 if ($tmp["enable-replace"] == true) {
                                     /*$length = strlen($messagewords[$i]);
                                     		 $replace = "";
                                     		for ($l = 0; $l < $length; $l++){
                                     		$replace = $replace . "*";
                                     		}
                                     		$tempmessage = str_replace($messagewords[$i],$replace,$tempmessage);*/
                                     $replace = $tmp["replace-word"];
                                     $tempmessage = str_replace($messagewords[$i], $replace, $tempmessage);
                                 }
                                 if ($this->cfg["censor"]["log-to-player"] == true) {
                                     $result = 1;
                                 }
                                 if ($tmp["sender"]["kick"] == true) {
                                     if ($iskicked == 0 && $isbanned == 0) {
                                         $player->kick($tmp["kick"]["message"]);
                                         $iskicked = 1;
                                     }
                                 } else {
                                     if ($tmp["sender"]["ban"] == true) {
                                         if ($iskicked == 0 && $isbanned == 0) {
                                             $this->plugin->getServer()->getNameBans()->addBan($player->getName(), $tmp["ban"]["message"]);
                                             $player->kick($tmp["ban"]["message"]);
                                             $isbanned = 1;
                                         }
                                     }
                                 }
                             }
                         }
                         $event->setMessage($tempmessage);
                         if ($result == 1) {
                             $player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cNo Swearing!"));
                         }
                     }
                 } else {
                     //No-bypassing
                     $tempmessage = $message;
                     $messagewords = str_word_count($message, 1);
                     for ($i = 0; $i < count($messagewords); $i++) {
                         if ($this->plugin->wordExists($messagewords[$i])) {
                             //Check Word Config
                             $tmp = $this->plugin->getWord($messagewords[$i]);
                             if ($tmp["delete-message"] == true) {
                                 $event->setCancelled(true);
                             }
                             if ($tmp["enable-replace"] == true) {
                                 /*$length = strlen($messagewords[$i]);
                                 		 $replace = "";
                                 		for ($l = 0; $l < $length; $l++){
                                 		$replace = $replace . "*";
                                 		}
                                 		$tempmessage = str_replace($messagewords[$i],$replace,$tempmessage);*/
                                 $replace = $tmp["replace-word"];
                                 $tempmessage = str_replace($messagewords[$i], $replace, $tempmessage);
                             }
                             if ($this->cfg["censor"]["log-to-player"] == true) {
                                 $result = 1;
                             }
                             if ($tmp["sender"]["kick"] == true) {
                                 if ($iskicked == 0 && $isbanned == 0) {
                                     $player->kick($tmp["kick"]["message"]);
                                     $iskicked = 1;
                                 }
                             } else {
                                 if ($tmp["sender"]["ban"] == true) {
                                     if ($iskicked == 0 && $isbanned == 0) {
                                         $this->plugin->getServer()->getNameBans()->addBan($player->getName(), $tmp["ban"]["message"]);
                                         $player->kick($tmp["ban"]["message"]);
                                         $isbanned = 1;
                                     }
                                 }
                             }
                         }
                     }
                     $event->setMessage($tempmessage);
                     if ($result == 1) {
                         $player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cNo Swearing!"));
                     }
                 }
             }
         }
     }
 }
Пример #15
0
 public function onMessage(PlayerCommandPreprocessEvent $event)
 {
     $message = $event->getMessage();
     $hash = HereAuth::hash($message, $this->getPlayer());
     if ($this->state === self::STATE_PENDING_LOGIN) {
         if ($hash === $this->accountInfo->passwordHash) {
             $this->onAuth();
         } else {
             $this->loginAttempts++;
             $chances = $this->main->getConfig()->getNested("Login.MaxAttempts", 5);
             $left = $chances - $this->loginAttempts;
             if ($left <= 0) {
                 $this->getPlayer()->kick("Failed to login in {$chances} attempts", false);
             }
             $msg = $this->getMain()->getConfig()->getNested("Messages.Login.WrongPass", "wrong pass");
             $msg = str_replace('$CHANCES', $left, $msg);
             $this->getPlayer()->sendMessage($msg);
         }
         $event->setCancelled();
         $event->setMessage("");
     } elseif ($this->state === self::STATE_PLAYING) {
         if ($hash === $this->accountInfo->passwordHash and $this->getMain()->getConfig()->getNested("BlockPasswordChat", true)) {
             $event->setCancelled();
             $event->setMessage("");
         }
     } elseif ($this->state === self::STATE_REGISTERING) {
         $this->registration->handle($message);
         $event->setCancelled();
         $event->setMessage("");
     }
 }
Пример #16
0
 /**
  * @priority LOW
  */
 public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     //echo __METHOD__.",".__LINE__."\n"; //##DEBUG;
     $pl = $ev->getPlayer();
     $n = $pl->getName();
     if ($this->auth->isPlayerAuthenticated($pl) && !isset($this->chpwd[$n])) {
         if ($this->cfg["chat-protect"]) {
             if ($this->authenticate($pl, $ev->getMessage())) {
                 $pl->sendMessage(TextFormat::RED . mc::_("chat protected"));
                 $ev->setMessage(mc::_("**CENSORED**"));
                 $ev->setCancelled();
             }
         }
         return;
     }
     if (!$this->auth->isPlayerRegistered($pl) || isset($this->chpwd[$n])) {
         if (!isset($this->pwds[$n])) {
             if ($this->cfg["leet-mode"] && preg_match(self::RE_REGISTER, $ev->getMessage())) {
                 $pl->sendMessage(TextFormat::YELLOW . mc::_("snob register"));
                 $ev->setMessage(preg_replace(self::RE_REGISTER, '', $ev->getMessage()));
             }
             if (!$this->checkPwd($pl, $ev->getMessage())) {
                 $ev->setCancelled();
                 $ev->setMessage("~");
                 return;
             }
             $this->pwds[$n] = $ev->getMessage();
             $pl->sendMessage(TextFormat::AQUA . mc::_("re-enter pwd"));
             $ev->setCancelled();
             $ev->setMessage("~");
             return;
         }
         if ($this->pwds[$n] != $ev->getMessage()) {
             unset($this->pwds[$n]);
             $ev->setCancelled();
             $ev->setMessage("~");
             $pl->sendMessage(TextFormat::RED . mc::_("passwords dont match"));
             return;
         }
         if (isset($this->chpwd[$n])) {
             // User is changing password...
             unset($this->chpwd[$n]);
             $ev->setMessage("~");
             $ev->setCancelled();
             $pw = $this->pwds[$n];
             unset($this->pwds[$n]);
             if (!$this->auth->unregisterPlayer($pl)) {
                 $pl->sendMessage(TextFormat::RED . mc::_("registration error"));
                 return;
             }
             if (!$this->auth->registerPlayer($pl, $pw)) {
                 $pl->kick(mc::_("registration error"));
                 return;
             }
             $pl->sendMessage(TextFormat::GREEN . mc::_("chpwd ok"));
             return;
         }
         // New user registration...
         if (!$this->auth->registerPlayer($pl, $this->pwds[$n])) {
             $pl->kick(mc::_("registration error"));
             return;
         }
         if (!$this->auth->authenticatePlayer($pl)) {
             $pl->kick(mc::_("auth error"));
             return;
         }
         unset($this->pwds[$n]);
         $ev->setMessage("~");
         $ev->setCancelled();
         $pl->sendMessage(TextFormat::GREEN . mc::_("register ok"));
         return;
     }
     if ($this->cfg["leet-mode"]) {
         $msg = $ev->getMessage();
         if (preg_match(self::RE_LOGIN, $msg)) {
             $pl->sendMessage(TextFormat::YELLOW . mc::_("snob login"));
         } else {
             $ev->setMessage("/login {$msg}");
         }
     } else {
         $ev->setMessage("/login " . $ev->getMessage());
     }
     if ($this->cfg["max-attempts"] > 0) {
         if (isset($this->pwds[$n])) {
             ++$this->pwds[$n];
         } else {
             $this->pwds[$n] = 1;
         }
         $this->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this, [$this, "checkLoginCount"], [$n]), 5);
     }
     return;
 }
Пример #17
0
 /**
  * @priority LOW
  */
 public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $res = $this->processCmd($ev->getMessage(), $ev->getPlayer());
     if ($res === false) {
         return;
     }
     $ev->setMessage($res);
 }