public function parse($path) { $mpq = new MPQFile($path, true, false); $init = $mpq->getState(); if (!$init) { return false; } $r = $mpq->parseReplay(); if (!$r) { return false; } $this->r_infos['version'] = $mpq->getVersionString(); $this->r_infos['realm'] = $r->getRealm(); $this->r_infos['speed'] = $r->getGameSpeed(); $this->r_infos['winner_known'] = $r->isWinnerKnown(); $this->r_infos['type'] = $r->getTeamSize(); $this->r_infos['length'] = $r->getGameLength(); $this->r_infos['real_length'] = (int) ($this->r_infos['length'] * 60) / 83.5; $this->r_infos['map'] = $r->getMapName(); $this->r_infos['map_hash'] = $r->getMapHash(); $this->r_infos['players'] = $r->getPlayers(); foreach ($this->r_infos['players'] as $k => &$player) { if ($player['isObs']) { $this->r_infos['obs'][] = $this->r_infos['players'][$k]; unset($this->r_infos['players'][$k]); continue; } $player['army'] = $player['race']; $player['bnet_id'] = (int) $player['uid']; } $this->computeAPM(); $this->_computeMessages($r); $this->_computeWinner(); return true; }
function test_file($file) { echo "Testing {$file} \n"; $mpq = new MPQFile($file); $rep = $mpq->parseReplay(); if (!$rep) { echo "Parse error!"; return; } $new = $rep->jsonify(); if (file_exists($file . '.parsed')) { $old = file_get_contents($file . '.parsed'); $diff = diff($old, $new); if ($diff != -1) { echo $file . ': position ' . $diff . ' old: >>' . substr($old, $diff - 5, 10) . '<< new: >>' . substr($new, $diff - 5, 10) . "<< "; file_put_contents($file . '.new.parsed', $new); echo "New content saved as " . $file . ".new.parsed\n"; //printDiff($old, $new); } } else { file_put_contents($file . '.parsed', $new); echo "Content saved as {$file}.parsed\n"; } }
if (!is_uploaded_file($tmpname)) { $text .= "Error: Uploaded filename doesn't point to an uploaded file.<br />"; $err = true; } if ($err !== true) { if (class_exists("MPQFile") || (include './include/replays/mpqfile.php')) { $start = microtime_float(); $parseDurationString = ""; $debug = 0; $a = new MPQFile($tmpname, true, $debug); $init = $a->getState(); if ($init == false) { $text .= "Error parsing uploaded file, make sure it is a valid MPQ archive!<br />\n"; } else { if ($a->getFileType() == "SC2replay") { $b = $a->parseReplay(); $parseDurationString .= sprintf("Parsed replay in %d ms.<br />\n", (microtime_float() - $start) * 1000); $players = $b->getPlayers(); $recorder = $b->getRecorder(); $error_str = ''; if ($event_id) { $event = new Event($event_id); $match = new Match(); // Check if replay->TeamSize == event->MatchType if ($b->getTeamSize() != $event->getField('MatchType')) { $error_str .= '<li>' . EB_SUBMITREPLAY_L3 . '</li>'; } // Check if winner is known if (!$b->isWinnerKnown()) { $error_str .= '<li>' . EB_SUBMITREPLAY_L4 . '</li>'; }