Esempio n. 1
0
function change_status($status, $message)
{
    $args = array('method' => 'change_status', 'status' => $status, 'message' => $message);
    call_method($args);
}
Esempio n. 2
0
 public function onSummary()
 {
     if ($this->game_state == self::IN_START) {
         echo "Something went wrong. GoodGameHost halt at preparing stage.\n";
     }
     if ($this->game_state == self::IN_GAME && $this->total_remaining_player > 0) {
         echo "Something went wrong. GoodGameHost halt at ingame stage.\n";
     }
     $game_name = $this->game_name;
     $creator = $this->creator;
     $hostname = $this->hostname;
     $host_id = $this->host_id;
     $created_time = $this->created_time;
     $game_state = $this->game_state;
     $winner = $this->winner;
     $game_started_time = $this->started_time;
     //stats calculation
     $endtime = time();
     $rantime = $endtime - $this->started_time;
     //upstream bandwidth
     $upload = $this->upload;
     //downstream bandwidth
     $download = $this->download;
     //bandwidth usage
     $total_bandwidth_usage = round(($upload + $download) / 1024, 0);
     //transfer rate
     $average_transfer_rate_per_second = round($total_bandwidth_usage / $rantime, 2);
     //how many people had joined the game.
     $hits = $this->hits;
     $total_player = $this->total_player;
     $game_length = round($this->game_time / 1000, 0);
     echo "\nSummary: \n";
     echo "Game name: {$game_name}\n";
     echo "Requested by: {$creator}\n";
     echo "Hosted by: {$hostname}\n";
     echo "Host id: {$host_id}\n";
     echo "Game started at: " . date("d M Y, h:i a", $game_started_time) . "\n";
     echo "Game ended at: " . date("d M Y, h:i a", $endtime) . "\n";
     echo "Total runtime: " . $rantime . " seconds\n";
     echo "Total bandwidth usage: " . $total_bandwidth_usage . " kilobyte\n";
     echo "Transfer rate: " . $average_transfer_rate_per_second . " kilobyte per seconds\n";
     echo "Hits: " . $hits . "\n";
     echo "Total player: " . $total_player . "\n";
     $upload = round($upload / 1024, 0);
     $download = round($download / 1024, 0);
     foreach ($this->dota_stats as $stat) {
         foreach ($this->left_players as $player) {
             if ($stat['slot_id'] == call_method('getSlot', $player)) {
                 switch (intval($stat['cat'])) {
                     case 1:
                         call_method('setHeroKills', $player, $stat['value']);
                         break;
                     case 2:
                         call_method('setHeroDeaths', $player, $stat['value']);
                         break;
                     case 3:
                         call_method('setCreepKills', $player, $stat['value']);
                         break;
                     case 4:
                         call_method('setCreepDenies', $player, $stat['value']);
                         break;
                     default:
                         //do nothing since we do not need the id cat
                 }
                 break;
             }
         }
     }
     //if superhost is connected to a valid database
     if ($this->db->db_connect_id) {
         $sql = "SELECT `uid` FROM `BNET` WHERE `username` = '{$creator}'";
         if ($result = $this->db->sql_query($sql)) {
             if ($row = $this->db->sql_fetchrow($result)) {
                 $game_name = $this->db->sql_string($game_name);
                 $game_requester_uid = $row['uid'];
                 $sql = "INSERT INTO `superhost_games` " . " (`host_id`, `game_requester_uid`, `game_name`, `created_time`, `game_state`, " . " `winner`,`game_started_at`, `game_length`, `total_player`" . ", `room_hits`, `upload_band`, `download_band`, `total_band`, `transfer_rate`) " . " VALUES('{$host_id}', '{$game_requester_uid}', {$game_name}, '{$created_time}', " . " '{$game_state}', '{$winner}', '{$game_started_time}', '{$game_length}', " . " '{$total_player}', '{$hits}', '{$upload}', '{$download}', '{$total_bandwidth_usage}', '{$average_transfer_rate_per_second}')";
                 if ($result = $this->db->sql_query($sql)) {
                     $sql = "SELECT `game_id` FROM `superhost_games` WHERE `host_id` = '{$host_id}' AND `created_time` = '{$created_time}' ";
                     if ($result = $this->db->sql_query($sql)) {
                         if ($row = $this->db->sql_fetchrow($result)) {
                             $game_id = $row['game_id'];
                             if ($this->game_state == self::IN_GAME) {
                                 $sql = "INSERT INTO `superhost_games_stats` " . "(`game_id`, `slot_id`, `uid`, `team`, `left_time`, " . " `left_reason`, `desync`, `loadtime`, `latency`, `herokills`, `herodeaths`, `creepkills`, `creepdenies`) VALUES";
                                 foreach ($this->players as $player) {
                                     $slot_id = call_method('getSlot', $player);
                                     $team = call_method('getTeam', $player);
                                     $left_time = call_method('getLeftTime', $player);
                                     $left_reason = call_method('getLeftReason', $player);
                                     $desync = call_method('getDesyncCounter', $player);
                                     $herokills = call_method('getHeroKills', $player);
                                     $herodeaths = call_method('getHeroDeaths', $player);
                                     $creepkills = call_method('getCreepKills', $player);
                                     $creepdenies = call_method('getCreepDenies', $player);
                                     $playername = call_method('getName', $player);
                                     $loadtime = call_method('getLoadTime', $player);
                                     $latency = call_method('getAverageLatency', $player);
                                     $sql2 = "SELECT `uid` FROM `BNET` WHERE `username` = '{$playername}'";
                                     if ($result2 = $this->db->sql_query($sql2)) {
                                         if ($row = $this->db->sql_fetchrow($result2)) {
                                             $uid = $row['uid'];
                                             $sql .= " ('{$game_id}', '{$slot_id}', '{$uid}', '{$team}', '{$left_time}', '{$left_reason}', " . " '{$desync}', '{$loadtime}', '{$latency}', '{$herokills}', '{$herodeaths}', '{$creepkills}', '{$creepdenies}'),";
                                         }
                                     }
                                     $sql3 = "INSERT INTO `superhost_games_packet_log` " . "(`game_id`, `slot_index`, `packet`) VALUES";
                                     while ($buffer = $player->getBufferLog()) {
                                         $packet = packet_dump_hex($buffer);
                                         $sql3 .= "('{$game_id}', '{$slot_id}', '{$packet}'),";
                                     }
                                     $last_char = strlen($sql3) - 1;
                                     if ($sql3[$last_char] == ',') {
                                         $sql3[$last_char] = '';
                                     }
                                     $result3 = $this->db->sql_query($sql3);
                                 }
                                 $last_char = strlen($sql) - 1;
                                 //remove the last ','
                                 if ($sql[$last_char] == ',') {
                                     $sql[$last_char] = '';
                                 }
                                 $result = $this->db->sql_query($sql);
                             }
                         }
                     }
                     if ($this->fatal_error) {
                         $back_trace = $this->fatal_error_event->getMessage();
                         $back_trace .= "\n\n" . $this->fatal_error_event->getTraceAsString();
                         $back_trace = $this->db->sql_string($back_trace);
                         $sql3 = "INSERT INTO `superhost_games_fatal_log` " . "(`game_id`, `log`) VALUES";
                         $sql3 .= "('{$game_id}', {$back_trace})";
                         $result3 = $this->db->sql_query($sql3);
                     }
                 }
             }
         }
         call_method('updateHostStatus', $this, self::HOST_STATUS_FREE);
         $this->db->sql_close();
     }
 }
Esempio n. 3
0
            if (count($_POST)) {
                debug('POST ' . json_encode(array($_POST)));
            }
            if (count($_GET)) {
                debug('GET ' . json_encode(array($_GET)));
            }
        } else {
            if (!is_file('views' . $request_uri . '.html')) {
                header('Content-Type: application/json', true);
                echo json_encode(array('view' => "missing"));
            }
        }
    } else {
        if (!is_file($request_uri)) {
            include $missing_page;
        }
    }
} else {
    if (isset($segments[0]) && $segments[0] == 'api') {
        $link = DB::connect();
        include 'app/controllers/ApiController.php';
        header('Content-Type: application/json', true);
        $obj = "App\\Controllers\\ApiController";
        $method = strstr($segments[1], '?', true);
        $c = new $obj();
        echo call_method($c, $method, $segments);
    } else {
        include "../app/index.php";
    }
}
http_response_code(200);
 /**
  * @param string $n
  * @param array  $args
  * @return mixed
  */
 function __call($n, $args)
 {
     return call_method([$this->decorated, $n], $this, ...$args);
 }
Esempio n. 5
0
    Test::assert('to_number "+1234.5678"', to_number('+1234.5678') === to_number('1234.5678'));
    Test::assert('to_number "+1234.5678e90"', to_number("+1234.5678e90") === to_number("1234.5678e90"));
    Test::assert('to_number "+1234.5678E90"', to_number("+1234.5678E90") === to_number("1234.5678E90"));
    Test::assert('to_number "+1234.5678e-90"', to_number("+1234.5678e-90") === to_number("1234.5678e-90"));
    Test::assert('to_number "+1234.5678E-90"', to_number("+1234.5678E-90") === to_number("1234.5678E-90"));
});
Test::suite('Number object', function () use($Number, $Object) {
    $num = $Number->construct(5.0);
    Test::assert('instanceof', $num instanceof Number);
    Test::assert('type is object', _typeof($num) === 'object');
    Test::assert('has value', $num->value === 5.0);
    Test::assert('to string', $num->callMethod('toString') === '5');
    $num = $Number->call(null, '5');
    Test::assert('is not object', !$num instanceof Str);
    Test::assert('primitive', _typeof($num) === 'number');
    Test::assert('can call on primitive', call_method($num, 'toString') === '5');
    $num = $Number->call(null, '');
    Test::assert('empty coerced', $num === 0.0);
    $num = $Number->callMethod('parseInt', '5.x');
    Test::assert('parseInt 1', $num === 5.0);
    $num = $Number->callMethod('parseInt', '+05.1');
    Test::assert('parseInt 2', $num === 5.0);
    $num = $Number->callMethod('parseInt', ' -15.0');
    Test::assert('parseInt 3', $num === -15.0);
    $num = $Number->callMethod('parseInt', 'x');
    Test::assert('parseInt 4', is_nan($num));
    $num = $Number->callMethod('parseFloat', '-05e2x');
    Test::assert('parseFloat 1', $num === -500.0);
    $num = $Number->callMethod('parseFloat', ' +05.0');
    Test::assert('parseFloat 2', $num === 5.0);
    $num = $Number->callMethod('parseFloat', 'x');