Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Weapon::create(['created_by' => 1, 'name' => 'Woodfang', 'type' => 'Dagger', 'die_quantity' => 2, 'die_sides' => 4, 'notes' => 'Created by his long lost love, Woodfang is the precursor of Ulazarin. <br> Causes long term
         neural damage to all those affected by it']);
 }
Пример #2
0
 /**
  * @return bool
  *
  * Track all round record into Database.
  */
 public function track()
 {
     /**
      * @var Game
      */
     $game = new Game();
     $game->tag = $this->roundTag;
     $game->server_time = $this->serverTime;
     $game->round_time = $this->timePlayed;
     $game->round_index = $this->roundIndex + 1 . " / " . $this->roundLimit;
     $game->gametype = $this->gameType;
     $game->outcome = $this->roundOutcome;
     $game->map_id = $this->gameMap;
     $game->total_players = $this->totalPlayers;
     $game->swat_score = $this->swatScore;
     $game->suspects_score = $this->suspectsScore;
     $game->swat_vict = $this->swatVictory;
     $game->suspects_vict = $this->suspectsVictory;
     if (!$game->save()) {
         return false;
     }
     /**
      * Iterate over each player array
      */
     foreach ($this->players as $p) {
         /**
          * @var Player
          */
         $player = new Player();
         $player->ingame_id = $p[0];
         $player->ip_address = $p[1];
         $player->name = str_replace('(VIEW)', '', $p[5]);
         $player->name = str_replace('(SPEC)', '', $player->name);
         $player->team = array_key_exists(6, $p) ? $p[6] : 0;
         $player->is_admin = array_key_exists(3, $p) ? $p[3] : 0;
         $player->is_dropped = array_key_exists(2, $p) ? $p[2] : 0;
         $player->score = array_key_exists(8, $p) ? $p[8] : 0;
         $player->time_played = array_key_exists(7, $p) ? $p[7] : 0;
         $player->kills = array_key_exists(9, $p) ? $p[9] : 0;
         $player->team_kills = array_key_exists(10, $p) ? $p[10] : 0;
         $player->deaths = array_key_exists(11, $p) ? $p[11] : 0;
         $player->suicides = array_key_exists(12, $p) ? $p[12] : 0;
         $player->arrests = array_key_exists(13, $p) ? $p[13] : 0;
         $player->arrested = array_key_exists(14, $p) ? $p[14] : 0;
         $player->kill_streak = array_key_exists(15, $p) ? $p[15] : 0;
         $player->arrest_streak = array_key_exists(16, $p) ? $p[16] : 0;
         $player->death_streak = array_key_exists(17, $p) ? $p[17] : 0;
         $player->game_id = $game->id;
         $player_ip_trim = substr($p[1], 0, strrpos($p[1], "."));
         $player_country_id = 0;
         $geoip = App::make('geoip');
         try {
             if ($player_geoip = $geoip->city($player->ip_address)) {
                 $player_isoCode = $player_geoip->country->isoCode;
                 $country = Country::where('countryCode', 'LIKE', $player_isoCode)->first();
                 /**
                  * Country returned is not in Countrie table
                  */
                 if ($country == null) {
                     $player_country_id = 0;
                 } else {
                     $player_country_id = $country->id;
                 }
             }
         } catch (\Exception $e) {
             switch ($e) {
                 case $e instanceof \InvalidArgumentException:
                     $player_country_id = 0;
                     break;
                 case $e instanceof \GeoIp2\Exception\AddressNotFoundException:
                     $player_country_id = 0;
                     break;
                 default:
                     $player_country_id = 0;
                     break;
             }
         }
         $loadout_array = array_key_exists(39, $p) ? $p[39] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
         /**
          * @var Loadout
          *
          * Create or find and return instance of Loadout and save to database.
          */
         $loadout = Loadout::firstOrCreate(['primary_weapon' => array_key_exists(0, $loadout_array) ? $loadout_array[0] : 0, 'primary_ammo' => array_key_exists(1, $loadout_array) ? $loadout_array[1] : 0, 'secondary_weapon' => array_key_exists(2, $loadout_array) ? $loadout_array[2] : 0, 'secondary_ammo' => array_key_exists(3, $loadout_array) ? $loadout_array[3] : 0, 'equip_one' => array_key_exists(4, $loadout_array) ? $loadout_array[4] : 0, 'equip_two' => array_key_exists(5, $loadout_array) ? $loadout_array[5] : 0, 'equip_three' => array_key_exists(6, $loadout_array) ? $loadout_array[6] : 0, 'equip_four' => array_key_exists(7, $loadout_array) ? $loadout_array[7] : 0, 'equip_five' => array_key_exists(8, $loadout_array) ? $loadout_array[8] : 0, 'breacher' => array_key_exists(9, $loadout_array) ? $loadout_array[9] : 0, 'body' => array_key_exists(10, $loadout_array) ? $loadout_array[10] : 0, 'head' => array_key_exists(11, $loadout_array) ? $loadout_array[11] : 0]);
         /**
          * Create or find and return instance of Alias.
          */
         $alias = Alias::firstOrNew(['name' => $player->name]);
         /**
          * If Alias is not present then new instance is created.
          */
         if ($alias->id == null) {
             //$profile = Profile::firstOrNew(['ip_address' => $player_ip_trim.'%']);
             $profile = Profile::where('ip_address', 'LIKE', $player_ip_trim . '%')->first();
             // If no profile present create new else ignore.
             if (!$profile) {
                 $profile = new Profile();
             }
             /**
              * Neither Alias not Profile is present.
              *
              * So it will create both new Alias and Profile.
              */
             if ($profile->id == null) {
                 $profile->name = $player->name;
                 $profile->team = $player->team;
                 $profile->country_id = $player_country_id;
                 $profile->loadout_id = $loadout->id;
                 $profile->game_first = $game->id;
                 $profile->game_last = $game->id;
                 $profile->ip_address = $player->ip_address;
                 $profile->save();
                 $alias->name = $player->name;
                 $alias->profile_id = $profile->id;
                 $alias->ip_address = $player->ip_address;
                 $alias->save();
             } else {
                 $alias->name = $player->name;
                 $alias->profile_id = $profile->id;
                 $alias->ip_address = $player->ip_address;
                 $alias->save();
                 $profile->team = $player->team;
                 $profile->game_last = $game->id;
                 $profile->loadout_id = $loadout->id;
                 $profile->ip_address = $player->ip_address;
                 $profile->country_id = $player_country_id;
                 $profile->save();
             }
         } else {
             $profile = Profile::find($alias->profile_id);
             $profile->team = $player->team;
             $profile->game_last = $game->id;
             $profile->loadout_id = $loadout->id;
             $profile->ip_address = $player->ip_address;
             $profile->country_id = $player_country_id;
             $profile->save();
             $alias->ip_address = $player->ip_address;
             $alias->save();
         }
         $player->alias_id = $alias->id;
         $player->loadout_id = $loadout->id;
         $player->country_id = $player_country_id;
         $player->save();
         /**
          * Iterate over all Weapon of each Player if exists
          */
         if (array_key_exists(40, $p)) {
             foreach ($p[40] as $w) {
                 $weapon = new Weapon();
                 $weapon->name = $w[0];
                 $weapon->player_id = $player->id;
                 $weapon->seconds_used = array_key_exists(1, $w) ? $w[1] : 0;
                 $weapon->shots_fired = array_key_exists(2, $w) ? $w[2] : 0;
                 $weapon->shots_hit = array_key_exists(3, $w) ? $w[3] : 0;
                 $weapon->shots_teamhit = array_key_exists(4, $w) ? $w[4] : 0;
                 $weapon->kills = array_key_exists(5, $w) ? $w[5] : 0;
                 $weapon->teamkills = array_key_exists(6, $w) ? $w[6] : 0;
                 $weapon->distance = array_key_exists(7, $w) ? $w[7] : 0;
                 $weapon->save();
             }
         }
     }
     //$pt = new App\Server\Repositories\PlayerTotalRepository();
     //$pt->calculate();
     //$response = Response::make("0\\nStats has been successfully tracked",200);
     printf("%s", "0\nRound report tracked.");
     exit(0);
 }