protected function getNewUser($username = "******", $role = Player::PLAYER) { // Try to find a valid bzid $bzid = 300; while (Player::getFromBZID($bzid)->isValid()) { ++$bzid; if ($bzid > 15000) { throw new Exception("bzid too big"); } } return Player::newPlayer($bzid, $username, null, "test", $role); }
public function playerByBzidAction(Player $me, Request $request, FlashBag $flashBag, $bzid = null) { if (!$me->hasPermission(Permission::VIEW_VISITOR_LOG)) { throw new ForbiddenException(); } if ($bzid === null) { if (!$request->query->has('bzid')) { throw new BadRequestException("Please provide the BZID to search for"); } $bzid = $request->query->get('bzid'); } $player = Player::getFromBZID($bzid); if (!$player->isValid()) { $flashBag->add('error', "Player with BZID {$bzid} not found"); return $this->goBack(); } return new RedirectResponse($player->getURL()); }
public function loginAction(Request $request, Player $me) { if ($me->isValid()) { throw new ForbiddenException("You are already logged in!"); } $query = $request->query; $session = $request->getSession(); $token = $query->get("token"); $username = $query->get("username"); if (!$token || !$username) { throw new BadRequestException(); } // Don't check whether IPs match if we're on a development environment $checkIP = !$this->isDebug(); $info = validate_token($token, $username, array(), $checkIP); if (!isset($info)) { throw new ForbiddenException("There was an error processing your login. Please go back and try again."); } $session->set("username", $info['username']); $session->set("groups", $info['groups']); $redirectToProfile = false; if (!Player::playerBZIDExists($info['bzid'])) { // If they're new, redirect to their profile page so they can add some info $player = Player::newPlayer($info['bzid'], $info['username']); $redirectToProfile = true; } else { $player = Player::getFromBZID($info['bzid']); if ($player->isDeleted()) { $player->setStatus('active'); } } $session->set("playerId", $player->getId()); $player->updateLastLogin(); $player->setUsername($info['username']); Visit::enterVisit($player->getId(), $request->getClientIp(), gethostbyaddr($request->getClientIp()), $request->server->get('HTTP_USER_AGENT'), $request->server->get('HTTP_REFERER')); $this->configPromoteAdmin($player); if ($redirectToProfile) { $profile = Service::getGenerator()->generate('profile_show'); return new RedirectResponse($profile); } else { return $this->goBack(); } }
#!/usr/bin/env php <?php use BZIon\Event\ConversationAbandonEvent; use BZIon\Event\ConversationJoinEvent; use BZIon\Event\ConversationKickEvent; use BZIon\Event\ConversationRenameEvent; use BZIon\Event\Events; use BZIon\Event\WelcomeEvent; require_once __DIR__ . "/../bzion-load.php"; $kernel = new AppKernel("dev", true); $kernel->boot(); $testPlayer = Player::getFromBZID(3030); if ($testPlayer->isValid()) { die("Please clear your current data in the database or you'll end up with duplicate entries.\n"); } echo "Adding players..."; $alezakos = Player::newPlayer(49434, "alezakos", null, "active", Player::DEVELOPER, "", "Sample description", 84); $allejo = Player::newPlayer(31098, "allejo", null, "active", Player::DEVELOPER, "", "I'm the one who breaks the build", 227); $ashvala = Player::newPlayer(34353, "ashvala", null, "active", Player::DEVELOPER, "", "", 100); $autoreport = Player::newPlayer(55976, "AutoReport", null, "test"); $blast = Player::newPlayer(180, "blast", null, "active", Player::S_ADMIN); $kierra = Player::newPlayer(2229, "kierra", null, "active", Player::ADMIN, "", "", 174); $mdskpr = Player::newPlayer(8312, "mdskpr"); $snake = Player::newPlayer(54497, "Snake12534"); $tw1sted = Player::newPlayer(9736, "tw1sted", null, "active", Player::DEVELOPER); $brad = Player::newPlayer(3030, "brad", null, "active", Player::S_ADMIN, "", "I keep nagging about when this project will be done"); $constitution = Player::newPlayer(9972, "Constitution", null, "active", Player::S_ADMIN); $themap = Player::newPlayer(57422, "the map", null, "active", Player::COP); $oldSnake = Player::newPlayer(54498, "Snake12534"); $oldSnake->setOutdated(true); $allPlayers = array($alezakos, $allejo, $ashvala, $autoreport, $blast, $kierra, $mdskpr, $snake, $tw1sted, $brad, $constitution, $themap);
/** * Convert a comma-separated list of bzids to player IDs so we can pass * them to Match::enterMatch() * * @param string $players A comma-separated list of BZIDs * @return int[] A list of Player IDs */ private function bzidsToIdArray($players) { $players = explode(',', $players); foreach ($players as &$player) { $player = Player::getFromBZID($player)->getId(); } return $players; }
/** * Get an array of players based on a string representation * @param string $playerString * @return Player[]|null Returns null if there were no players recorded for this match */ private static function parsePlayers($playerString) { $players = array(); if ($playerString == null) { return null; } $BZIDs = explode(",", $playerString); foreach ($BZIDs as $bzid) { $players[] = Player::getFromBZID($bzid); } return $players; }