Ejemplo n.º 1
0
 protected function onRun(Session $ses, array $args)
 {
     if (!isset($args[0])) {
         return TextFormat::RED . "Usage: " . $this->getUsage();
     }
     if ($ses->getTeam() instanceof Team) {
         return TextFormat::RED . "You are already in a team!";
     }
     $team = $this->main->getTeamManager()->getTeamByName($name = array_shift($args));
     if (!$team instanceof Team) {
         return TextFormat::RED . "Team \"{$name}\" not found! Try using \"/team list\" to search discover teams.";
     }
     if ($team->isFull()) {
         return TextFormat::RED . "Team {$team} is already full!";
     }
     if (!$team->canJoin($ses)) {
         return TextFormat::RED . "You must be invited to join the team!";
     }
     $team->tell(TextFormat::AQUA . "{$ses} joined the team!");
     $team->join($ses);
     if (isset($team->invited[$ses->getUID()])) {
         unset($team->invited[$ses->getUID()]);
     }
     $ses->getPlayer()->kick(TextFormat::YELLOW . "You have joined Team {$team}. You have been kicked from the server to aply the changes.", false);
     return TextFormat::GREEN . "You have joined Team {$team}! You are going to be kicked to apply the changes.";
 }
Ejemplo n.º 2
0
 protected function run(Session $ses, array $args)
 {
     if (!isset($args[0])) {
         $ses->tell("Usage: /auth <option> [value]");
         goto listopts;
     }
     $opt = array_shift($args);
     $value = array_shift($args);
     switch ($opt) {
         case "lastip":
             if ($value === "yes") {
                 $ses->getMysqlSession()->data["ipconfig"] = Session::IPCONFIG_LASTIP;
                 return "You are now going to be authenticated by your last IP OR your password.";
             }
             if ($value === "no") {
                 $ses->getMysqlSession()->data["ipconfig"] = Session::IPCONFIG_DISABLE;
                 return "You are now going to be authenticated by your password ONLY.";
             }
             return "Last-IP authentication is {$this->boolStr($ses->getMysqlSession()->data["ipconfig"] === Session::IPCONFIG_LASTIP)} for you.";
     }
     $ses->tell("Unknown option. Available options:");
     listopts:
     $ses->tell("_____________________");
     $ses->tell("| Option |  Value   |");
     $ses->tell("| lastip | no / yes |");
     $ses->tell("---------------------");
     return "Example: /auth ip no";
 }
 protected function onRun(Session $ses, array $args)
 {
     if ($ses->openChooseGameInv()) {
         return TextFormat::GREEN . "Open your inventory and click on an item to choose a game.";
     }
     return null;
 }
 protected function onRun(Session $ses, array $args)
 {
     if (isset($args[0])) {
         $name = array_shift($args);
         $team = $this->main->getTeamManager()->getTeamByName($name);
     } else {
         $team = $ses->getTeam();
     }
     if (!$team instanceof Team) {
         return TextFormat::RED . "Usage: /team members [team name]";
     }
     $lightPurple = TextFormat::LIGHT_PURPLE;
     $darkBlue = TextFormat::DARK_BLUE;
     $ses->tell(TextFormat::DARK_BLUE . "Members in {$lightPurple}{$team->name}{$darkBlue}: (%d / %d)", $lightPurple . count($team->members) . $darkBlue, $lightPurple . $team->maxCapacity . $darkBlue);
     $members = array_fill_keys(array_keys(Team::$RANK_NAMES), []);
     $this->main->getTeamManager()->saveTeam($team);
     $sess = array_map(function (Session $session) {
         return $session->getMysqlSession();
     }, $this->main->getTeamManager()->getSessionsOfTeam($team));
     if (count($sess) > 0) {
         MysqlSession::saveData($sess, $this->main->getMySQLi());
     }
     $result = $this->main->getMySQLi()->query("SELECT names,teamrank FROM players WHERE tid=%d", MysqlConnection::ALL, $team->tid);
     foreach ($result as $r) {
         $members[(int) $r["teamrank"]][] = substr($r["names"], 0, -1);
     }
     foreach ($members as $rank => $group) {
         $ses->tell($lightPurple . Team::$RANK_NAMES[$rank] . $darkBlue . ": " . $lightPurple . implode(", ", $group) . $darkBlue);
     }
     return TextFormat::DARK_BLUE . "--- END OF MEMBERS LIST ---";
 }
Ejemplo n.º 5
0
 protected function onRun(Session $ses, array $args)
 {
     $team = $ses->getTeam();
     if (!$team instanceof Team) {
         return TextFormat::RED . "You are not in a team!";
     }
     if (!$ses->quitTeamConfirmed) {
         $ses->quitTeamConfirmed = true;
         return TextFormat::YELLOW . "Are you sure to quit your team? You may not be able to join the team again! If you are the leader, you are going to disband the team! Run \"/team q\" again to confirm.";
     }
     $ses->quitTeamConfirmed = false;
     if ($ses->getTeamRank() === Team::RANK_LEADER) {
         $team->tell(TextFormat::YELLOW . "Team {$team} is disbanding because the leader is quitting the team! You are going to be kicked to apply the changes.");
         /** @var Session $ses */
         foreach ($team->getSessionsOnline() as $ses) {
             $team->quit($ses);
             $ses->getPlayer()->kick(TextFormat::YELLOW . "Your team has been disbanded. You have been kicked to apply the changes", false);
         }
         $this->main->getMySQLi()->query("UPDATE PLAYERS SET tid=-1,teamrank=0,teamjointime=0 WHERE tid={$team->tid}", MysqlConnection::RAW);
         $this->main->getTeamManager()->rmTeam($team);
         return null;
     }
     $team->quit($ses);
     $ses->getPlayer()->kick(TextFormat::YELLOW . "You have quitted your team. You have been kicked to apply the changes.", false);
     return null;
 }
Ejemplo n.º 6
0
 protected function onRun(Session $ses, array $args)
 {
     if (!($team = $ses->getTeam()) instanceof Team) {
         return TextFormat::RED . "You aren't in a team!";
     }
     $ses->setWriteToChannel($ch = $team->getChannel());
     return TextFormat::GREEN . "You are now talking on #{$ch}.";
 }
Ejemplo n.º 7
0
 protected function run(Session $ses, array $args)
 {
     $game = $ses->getGame();
     if ($game instanceof Game) {
         return $game->onStats($ses, $args);
     } else {
         return TextFormat::RED . "You aren't in a game.";
     }
 }
 protected function onRun(Session $ses, array $args)
 {
     $session = "UNKNOWN";
     foreach ((new \ReflectionClass(Session::class))->getConstants() as $name => $value) {
         if ($value === $ses->getSessionId()) {
             $session = $name;
             break;
         }
     }
     return TextFormat::AQUA . "You are in session " . $session . "({$ses->getSessionId()}";
 }
 protected function onRun(Session $ses, array $args)
 {
     if ($ses->getInventorySession() === Session::INV_NORMAL_ACCESS) {
         return TextFormat::RED . "Your inventory type is already at normal access";
     }
     if (in_array($ses->getInventorySession(), [Session::INV_CHOOSE_GAME])) {
         $ses->invSession = Session::INV_NORMAL_ACCESS;
         return TextFormat::GREEN . "Your inventory type has been normalized.";
     }
     return TextFormat::YELLOW . "Error! Your inventory type is unknown!";
 }
Ejemplo n.º 10
0
 protected function onRun(Session $ses, array $args)
 {
     if (($game = $ses->getGame()) instanceof Game) {
         $ch = $game->getDefaultChatChannel();
     } else {
         $ch = $this->main->getDefaultChannel();
     }
     if (!$ch->isSubscribing($ses)) {
         return TextFormat::RED . "It seems like you were kicked from your current game's or hub's chat channel.";
     }
     $ses->setWriteToChannel($ch);
     return TextFormat::GREEN . "You are now talking on #{$ch}.";
 }
 protected function onRun(Session $ses, array $args)
 {
     if (!($team = $ses->getTeam()) instanceof Team) {
         return TextFormat::RED . "You aren't in a team!";
     }
     if ($ses->getTeamRank() < Team::RANK_CO_LEADER) {
         return TextFormat::RED . "You must be a leader or a co-leader to change the state of your team!";
     }
     if ($team->open === $this->open) {
         return TextFormat::RED . "Your team is already a " . TextFormat::LIGHT_PURPLE . ($this->open ? "open" : "closed") . TextFormat::GREEN . " team!";
     }
     $team->open = $this->open;
     return TextFormat::GREEN . "Your team is now a " . TextFormat::LIGHT_PURPLE . ($this->open ? "open" : "closed") . TextFormat::GREEN . " team.";
 }
 protected function onRun(Session $ses, array $args)
 {
     if (!($team = $ses->getTeam()) instanceof Team) {
         return TextFormat::RED . "You are not in a team!";
     }
     $value = trim(implode(" ", array_filter($args)));
     $field = $this->fieldName;
     if ($value === "") {
         return TextFormat::GREEN . ucfirst($this->humanName) . " for Team {$team}:\n" . TextFormat::RESET . str_replace("\n", "\n" . TextFormat::RESET, $team->{$field});
     }
     $value = preg_replace('/ ?\\| ?/', "\n", $value);
     $team->{$field} = $value;
     return TextFormat::GREEN . "The {$this->humanName} for Team {$team} has been changed to:\n" . TextFormat::RESET . str_replace("\n", "\n" . TextFormat::RESET, $value);
 }
Ejemplo n.º 13
0
 protected function run(Session $ses, array $args)
 {
     if (!isset($args[0])) {
         $args = ["help"];
     }
     switch (array_shift($args)) {
         case "on":
             $ses->getMysqlSession()->data["notag"] = 0;
             return TextFormat::GREEN . "Chat tags have been enabled.";
         case "off":
             $ses->getMysqlSession()->data["notag"] = 1;
             return TextFormat::GREEN . "Chat tags have been disabled.";
         case "check":
             return TextFormat::AQUA . "Your tag is " . ($ses->getMysqlSession()->data["notag"] === 0 ? "on" : "off");
     }
     return TextFormat::RED . "Usage: " . $this->getUsage();
 }
Ejemplo n.º 14
0
 public function onRun(Session $session, array $args)
 {
     if (!$session->getTeam() instanceof Team) {
         return TextFormat::RED . "You aren't in a team!";
     }
     if (!isset($args[0])) {
         return TextFormat::RED . "Usage: " . $this->getUsage();
     }
     $kicked = $this->getSession(array_shift($args));
     if (!$kicked instanceof Session) {
         return TextFormat::RED . "There is no player online by that name.";
     }
     if ($kicked === $session) {
         return TextFormat::RED . "You can't kick yourself from your team!\n" . TextFormat::AQUA . "Use " . TextFormat::LIGHT_PURPLE . "/team rank" . TextFormat::AQUA . " instead.";
     }
     if ($kicked->getTeam() !== $session->getTeam()) {
         return TextFormat::RED . "{$kicked} is not in your team.";
     }
     if ($session->getTeamRank() < Team::RANK_CO_LEADER) {
         return TextFormat::RED . "You must be at least a Co-Leader to kick a team member.";
     }
     if ($kicked->getTeamRank() >= $session->getTeamRank()) {
         return TextFormat::RED . "You can only kick team members of lower rank than you.";
     }
     $session->getTeam()->quit($kicked);
     $session->getPlayer()->kick(TextFormat::YELLOW . "You have been kicked from your team. You are kicked from the server to apply the changes.", false);
     return "{$session} has been kicked from the team.";
 }
Ejemplo n.º 15
0
 public function __construct(Session $session)
 {
     $this->session = $session;
     $this->onSince = time();
     //		$this->data = $this->session->getMain()->getMySQLi()->query(
     //			"SELECT * FROM players WHERE INSTR(names, %s);",
     //			MysqlConnection::ASSOC, $session->getPlayer()->getName() . "|");
     $isOld = is_array($this->data = $this->session->getMain()->getMySQLi()->query("SELECT * FROM players WHERE primaryname=%s;", MysqlConnection::ASSOC, strtolower($session->getPlayer()->getName())));
     if (!$isOld) {
         $session->getMain()->getStats()->increment(LegionPE::TITLE_LEGIONPE_NEW_JOINS);
     } else {
         foreach (["uid", "lastonline", "registry", "ipconfig", "notag", "lastgrind", "rank", "tid", "teamrank", "teamjointime", "warnpts"] as $key) {
             if (!isset($this->data[$key])) {
                 $this->data[$key] = 0;
             } else {
                 $this->data[$key] = (int) $this->data[$key];
             }
         }
         $this->data["coins"] = $this->lastCoins = (double) $this->data["coins"];
     }
 }
 protected function onRun(Session $ses, array $args)
 {
     $team = $ses->getTeam();
     if (!$team instanceof Team) {
         return TextFormat::RED . "You are not in a team!";
     }
     if (!isset($args[0])) {
         return TextFormat::RED . "Usage: " . $this->getUsage();
     }
     $target = $this->getSession(array_shift($args));
     if (!$target instanceof Session) {
         return TextFormat::RED . "There is no player online by that name!";
     }
     if (!isset($team->members[$target->getUID()])) {
         return TextFormat::RED . $target->getRealName() . " is not in your team!";
     }
     $myRank = $ses->getTeamRank();
     $lightPurple = TextFormat::LIGHT_PURPLE;
     $red = TextFormat::RED;
     $aqua = TextFormat::AQUA;
     if ($myRank < Team::RANK_CO_LEADER) {
         return $red . "You must be{$lightPurple} a team leader or co-leader{$red} to promote/demote players!";
     }
     $hisRank = $ses->getTeamRank();
     if ($hisRank === Team::RANK_CO_LEADER and $this->promote) {
         return TextFormat::RED . "There can only be one leader per team, and the leadership cannot be transferred. \n{$aqua}" . "You can contact an{$lightPurple} admin{$aqua}, a{$lightPurple} developer{$aqua} or an{$lightPurple} owner{$aqua} if you have special reasons.";
     }
     if ($hisRank === Team::RANK_JUNIOR and !$this->promote) {
         return TextFormat::RED . "Junior-Member is already the lowest rank. \n{$aqua}" . "Use {$lightPurple}/t k{$aqua} if you wish to kick the player.";
     }
     if ($hisRank >= $myRank) {
         return TextFormat::RED . "You can only promote/demote members of lower rank than you!";
     }
     $team->members[$target->getUID()] = $target->getMysqlSession()->data["teamrank"] = $this->promote ? ++$hisRank : --$hisRank;
     $rankName = Team::$RANK_NAMES[$hisRank];
     $target->tell(TextFormat::AQUA . "You have been " . $this->getName() . "d to a{$lightPurple} {$rankName}{$aqua} by " . $ses->getRealName() . ". \n" . TextFormat::GREEN . "If you wish to have your nametag updated, please rejoin.\n{$aqua}" . "If you don't mind, you don't need to rejoin; your nametag will be updated the next time you join.");
     // TODO $session->recalculateNametag()
     return TextFormat::GREEN . $target->getRealName() . " has been " . $this->getName() . "d to a{$lightPurple} {$rankName}.";
 }
Ejemplo n.º 17
0
 protected function run(Session $ses, array $args)
 {
     $args = array_filter($args);
     if (!isset($args[0])) {
         return "Usage: " . $this->getUsage();
     }
     if (count($args) === 1) {
         $isOn = $ses->isChatOn();
         $req = $this->strBool($args[0], true);
         if ($req === $isOn) {
             return "Your chat is already {$this->boolStr($req)}!";
         }
         $ses->setChat($req);
         return "Your chat is now {$this->boolStr($req)}. Note that you may still be not listening to some channels if you have used /chat off <channel>.";
     }
     $req = $this->strBool(array_shift($args), true);
     $chan = ltrim(array_shift($args), "#");
     $isOn = !$ses->isIgnoringChannel($chan);
     if ($req === $isOn) {
         return "You were {$this->boolNot(!$req)}ignoring chat from #{$chan}!";
     }
     $req ? $ses->unignoreChannel($chan) : $ses->ignoreChannel($chan);
     return "You are now {$this->boolNot(!$req)}ignoring chat from #{$chan}.";
 }
Ejemplo n.º 18
0
 public function broadcastProgress(Session $session, $progress)
 {
     if (isset($this->won[$session->getUID()])) {
         return;
     }
     $diff = microtime(true) - $this->startTime;
     $time = MUtils::time_secsToString($diff);
     $this->broadcast("{$session} arrive at %s, spending %s!", $progress === 0 ? "the end" : "checkpoint {$progress}", substr($time, 0, -2));
     if ($progress === 0) {
         $this->won[$session->getUID()] = true;
     }
     if (count($this->won) === count($this->players)) {
         $this->broadcast("All players have finished. Race has ended.");
     }
 }
Ejemplo n.º 19
0
 public function __construct(Session $session)
 {
     $this->ses = $session;
     $this->bypass = ($session->getRank() & Settings::RANK_PERM_SPAM) > 0;
 }
Ejemplo n.º 20
0
 protected function checkPerm(Session $session)
 {
     return ($session->getImportanceRank() & Settings::RANK_IMPORTANCE_DONATOR) > 0;
 }
Ejemplo n.º 21
0
 protected function onRun(Session $ses, array $args)
 {
     if (isset($args[0])) {
         $team = $this->main->getTeamManager()->getTeamByName($args[0]);
     } elseif (!($team = $ses->getTeam()) instanceof Team) {
         return TextFormat::RED . "You are not in a team! Usage: " . $this->getUsage();
     }
     $this->main->updateGameSessionData();
     $info = $team->getStats();
     $new = $info->totalMembers - $info->oldMembers;
     $ses->tell(TextFormat::DARK_BLUE . "%s team {$team} ({$info->totalMembers} / {$team->maxCapacity} members%s)", $team->open ? "Open" : "Invite-only", $new > 0 ? $new > 1 ? ", {$new} are new" : ", 1 is new" : "");
     $ses->tell("Requirements to join the team: ");
     foreach (explode("\n", $team->requires) as $line) {
         $ses->tell(TextFormat::RESET . $line);
     }
     $ses->tell("Team rules:");
     foreach (explode("\n", $team->rules) as $line) {
         $ses->tell(TextFormat::RESET . $line);
     }
     $gold = TextFormat::GOLD;
     $dg = TextFormat::DARK_GREEN;
     $kd = $info->pvpDeaths > 0 ? (string) round($info->pvpKills / $info->pvpDeaths, 3) : "N/A";
     $ses->tell($gold . "KitPvP:{$dg} {$info->pvpKills} kills, {$info->pvpDeaths} deaths, max killstreak {$info->pvpMaxStreak}, Overall K/D {$kd}");
     $ses->tell($gold . "Parkour:{$dg} {$info->parkourWins} completions, average {$info->parkourAvgFalls()} falls per completion");
     $ses->tell($gold . "Spleef:{$dg} {$info->spleefWins} wins, {$info->spleefLosses} losses, {$info->spleefDraws} draws");
     $ses->tell($gold . "Overall team points:{$dg} " . round($info->totalPoints() / $info->oldMembers, 3));
     return null;
 }
Ejemplo n.º 22
0
 public function checkPerm(Session $ses)
 {
     return $ses->isMod();
 }
Ejemplo n.º 23
0
 public function __toString()
 {
     return $this->session->__toString();
 }
Ejemplo n.º 24
0
 protected function checkPerm(Session $ses)
 {
     return $ses->isMod();
 }
Ejemplo n.º 25
0
 public function tellWrongUsage(Session $session)
 {
     $session->tell("Wrong usage. Usage: " . $this->getUsage());
 }
Ejemplo n.º 26
0
 public function canJoin(Session $session)
 {
     $a = count($this->members) < $this->maxCapacity;
     $b = $this->open;
     $c = isset($this->invited[$session->getUID()]);
     return $a and ($b or $c);
 }
Ejemplo n.º 27
0
 private function warn($column, Session $issuer, $msg)
 {
     $this->tell("{$issuer} issued you a warning: {$msg}!");
     $times = ++$this->mysqlSession->data[$column];
     $this->tell("This is your %s time being warned for this!", $ord = $times . MUtils::num_getOrdinal($times));
     $this->mysqlSession->setData();
     $issuer->tell("Warned {$this} for the {$ord} time");
     return $times;
 }
Ejemplo n.º 28
0
 protected function run(Session $ses, array $args)
 {
     return "You have {$ses->getCoins()} coins left.";
 }
Ejemplo n.º 29
0
 /**
  * @param string|Player $player
  * @return false|Session
  */
 public function getSession($player)
 {
     if (!$player instanceof Player) {
         $player = $this->getMain()->getServer()->getPlayer($player);
     }
     if (!$player instanceof Player) {
         return false;
     }
     return isset($this->sessions[$i = Session::offset($player)]) ? $this->sessions[$i] : false;
 }
Ejemplo n.º 30
0
 protected function onRun(Session $ses, array $args)
 {
     return TextFormat::AQUA . "You are currently talking on #" . $ses->getWriteToChannel() . ".";
 }