} if (!$DevAAC->auth_account) { throw new InputErrorException('You are not logged in.', 401); } $request = $DevAAC->request; $house = House::findOrFail($id); if ($house->owner()->first() instanceof Player) { throw new InputErrorException('This house is not on auction, ' . $house->owner()->first()->name . ' owns it.', 412); } if ($house->bid_end !== 0 && new DateTime() > $house->bid_end) { throw new InputErrorException('Auction has ended.', 410); } if ($request->getAPIParam('bid') < $house->bid + HOUSES_BID_RAISE || $request->getAPIParam('bid') < $house->bid + $house->bid * HOUSES_BID_RAISE_PERCENT) { throw new InputErrorException('The bid is too low! You need to offer at least ' . max($house->bid + HOUSES_BID_RAISE, $house->bid + $house->bid * HOUSES_BID_RAISE_PERCENT), 409); } $player = Player::findOrFail($request->getAPIParam('player_id')); if ($player->account->id != $DevAAC->auth_account->id && !$DevAAC->auth_account->isGod()) { throw new InputErrorException('You do not have permission to bid with this player.', 403); } if ($house->highest_bidder != $player->id && count($player->houses()->get()->toArray()) + count($player->houseBids()->get()->toArray()) >= HOUSES_PER_PLAYER) { throw new InputErrorException('Your player already owns or participates in an auction for a maximum number of houses (' . HOUSES_PER_PLAYER . ')!', 405); } if ($house->highest_bidder != $player->id && count($player->account->houses()->get()->toArray()) + count($player->account->houseBids()->get()->toArray()) >= HOUSES_PER_ACCOUNT) { throw new InputErrorException('Your account already owns or participates in an auction for a maximum number of houses (' . HOUSES_PER_ACCOUNT . ')!', 405); } if ($player->balance < $request->getAPIParam('bid') + $house->rent) { throw new InputErrorException('You do not have enough money! You need the bid amount plus ' . $house->rent . ' for first rent payment.', 402); } if ($request->getAPIParam('bid') > $house->last_bid) { // this is a winning bid, it is over previous winner's limit $house->highest_bidder = $player->id;
$DevAAC->flashNow('danger', 'Password must have 6-20 characters.'); $error = true; } // VALIDATE EMAIL ONLY IF THE ACCOUNT DOES NOT EXIST if (!filter_var($req->post('email'), FILTER_VALIDATE_EMAIL)) { $DevAAC->flashNow('email_class', 'has-error'); $DevAAC->flashNow('danger', 'Enter valid email address'); $error = true; } // IF VALIDATION ERROR, EXIT if ($error) { goto render; } // IF ACCOUNT DOES NOT EXIST, CREATE IT NOW $account = DevAAC\Models\Account::create(array('name' => $req->post('account-name'), 'password' => $req->post('password'), 'email' => $req->post('email'), 'creation' => time())); createcharacter: $player = new DevAAC\Models\Player(); $player->account()->associate($account); $player->name = $name; $player->vocation = $req->post('vocation'); $player->sex = $req->post('sex'); $player->town_id = 1; $player->level = 8; $player->push(); // SAVE PLAYER AND ASSOCIATED OBJECTS (ACCOUNT IN THIS CASE) $DevAAC->flashNow('success', 'Player ' . ucwords(strtolower($req->post('character-name'))) . ' has been created!'); } render: $DevAAC->render('simple.php', $data); })->via('GET', 'POST'); return array_merge($meta, array('enabled' => true));
* ) * ) */ $DevAAC->post(ROUTES_API_PREFIX . '/server/ipBans', function () use($DevAAC) { $req = $DevAAC->request; if (!$DevAAC->auth_account || !$DevAAC->auth_account->isGod()) { throw new InputErrorException('You are not an admin.', 403); } $ipban = IpBan::find(ip2long($req->getAPIParam('ip'))); if ($ipban) { throw new InputErrorException('This IP is already banned.', 409); } if (!filter_var($req->getAPIParam('ip'), FILTER_VALIDATE_IP)) { throw new InputErrorException('IP address is not valid.', 400); } $player = Player::find($req->getAPIParam('banned_by')); if (!$player) { throw new InputErrorException('The banned_by player not found.', 404); } if ($player->account->id !== $DevAAC->auth_account->id) { throw new InputErrorException('The banned_by player is not yours!', 406); } if ($player->group_id < 2) { throw new InputErrorException('The banned_by player must have group_id > 1.', 406); } $ban = new IpBan(array('ip' => $req->getAPIParam('ip'), 'reason' => $req->getAPIParam('reason'), 'banned_at' => new \DevAAC\Helpers\DateTime(), 'expires_at' => $req->getAPIParam('expires_at', 0), 'banned_by' => $player->id)); $ban->save(); $DevAAC->response->headers->set('Content-Type', 'application/json'); $DevAAC->response->setBody($ban->toJson(JSON_PRETTY_PRINT)); }); /**
* required=false, * type="string"), * @SWG\Parameter( name="limit", * description="The number of records to return at maximum (Non-admin: max 100)", * paramType="query", * required=false, * type="string") * ) * ) * ) */ $DevAAC->get(ROUTES_API_PREFIX . '/players', function () use($DevAAC) { $req = $DevAAC->request; $players = Capsule::table('players'); // for field validation - it's not the best way ;/ $tmp = new Player(); $visible = $tmp->getVisibleFields(); // support ?q=partialname if ($req->get('q')) { $players->where('name', 'LIKE', '%' . $req->get('q') . '%'); } if ($req->get('account_id')) { $players->where('account_id', $req->get('account_id')); } // support ?sort=level,-skill_club if ($req->get('sort')) { $sort_rules = explode(',', $req->get('sort')); foreach ($sort_rules as $rule) { if (0 === strpos($rule, '-')) { $rule = trim($rule, '-'); $players->orderBy($rule, 'desc');