Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
 /**
  * Sets the admin for future use
  */
 private function setAdmin()
 {
     $this->admin = MainHelper::getAdminPlayer($this->user, $this->gameID);
 }