Exemplo n.º 1
0
 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!']);
 }
Exemplo n.º 2
0
 /**
  * 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];
 }