コード例 #1
0
ファイル: pvpgn_stats.php プロジェクト: pvpgn/phputils
 function d2ladder_update()
 {
     global $d2ladder_file, $d2update_time, $game, $type, $db_d2;
     $ranking = new pvpgn_rank();
     $S_INIT = 0x1;
     $S_EXP = 0x20;
     $S_HC = 0x4;
     $S_DEAD = 0x8;
     $sexes = array("Amazon" => "f", "Sorceress" => "f", "Necromancer" => "m", "Paladin" => "m", "Barbarian" => "m", "Druid" => "m", "Assassin" => "f");
     $diff = array("D2XP" => array(1 => array("SC" => array("m" => "Slayer", "f" => "Slayer"), "HC" => array("m" => "Destroyer", "f" => "Destroyer")), 2 => array("SC" => array("m" => "Champion", "f" => "Champion"), "HC" => array("m" => "Conqueror", "f" => "Conqueror")), 3 => array("SC" => array("m" => "Patriarch", "f" => "Matriarch"), "HC" => array("m" => "Guardian", "f" => "Guardian"))), "D2DV" => array(1 => array("SC" => array("m" => "Sir", "f" => "Dame"), "HC" => array("m" => "Count", "f" => "Countess")), 2 => array("SC" => array("m" => "Lord", "f" => "Lady"), "HC" => array("m" => "Duke", "f" => "Duchess")), 3 => array("SC" => array("m" => "Baron", "f" => "Baroness"), "HC" => array("m" => "King", "f" => "Queen"))));
     $classes = array("Amazon", "Sorceress", "Necromancer", "Paladin", "Barbarian", "Druid", "Assassin");
     $query = "SELECT d2ladder_time FROM counters";
     $result = $this->data->db_query($query);
     $last_update = $this->data->sql_fetch_assoc($result);
     $now = time();
     if ($d2update_time != 0) {
         if ($last_update['d2ladder_time'] == '') {
             $update = true;
             $query = "INSERT INTO `counters` (`d2ladder_time`) VALUES ('{$now}')";
             $result = $this->data->db_query($query);
         } else {
             if ($now >= $last_update['d2ladder_time'] + $d2update_time || $last_update['d2ladder_time'] == 0) {
                 $update = true;
                 $query = "UPDATE counters SET d2ladder_time = {$now} LIMIT 1";
                 $result = $this->data->db_query($query);
             } else {
                 $update = false;
             }
         }
     } else {
         $update = false;
     }
     if ($update) {
         $fp = fopen($d2ladder_file, "rb");
         $size = filesize($d2ladder_file);
         $maxtype = fread($fp, 4);
         $checksum = fread($fp, 4);
         $size = $size - 8;
         $checksumi = $this->get_int($checksum);
         $maxtypei = $this->get_int($maxtype);
         $types = array();
         while (!feof($fp) && $maxtypei > $type + 1) {
             $typ_a = array();
             $type = $this->get_int(fread($fp, 4));
             $typ_a[offset] = $this->get_int(fread($fp, 4));
             $typ_a[records] = $this->get_int(fread($fp, 4));
             $types[$type] = $typ_a;
         }
         $size = filesize($d2ladder_file) - ftell($fp);
         $ladder = array();
         foreach ($types as $type => $typ_a) {
             for ($i = 0; $i <= $typ_a[records] - 1; $i++) {
                 $offset = $i * 24 + $typ_a[offset];
                 fseek($fp, $offset, SEEK_SET);
                 $xp_r = fread($fp, 4);
                 $status_r = fread($fp, 2);
                 $level_r = fread($fp, 1);
                 $class_r = fread($fp, 1);
                 $charname_r = fread($fp, 16);
                 if (trim($charname_r) !== '') {
                     $charakter = array();
                     $status = $this->get_int($status_r);
                     $charakter[xp] = $this->get_int($xp_r);
                     $charakter[level] = $this->get_int($level_r);
                     $charakter[classs] = $classes[$this->get_int($class_r)];
                     $charakter[game] = $status & $S_EXP ? "D2XP" : "D2DV";
                     $charakter[hc] = $status & $S_HC ? "HC" : "SC";
                     if ($status & $S_HC) {
                         $charakter[dead] = $status & $S_DEAD ? "DEAD" : "ALIVE";
                     }
                     $charakter[difficulty] = floor(($status >> 0x8 & 0xf) / 5);
                     $charakter[prefix] = $diff[$charakter[game]][$charakter[difficulty]][$charakter[hc]][$sexes[$charakter[classs]]];
                     $charakter[charname] = trim($charname_r);
                     $ladder[$type][] = $charakter;
                 }
             }
         }
         foreach ($ladder as $type => $charakters) {
             foreach ($charakters as $charakter) {
                 $query = "SELECT * FROM `{$db_d2}` WHERE charname = '{$charakter['charname']}'";
                 $result = $this->data->db_query($query);
                 $row = $this->data->db_fetch($result);
                 if ($this->data->sql_num_rows($result) == 0) {
                     $query = "INSERT INTO `{$db_d2}` (`charname`,`title`,`level`,`class`,`experience`,`type`,`dead`,`game`) VALUES ('{$charakter['charname']}','{$charakter['prefix']}','{$charakter['level']}','{$charakter['classs']}','{$charakter['xp']}','{$charakter['hc']}','{$charakter['dead']}','{$charakter['game']}')";
                     $result = $this->data->db_query($query);
                 } else {
                     $query = "UPDATE `{$db_d2}` SET experience={$charakter['xp']}, title='{$charakter['prefix']}', level={$charakter['level']}, class='" . $charakter[classs] . "', type='{$charakter['hc']}', dead='{$charakter['dead']}', game='{$charakter['game']}' WHERE charname='{$charakter['charname']}'";
                     $result = $this->data->db_query($query);
                     if ($result != 1) {
                         print "Failed UPDATE Query: {$query} <br />";
                     }
                 }
             }
             $ranking->update_ranks($charakter[game], $charakter[hc]);
         }
     }
 }
コード例 #2
0
 function d2ladder_update()
 {
     global $d2ladder_file, $d2update_time, $game, $type;
     $ranking = new pvpgn_rank();
     $S_INIT = 0x1;
     $S_EXP = 0x20;
     $S_HC = 0x4;
     $S_DEAD = 0x8;
     $sexes = array("Amazon" => "f", "Sorceress" => "f", "Necromancer" => "m", "Paladin" => "m", "Barbarian" => "m", "Druid" => "m", "Assassin" => "f");
     $diff = array("D2XP" => array(1 => array("SC" => array("m" => "Slayer", "f" => "Slayer"), "HC" => array("m" => "Destroyer", "f" => "Destroyer")), 2 => array("SC" => array("m" => "Champion", "f" => "Champion"), "HC" => array("m" => "Conqueror", "f" => "Conqueror")), 3 => array("SC" => array("m" => "Patriarch", "f" => "Matriarch"), "HC" => array("m" => "Guardian", "f" => "Guardian"))), "D2DV" => array(1 => array("SC" => array("m" => "Sir", "f" => "Dame"), "HC" => array("m" => "Count", "f" => "Countess")), 2 => array("SC" => array("m" => "Lord", "f" => "Lady"), "HC" => array("m" => "Duke", "f" => "Duchess")), 3 => array("SC" => array("m" => "Baron", "f" => "Baroness"), "HC" => array("m" => "King", "f" => "Queen"))));
     $classes = array("Amazon", "Sorceress", "Necromancer", "Paladin", "Barbarian", "Druid", "Assassin");
     $query = "SELECT d2ladder_time FROM counters";
     $result = $this->data->db_query($query);
     $last_update = $this->data->sql_fetch_assoc($result);
     $now = time();
     if ($d2update_time != 0) {
         if ($now >= $last_update['d2ladder_time'] + $d2update_time || $last_update['d2ladder_time'] == 0) {
             $update = true;
             $query = "UPDATE counters SET d2ladder_time = {$now} LIMIT 1";
             $result = $this->data->db_query($query);
         } else {
             $update = false;
         }
     } else {
         $update = false;
     }
     if ($update) {
         $fp = fopen($d2ladder_file, "rb");
         $size = filesize($d2ladder_file);
         $maxtype = fread($fp, 4);
         $checksum = fread($fp, 4);
         $size = $size - 8;
         $checksumi = $this->get_int($checksum);
         $maxtypei = $this->get_int($maxtype);
         for ($n = 0; $n < $maxtypei; $n++) {
             $type = $this->get_int(fread($fp, 4));
             $offset = $this->get_int(fread($fp, 4));
             $number = $this->get_int(fread($fp, 4));
             $size = $size - 12;
         }
         for ($n = 0; $size > 0; $n++) {
             $xp = $this->get_int(fread($fp, 4));
             $status_hex = fread($fp, 2);
             $status = $this->get_int($status_hex);
             $level = $this->get_int(fread($fp, 1));
             $class = $this->get_int(fread($fp, 1));
             $charname = fread($fp, 16);
             $size = $size - 24;
             $str_status = array();
             if ($status & $S_EXP) {
                 $game = "D2XP";
             } else {
                 $game = "D2DV";
             }
             if ($status & $S_HC) {
                 $hc = "HC";
                 if ($status & $S_DEAD) {
                     $dead = "DEAD";
                 } else {
                     $dead = "ALIVE";
                 }
             } else {
                 $hc = "SC";
             }
             $difficulty = ($status >> 0x8 & 0xf) / 5;
             $difficulty = floor($difficulty);
             $charname = trim($charname);
             $prefix = $diff[$game][$difficulty][$hc][$sexes[$classes[$class]]];
             $query = "SELECT * FROM d2ladder WHERE charname = '{$charname}'";
             $result = $this->data->db_query($query);
             $row = $this->data->db_fetch($result);
             if ($this->data->sql_num_rows($result) == 0) {
                 $query = "INSERT INTO d2ladder (`charname`,`title`,`level`,`class`,`experience`,`type`,`dead`,`game`) VALUES ('{$charname}','{$prefix}','{$level}','{$classes[$class]}','{$xp}','{$hc}','{$dead}','{$game}')";
                 $result = $this->data->db_query($query);
             } else {
                 if ($row['experience'] < $xp) {
                     $query = "UPDATE d2ladder SET experience={$xp}, title='{$prefix}', level={$level}, class='" . $classes[$class] . "', type='{$hc}', dead='{$dead}', game='{$game}' WHERE charname='{$charname}'";
                     $result = $this->data->db_query($query);
                     if ($result != 1) {
                         print "Failed UPDATE Query: {$query} <br />";
                     }
                 }
             }
         }
     }
     $ranking->update_ranks($game, $type);
 }