예제 #1
0
 }
 // IF VALIDATION ERROR, EXIT
 if ($error) {
     goto render;
 }
 $account = Account::where('name', $req->post('account-name'))->first();
 // IF ACCOUNT EXISTS AND PASSWORD IS WRONG, EXIT
 if ($account && !$account->comparePassword($req->post('password'))) {
     $DevAAC->flashNow('danger', 'This account already exists and password is not correct. Cannot add a character.
                               Enter correct password or try a different account name.');
     $DevAAC->flashNow('password_class', 'has-error');
     goto render;
 }
 $name = ucwords(strtolower($req->post('character-name')));
 // check if character name is available
 $player = Player::where('name', $name)->first();
 if ($player) {
     $DevAAC->flashNow('danger', 'This character already exists.');
     $DevAAC->flashNow('character-name_class', 'has-error');
     goto render;
 }
 // IF THE ACCOUNT EXISTS, JUMP TO CREATING PLAYER
 if ($account) {
     goto createcharacter;
 }
 // VALIDATE ACCOUNT NAME ONLY IF THE ACCOUNT DOES NOT EXIST
 if (!filter_var($req->post('account-name'), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z]{2,12}\$/")))) {
     $DevAAC->flashNow('account-name_class', 'has-error');
     $DevAAC->flashNow('danger', 'Account name must have 2-12 characters, only letters.');
     $error = true;
 }
예제 #2
0
 *      @SWG\ResponseMessage(code=401, message="Authentication required")
 *   )
 *  )
 * )
 */
$DevAAC->post(ROUTES_API_PREFIX . '/players', function () use($DevAAC) {
    if (!$DevAAC->auth_account) {
        throw new InputErrorException('You are not logged in.', 401);
    }
    $req = $DevAAC->request;
    if (!filter_var($req->getAPIParam('name'), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z ]{5,20}\$/")))) {
        throw new InputErrorException('Player name must have 5-20 characters, only letters and space.', 400);
    }
    if (filter_var($req->getAPIParam('name'), FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/\\b(Tutor|GM|God|CM|Admin)\\b/i'))) && !$DevAAC->auth_account->isGameMaster()) {
        throw new InputErrorException('Player name must not include GM/CM/God/Admin words.', 400);
    }
    if (!in_array($req->getAPIParam('vocation'), unserialize(ALLOWED_VOCATIONS))) {
        throw new InputErrorException('Vocation is out of bounds.', 400);
    }
    if (!in_array($req->getAPIParam('sex'), array(0, 1))) {
        throw new InputErrorException('Sex is invalid.', 400);
    }
    $player = Player::where('name', $req->getAPIParam('name'))->first();
    if ($player) {
        throw new InputErrorException('Player with this name already exists.', 400);
    }
    $player = new Player(array('name' => ucwords(strtolower($req->getAPIParam('name'))), 'vocation' => $req->getAPIParam('vocation'), 'sex' => $req->getAPIParam('sex'), 'level' => NEW_PLAYER_LEVEL, 'looktype' => $req->getAPIParam('sex') ? 128 : 136));
    $DevAAC->auth_account->players()->save($player);
    $DevAAC->response->headers->set('Content-Type', 'application/json');
    $DevAAC->response->setBody($player->toJson(JSON_PRETTY_PRINT));
});