Example #1
0
 /**
  * Fetchs 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;
 }
Example #2
0
 /**
  * Create a new user
  * @param  array   $input
  * @param  integer $role  Default role is 2
  * @return BFACP\Account\User
  */
 public function signup($input = [], $role = 2, $confirmed = false)
 {
     $user = new User();
     $user->username = array_get($input, 'username');
     $user->email = array_get($input, 'email');
     $user->password = array_get($input, 'password');
     // The password confirmation will be removed from model
     // before saving. This field will be used in Ardent's
     // auto validation.
     $user->password_confirmation = array_get($input, 'password_confirmation');
     // Generate a random confirmation code
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // Update last seen timestamp
     $user->lastseen_at = Carbon::now();
     $user->confirmed = $confirmed;
     // Save if valid. Password field will be hashed before save
     $user->save();
     if (!is_null($user->id)) {
         $user->roles()->attach($role);
         $user->setting()->save(new Setting(['lang' => array_get($input, 'lang', 'en')]));
         if (!empty(array_get($input, 'ign'))) {
             $players = Player::where('SoldierName', array_get($input, 'ign'))->lists('PlayerID');
             foreach ($players as $player) {
                 // Check if an existing user already has claimed the player
                 // and if so do not associate with the new account.
                 if (Soldier::where('player_id', $player)->count() == 0) {
                     $soldier = new Soldier(['player_id' => $player]);
                     $soldier->user()->associate($user)->save();
                 }
             }
         }
     }
     return $user;
 }
Example #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $_playerFound = false;
     try {
         $metabans = App::make('BFACP\\Libraries\\Metabans');
     } catch (MetabansException $e) {
         $this->error('Failed to initialize the Metabans Library.');
         die;
     }
     do {
         $playerID = $this->ask('What is the id of the player you wish to unban? ');
         try {
             if (!is_numeric($playerID)) {
                 throw new \InvalidArgumentException();
             }
             $player = Player::findOrFail($playerID);
             $question = sprintf('Is this the correct player? [%s] %s. [yes|no] ', $player->game->Name, $player->SoldierName);
             if ($this->confirm($question, false)) {
                 $_playerFound = true;
                 if (!is_null($metabans)) {
                     $unbanReason = $this->ask('What is the reason for unbanning? (Leave blank to use default): ');
                     if (empty($unbanReason)) {
                         $unbanReason = 'Unbanned';
                     }
                     $question2 = sprintf('%s will be unbanned from metabans with the reason of "%s". Continue? [yes|no] ', $player->SoldierName, $unbanReason);
                     if ($this->confirm($question2, false)) {
                         $metabans->assess($player->game->Name, $player->EAGUID, 'None', $unbanReason);
                         $this->info(sprintf('%s should now have been unbanned on metabans. Verify that it went through.', $player->SoldierName));
                     } else {
                         $this->info('Request canceled!');
                     }
                 }
             }
         } catch (ModelNotFoundException $e) {
             $this->error(sprintf('Could not find the player with the ID "%s". Please try again.', $playerID));
         } catch (\InvalidArgumentException $e) {
             $this->error(sprintf('Only integers are allowed for the player id. Input was: %s', $playerID));
         } catch (MetabansException $e) {
             $this->error('Failed to initialize the Metabans Library.');
             die;
         }
     } while ($_playerFound == false);
 }
Example #4
0
 /**
  * Gets the soldier information so we can update the clantag and name if needed
  * @return mixed
  */
 private function getSoldierAndUpdate()
 {
     // Generate URI for request
     $uri = sprintf($this->uris[$this->game]['soldier'], $this->game, $this->personaUserID, $this->personaID);
     // Send request
     $results = $this->sendRequest($uri);
     $oldName = $this->player->SoldierName;
     $oldClan = $this->player->ClanTag;
     $persona = $results['context']['statsPersona'];
     if ($this->player->SoldierName != $persona['personaName']) {
         $this->player->SoldierName = $persona['personaName'];
     }
     if ($this->player->ClanTag != $persona['clanTag']) {
         $this->player->ClanTag = empty($persona['clanTag']) ? null : $persona['clanTag'];
     }
     if ($oldName != $persona['personaName'] || $oldClan != $persona['clanTag']) {
         Cache::forget(sprintf('api.player.%u', $this->player->PlayerID));
         Cache::forget(sprintf('player.%u', $this->player->PlayerID));
         $this->player->save();
     }
     return $this;
 }
Example #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     DB::connection()->disableQueryLog();
     $r = App::make('BFACP\\Libraries\\Reputation');
     $this->info("Counting up total players.");
     $count = Player::where('GameID', '>', 0)->count();
     $this->info(sprintf('Found %s players.', number_format($count)));
     $chunk = 20000;
     Player::where('GameID', '>', 0)->chunk($chunk, function ($players) use(&$r) {
         foreach ($players as $player) {
             try {
                 $startClock = microtime(true) * 1000;
                 $r->setPlayer($player)->createOrUpdate()->resetValues();
                 $endClock = microtime(true) * 1000;
                 $execClock = $endClock - $startClock;
                 $txt = sprintf("[%u][%u ms] %s", $player->PlayerID, $execClock, $player->SoldierName);
                 $this->info("Updated player: " . $txt);
             } catch (Exception $e) {
                 $this->error('Update failed. Reason: ' . $e->getMessage());
             }
         }
     });
 }
Example #6
0
 /**
  * Gets the soldier information so we can update the clan tag and name if needed
  *
  * @return mixed
  * @throws BattlelogException
  */
 private function getSoldierAndUpdate()
 {
     // Generate URI for request
     $uri = sprintf($this->uris[$this->game]['soldier'], $this->game, $this->personaUserID, $this->personaID);
     // Send request
     $results = $this->sendRequest($uri);
     $oldName = $this->player->SoldierName;
     $oldClan = $this->player->ClanTag;
     if (!array_key_exists('statsPersona', $results['context'])) {
         throw new BattlelogException(500, sprintf('Could not retrieve stats for %s.', $oldName));
     }
     $persona = $results['context']['statsPersona'];
     if ($oldName != $persona['personaName']) {
         $this->player->SoldierName = $persona['personaName'];
     }
     if ($oldClan != $persona['clanTag']) {
         $this->player->ClanTag = empty($persona['clanTag']) ? null : $persona['clanTag'];
     }
     if ($oldName != $persona['personaName'] || $oldClan != $persona['clanTag']) {
         $this->player->forget();
         $this->player->save();
     }
     return $this;
 }
Example #7
0
 public function store()
 {
     try {
         $player = Player::findOrfail(Input::get('player_id'));
         if (!is_null($player->ban)) {
             return Redirect::route('admin.adkats.bans.edit', [$player->ban->ban_id]);
         }
         $bfacp = App::make('bfadmincp');
         $admin = MainHelper::getAdminPlayer($bfacp->user, $player->game->GameID);
         // Save the POST data
         $ban_notes = trim(Input::get('notes', null));
         $ban_message = trim(Input::get('message', null));
         $ban_server = Input::get('server', null);
         $ban_start = Input::get('banStartDateTime', null);
         $ban_end = Input::get('banEndDateTime', null);
         $ban_type = Input::get('type', null);
         $ban_enforce_guid = (bool) Input::get('enforce_guid', false) ? 'Y' : 'N';
         $ban_enforce_name = (bool) Input::get('enforce_name', false) ? 'Y' : 'N';
         $ban_enforce_ip = (bool) Input::get('enforce_ip', false) ? 'Y' : 'N';
         $admin_id = is_null($admin) ? null : $admin->PlayerID;
         $admin_name = is_null($admin) ? Auth::user()->username : $admin->SoldierName;
         $input = compact('ban_notes', 'ban_message', 'ban_server', 'ban_start', 'ban_end', 'ban_type', 'ban_enforce_guid', 'ban_enforce_name', 'ban_enforce_ip', 'admin_id', 'admin_name');
         $response = Event::fire('player.ban', [$input, $player])[0];
         $this->messages[] = sprintf('Ban #%u has been created.', $response->ban_id);
         return Redirect::route('admin.adkats.bans.edit', [$response->ban_id])->with('messages', $this->messages);
     } catch (ModelNotFoundException $e) {
         return Redirect::route('admin.adkats.bans.index')->withErrors([sprintf('Player #%u doesn\'t exist.', Input::get('player_id'))]);
     }
 }
Example #8
0
 /**
  * Gets players DB information and passes it to playerDBLoop function
  *
  * @return $this|bool
  */
 private function getPlayerDBData()
 {
     // If the server is empty do not continue
     if ($this->data['server']['players']['online'] == 0) {
         return false;
     }
     $players = [];
     foreach ($this->data['teams'] as $teamID => $team) {
         if (array_key_exists('players', $team)) {
             foreach ($team['players'] as $player) {
                 $players[] = $player['guid'];
             }
         }
         if (array_key_exists('spectators', $team)) {
             foreach ($team['spectators'] as $player) {
                 $players[] = $player['guid'];
             }
         }
     }
     // If players array is empty do not continue
     if (empty($players)) {
         return false;
     }
     $playersDB = Player::where('GameID', $this->gameID)->whereIn('EAGUID', $players)->get();
     $this->playerDBLoop($playersDB);
     $this->playerDBLoop($playersDB, 'spectators');
     $this->playerDBLoop($playersDB, 'commander');
     $this->getOnlineAdmins();
     return $this;
 }
Example #9
0
 /**
  * Update user
  *
  * @param  integer $id User ID
  */
 public function update($id)
 {
     try {
         $user = User::findOrFail($id);
         $username = trim(Input::get('user_name', null));
         $email = trim(Input::get('user_email', null));
         $roleId = trim(Input::get('user_role', null));
         $expiration = trim(Input::get('user_expiration', null));
         $notes = trim(Input::get('user_notes', 'No Notes'));
         $soldiers = explode(',', Input::get('soldiers', ''));
         $v = Validator::make(Input::all(), ['user_name' => 'required|alpha_dash', 'user_email' => 'email', 'user_role' => 'required|exists:adkats_roles,role_id', 'user_notes' => 'max:1000']);
         if ($v->fails()) {
             return Redirect::route('admin.adkats.users.edit', [$id])->withErrors($v)->withInput();
         }
         if (Input::has('user_name') && $user->user_name != $username) {
             $user->user_name = $username;
         }
         if (Input::has('user_email') && $user->user_email != $email) {
             $user->user_email = $email;
         }
         if ($user->user_role != $roleId) {
             $user->user_role = $roleId;
         }
         if (Input::has('user_expiration')) {
             $user->user_expiration = Carbon::parse($expiration)->toDateTimeString();
         } else {
             $user->user_expiration = Carbon::now()->addYears(20)->toDateTimeString();
         }
         // Always save the notes field
         $user->user_notes = $notes;
         $soldier_ids = [];
         $user->soldiers()->delete();
         if (Input::has('soldiers')) {
             foreach ($soldiers as $soldier) {
                 $soldier_ids[] = new Soldier(['player_id' => $soldier]);
             }
         }
         if (Input::has('soldier')) {
             $players = Player::where('SoldierName', Input::get('soldier'))->lists('PlayerID');
             foreach ($players as $player) {
                 if (!in_array($player, $soldiers)) {
                     $soldier_ids[] = new Soldier(['player_id' => $player]);
                 }
             }
         }
         if (!empty($soldier_ids)) {
             $user->soldiers()->saveMany($soldier_ids);
         }
         $user->save();
         $this->messages[] = sprintf('Changes Saved!');
         return Redirect::route('admin.adkats.users.edit', [$id])->with('messages', $this->messages);
     } catch (ModelNotFoundException $e) {
         return Redirect::route('admin.adkats.users.index')->withErrors([sprintf('User #%u doesn\'t exist.', $id)]);
     }
 }
Example #10
0
 /**
  * Gets the total number of players in the database
  * @return integer
  */
 public function getPlayerCount()
 {
     $count = Cache::remember('player.count', 60, function () {
         return Player::count();
     });
     return intval($count);
 }
Example #11
0
 /**
  * Update user
  *
  * @param  integer $id User ID
  */
 public function update($id)
 {
     try {
         $user = User::findOrFail($id);
         $username = trim(Input::get('username', null));
         $email = trim(Input::get('email', null));
         $roleId = trim(Input::get('role', null));
         $lang = trim(Input::get('language', null));
         $status = trim(Input::get('confirmed', null));
         $soldiers = explode(',', Input::get('soldiers', ''));
         $v = Validator::make(Input::all(), ['username' => 'required|alpha_dash|min:4|unique:bfacp_users,username,' . $id, 'email' => 'required|email|unique:bfacp_users,email,' . $id, 'language' => 'required|in:' . implode(',', array_keys(Config::get('bfacp.site.languages'))), 'generate_pass' => 'boolean', 'confirmed' => 'boolean']);
         if ($v->fails()) {
             return Redirect::route('admin.site.users.edit', [$id])->withErrors($v)->withInput();
         }
         // Update the user role if it's been changed
         if ($roleId != $user->roles[0]->id) {
             $user->roles()->detach($user->roles[0]->id);
             $user->roles()->attach($roleId);
         }
         // Update the user language if it's been changed
         if ($lang != $user->setting->lang) {
             $user->setting()->update(['lang' => $lang]);
         }
         // Update account stats
         if ($status != $user->confirmed) {
             $user->confirmed = $status;
         }
         // Update username
         if ($username != $user->username) {
             $user->username = $username;
         }
         // Update email
         if ($email != $user->email) {
             $user->email = $email;
         }
         if (Input::has('generate_pass')) {
             $repo = app('BFACP\\Repositories\\UserRepository');
             // Generate a new password
             $newPassword = $repo->generatePassword();
             $repo->sendPasswordChangeEmail($user->username, $user->email, $newPassword);
             // Change the user password
             $user->password = $newPassword;
             $user->password_confirmation = $newPassword;
             $this->messages[] = Lang::get('site.admin.users.updates.password.generated', ['username' => $user->username, 'email' => $user->email]);
         }
         $soldier_ids = [];
         $user->soldiers()->delete();
         if (Input::has('soldiers')) {
             foreach ($soldiers as $soldier) {
                 $soldier_ids[] = new Soldier(['player_id' => $soldier]);
             }
         }
         if (Input::has('soldier')) {
             $players = Player::where('SoldierName', Input::get('soldier'))->lists('PlayerID');
             foreach ($players as $player) {
                 if (!in_array($player, $soldiers)) {
                     $soldier_ids[] = new Soldier(['player_id' => $player]);
                 }
             }
         }
         if (!empty($soldier_ids)) {
             foreach ($soldier_ids as $key => $soldier) {
                 // Check if an existing user already has claimed the player
                 // and if so do not associate with the account.
                 if (Soldier::where('player_id', $soldier->player_id)->count() == 1) {
                     $this->messages[] = Lang::get('alerts.user.soldier_taken', ['playerid' => $soldier->player_id]);
                     unset($soldier_ids[$key]);
                 }
             }
             $user->soldiers()->saveMany($soldier_ids);
         }
         $user->save();
         return Redirect::route('admin.site.users.edit', [$id])->withMessages($this->messages);
     } catch (ModelNotFoundException $e) {
         $this->messages[] = Lang::get('alerts.user.invlid', ['userid' => $id]);
         return Redirect::route('admin.site.users.edit', [$id])->withErrors($this->messages);
     }
 }
Example #12
0
 /**
  * Returns the player session history
  *
  * @param  integer $id Player ID
  *
  * @return object
  */
 public function getPlayerSessions($id)
 {
     try {
         $sessions = Player::findOrFail($id)->sessions()->orderBy('StartTime', 'desc')->get();
         return $sessions;
     } catch (ModelNotFoundException $e) {
         throw new PlayerNotFoundException(404, 'Player Not Found');
     }
 }
Example #13
0
 /**
  * Returns a list of accounts that match $player
  *
  * @param  object $player \BFACP\Battlefield\Player
  *
  * @return array
  */
 public function linkedAccounts($player)
 {
     $players = Player::where('PlayerID', '!=', $player->PlayerID)->where(function ($query) use(&$player) {
         if (!empty($player->EAGUID)) {
             $query->orWhere('EAGUID', $player->EAGUID);
         }
         if (!empty($player->PBGUID)) {
             $query->orWhere('PBGUID', $player->PBGUID);
         }
         if (!empty($player->SoldierName)) {
             $query->orWhere('SoldierName', $player->SoldierName);
         }
         if (!empty($player->IP_Address)) {
             $query->orWhere('IP_Address', $player->IP_Address);
         }
     });
     return $players->get();
 }