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; } }
public function onCompletion(Server $server) { $main = BasePlugin::getInstance($server); $data = ["teamname" => $this->teamName]; foreach ($main->getSessions() as $ses) { if ($ses->getUid() === $this->uid) { $data["name"] = $ses->getPlayer()->getName(); switch ($this->type) { case self::REQUEST_FROM_USER: $ses->send(Phrases::CMD_TEAM_JOIN_ALREADY_REQUESTED, $data); break 2; case self::REQUEST_FROM_TEAM: $ses->send(Phrases::CMD_TEAM_JOIN_ACCEPTED, $data); $joined = true; $ses->recalculateNametag(); break 2; case self::DIRECT_JOIN: $ses->send(Phrases::CMD_TEAM_JOIN_DIRECTLY_JOINED, $data); $joined = true; $ses->recalculateNametag(); break 2; default: $ses->send(Phrases::CMD_TEAM_JOIN_REQUESTED, $data); break 2; } } } if (isset($joined)) { $type = new TeamChatType($main, "Network", "%tr%" . Phrases::CMD_TEAM_JOINED, Settings::CLASS_ALL, ["tid" => $this->tid, "teamName" => $this->teamName, "ign" => "Network", "data" => $data]); $type->push(); } }