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]); }
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 } }
protected function init() { $consequence = $this->getEffectiveConsequence(); if ($consequence->banLength > 0) { $left = MUtils::time_secsToString($consequence->banLength); $this->getPlayer()->kick(TextFormat::RED . "You are banned. You have accumulated " . TextFormat::DARK_PURPLE . $this->getWarningPoints() . TextFormat::RED . " warning points, and you still have " . TextFormat::BLUE . $left . TextFormat::RED . " before you are unbanned. " . TextFormat::AQUA . "Believe this to be a mistake? Email us at " . TextFormat::DARK_PURPLE . "*****@*****.**" . TextFormat::AQUA . " or visit our chatroom at " . TextFormat::DARK_PURPLE . "http://lgpe.co/chat"); return false; } $this->spamDetector = new SpamDetector($this); return true; }
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); } } }