protected function run(array $args, Session $sender) { if (Settings::$LOCALIZE_CLASS === $this->class) { return TextFormat::RED . "You are already in {$this->human}!"; } $this->getPlugin()->transferGame($sender->getPlayer(), $this->class); return TextFormat::AQUA . "Finding an available " . MUtils::word_addSingularArticle($this->human) . " server for you..."; }
public function onPostRelease($rowId) { if ($this->src === "{BOT}CapsDetector" or $this->src === "{BOT}SwearDetector") { return; } $message = implode("\n", ["{$this->src} @ `{$this->ip}:{$this->port}` executed /console. Message `#{$rowId}``:", MUtils::toMd($this->msg)]); $isBot = substr($this->src, 0, 5) === "{BOT}"; $this->main->getServer()->getScheduler()->scheduleAsyncTask(new PostUrlTask(Credentials::SLACK_WEBHOOK, json_encode(["text" => TextFormat::clean($message), "icon_url" => Credentials::LEGIONPE_ICON_URL, "username" => $isBot ? substr($this->src, 5) : $this->src, "channel" => $isBot ? "#spam" : "#support"]))); }
public function execute(CommandSender $sender, $commandLabel, array $args) { $leftTicks = $this->getMain()->getServer()->getTick() - $this->getMain()->getRestartTime(); $leftSecs = $leftTicks / 20; $string = MUtils::time_secsToString((int) $leftSecs); if ($sender instanceof Player and ($ses = $this->getSession($sender)) instanceof Session) { $ses->translate(Phrases::CMD_RESTART_RESPONSE, ["time" => $string]); } else { $sender->sendMessage(Phrases::VAR_em . $string . Phrases::VAR_info . " left before server restart"); } }
public function execute() { if (time() >= $this->since + $this->length) { return; } $this->main->getLogger()->notice("Muting user #{$this->uid} of IP address {$this->ip} (client ID {$this->cid}) for " . MUtils::time_secsToString(time() - $this->since - $this->length)); $issue = new MuteIssue(); $issue->since = $this->since; $issue->length = $this->length; $issue->uid = $this->uid; $issue->ip = $this->ip; $issue->cid = $this->cid; $issue->msg = $this->msg; $issue->src = $this->src; $this->main->addMute($issue); }
protected function run(array $args, Session $sender) { $lbl = func_get_arg(2); if (is_string($lbl) and $lbl !== "cg") { $sender->send(Phrases::CMD_GRIND_COIN_ADVICE); } if (!$sender->canStartGrind()) { return $sender->translate(Phrases::CMD_GRIND_COIN_CANNOT_START, ["time" => MUtils::time_secsToString($sender->getGrindWaitTime())]); } if (!$sender->confirmGrind) { $sender->confirmGrind = true; return $sender->translate(Phrases::CMD_GRIND_COIN_REQUEST_CONFIRM, ["length" => MUtils::time_secsToString(Settings::getGrindLength($sender->getRank())), "amplitude" => Settings::getGrindFactor($sender->getRank())]); } $sender->confirmGrind = false; $sender->startGrinding(); return $sender->translate(Phrases::CMD_GRIND_COIN_STARTED); }
public function onCompletion(Server $server) { $main = BasePlugin::getInstance($server); foreach ($server->getOnlinePlayers() as $p) { if ($p->getId() === $this->sesId) { $player = $p; break; } } if (!isset($player)) { $main->getLogger()->notice("Player of {$this->sesId} quitted the server before data were fetched."); return; } $consequence = Settings::getWarnPtsConsequence($this->totalWarnPts, $this->lastWarnTime); if ($consequence->banLength > 0) { $player->kick(TextFormat::RED . "You are banned. You have accumulated " . TextFormat::DARK_PURPLE . $this->totalWarnPts . TextFormat::RED . " warning points, and you still have " . TextFormat::BLUE . MUtils::time_secsToString($consequence->banLength) . TextFormat::RED . " before you are unbanned." . TextFormat::AQUA . "Believe this to be a mistake? Contact us with email at " . TextFormat::DARK_PURPLE . "*****@*****.**"); return; } /** @var bool $success */ /** @var string $query */ extract($this->getResult()); if (!$success) { $player->kick(TextFormat::RED . "Sorry, our server has encountered an internal error when trying to retrieve your data from the database.", false); return; } /** @var int $resulttype */ if ($resulttype === AsyncQuery::TYPE_RAW) { $main->getLogger()->notice("New account pending to register: {$this->name}"); $loginData = null; } else { /** @var mixed[] $result */ $loginData = $result; if (count($main->getSessions()) >= Settings::$SYSTEM_MAX_PLAYERS) { $main->getLogger()->notice("Server slots exceeded optimum level!"); $rank = (int) $loginData["rank"]; if ($rank & Settings::RANK_PERM_MOD) { $main->getLogger()->notice($player->getName() . " bypassed as mod"); } elseif ($rank & Settings::RANK_IMPORTANCE_DONATOR) { $main->getLogger()->notice($player->getName() . " bypassed as donator"); } else { $main->getAltServer($ip, $port); if ($ip !== "0.0.0.0") { $main->getLogger()->notice($player->getName() . " is transferred to {$ip}:{$port}. Feature suppressed in 0.12.1"); // $main->transfer($player, $ip, $port, "This server is full.", false); } } } } $main->newSession($player, $loginData); }
public function sendToSession(Session $session) { $session->send(Phrases::WARNING_MUTED_NOTIFICATION, ["length" => MUtils::time_secsToString($this->length), "since" => date($session->translate(Phrases::WORDS_DATE_FORMAT), $this->since), "till" => date($session->translate(Phrases::WORDS_DATE_FORMAT), $this->since + $this->length), "passed" => MUtils::time_secsToString(time() - $this->since), "left" => MUtils::time_secsToString($this->since + $this->length - time()), "issuer" => $this->src]); }
* @param string $text * @param string $char * @param int $mode * @param bool $array * @return array|string */ public static function align($text, $char = " ", $mode = self::ALIGN_CENTER, $array = false) { $lengths = []; $lines = explode("\n", $text); foreach ($lines as $i => $line) { $lengths[$i] = self::getLength($line); } $paddingLength = self::getLength($char); foreach ($lines as $i => &$line) { $deficit = $lengths[$i]; $need = round($deficit / $paddingLength); if ($mode === self::ALIGN_LEFT) { $line .= str_repeat(" ", $need); } elseif ($mode === self::ALIGN_RIGHT) { $line = str_repeat(" ", $need) . $line; } else { $need /= 2; $line = str_repeat(" ", (int) $need) . $line . str_repeat(" ", ceil($need)); } } return $array ? $lines : implode("\n", $lines); } } MUtils::init();
public function onCompletion(Server $server) { $main = BasePlugin::getInstance($server); foreach ($server->getOnlinePlayers() as $player) { if ($player->getId() === $this->sesId) { break; } } if (!isset($player)) { return; } /** @var bool $success */ /** @var string $query */ extract($this->getResult()); if (!$success) { $player->kick(TextFormat::RED . "Sorry, our server has encountered an internal error when trying to retrieve your data from the database.", false); return; } /** @var int $resulttype */ if ($resulttype === AsyncQuery::TYPE_RAW) { $main->getLogger()->notice("New account pending to register: {$this->name}"); $loginData = null; } else { /** @var mixed[] $result */ $loginData = $result; if (count($main->getSessions()) >= Settings::$SYSTEM_MAX_PLAYERS and isset($loginData["rank"]) and !($loginData["rank"] & Settings::RANK_IMPORTANCE_DONATOR or $loginData["rank"] & Settings::RANK_PERM_MOD)) { $main->getAltServer($ip, $port); $main->transfer($player, $ip, $port, "This server is full.", false); } $conseq = Settings::getWarnPtsConseq($this->totalWarnPts, $loginData["lastwarn"]); if ($conseq->banLength > 0) { $player->kick(TextFormat::RED . "You are banned.\nYou have accumulated " . TextFormat::DARK_PURPLE . $this->totalWarnPts . TextFormat::RED . " warning points,\nand you still have " . TextFormat::BLUE . MUtils::time_secsToString($conseq->banLength) . TextFormat::RED . " before you are unbanned.\n" . TextFormat::AQUA . "Believe this to be a mistake? Contact us with email at " . TextFormat::DARK_PURPLE . "*****@*****.**"); return; } } $main->newSession($player, $loginData); }
private function execWarnOn(CommandSender $issuer, Session $ses) { $msg = $ses->translate(Phrases::WARNING_RECEIVED_NOTIFICATION, ["issuer" => $issuer->getName(), "message" => $this->msg, "points" => $this->points, "totalpoints" => $ses->getWarningPoints()]); $conseq = Settings::getWarnPtsConseq($ses->getWarningPoints()); if ($conseq->banLength) { $msg .= $ses->translate(Phrases::WARNING_BANNED_NOTIFICATION, ["length" => MUtils::time_secsToString($conseq->banLength)]); $msg = "\n" . $msg; $ses->getPlayer()->kick($msg, false); } elseif ($conseq->muteSecs) { $msg .= $ses->translate(Phrases::WARNING_MUTED_NOTIFICATION, ["length" => MUtils::time_secsToString($conseq->muteSecs)]); $ses->getPlayer()->sendMessage($msg); // TODO mute } }
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; } }
public function onEnable() { $this->langs = new LanguageManager($this); ThetaCommand::registerAll($this, $this->getServer()->getCommandMap()); $this->getServer()->getNetwork()->registerPacket(OldLoginPacket::NETWORK_ID, OldLoginPacket::class); $class = $this->getBasicListenerClass(); $this->getServer()->getPluginManager()->registerEvents($this->listener = new $class($this), $this); $class = $this->getSessionListenerClass(); $this->getServer()->getPluginManager()->registerEvents($this->sesList = new $class($this), $this); $this->db = Credentials::getMysql(); new InitDbQuery($this); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new SyncStatusTask($this), 40, 20); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new SessionTickTask($this), 1, 10); $this->getServer()->getScheduler()->scheduleRepeatingTask($this->syncChatTask = new FireSyncChatQueryTask($this), 5); $this->getServer()->getScheduler()->scheduleRepeatingTask(new DbPingQuery($this), 1200); $this->getServer()->getScheduler()->scheduleRepeatingTask(new RestartServerTask($this), 6000); $this->restartTime = $this->getServer()->getTick() + 72000; $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new RandomBroadcastTask($this), 2400, 2400); $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this, function () { $plugin = $this->getServer()->getPluginManager()->getPlugin("FastTransfer"); if ($plugin instanceof Plugin and $plugin->isEnabled()) { $this->getServer()->getPluginManager()->disablePlugin($plugin); } }), 2); // $RESEND_ADD_PLAYER = $this->getResendAddPlayerFreq(); // if($RESEND_ADD_PLAYER > 0){ // $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new ResendPlayersTask($this), $RESEND_ADD_PLAYER, $RESEND_ADD_PLAYER); // } /** @noinspection PhpUsageOfSilenceOperatorInspection */ @touch($this->getDataFolder() . "privmsg.log"); $this->pmLog = fopen($this->getDataFolder() . "privmsg.log", "at"); $this->faceSeeks = json_decode($this->getResourceContents("head.json")); $this->badWords = json_decode($this->getResourceContents("words.json")); $this->approvedDomains = json_decode($this->getResourceContents("approvedDomains.json")); $buildInfo = json_decode($this->getResourceContents("build.json")); $compileTime = $buildInfo->time; $buildNumber = $buildInfo->buildNumber; $buildAuthor = $buildInfo->buildAuthor; Utils::getURL(Credentials::IRC_WEBHOOK_STATUS . urlencode("[Status] [" . Settings::$CLASSES_NAMES[Settings::$LOCALIZE_CLASS] . "] Server at " . Settings::$LOCALIZE_IP . ":" . Settings::$LOCALIZE_PORT . " started."), 3); $this->getServer()->getPluginManager()->setUseTimings(true); TimingsHandler::reload(); $this->getLogger()->alert("Enabled " . $this->getDescription()->getFullName() . " Build {$buildNumber} compiled at " . date("d/m/Y H:i:s (P)", $compileTime) . " (" . MUtils::time_secsToString(time() - $compileTime) . " ago) by {$buildAuthor}. MyPID is " . \getmypid() . "."); }
public function execWarnOn(CommandSender $issuer, Session $ses) { $msg = $ses->translate(Phrases::WARNING_RECEIVED_NOTIFICATION, ["issuer" => $issuer->getName(), "message" => $this->msg, "points" => $this->points, "totalpoints" => $ses->getWarningPoints()]); $consequence = Settings::getWarnPtsConsequence($ses->getWarningPoints(), $this->creation); if ($consequence->banLength) { $msg .= $ses->translate(Phrases::WARNING_BANNED_NOTIFICATION, ["length" => MUtils::time_secsToString($consequence->banLength)]); $msg = "\n" . $msg; $ses->getPlayer()->kick($msg, false); } elseif ($consequence->muteSecs) { $mute = new MuteIssue(); $mute->cid = $this->clientId; $mute->ip = $ses->getPlayer()->getAddress(); $mute->uid = $this->uid; $mute->length = $consequence->muteSecs; $mute->msg = $this->msg; $mute->since = $this->creation; $mute->src = $issuer->getName(); $ses->getPlayer()->sendMessage($msg); MuteHormone::fromObject($ses->getMain(), $mute)->release(); } }
/** * @param string $msg * @param int $type */ public function onChat($msg, $type) { $msg = TextFormat::clean($msg); /** @var MuteIssue $mute */ if ($this->getMain()->isMuted($this, $mute)) { $this->send(Phrases::WARNING_MUTED_NOTIFICATION, ["length" => MUtils::time_secsToString($mute->length), "since" => date($this->translate("date.format"), $mute->since), "till" => date($this->translate("date.format"), $mute->since + $mute->length), "passed" => MUtils::time_secsToString(time() - $mute->since), "left" => MUtils::time_secsToString($mute->since + $mute->length - time())]); return; } $msg = $this->getChatColor() . preg_replace_callback('/@([A-Za-z_]{2,16})/', function ($match) { if (($player = $this->getMain()->getServer()->getPlayer($match[1])) !== null) { return TextFormat::DARK_AQUA . TextFormat::ITALIC . $player->getName() . TextFormat::RESET . $this->getChatColor(); } return TextFormat::ITALIC . TextFormat::GRAY . $match[0] . TextFormat::RESET . $this->getChatColor(); }, $msg); foreach ($this->getMain()->getSessions() as $ses) { // TODO handle $type if ($ses->isLocalChatOn() and ($type !== self::CHAT_LOCAL or Settings::isLocalChat($ses->getPlayer(), $this->getPlayer()))) { $ses->getPlayer()->sendMessage($this->getPlayer()->getDisplayName() . ($type === self::CHAT_ME ? ": " : ">") . $this->getChatColor() . $msg); } } }