public function onCompletion(Server $server)
 {
     $id = $this->getId();
     $main = BasePlugin::getInstance($server);
     /** @var CommandSender $issuer */
     $issuer = $main->fetchObject($this->issuer);
     if ($id === -1) {
         $issuer->sendMessage("Failed to create warning");
         $issuer = null;
         // release instance
         return;
     }
     new LogWarningQuery($main, $id, $this->uid, $this->ip, $this->clientId, $issuer->getName(), $this->points, $this->msg, $this->creation, $this->expiry);
     foreach ($main->getSessions() as $ses) {
         if ($ses->getUid() === $this->uid) {
             $ses->addWarningPoints($this->points);
             $done = true;
             $issuer->sendMessage("{$this->points} warning points have been successfully issued to player {$ses->getPlayer()->getName()}.");
             $this->execWarnOn($issuer, $ses);
             Hormone::get($main, Hormone::CONSOLE_MESSAGE, "(Auto){$issuer->getName()}", "Issued {$this->points} warning points to player {$ses->getPlayer()->getName()}: {$this->msg}", Settings::CLASS_ALL, ["ip" => Settings::$LOCALIZE_IP, "port" => Settings::$LOCALIZE_PORT])->release();
             break;
         }
     }
     if (!isset($done)) {
         // you think leaving the game can keep you away from trouble?
         new IncrementWarningPointsQuery($main, $this->points, $this->uid);
         $issuer->sendMessage(TextFormat::GREEN . "Warning points have been successfully issued to offline player.");
     }
 }
 protected function run(array $args, Session $sender)
 {
     if ($sender->getTeamId() === -1) {
         return $sender->translate(Phrases::CMD_TEAM_ERR_NOT_IN_TEAM);
     }
     if (!$sender->confirmQuitTeam) {
         $sender->confirmQuitTeam = true;
         return $sender->getTeamRank() === Settings::TEAM_RANK_LEADER ? $sender->translate(Phrases::CMD_TEAM_QUIT_WARNING_LEADER) : ($sender->getTeamRank() === Settings::TEAM_RANK_JUNIOR ? $sender->translate(Phrases::CMD_TEAM_QUIT_WARNING_JUNIOR) : $sender->translate(Phrases::CMD_TEAM_QUIT_WARNING_NORMAL));
     }
     if ($sender->getTeamRank() === 4) {
         $prop = Hormone::get($this->getMain(), Hormone::TEAM_DISBAND_PROPAGANDA, $sender->getInGameName(), "Team disbanded by owner /tq", Settings::CLASS_ALL, ["tid" => $sender->getTeamId()]);
         $prop->release();
         new RawAsyncQuery($this->getMain(), "UPDATE users SET tid=-1,teamrank=0,teamjoin=0,teampts=0 WHERE tid={$sender->getTeamId()}");
         new RawAsyncQuery($this->getMain(), "DELETE FROM teams WHERE tid=" . $sender->getTeamId());
         return true;
     }
     $type = Hormone::get($this->getMain(), Hormone::TEAM_CHAT, "Network", "%tr%" . Phrases::CMD_TEAM_QUITTED, Settings::CLASS_ALL, ["tid" => $sender->getTeamId(), "teamName" => $sender->getTeamName(), "ign" => "Network", "data" => ["name" => $sender->getPlayer()->getName(), "teamname" => $sender->getTeamName()]]);
     $type->release();
     $sender->setLoginDatum("tid", -1);
     $sender->setLoginDatum("teamname", null);
     $sender->setLoginDatum("teamrank", 0);
     $sender->setLoginDatum("teamjoin", 0);
     $sender->setLoginDatum("teampts", 0);
     return $sender->translate(Phrases::CMD_TEAM_QUITTED);
 }
 protected function run(array $args, Session $sender)
 {
     if (!isset($args[0])) {
         return false;
     }
     $msg = implode(" ", $args);
     $local = true;
     if (substr($msg, 0, 1) === ".") {
         $msg = substr($msg, 1);
         $local = false;
     }
     $type = Hormone::get($sender->getMain(), Hormone::CONSOLE_MESSAGE, $sender->getInGameName(), $msg, $local ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, ["ip" => Settings::$LOCALIZE_IP, "port" => Settings::$LOCALIZE_PORT]);
     $type->release();
     return "Message sent to every staff member.";
 }
 public function execute(CommandSender $sender, $commandLabel, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     $msg = implode(" ", $args);
     $local = true;
     if (substr($msg, 0, 1) === ".") {
         $msg = substr($msg, 1);
         $local = false;
     }
     $type = Hormone::get($this->getMain(), Hormone::SERVER_BROADCAST, $sender->getName(), $msg, $local ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, []);
     $type->release();
     return true;
 }
 public function onCompletion(Server $server)
 {
     $main = BasePlugin::getInstance($server);
     $result = $this->getResult();
     if ($this->lastId === null) {
         $main->setInternalLastChatId($this->fetchedMaxId);
         $result = $this->getResult()["result"];
         foreach ($result as $row) {
             $type = Hormone::get($main, Hormone::MUTE_CHAT, $row["src"], $row["msg"], Settings::$LOCALIZE_CLASS, json_decode($row["json"]));
             $type->execute();
         }
     } elseif ($result["resulttype"] === self::TYPE_ALL) {
         $result = $this->getResult()["result"];
         foreach ($result as $row) {
             $row["json"] = json_decode($row["json"], true);
             $main->handleChat($row);
         }
     }
     $task = $main->getFireSyncChatQueryTask();
     $task->canFireNext = true;
 }
 public function onCompletion(Server $server)
 {
     $result = $this->getResult();
     if ($result["resulttype"] !== self::TYPE_ASSOC) {
         return;
     }
     $main = BasePlugin::getInstance($server);
     /** @var Session $sender */
     $sender = $main->fetchObject($this->sender);
     $result = $result["result"];
     if ($result["tid"] !== $sender->getTeamId()) {
         $sender->send(Phrases::CMD_TEAM_ERR_DIFFERENT_TEAM);
         return;
     }
     if ($result["teamrank"] >= $sender->getTeamRank()) {
         $sender->send(Phrases::CMD_TEAM_KICK_LOW_TO_HIGH);
         return;
     }
     Hormone::get($main, Hormone::TEAM_KICK_PROPAGANDA, $sender->getInGameName(), $this->msg, Settings::CLASS_ALL, ["uid" => $result["uid"]])->release();
     new RawAsyncQuery($main, "UPDATE users SET tid=-1, teamrank=0, teamjoin=0, teampts=0 WHERE uid=" . $result["uid"]);
     $sender->send(Phrases::CMD_TEAM_KICK_SUCCESS);
 }
 public function onCompletion(Server $server)
 {
     $main = BasePlugin::getInstance($server);
     $ses = $main->getSessionByUid($this->senderUid);
     if (!$ses instanceof Session) {
         return;
     }
     $result = $this->getResult();
     if ($result["resulttype"] !== self::TYPE_ASSOC) {
         $ses->send(Phrases::CMD_ERR_NOT_FOUND, ["name" => $this->name]);
         return;
     }
     $targetUid = $result["result"]["uid"];
     $result = $ses->setFriendAttempt($targetUid, $this->type, $prop);
     if ($prop) {
         $type = Hormone::get($main, Hormone::RELOAD_FRIENDS_PROPAGANDA, $ses->getPlayer()->getName(), "{$result}", Settings::CLASS_ALL, ["uid" => $targetUid]);
         $type->release();
         $type = Hormone::get($main, Hormone::RELOAD_FRIENDS_PROPAGANDA, $this->name, "{$result}", Settings::CLASS_ALL, ["uid" => $this->senderUid]);
         $type->release();
     }
     $ses->send(self::$RESPONSES[$result], ["from" => $ses->getInGameName(), "to" => $this->name, "target" => $this->name, "req" => self::$TYPES[$this->type], "cur" => self::$TYPES[$ses->getFriend($targetUid)->type]]);
 }
 public function onCompletion(Server $server)
 {
     $main = BasePlugin::getInstance($server);
     $result = $this->getResult();
     $ses = $main->getSessionByUid($this->uid);
     if (!$ses instanceof Session) {
         return;
     }
     if ($result["success"] === false) {
         $ses->send($result["error"]);
         return;
     }
     $data = ["teamname" => $this->teamName];
     $data["name"] = $ses->getPlayer()->getName();
     switch ($this->type) {
         case self::REQUEST_FROM_USER:
             $ses->send(Phrases::CMD_TEAM_JOIN_ALREADY_REQUESTED, $data);
             break;
         case self::REQUEST_FROM_TEAM:
             $ses->send(Phrases::CMD_TEAM_JOIN_ACCEPTED, $data);
             $joined = true;
             break;
         case self::DIRECT_JOIN:
             $ses->send(Phrases::CMD_TEAM_JOIN_DIRECTLY_JOINED, $data);
             $joined = true;
             break;
         default:
             $type = Hormone::get($main, Hormone::TEAM_CHAT, "Network", "%tr%" . Phrases::CMD_TEAM_REQUEST_RECEIVED, Settings::CLASS_ALL, ["tid" => $this->tid, "teamName" => $this->teamName, "ign" => "Network", "data" => ["name" => $this->playerName]]);
             $type->release();
             $ses->send(Phrases::CMD_TEAM_JOIN_REQUESTED, $data);
             break;
     }
     if (isset($joined, $ses)) {
         $ses->setLoginDatum("tid", $this->tid);
         $ses->setLoginDatum("teamname", $this->teamName);
         $ses->setLoginDatum("teamjoin", time());
         $ses->setLoginDatum("teampts", 0);
         $ses->setLoginDatum("teamrank", 0);
         $ses->recalculateNameTag();
         $type = Hormone::get($main, Hormone::TEAM_CHAT, "Network", "%tr%" . Phrases::CMD_TEAM_JOINED, Settings::CLASS_ALL, ["tid" => $this->tid, "teamName" => $this->teamName, "ign" => "Network", "data" => $data]);
         $type->release();
     }
 }
 public function partChannel($channel)
 {
     $subs = $this->getChannelSubscriptions();
     $lowerChannels = array_keys(array_change_key_case($subs, CASE_LOWER));
     $pos = array_search(strtolower($channel), $lowerChannels);
     if ($pos !== false) {
         $caseName = array_keys($subs)[$pos];
         unset($subs[$caseName]);
         $this->setLoginDatum("channels", $subs);
         new PartChannelQuery($this->getMain(), $this->getUid(), $caseName);
         $type = Hormone::get($this->getMain(), Hormone::CHANNEL_CHAT, $this->getPlayer()->getName(), "%tr%" . Phrases::CMD_CHANNEL_QUITTED, Settings::CLASS_ALL, ["channel" => $channel, "fromClass" => Settings::$LOCALIZE_CLASS, "ign" => $this->inGameName, "level" => self::CHANNEL_SUB_VERBOSE, "data" => ["player" => $this->getInGameName(), "ip" => Settings::$LOCALIZE_IP, "port" => Settings::$LOCALIZE_PORT, "channel" => $channel]]);
         $type->release();
     }
 }
 public function onCompletion(Server $server)
 {
     $result = $this->getResult();
     $main = BasePlugin::getInstance($server);
     $sender = $main->getSessionByUid($this->issuerUid);
     if ($sender === null) {
         return;
     }
     if ($result["success"] === false) {
         $sender->send($result["error"]);
         return;
     }
     if ($this->warnInTeam) {
         $sender->send(Phrases::CMD_TEAM_INVITE_TARGET_IN_TEAM);
     }
     if ($this->type === JoinTeamQuery::REQUEST_FROM_USER) {
         $sender->send(Phrases::CMD_TEAM_INVITE_ACCEPTED_SENDER, ["name" => $this->targetName]);
     } else {
         $sender->send(Phrases::CMD_TEAM_INVITE_SENT, ["name" => $this->targetName]);
         $main->sendPrivateMessage($this->targetUid, "%tr%" . Phrases::CMD_TEAM_INVITED, ["team" => $sender->getTeamName()]);
         return;
     }
     $type = Hormone::get($main, Hormone::TEAM_JOIN_PROPAGANDA, $this->issuerName, "", Settings::CLASS_ALL, ["uid" => $this->targetUid, "tid" => $this->tid, "teamName" => $this->teamName]);
     $type->release();
     $type = Hormone::get($main, Hormone::TEAM_CHAT, "Network", "%tr%" . Phrases::CMD_TEAM_JOINED, Settings::CLASS_ALL, ["tid" => $this->tid, "teamName" => $this->teamName, "ign" => "Network", "data" => ["teamname" => $this->teamName, "name" => $this->targetName]]);
     $type->release();
 }
 public function onCompletion(Server $server)
 {
     $main = BasePlugin::getInstance($server);
     /** @var Session $sender */
     $sender = $main->fetchObject($this->sender);
     $result = $this->getResult();
     if ($sender->getPlayer() === null) {
         return;
     }
     if ($result["resulttype"] !== self::TYPE_ASSOC) {
         $sender->send(Phrases::CMD_ERR_NOT_FOUND, ["name" => $this->name]);
         return;
     }
     $result = $result["result"];
     $teamrank = $result["teamrank"];
     $tid = $result["tid"];
     if ($tid !== $sender->getTeamId()) {
         $sender->send(Phrases::CMD_TEAM_ERR_DIFFERENT_TEAM);
         return;
     }
     if ($sender->getTeamRank() <= $teamrank) {
         $sender->send(Phrases::CMD_TEAM_RANK_CHANGE_NEED_TO_LOW);
         return;
     }
     if ($teamrank === Settings::TEAM_RANK_JUNIOR and !$this->promote) {
         $sender->send(Phrases::CMD_TEAM_RANK_CHANGE_NO_DEMOTE_JUNIOR);
         return;
     }
     if ($teamrank === Settings::TEAM_RANK_COLEAD and $this->promote) {
         $sender->send(Phrases::CMD_TEAM_RANK_CHANGE_NO_PROMOTE_CO_LEADER);
         return;
     }
     if ($teamrank === Settings::TEAM_RANK_LEADER) {
         $sender->send(Phrases::CMD_TEAM_RANK_CHANGE_ONE_LEADER);
         return;
     }
     if ($this->promote) {
         $teamrank++;
         $sender->translate(Phrases::CMD_TEAM_RANK_CHANGE_PROMOTED, ["name" => $this->name, "newrank" => $sender->translate(Phrases::WORDS_TEAM_RANKS)[$teamrank]]);
     } else {
         $teamrank--;
         $sender->translate(Phrases::CMD_TEAM_RANK_CHANGE_PROMOTED, ["name" => $this->name, "newrank" => $sender->translate(Phrases::WORDS_TEAM_RANKS)[$teamrank]]);
     }
     $hormone = Hormone::get($main, Hormone::TEAM_RANK_CHANGE_HORMONE, $sender->getInGameName(), "", Settings::CLASS_ALL, ["uid" => (int) $result["uid"], "newRank" => $teamrank]);
     $hormone->release();
     new RawAsyncQuery($main, "UPDATE users SET teamrank={$teamrank} WHERE uid=" . $result["uid"]);
 }
 public function handleChat(array $row)
 {
     $this->setInternalLastChatId($row["id"]);
     $source = $row["src"];
     $message = $row["msg"];
     $type = $row["type"];
     $class = $row["class"];
     $data = $row["json"];
     $exe = Hormone::get($this, $type, $source, $message, $class, $data, (int) $row["id"]);
     $exe->execute();
 }
 public function detectCaps(&$string)
 {
     if (strtoupper($string) === $string and strtolower($string) !== $string) {
         $string = strtolower($string);
         $type = Hormone::get($this->session->getMain(), Hormone::CONSOLE_MESSAGE, "{BOT}CapsDetector", Phrases::VAR_notify2 . "Player {$this->session->getPlayer()->getName()}@" . Settings::$LOCALIZE_IP . ":" . Settings::$LOCALIZE_PORT . " said: " . $string . " (automatically de-capitalized)", Settings::CLASS_ALL, ["ip" => Settings::$LOCALIZE_IP, "port" => Settings::$LOCALIZE_PORT]);
         $type->release();
     }
 }