Example #1
0
<?php

require_once 'includes/functions.php';
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if ($_POST['submit']) {
    $from_value = $_POST['from_value'];
    $from_unit = $_POST['from_unit'];
    $to_unit = $_POST['to_unit'];
    $to_value = convert_speed($from_value, $from_unit, $to_unit);
}
$speed_options = array("feet per second", "miles per hour", "meters per second", "kilometers per hour", "knots");
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Convert Speed</title>
    <link href="styles.css" rel="stylesheet" type="text/css">
  </head>
  <body>

    <div id="main-content">

      <h1>Convert Speed</h1>
  
      <form action="" method="post">
        
        <div class="entry">
Example #2
0
 function loadgame()
 {
     // 4.2 [GameName]
     $this->game['name'] = '';
     for ($i = 0; $this->data[$i] != chr(0); $i++) {
         $this->game['name'] .= $this->data[$i];
     }
     $this->data = substr($this->data, $i + 2);
     // 0-byte ending the string + 1 unknown byte
     // 4.3 [Encoded String]
     $temp = '';
     for ($i = 0; $this->data[$i] != chr(0); $i++) {
         if ($i % 8 == 0) {
             $mask = ord($this->data[$i]);
         } else {
             $temp .= chr(ord($this->data[$i]) - !($mask & 1 << $i % 8));
         }
     }
     $this->data = substr($this->data, $i + 1);
     // 4.4 [GameSettings]
     $this->game['speed'] = convert_speed(ord($temp[0]));
     if (ord($temp[1]) & 1) {
         $this->game['visibility'] = convert_visibility(0);
     } else {
         if (ord($temp[1]) & 2) {
             $this->game['visibility'] = convert_visibility(1);
         } else {
             if (ord($temp[1]) & 4) {
                 $this->game['visibility'] = convert_visibility(2);
             } else {
                 if (ord($temp[1]) & 8) {
                     $this->game['visibility'] = convert_visibility(3);
                 }
             }
         }
     }
     $this->game['observers'] = convert_observers(((ord($temp[1]) & 16) == true) + 2 * ((ord($temp[1]) & 32) == true));
     $this->game['teams_together'] = convert_bool(ord($temp[1]) & 64);
     $this->game['lock_teams'] = convert_bool(ord($temp[2]));
     $this->game['full_shared_unit_control'] = convert_bool(ord($temp[3]) & 1);
     $this->game['random_hero'] = convert_bool(ord($temp[3]) & 2);
     $this->game['random_races'] = convert_bool(ord($temp[3]) & 4);
     if (ord($temp[3]) & 64) {
         $this->game['observers'] = convert_observers(4);
     }
     $temp = substr($temp, 13);
     // 5 unknown bytes + checksum
     // 4.5 [Map&CreatorName]
     $temp = explode(chr(0), $temp);
     $this->game['creator'] = $temp[1];
     $this->game['map'] = $temp[0];
     // 4.6 [PlayerCount]
     $temp = unpack('Vslots', $this->data);
     $this->data = substr($this->data, 4);
     $this->game['slots'] = $temp['slots'];
     // 4.7 [GameType]
     $this->game['type'] = convert_game_type(ord($this->data[0]));
     $this->game['private'] = convert_bool(ord($this->data[1]));
     $this->data = substr($this->data, 8);
     // 2 bytes are unknown and 4.8 [LanguageID] is useless
     // 4.9 [PlayerList]
     while (ord($this->data[0]) == 0x16) {
         $this->loadplayer();
         $this->data = substr($this->data, 4);
     }
     // 4.10 [GameStartRecord]
     $temp = unpack('Crecord_id/vrecord_length/Cslot_records', $this->data);
     $this->data = substr($this->data, 4);
     $this->game = array_merge($this->game, $temp);
     $slot_records = $temp['slot_records'];
     // 4.11 [SlotRecord]
     for ($i = 0; $i < $slot_records; $i++) {
         if ($this->header['major_v'] >= 7) {
             $temp = unpack('Cplayer_id/x1/Cslot_status/Ccomputer/Cteam/Ccolor/Crace/Cai_strength/Chandicap', $this->data);
             $this->data = substr($this->data, 9);
         } elseif ($this->header['major_v'] >= 3) {
             $temp = unpack('Cplayer_id/x1/Cslot_status/Ccomputer/Cteam/Ccolor/Crace/Cai_strength', $this->data);
             $this->data = substr($this->data, 8);
         } else {
             $temp = unpack('Cplayer_id/x1/Cslot_status/Ccomputer/Cteam/Ccolor/Crace', $this->data);
             $this->data = substr($this->data, 7);
         }
         $temp['color'] = convert_color($temp['color']);
         $temp['race'] = convert_race($temp['race']);
         $temp['ai_strength'] = convert_ai($temp['ai_strength']);
         if ($temp['slot_status'] == 2) {
             // do not add empty slots
             $this->players[$temp['player_id']] = array_merge($this->players[$temp['player_id']], $temp);
             // Tome of Retraining
             $this->players[$temp['player_id']]['retraining_time'] = 0;
         }
     }
     // 4.12 [RandomSeed]
     $temp = unpack('Vrandom_seed/Cselect_mode/Cstart_spots', $this->data);
     $this->data = substr($this->data, 6);
     $this->game['random_seed'] = $temp['random_seed'];
     $this->game['select_mode'] = convert_select_mode($temp['select_mode']);
     if ($temp['start_spots'] != 0xcc) {
         // tournament replays from battle.net website don't have this info
         $this->game['start_spots'] = $temp['start_spots'];
     }
 }