Exemple #1
0
 function glue($key, $value, $sep = ',')
 {
     if (is_array($value) && !empty($value)) {
         // Ignore exceptions and just return key
         if (key($value) === '*') {
             return '.' . $key . $sep;
         }
         $slds = empty($key) ? '' : '.' . $key . $sep;
         foreach ($value as $k => $v) {
             $glued = glue($k . (empty($key) ? '' : '.' . $key), $v, $sep);
             if ($glued === false) {
                 $slds .= 'HAI';
             } else {
                 $slds .= !empty($glued) ? $glued : '';
             }
         }
         return $slds;
     } else {
         return '.' . $key . $sep;
     }
 }
         echo $i . ". {$row['name']} ({$row['cnt']} games, for total " . timeDiff($row[sum]) . " - average game took " . timeDiff($row[avg]) . " and had " . round($row[plr]) . " players)\n";
         $i++;
     }
     $res = mysql_query("SELECT name, count(*) as cnt, avg(duration) as avg, sum(duration) AS sum, avg(players) AS plr FROM Games JOIN Maps ON mapId = Maps.id GROUP BY mapId ORDER BY sum DESC LIMIT 0,20");
     echo "== Globally most popular maps ==\n";
     $i = 1;
     while ($row = mysql_fetch_array($res)) {
         echo $i . ". {$row['name']} ({$row['cnt']} games, for total " . timeDiff($row[sum]) . " - average game took " . timeDiff($row[avg]) . " and had " . round($row[plr]) . " players)\n";
         $i++;
     }
     break;
 case "player":
     if ($args[1] == "") {
         $args[1] = $_GET[user];
     }
     $ida = filterPlayers(glue($args, 1));
     $pid = $ida[0];
     if ($pid == 0) {
         exit("this player has no games in database yet\n");
     }
     $total = mysql_result(mysql_query("SELECT count(*) FROM Games2players WHERE playerId = {$pid} AND spectator=0"), 0, 0);
     $wins = mysql_result(mysql_query("SELECT count(*) FROM Games2players WHERE playerId = {$pid} AND spectator=0 AND victoryTeam=1 AND aliveTillEnd=1"), 0, 0);
     $quit = mysql_result(mysql_query("SELECT count(*) FROM Games2players WHERE playerId = {$pid} AND spectator=0 AND (dropTime<>0 OR leaveTime<>0) AND (dropTime < loseTime OR leaveTime < loseTime)"), 0, 0);
     @(print getPlayerName($pid) . " - skill rating:" . eloToText($pid) . ", played {$total} games, has won " . round(100 * $wins / $total) . "% and quit " . round(100 * $quit / $total) . "%\n");
     $res = mysql_query("SELECT name, sum(duration) AS sum FROM Games JOIN Maps ON mapId = Maps.id AND Games.id IN (SELECT distinct gameId AS cnt FROM Games2players WHERE playerId={$pid}) GROUP BY mapId ORDER BY sum DESC LIMIT 0,5 ");
     echo "most played MAPS are:\n";
     $i = 1;
     while ($row = mysql_fetch_array($res)) {
         echo $i . ". {$row['name']} - " . timeDiff($row[sum]) . "\n";
         $i++;
     }