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 ---";
 }
Example #2
0
 public function setKills($kills)
 {
     $this->data["kills"] = $kills;
     if ($kills === 500) {
         $this->session->tell("You are now an experienced KitPvP player! You no longer need the 8 eggs for new players.");
     }
     $this->needSave = true;
 }
 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;
 }
 public function addDraw()
 {
     $draws = ++$this->data["draws"];
     $this->needChange = true;
     $this->session->tell("You totally have {$draws} draw(s).");
     return $draws;
 }
Example #5
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 run(Session $ses, array $args)
 {
     if (!$ses->canActivateGrindCoins($secs)) {
         return TextFormat::RED . "You need to wait for at least " . MUtils::time_secsToString($secs) . " to activate coins grinding again.";
     }
     if (!$ses->wannaGrind) {
         $ses->wannaGrind = true;
         $ses->tell(TextFormat::AQUA . "After enabling coins grinding, coins you received will be multiplied by %s times. This doesn't apply to spending coins.", TextFormat::LIGHT_PURPLE . Settings::coinsFactor($ses, true) . TextFormat::AQUA);
         $ses->tell(TextFormat::AQUA . "It will last for %s each time, and you can't enable it again %s after activation.", TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::AQUA, TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindActivationWaiting($ses)) . TextFormat::AQUA);
         return TextFormat::AQUA . "Run /grindcoin again to confirm enabling coins grinding.";
     }
     $ses->wannaGrind = false;
     $ses->getMysqlSession()->data["lastgrind"] = time();
     return TextFormat::GREEN . "You have activated coins grinding. You will receive an extra of " . TextFormat::LIGHT_PURPLE . (Settings::coinsFactor($ses) * 100 - 100) . "%" . TextFormat::GREEN . " coins for those you earn in the following " . TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::GREEN . ".";
 }
Example #7
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;
 }
 public function tellWrongUsage(Session $session)
 {
     $session->tell("Wrong usage. Usage: " . $this->getUsage());
 }
Example #9
0
 public function onCommand(Command $cmd, array $args, Session $session)
 {
     $data = $this->data[$session->getUID()];
     switch ($cmd->getName()) {
         case "restart":
             $data->setProgress(0);
             $session->teleport($pos = Settings::parkour_checkpoint_startPos(0, $this->getMain()->getServer()));
             $session->getPlayer()->setSpawn($pos);
             $data->resetTmpFalls();
             $session->tell("Your parkour progress has been reset.");
             return;
         case "race":
             if (!isset($args[0])) {
                 $args = ["help"];
             }
             switch ($sub = array_shift($args)) {
                 case "start":
                     if ($data->race !== null) {
                         $session->tell("You can't start a race, because you are already in a race started by {$data->race->starter}. `/race quit` to quit it.");
                         break;
                     }
                     $isOpen = true;
                     while (isset($args[0])) {
                         switch (array_shift($args)) {
                             case "close":
                                 $isOpen = false;
                                 break;
                         }
                     }
                     if ($isOpen) {
                         foreach ($this->data as $dat) {
                             $dat->getSession()->tell("{$session} started an open race. Use `/race join {$session}` to join!");
                         }
                     }
                     $data->race = new ParkourRace($this, $session, $isOpen);
                     $session->tell("Race has been created. Do `/race begin` when all players have joined.");
                     break;
                 case "join":
                     if ($data->race !== null) {
                         $session->tell("You can't join a race because you are already in a race started by {$data->race->starter}. `/race quit` to quit it.");
                         break;
                     }
                     if (!isset($args[0])) {
                         $session->tell("Usage: /race join <starter>");
                         break;
                     }
                     $name = array_shift($args);
                     $starter = $this->getMain()->getSessions()->getSession($name);
                     if (!$starter instanceof Session) {
                         $session->tell("Player {$name} not found!");
                         break;
                     }
                     $starterData = $this->getSessionData($starter);
                     if (!$starterData instanceof ParkourSessionData) {
                         $session->tell("Player {$starter} is not in parkour!");
                         break;
                     }
                     $race = $starterData->race;
                     if (!$race instanceof ParkourRace) {
                         $session->tell("{$starter} isn't holding a race!");
                         $session->tell("Usage: /race join <starter>");
                         break;
                     }
                     if ($race->isStarted()) {
                         $session->tell("The race held by {$starter} was already started!");
                         break;
                     }
                     if (!$race->isInvited($session)) {
                         $session->tell("The race held by {$starter} is not open, and you aren't invited!");
                         break;
                     }
                     $race->join($session);
                     break;
                 case "invite":
                     if (!isset($args[0])) {
                         $session->tell("Usage: /race invite <player>");
                     }
                     $name = array_shift($args);
                     if (!$data->race instanceof ParkourRace) {
                         $session->tell("You are not in a race!");
                         break;
                     }
                     if ($data->race->starter !== $session) {
                         $session->tell("You are not the starter of the race; you don't have permission to invite a player.");
                         break;
                     }
                     if ($data->race->isStarted()) {
                         $session->tell("The race is already started!");
                         break;
                     }
                     $data->race->invite($name);
                     $session->tell("{$name} has been invited.");
                     $player = $this->getMain()->getServer()->getPlayerExact($name);
                     if (!$player instanceof Player) {
                         $session->tell(TextFormat::YELLOW . "Warning: {$name} is not online! Make sure you typed the full name of the player!");
                     } elseif (!($invitedSession = $this->getMain()->getSessions()->getSession($player)) instanceof Session) {
                         $session->tell(TextFormat::YELLOW . "Warning: {$name} is not online! Make sure you typed the full name of the player!");
                     } else {
                         if (!isset($this->data[$invitedSession->getUID()])) {
                             $session->tell(TextFormat::YELLOW . "Warning: {$invitedSession} isn't in parkour!");
                         } elseif ($this->data[$invitedSession->getUID()]->race instanceof ParkourRace) {
                             $session->tell(TextFormat::YELLOW . "Warning: {$invitedSession} is in another race!");
                         }
                         $invitedSession->tell("You have been invited to a parkour race held by {$session}.");
                         break;
                     }
                     break;
                 case "begin":
                     if (!$data->race instanceof ParkourRace) {
                         $session->tell("You aren't in a race. Use `/race start` to start a race!");
                         break;
                     }
                     if ($data->race->starter !== $session) {
                         $session->tell("You don't have permission to start the race. Ask {$data->race->starter} to begin the race!");
                         break;
                     }
                     $data->race->begin();
                     break;
                 case "quit":
                     if ($data->race === null) {
                         $session->tell("You aren't in a race!");
                         break;
                     }
                     $data->race->quit($session);
                     break;
                 default:
                     $session->tell(str_repeat("~", 34));
                     $session->tell("Usage: /race start|invite|join|quit");
                     $session->tell("/race start [open]");
                     $session->tell("/race invite <exact name>");
                     $session->tell("/race join <starter>");
                     $session->tell("/race quit");
                     break;
             }
             return;
     }
     return;
 }
Example #10
0
 public function onCommand(Command $cmd, array $args, Session $session)
 {
     if ($cmd->getName() === "slist") {
         if (!isset($args[0])) {
             $args[0] = "a";
         }
         if ($args[0] === "a") {
             $output = "";
             foreach ($this->arenas as $arena) {
                 $output .= "{$arena}: ";
                 $output .= $arena->isPlaying() ? "playing" : "waiting";
                 $output .= ". Players: ";
                 $closure = function (SpleefSessionData $data) {
                     return $data->getSession()->getPlayer()->getName();
                 };
                 $output .= implode(", ", array_map($closure, $arena->getPlayers()));
                 $output .= ". Spectators: ";
                 $output .= implode(", ", array_map($closure, $arena->getSpectators()));
                 $output .= "\n";
             }
             $session->tell($output);
             return;
         }
         if ($args[0] === "p") {
             $output = "";
             foreach ($this->playerData as $data) {
                 $arena = $data->getArena();
                 $action = $data->isSpectating() ? "spectating" : "playing";
                 $output .= "\n{$data} is {$action} in " . ($arena === null ? "null" : $arena);
             }
             $session->tell($output);
             return;
         }
     }
 }
Example #11
0
 private function onAddFriendCommand(array $args, Session $session)
 {
     if (!isset($args[1])) {
         return "Usage: /friend add <name> (Accept friend request from <name> or send a friend request to <name>";
     }
     $other = $args[1];
     $db = $this->main->getMySQLi();
     $from = $session->getUID();
     $to = $db->fastSearchPlayerUID($other);
     if (!is_int($to)) {
         return "{$other} has never been on this server!";
     }
     if ($from === $to) {
         return "You cannot add yourself as friend!";
     }
     if ($toLarger = $to > $from) {
         $large = $to;
         $small = $from;
     } else {
         $large = $from;
         $small = $to;
     }
     $result = $db->query("SELECT * FROM kitpvp_friends WHERE smalluid={$small} AND largeuid={$large};", MysqlConnection::ASSOC);
     if (!is_array($result)) {
         $result = ["smalluid" => $small, "largeuid" => $large, "type" => self::TYPE_BROKE];
         $null = true;
         // insert
     } else {
         foreach (["smalluid", "largeuid", "type"] as $key) {
             $result[$key] = (int) $result[$key];
         }
     }
     switch ($result["type"]) {
         case self::TYPE_BROKE:
             // send
             $type = $toLarger ? self::TYPE_FROM_SMALL : self::TYPE_FROM_LARGE;
             if (isset($null) and $null === true) {
                 $db->query("INSERT INTO kitpvp_friends(smalluid,largeuid,type)VALUES(%d,%d,%d);", MysqlConnection::RAW, $small, $large, $type);
             } else {
                 $db->query("UPDATE kitpvp_friends SET type=%d WHERE smalluid=%d AND largeuid=%d;", $type, $small, $large);
             }
             $otherSession = $this->main->getSessions()->getSessionByUID($to);
             if ($otherSession instanceof Session) {
                 $otherSession->tell("{$session} sent you a friend request!");
             }
             return "A friend request has been sent to {$other}!";
         case self::TYPE_FROM_SMALL:
         case self::TYPE_FROM_LARGE:
             if (!$this->checkSessionFriendsCount($from, $session->getRank())) {
                 $session->tell("You cannot have more than %d friends. Donate to get a larger quota.", Settings::kitpvp_maxFriends($session));
                 return "";
             }
             if (!$this->checkSessionFriendsCount($to)) {
                 $session->tell("{$other} already has his maximum number of friends!");
                 return "";
             }
             if ($result["type"] === self::TYPE_FROM_SMALL and $toLarger) {
                 return "You have already sent a friend request to {$other}!";
             }
             if ($result["type"] === self::TYPE_FROM_LARGE and !$toLarger) {
                 return "You have already sent a friend request to {$other}!";
             }
             // accept
             $db->query("UPDATE kitpvp_friends SET type=%d WHERE smalluid=%d AND largeuid=%d;", MysqlConnection::ASSOC, self::TYPE_FRIEND, $small, $large);
             $otherSession = $this->main->getSessions()->getSessionByUID($to);
             $this->playerData[$session->getUID()]->addToFriends($to);
             if ($otherSession instanceof Session) {
                 $otherSession->tell("{$session} accepted your friend request!");
                 if (isset($this->playerData[$to])) {
                     $this->playerData[$to]->addToFriends($from);
                 }
             }
             return "You are now friend with {$other}!";
         case self::TYPE_FRIEND:
             return "You are already friend with {$other}!";
     }
     return "";
 }