public function update($id) { try { $groups = Cache::get('admin.adkats.special.groups'); $player = Special::findOrFail($id); foreach ($groups as $group) { if ($group['group_key'] == Input::get('group')) { $newGroup = $group['group_name']; break; } } $player->player_group = Input::get('group'); $player->save(); if (is_null($player->player)) { $soldierName = $player->player_identifier; } else { $soldierName = $player->player->SoldierName; } $message = sprintf('%s group has been changed to %s.', $soldierName, $newGroup); return MainHelper::response(null, $message); } catch (ModelNotFoundException $e) { $message = sprintf('No player found with special id of %u', $id); return MainHelper::response(null, $message, 'error', 404); } catch (Exception $e) { return MainHelper::response($e, $e->getMessage(), 'error', 500); } }
public function getIndex() { $limit = 100; $chat = $this->chat->leftJoin('tbl_server', 'tbl_chatlog.ServerID', '=', 'tbl_server.ServerID')->select('tbl_chatlog.*', 'tbl_server.ServerName')->orderBy('logDate', 'desc'); if (Input::has('limit') && in_array(Input::get('limit'), range(10, 100, 10))) { $limit = Input::get('limit'); } if (Input::has('nospam') && Input::get('nospam') == 1) { $chat = $chat->excludeSpam(); } if (Input::has('between')) { $between = explode(',', Input::get('between')); $startDate = Carbon::createFromFormat('Y-m-d H:i:s', $between[0]); if (count($between) == 1) { $endDate = Carbon::now(); } else { $endDate = Carbon::createFromFormat('Y-m-d H:i:s', $between[1]); } if ($startDate->gte($endDate)) { return MainHelper::response(null, sprintf("%s is greater than %s. Please adjust your dates.", $startDate->toDateTimeString(), $endDate->toDateTimeString()), 'error', null, false, true); } $chat = $chat->whereBetween('logDate', [$startDate->toDateTimeString(), $endDate->toDateTimeString()])->paginate($limit); } else { $chat = $chat->simplePaginate($limit); } return MainHelper::response($chat, null, null, null, false, true); }
/** * Shows the player profile * * @param integer $id * @param string $name */ public function profile($id, $name = '') { // Cache key $key = sprintf('player.%u', $id); // Is there already a cached version for the player $isCached = Cache::has($key); // Get or Set cache for player $player = Cache::remember($key, 5, function () use($id) { $json = $this->repository->setopts(['ban.previous.server', 'ban.record.server', 'reputation', 'infractionsGlobal', 'infractionsServer.server', 'stats.server', 'specialGroups'], true)->getPlayerById($id)->toJson(); return json_decode($json); }); $charts = Cache::remember(sprintf('player.%u.charts', $id), 5, function () use($id) { $charts = []; $charts['overview'] = new Collection(DB::select(File::get(storage_path() . '/sql/playerCommandOverview.sql'), [$id])); $charts['spline'] = new Collection(DB::select(File::get(storage_path() . '/sql/playerCommandHistory.sql'), [$id])); $charts['aliases'] = Record::where('command_type', 48)->where('target_id', $id)->select(DB::raw('record_message AS `player_name`, COUNT(record_id) AS `seen`'))->groupBy('player_name')->get(); $charts['iphistory'] = Record::where('command_type', 49)->where('target_id', $id)->where('record_message', '!=', 'No previous IP on record')->select(DB::raw('record_message AS `ip`, COUNT(record_id) AS `seen`'))->groupBy('ip')->get(); $charts['overview'] = $charts['overview']->map(function ($command) { return [$command->label, intval($command->value)]; }); $charts['aliases'] = $charts['aliases']->map(function ($a) { return [$a->player_name, intval($a->seen)]; }); $charts['iphistory'] = $charts['iphistory']->map(function ($ip) { return [$ip->ip, intval($ip->seen)]; }); return $charts; }); $groups = MainHelper::specialGroups($player->special_groups, 'player_group'); $page_title = !empty($player->ClanTag) ? sprintf('[%s] %s', $player->ClanTag, $player->SoldierName) : $player->SoldierName; return View::make('player.profile', compact('player', 'page_title', 'charts', 'isCached', 'groups')); }
public function index() { $games = $this->game->with(['servers' => function ($query) { $query->active(); }])->get(); $page_title = Lang::get('navigation.main.items.chatlogs.title'); $chat = $this->chat->with('player', 'server')->orderBy('logDate', 'desc'); // If the show spam checkbox was not checked then exclude it if (!Input::has('showspam')) { $chat = $chat->excludeSpam(); } // Check if user hit the submit button if ($this->hasInput()) { // Filtering by dates if (Input::has('StartDateTime') && Input::has('EndDateTime')) { $startDate = Carbon::parse(Input::get('StartDateTime'))->setTimezone(new \DateTimeZone('UTC')); $endDate = Carbon::parse(Input::get('EndDateTime'))->setTimezone(new \DateTimeZone('UTC')); $chat = $chat->whereBetween('logDate', [$startDate, $endDate]); } // Specific keywords the user has typed. Each word separated by a comma. // This can add significant time to fetching the results if (Input::has('keywords')) { $keywords = array_map('trim', explode(',', Input::get('keywords'))); if (MainHelper::hasFulltextSupport('tbl_chatlog', 'logMessage')) { $chat = $chat->whereRaw('MATCH(logMessage) AGAINST(? IN BOOLEAN MODE)', [implode(' ', $keywords)]); } else { $chat = $chat->where(function ($query) use($keywords) { foreach ($keywords as $keyword) { $query->orWhere('logMessage', 'LIKE', '%' . $keyword . '%'); } }); } } // Player names the user has typed. Partal names can be provided. Must be seprated // by a comma to search multiple players. if (Input::has('players')) { $players = array_map('trim', explode(',', Input::get('players'))); $playerIds = $this->player->where(function ($query) use($players) { foreach ($players as $player) { $query->orWhere('SoldierName', 'LIKE', sprintf('%s%%', $player)); } }); $playerIds = $playerIds->lists('PlayerID'); $chat = $chat->whereIn('logPlayerID', $playerIds); } if (Input::has('pid')) { if (Input::get('pid') > 0 && is_numeric(Input::get('pid'))) { $chat = $chat->where('logPlayerID', Input::get('pid')); } } // Filter based on server if one is selected if (Input::has('server') && is_numeric(Input::get('server')) && Input::get('server') > 0) { $chat = $chat->where('ServerID', Input::get('server')); } } // Return paginated results $chat = $chat->simplePaginate(60); return View::make('chatlogs', compact('games', 'chat', 'page_title')); }
public function putIndex() { if (!$this->isLoggedIn || !$this->user->ability(null, 'admin.adkats.reports.edit')) { throw new AccessDeniedHttpException('Authorization Denied!'); } $r = App::make('BFACP\\Repositories\\ReportRepository'); $v = Validator::make(Input::all(), ['id' => 'required|numeric|exists:adkats_records_main,record_id', 'action' => 'required|numeric|in:' . implode(',', $r::$allowedCommands), 'reason' => 'required|string|between:3,500', 'extras.tban.duration' => 'required_if:action,7|numeric|between:1,525960'], ['extras.tban.duration.required_if' => 'The duration is required for temp bans.', 'extras.tban.duration.between' => 'The duration must be between :min minute and :max minutes.']); if ($v->fails()) { throw new ResourceException(null, $v->errors()); } try { $record = $r->getReportById(Input::get('id')); if (!in_array($record->command_action, [18, 20])) { throw new UpdateResourceFailedException('Unable to complete action. Report has already been acted on.'); } // If the action is {Accept, Deny, Ignore} Round Report then we just need to update the existing record. if (in_array(Input::get('action'), [40, 41, 61])) { $record->command_action = Input::get('action'); $record->save(); } else { $newRecord = $record->replicate(); $newRecord->command_type = Input::get('action'); $newRecord->command_action = Input::get('action'); if (Input::get('action') == 7) { $maxDuration = Setting::where('setting_name', 'Maximum Temp-Ban Duration Minutes')->where('server_id', 1)->pluck('setting_value'); $duration = Input::get('extras.tban.duration', $maxDuration); $commandNumeric = (int) $duration > (int) $maxDuration ? $maxDuration : $duration; } else { $commandNumeric = 0; } $newRecord->command_numeric = $commandNumeric; $newMessage = trim(Input::get('reason', $newRecord->record_message)); $oldMessage = trim($newRecord->record_message); if ($newMessage != $oldMessage && !empty($newMessage)) { $newRecord->record_message = $newMessage; } $source = MainHelper::getAdminPlayer($this->user, $newRecord->server->game->GameID); if (!is_null($source)) { $newRecord->source_id = $source->PlayerID; $newRecord->source_name = $source->SoldierName; } else { $newRecord->source_id = null; $newRecord->source_name = $this->user->username; } $newRecord->record_time = Carbon::now(); $newRecord->adkats_read = 'N'; $newRecord->save(); $record->command_action = 40; $record->save(); } return MainHelper::response(['old' => $record, 'new' => isset($newRecord) ? $newRecord : null], 'Report updated', null, null, false, true); } catch (ModelNotFoundException $e) { return MainHelper::response(null, 'Report was not found. Aborting!', 'error', null, false, true); } }
public function stats() { $yesterdaysBans = Cache::remember('bans.stats.yesterday', 120, function () { return Ban::yesterday()->count(); }); $avgBansPerDay = Cache::remember('bans.stats.average', 180, function () { $result = head(DB::select(File::get(storage_path() . '/sql/avgBansPerDay.sql'))); return intval($result->total); }); return MainHelper::response(['bans' => ['yesterday' => $yesterdaysBans, 'average' => $avgBansPerDay]], null, null, null, false, true); }
public function onlineAdmins() { $admins = DB::table('tbl_currentplayers')->select('SoldierName', 'ServerName', 'tbl_currentplayers.ServerID', 'PlayerJoined')->join('tbl_server', 'tbl_currentplayers.ServerID', '=', 'tbl_server.ServerID')->whereIn('EA_GUID', function ($query) { $query->from('adkats_usersoldiers')->select('EAGUID')->join('adkats_users', 'adkats_usersoldiers.user_id', '=', 'adkats_users.user_id')->join('adkats_roles', 'adkats_users.user_role', '=', 'adkats_roles.role_id')->join('tbl_playerdata', 'adkats_usersoldiers.player_id', '=', 'tbl_playerdata.PlayerID')->groupBy('EAGUID')->whereExists(function ($query2) { $query2->select('adkats_rolecommands.role_id')->from('adkats_rolecommands')->join('adkats_commands', 'adkats_rolecommands.command_id', '=', 'adkats_commands.command_id')->where('command_playerInteraction', 1)->whereRaw('adkats_rolecommands.role_id = adkats_users.user_role')->groupBy('adkats_rolecommands.role_id'); }); })->get(); foreach ($admins as $key => $admin) { $admins[$key]->stamp = Carbon::parse($admin->PlayerJoined, 'UTC')->toIso8601String(); } return MainHelper::response($admins, null, null, null, false, true); }
public function update() { $settings = Option::lists('option_value', 'option_key'); foreach (Input::all() as $key => $value) { if (starts_with($key, '_') === false) { $key = str_replace('-', '.', $key); $value = trim($value); if (!is_null(MainHelper::stringToBool($value))) { $value = MainHelper::stringToBool($value); } else { if (empty($value)) { $value = null; } } if ($value != $settings[$key]) { Option::where('option_key', $key)->update(['option_value' => $value]); } } } Cache::forget('site.options'); return Redirect::route('admin.site.settings.index')->with('messages', ['Settings Saved!']); }
/** * Delete user * * @param integer $id User ID * * @return \Illuminate\Support\Facades\Response */ public function destroy($id) { try { $user = User::findOrFail($id); $username = $user->user_name; $user->delete(); return MainHelper::response(['url' => route('admin.adkats.users.index')], sprintf('%s was deleted', $username)); } catch (ModelNotFoundException $e) { return Redirect::route('admin.adkats.users.index')->withErrors([sprintf('User #%u doesn\'t exist.', $id)]); } }
/** * Wrapper for \BFACP\Facades\Main * * @param array $data * @param string $message * @param string $type * * @return MainHelper */ private function _response($data = null, $message = null, $type = null) { $data = ['failed' => $this->errors, 'passed' => $this->data, 'other' => $data]; if (!empty($this->errors)) { $message = self::COMPLETE_WITH_ERRORS; } return MainHelper::response($data, $message, $type, null, false, true); }
/** * Get the country name * * @return string */ public function getCountryNameAttribute() { try { if ($this->CountryCode == '--' || empty($this->CountryCode)) { throw new Exception(); } $cc = MainHelper::countries($this->CountryCode); if ($cc === null) { throw new Exception(); } return $cc; } catch (Exception $e) { return 'Unknown'; } }
/** * Parse the battlelog weapons list * * @param array $weapons * * @return $this */ public function parse($weapons) { if (!array_key_exists($this->game, $this->weapons)) { throw new HttpException(500, sprintf('The game "%s" is not supported.', $this->game)); } foreach ($weapons as $weapon) { $category = str_replace(' ', '_', strtolower(trim($weapon['category']))); if (!in_array($category, $this->allowedCategories[$this->game]) || !array_key_exists($category, $this->weapons[$this->game]) || !array_key_exists($weapon['slug'], $this->weapons[$this->game][$category])) { continue; } $status = ['DPS' => false, 'HKP' => false, 'KPM' => false]; $_weaponDPS = $this->weapons[$this->game][$category][$weapon['slug']]; $DPSDiff = 1 - MainHelper::divide($_weaponDPS['max'] - $weapon['dps'], $_weaponDPS['max']); // Convert first letter of each word to an uppercase $weapon['category'] = ucwords($weapon['category']); // Check if the weapon has been used with a damage mod if ($DPSDiff > 1.5 && $weapon['kills'] >= $this->triggers['Kills']) { $status['DPS'] = true; } // Check if the weapon has a high headshot to kill ratio in percentages if ($weapon['hskp'] >= $this->triggers['HKP'] && $weapon['kills'] >= $this->triggers['Kills']) { $status['HKP'] = true; } // Check if the weapon has a high kill per minute if ($weapon['kpm'] >= $this->triggers['KPM'] && $weapon['kills'] >= $this->triggers['Kills']) { $status['KPM'] = true; } // If either DPS, KPM, or HKP get triggered add the weapon to the triggered weapons list if ($status['DPS'] || $status['KPM'] || $status['HKP']) { $this->triggered[] = $weapon + ['triggered' => $status]; } } return $this; }
public function destroy($id) { try { // Disable rules on model Role::$rules = []; // Get role $role = Role::findOrFail($id); if (in_array($role->id, [1, 2])) { return MainHelper::response(null, sprintf('You can\'t delete the %s role.', $role->name), 'error'); } // Save role name $roleName = $role->name; foreach ($role->users as $user) { $user->roles()->detach($id); $user->roles()->attach(2); } $role->delete(); return MainHelper::response(['url' => route('admin.site.roles.index')], sprintf('%s was deleted', $roleName)); } catch (ModelNotFoundException $e) { return Redirect::route('admin.site.roles.index')->withErrors([sprintf('Role #%u doesn\'t exist.', $id)]); } }
/** * Gets the player vehicle stats * * @return array */ public function getVehicleStats() { // Generate URI for request $uri = sprintf($this->uris[$this->game]['vehicles'], $this->game, $this->personaID); // Send request $results = $this->sendRequest($uri)['data']; // Create vehicles array $vehicles = new Collection(); foreach ($results['mainVehicleStats'] as $vehicle) { $vehicles->push(['slug' => $vehicle['slug'], 'code' => $vehicle['code'], 'category' => $vehicle['category'], 'kills' => $vehicle['kills'], 'score' => array_key_exists('score', $vehicle) ? $vehicle['score'] : null, 'timeEquipped' => $vehicle['timeIn'], 'serviceStars' => $vehicle['serviceStars'], 'kpm' => MainHelper::divide($vehicle['kills'], MainHelper::divide($vehicle['timeIn'], 60))]); } return $vehicles; }
/** * Delete user * * @param integer $id User ID * * @return \Illuminate\Support\Facades\Response */ public function destroy($id) { try { $user = User::findOrFail($id); $username = $user->username; $user->delete(); return MainHelper::response(['url' => route('admin.site.users.index')], Lang::get('alerts.user.deleted', compact('username'))); } catch (ModelNotFoundException $e) { $this->messages[] = Lang::get('alerts.user.invlid', ['userid' => $id]); return Redirect::route('admin.site.users.index')->withErrors($this->messages); } }
/** * Moves the player to a different team and/or squad * * @param $player * @param null $teamId * @param int $squadId * @param bool|false $locked * * @return bool * @throws PlayerNotFoundException|RconException */ public function adminMovePlayer($player, $teamId = null, $squadId = 0, $locked = false) { if (!is_numeric($squadId) || empty($squadId) || !in_array($squadId, range(0, 32))) { $squadId = 0; } if (!is_numeric($teamId) || empty($teamId) || !in_array($teamId, range(1, 4))) { $teamId = $this->client->getPlayerTeamId($player); } $teamName = $this->getTeamName($teamId); $squadName = BattlefieldHelper::squad($squadId); if (is_array($teamName)) { $teamName = $teamName['full_name']; } if ($this->isValidName($player)) { if (method_exists($this->client, 'adminGetSquadPrivate') && method_exists($this->client, 'adminSetSquadPrivate')) { // Check if squad is private if ($squadId != 0 && $this->client->adminGetSquadPrivate($teamId, $squadId)) { // Check if squad is full $playersInSquad = $this->client->adminSquadListPlayer($teamId, $squadId)[1]; // If squad is full throw an exception with an error message // else unlock the squad so we can move them in. if ($playersInSquad == 5) { throw new RconException(200, sprintf('%s squad is full. Cannot switch %s to squad.', $squadName, $player)); } else { $this->client->adminSetSquadPrivate($teamId, $squadId, false); } } } $response = $this->client->adminMovePlayerSwitchSquad($player, (int) $squadId, true, (int) $teamId); // Check if the server returned a player not found error if ($response == 'InvalidPlayerName') { throw new PlayerNotFoundException(404, sprintf('No player found with the name "%s"', $player)); } // Lock squad if $locked is truthy if (MainHelper::stringToBool($locked)) { $this->client->adminSetSquadPrivate($teamId, $squadId, $locked); } if ($response == 'SetSquadFailed') { $squadId = 0; } if ($squadId == 0) { $message = sprintf('You were switched to team %s and not placed in a squad.', $teamName); } else { $message = sprintf('You were switched to team %s and placed in squad %s.', $teamName, $squadName); } $dbMessage = sprintf('Switched to %s and placed in squad %s', $teamName, $squadName); $this->adminTell($player, $message, 5, false, true, 1); $this->log($player, 'player_fmove', $dbMessage); } else { throw new RconException(400, sprintf('"%s" is not a valid name.', $player)); } return ['player' => $player, 'message' => $dbMessage]; }
/** * Unbans the player * * @param integer $id Ban ID * * @return \Illuminate\Support\Facades\Response */ public function destroy($id) { try { // Fetch the ban $ban = $this->repository->getBanById($id); $bfacp = App::make('bfadmincp'); $oldRecord = $ban->record; $admin = MainHelper::getAdminPlayer($bfacp->user, $ban->player->game->GameID); // Only modify the old record if the command action is a temp or perma ban. if (in_array((int) $oldRecord->command_action, [7, 8])) { // 72 => Previous Temp Ban // 73 => Previous Perm Ban $oldRecord->command_action = $oldRecord->command_action == 8 ? 73 : 72; $oldRecord->save(); } // Duplicate the record and save the changes $record = $ban->record->replicate(); $record->command_type = 37; $record->command_action = 37; $record->source_id = is_null($admin) ? null : $admin->PlayerID; $record->source_name = is_null($admin) ? Auth::user()->username : $admin->SoldierName; $record->record_message = Input::get('message', 'Unbanned'); $record->record_time = Carbon::now(); $record->adkats_web = true; $record->save(); // Update the ban record and save the changes $ban->record()->associate($record); $ban->ban_status = 'Disabled'; if (!is_null(Input::get('notes', null))) { $ban->ban_notes = Input::get('notes', 'NoNotes'); } $ban->save(); try { if (!is_null($this->metabans)) { $this->metabans->assess($ban->player->game->Name, $ban->player->EAGUID, 'None', Input::get('message', 'Unbanned')); } } catch (MetabansException $e) { } // Purge the cache for the player Cache::forget(sprintf('api.player.%u', $ban->player_id)); Cache::forget(sprintf('player.%u', $ban->player_id)); return MainHelper::response(); } catch (ModelNotFoundException $e) { return MainHelper::response(null, $e->getMessage(), 'error', 404); } catch (\Exception $e) { return MainHelper::response(null, $e->getMessage(), 'error', 500); } }
/** * Generates a strong password * * @param integer $len Length of generated password * * @return string */ public function generatePassword($len = 12) { $pass = MainHelper::generateStrongPassword($len); return $pass; }
/** * @param Player $player * * @return mixed */ public function getCheatDetection(Player $player) { $acs = new AntiCheat($player); $data = $acs->parse($acs->battlelog->getWeaponStats())->get(); return MainHelper::response($data, null, null, null, false, true); }
public function scoreboardAdmin() { try { $id = Input::get('server_id'); if (!is_numeric($id) || $id <= 0) { throw new NotFoundHttpException('Invalid Server ID'); } $allowedMethods = ['yell', 'say', 'kill', 'move', 'kick', 'punish']; $permissions = Cache::get('admin.perm.list'); if (!Input::has('method') || !in_array(Input::get('method'), $allowedMethods)) { throw new NotFoundHttpException(); } if (!$this->isLoggedIn || !$this->user->ability(null, $permissions['scoreboard'])) { throw new AccessDeniedHttpException(); } $scoreboard = new LiveServerRepository(Server::findOrFail($id)); if ($scoreboard->attempt()->check()) { $players = []; if (Input::has('players')) { $players = explode(',', Input::get('players')); } switch (Input::get('method')) { case 'yell': $this->hasPermission('admin.scoreboard.yell'); if (Input::get('type') == 'Player' && Input::has('players')) { foreach ($players as $player) { $scoreboard->adminYell(Input::get('message', null), $player, null, Input::get('duration', 5), 'Player'); } } else { $scoreboard->adminYell(Input::get('message', null), Input::get('player', null), Input::get('team', null), Input::get('duration', 5), Input::get('type', 'All')); } break; case 'say': $this->hasPermission('admin.scoreboard.say'); if (Input::get('type') == 'Player' && Input::has('players')) { foreach ($players as $player) { $scoreboard->adminSay(Input::get('message', null), $player, null, 'Player'); } } else { $scoreboard->adminSay(Input::get('message', null), Input::get('player', null), Input::get('team', null), Input::get('type', 'All')); } break; case 'kill': $this->hasPermission('admin.scoreboard.kill'); if (Input::has('players')) { $unkilled = []; foreach ($players as $player) { try { $scoreboard->adminKill($player, Input::get('message', null)); } catch (PlayerNotFoundException $e) { $unkilled[] = ['name' => $player, 'reason' => $e->getMessage()]; } } if (!empty($unkilled)) { $data = $unkilled; } } else { throw new RconException(400, 'No players selected.'); } break; case 'kick': $this->hasPermission('admin.scoreboard.kick'); if (Input::has('players')) { $unkicked = []; foreach ($players as $player) { try { $scoreboard->adminKick($player, Input::get('message', null)); } catch (PlayerNotFoundException $e) { $unkicked[] = ['name' => $player, 'reason' => $e->getMessage()]; } } if (!empty($unkicked)) { $data = $unkicked; } } else { throw new RconException(400, 'No player selected.'); } break; case 'move': $this->hasPermission('admin.scoreboard.teamswitch'); if (Input::has('players')) { $unmoved = []; foreach ($players as $player) { try { $scoreboard->adminMovePlayer($player, Input::get('team', null), Input::get('squad', null)); } catch (PlayerNotFoundException $e) { $unmoved[] = ['name' => $player, 'reason' => $e->getMessage()]; } catch (RconException $e) { $unmoved[] = ['name' => $player, 'reason' => $e->getMessage()]; } } if (!empty($unmoved)) { $data = $unmoved; } } else { throw new RconException(400, 'No player selected.'); } break; case 'punish': $this->hasPermission('admin.scoreboard.punish'); if (Input::has('players')) { foreach ($players as $player) { $data[] = $scoreboard->adminPunish($player, Input::get('message')); } } else { throw new RconException(400, 'No player selected.'); } break; case 'forgive': $this->hasPermission('admin.scoreboard.forgive'); if (Input::has('players')) { foreach ($players as $player) { $scoreboard->adminForgive($player, Input::get('message')); } } else { throw new RconException(400, 'No player selected.'); } break; default: throw new NotFoundHttpException(); } if (!isset($data)) { $data = []; } return MainHelper::response($data, null, null, null, false, true); } } catch (PlayerNotFoundException $e) { return MainHelper::response(null, $e->getMessage(), 'error', null, false, true); } catch (ModelNotFoundException $e) { throw new NotFoundHttpException(sprintf('No server found with id %s', $id)); } catch (Exception $e) { throw $e; } }
/** * Fetches records targeted on player to calculate the target reputation * * @return mixed */ public function target() { // Retrieve the punish records $punishments = $this->player->recordsOn()->where('command_type', 9)->get(); foreach ($punishments as $punishment) { $days = Carbon::now()->diffInDays($punishment->record_time); if ($days < 50) { $this->targetReputation -= 20 * MainHelper::divide(50 - $days, 50); } } // Retrieve the forgive records $forgives = $this->player->recordsOn()->where('command_type', 10)->get(); foreach ($forgives as $forgive) { $days = Carbon::now()->diffInDays($forgive->record_time); if ($days < 50) { $this->targetReputation += 20 * MainHelper::divide(50 - $days, 50); } } // Retrieve the rest $records = Record::select(DB::raw('command_type, command_action, COUNT(record_id) AS command_count'))->where('target_id', $this->player->PlayerID)->whereRaw('target_name != source_name')->groupBy('command_type')->groupBy('command_action')->get(); foreach ($records as $record) { $command = sprintf('%u|%u', $record->command_type, $record->command_action); foreach ($this->weights as $weight) { if ($command == $weight['command_typeaction']) { $this->targetReputation += $weight['target_weight'] * $record->command_count; break; } } } return $this; }
/** * Gets users gravatar image * * @return string */ public function getGravatarImgAttribute() { return MainHelper::gravatar(null, $this->gravatar, 128); }
/** * Search for playeers * * @param string $phrase * * @return \Illuminate\Support\Facades\Response */ public function search($phrase = '') { $rules = ['phrase' => 'required']; $data = ['phrase' => trim($phrase)]; if (!$this->validate($data, $rules)) { return MainHelper::response($this->getErrors(), 'Validation failed.', 'error', 400); } $matches = new Collection($this->request(['mbo_search' => $data])['matches']); return MainHelper::response($matches); }
public function destroy($id) { try { // Get role $role = Role::findOrFail($id); if ($role->role_id == 1) { return MainHelper::response(null, sprintf('You can\'t delete the %s role.', $role->role_name), 'error'); } // Save role name $roleName = $role->role_name; $guestRole = Role::findOrFail(1); foreach ($role->users as $user) { $user->role()->associate($guestRole)->save(); } $role->delete(); return MainHelper::response(['url' => route('admin.adkats.roles.index')], sprintf('%s was deleted', $roleName)); } catch (ModelNotFoundException $e) { return Redirect::route('admin.adkats.roles.index')->withErrors([sprintf('Role #%u doesn\'t exist.', $id)]); } }
public function getAssessments() { $assessments = $this->metabans->assessments(); return MainHelper::response($assessments, null, null, null, false, true); }
/** * Gets the players sessions * * @param integer $id * * @return \Illuminate\Support\Facades\Response */ public function showSessions($id) { $sessions = $this->repository->getPlayerSessions($id); return MainHelper::response($sessions, null, null, null, false, true); }
public function getGroupAttribute() { $group = MainHelper::specialGroups($this->player_group); return $group; }
/** * Gets users gravatar image * * @return string */ public function getGravatarAttribute() { return MainHelper::gravatar($this->email); }
/** * Calculates how full the server is represented by a percentage * * @return float */ public function getPercentageAttribute() { return MainHelper::percent($this->usedSlots, $this->maxSlots); }