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 alerady in a team!"; } $name = array_shift($args); if (preg_match('#^[A-Za-z][A-Za-z0-9_\\-]{2,62}$#', $name) === 0) { $red = TextFormat::RED; $yellow = TextFormat::YELLOW; $aqua = TextFormat::AQUA; return $red . "A team name must{$yellow} start with an alphabet{$red}, must{$yellow} only contain{$aqua} alphabets{$red},{$aqua} numerals{$red},{$aqua} underscore{$red} and{$aqua} hyphens{$red}, must be{$yellow} at least 3 characters{$red} long and{$yellow} at most 63 characters{$red} long."; } if ($this->main->getTeamManager()->getTeamByExactName($name) instanceof Team) { return TextFormat::RED . "A team with this name already exists!"; } $team = new Team($this->main, $this->main->getMySQLi()->nextTID(), $name, Settings::team_maxCapacity($ses->getRank()), false, [$ses->getUID() => Team::RANK_LEADER]); $ses->getMysqlSession()->data["tid"] = $team->tid; $ses->getMysqlSession()->data["teamrank"] = Team::RANK_LEADER; $ses->getMysqlSession()->data["teamjointime"] = time(); $this->main->getTeamManager()->addTeam($team); $ses->getPlayer()->kick(TextFormat::YELLOW . "You have been kicked from the server in order to apply your changes about creating a team.", false); return null; }
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."); } }
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); }
public function update() { $this->game->getMain()->getMySQLi()->query('INSERT INTO spleef(uid,wins,losses,draws,current_streak)VALUES(%d,%d,%d,%d,%d)ON DUPLICATE KEY UPDATE wins=VALUES(wins),losses=VALUES(losses),draws=VALUES(draws),current_streak=VALUES(current_streak);', MysqlConnection::RAW, (int) $this->session->getUID(), (int) $this->getWins(), (int) $this->getLosses(), (int) $this->getDraws(), 0); }
public function update() { if ($this->changed) { $this->main->getMySQLi()->query("INSERT INTO parkour(uid,progress,completions,falls,tmpfalls)VALUES({$this->session->getUID()},{$this->progress},{$this->completions},{$this->falls},{$this->tmpFalls})ON DUPLICATE KEY UPDATE progress={$this->progress},completions={$this->completions},falls={$this->falls},tmpfalls={$this->tmpFalls};", MysqlConnection::RAW); } }
protected function onRun(Session $ses, array $args) { return TextFormat::AQUA . "Your user ID is " . $ses->getUID() . "."; }
public function getSessionData(Session $session) { return isset($this->data[$session->getUID()]) ? $this->data[$session->getUID()] : null; }
/** * @param Session|Player $player * @param bool $revSearch * @return PvpSessionData|null */ public function getPlayerData($player, $revSearch = false) { if ($player instanceof Session) { return isset($this->playerData[$player->getUID()]) ? $this->playerData[$player->getUID()] : null; } elseif ($player instanceof Player) { if ($revSearch) { $keys = array_keys($this->playerData); for ($i = count($this->playerData); $i > 0;) { if ($this->playerData[$keys[--$i]]->getSession()->getPlayer() === $player) { return $this->playerData[$keys[$i]]; } } } else { foreach ($this->playerData as $data) { if ($data->getSession()->getPlayer() === $player) { return $data; } } } } return null; }