foreach ($short_matches as $short_match) {
        echo "\n* Match {$short_match['match_id']} is less than 8 minutes, deducting points from players.\n";
        $players = $short_match['stage_3']->players;
        /**
         *   Perform the point deductions.
         */
        foreach ($players as $player) {
            $payload_steamid = $player['steamID32'];
            $match_id = $short_match['match_id'];
            $player_profile = $app['mongo.db']->selectCollection('player_profiles')->findOne(['payload_steamid' => $payload_steamid]);
            if (empty($player_profile)) {
                continue;
            }
            /**
             *   Match has already been deducted for user.
             */
            if (in_array($match_id, @$player_profile['short_matches'] ?: [])) {
                "\n* Deductions for {$match_id} have already occurred, skipping.\n";
                continue;
            }
            /**
             *   Careful, as this actually modifies the player's points. Doing this wrong could make people upset.
             */
            $deduct_result = PlayerProfile::deductShortGame($payload_steamid, $player['isWinner'], sizeof($players));
            echo "\n* Deducting points from player payload_steamid = {$payload_steamid} for match_id = {$match_id}\n";
            $app['mongo.db']->selectCollection('player_profiles')->update(['_id' => $player_profile['_id']], ['$push' => ['short_matches' => $match_id ?: 'empty']]);
            print_r($deduct_result);
        }
    }
    return 'ok';
});
Esempio n. 2
0
  *   Remove match results with no winners, as results are provided for both stage 2 and stage 3.
  */
 $match_results = array_filter($match_results, function ($match_result) {
     if (empty($match_result['winners']) && empty($match_result['losers'])) {
         return false;
     } else {
         return true;
     }
 });
 print_r($match_results);
 /**
  *   Winners and losers have been determined. Perform major procedures here.
  *   There are lots of queries being performed here; the script execution time may be 30s+.
  */
 foreach ($match_results as $match_result) {
     $player_profile = new \BarracksMaster\PlayerProfile();
     $num_players_total = sizeof($match_result['winners']) + sizeof($match_result['losers']);
     foreach ($match_result['winners'] as $payload_steamid) {
         if (!$player_profile->getByPayloadSteamId($payload_steamid)) {
             echo "\nCreating new profile for player: {$payload_steamid}\n";
             $player_profile->create(['payload_steamid' => $payload_steamid]);
         }
         $player_profile->addMatch($match_result['match_id'], 'win', $num_players_total);
     }
     foreach ($match_result['losers'] as $payload_steamid) {
         if (!$player_profile->getByPayloadSteamId($payload_steamid)) {
             echo "\nCreating new profile for player: {$payload_steamid}\n";
             $player_profile->create(['payload_steamid' => $payload_steamid]);
         }
         $player_profile->addMatch($match_result['match_id'], 'loss', $num_players_total);
     }