From 7372bb2efa763db517eaad0b5150f6d2bf26ced6 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Mon, 2 Apr 2018 02:47:56 -0700 Subject: [PATCH] Remove mgu_create*.php These files do not appear to be used anywhere. --- engine/Default/mgu_create.php | 210 -------------- engine/Default/mgu_create_full.php | 178 ------------ engine/Default/mgu_create_new.php | 437 ----------------------------- 3 files changed, 825 deletions(-) delete mode 100644 engine/Default/mgu_create.php delete mode 100644 engine/Default/mgu_create_full.php delete mode 100644 engine/Default/mgu_create_new.php diff --git a/engine/Default/mgu_create.php b/engine/Default/mgu_create.php deleted file mode 100644 index d4632b1f6..000000000 --- a/engine/Default/mgu_create.php +++ /dev/null @@ -1,210 +0,0 @@ -getSector(); - -$game_id = $player->getGameID(); -//init file so we can get a size later -$file = ''; -//function for writing a ushort -function add2bytes($int) { - $temp = pack('c', $int % 256); - $temp .= pack('c', $int / 256); - return $temp; - -} -function addbyte($int) { - return pack('c', $int); -} -//generate the players alliance list... -$alliance = '(0'; -$db->query('SELECT * FROM player WHERE alliance_id = ' . $db->escapeNumber($player->getAllianceID()) . ' AND alliance_id != 0 LIMIT 1'); -while ($db->nextRecord()) { - $alliance .= ','; - $alliance .= $db->getField('account_id'); -} -$alliance .= ')'; -$db->query('SELECT * FROM game WHERE game_id = '.$game_id.' LIMIT 1'); -if ($db->nextRecord()) - $game_name = $db->getField('game_name'); - -$file .= 'CMF by ^V^ Productions ©2004 '; -//get number of galaxies -$db->query('SELECT sector.galaxy_id, count(*) as num_sec, galaxy_name ' . - 'FROM sector NATURAL JOIN galaxy ' . - 'WHERE game_id = '.$game_id.' ' . - 'GROUP BY sector.galaxy_id ORDER BY sector_id'); -$file .= addbyte($db->getNumRows()); -//get galaxy name length -while ($db->nextRecord()) { - //gal name - $file .= addbyte(strlen($db->getField('galaxy_name'))); - $file .= $db->getField('galaxy_name'); - //gal owner - $file .= addbyte(0); - //$file .= addbyte(33); - //$file .= 'Not Supported By SMR Download Yet'; - //default port owner - if ($db->getField('galaxy_id') <= 8) - $file .= addbyte($db->getField('galaxy_id')); - else - $file .= addbyte(9); - //gal size - $file .= addbyte(sqrt($db->getField('num_sec'))); - $file .= addbyte(sqrt($db->getField('num_sec'))); -} -//planet definitions (num of, [size of name, name]) -$file .= addbyte(2); -$file .= addbyte(8); -$file .= 'Friendly'; -$file .= addbyte(5); -$file .= 'Enemy'; -//done with all header info - -$db2 = new SmrMySqlDatabase(); -$db3 = new SmrMySqlDatabase(); - -$db->query('SELECT * FROM sector WHERE game_id = '.$game_id.' ORDER BY sector_id'); -while ($db->nextRecord()) { - $sector_id = $db->getField('sector_id'); - $db2->query('SELECT * FROM player_visited_sector WHERE sector_id = '.$sector_id.' AND game_id = '.$game_id.' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); - - if ($db2->getNumRows() > 0) { - $CurrByte = 3; - $up = $db->getField('link_up'); - $db2->query('SELECT * FROM player_visited_sector WHERE sector_id = '.$up.' AND game_id = '.$game_id.' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); - if ($db2->getNumRows() == 0 && $up != 0) $CurrByte += 128; - $right = $db->getField('link_right'); - $db2->query('SELECT * FROM player_visited_sector WHERE sector_id = '.$right.' AND game_id = '.$game_id.' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); - if ($db2->getNumRows() == 0 && $right != 0) $CurrByte += 64; - $down = $db->getField('link_down'); - $db2->query('SELECT * FROM player_visited_sector WHERE sector_id = '.$down.' AND game_id = '.$game_id.' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); - if ($db2->getNumRows() == 0 && $down != 0) $CurrByte += 32; - $left = $db->getField('link_left'); - $db2->query('SELECT * FROM player_visited_sector WHERE sector_id = '.$left.' AND game_id = '.$game_id.' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); - if ($db2->getNumRows() == 0 && $left != 0) $CurrByte += 16; - $file .= addbyte($CurrByte); - $file .= addbyte(0); - continue; - } - $db2->query('SELECT * FROM player_visited_port ' . - 'WHERE account_id = ' . $db->escapeNumber($player->getAccountID()) . ' AND ' . - 'game_id = '.$game_id.' AND ' . - 'sector_id = '.$sector_id.' LIMIT 1'); - - if ($db2->nextRecord()) { - $port_info = unserialize(stripslashes($db2->getField('port_info'))); - } - // link infos - $CurrByte = 0; - if ($db->getField('link_up') > 0) $CurrByte += 128; - if ($db->getField('link_right') > 0) $CurrByte += 64; - if ($db->getField('link_down') > 0) $CurrByte += 32; - if ($db->getField('link_left') > 0) $CurrByte += 16; - //do we have a planet here? - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' LIMIT 1'); - if ($db2->nextRecord()) { - $CurrByte += 8; - } - //do we have a port here? - $db2->query('SELECT * FROM port WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' LIMIT 1'); - if ($db2->nextRecord()) { - $CurrByte += 4; - } - //sector friendliness - $db2->query('SELECT * FROM sector_has_forces WHERE sector_id = '.$sector_id.' AND mines > 0 AND owner_id IN '.$alliance.' LIMIT 1'); - if ($db2->getNumRows() > 0) { - //we want a green 'friendly' sector - $CurrByte += 1; - } - else { - //we want a blue 'neutral' sector - $CurrByte += 0; - } - $file .= addbyte($CurrByte); - $db2->query('SELECT * FROM port WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' LIMIT 1'); - $race = 0; - $has_port = FALSE; - if ($db2->nextRecord()) { - $has_port = TRUE; - $race = $db2->getField('race_id'); - if ($race == 1) $race = 9; - else $race -= 1; - //3 bytes total... - $db2->query('SELECT * FROM good ORDER BY good_id'); - for ($i=0;$i<=2;$i++) { - $CurrByte = 0; - for ($j=0;$j<=3;$j++) { - $db2->nextRecord(); - $good_id = $db2->getField('good_id'); - if (isset($port_info[$good_id])) { - if ($port_info[$good_id] == 'Sell') $CurrByte |= 1 << (2*(4 - $j) - 1); - else $CurrByte |= 1 << (2*(4 - $j) - 2); - } - } - $file .= addbyte($CurrByte); - } - } - //add port race byte... - $race = $race * 16; - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' LIMIT 1'); - if ($db2->nextRecord()) { - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' AND owner_id IN '.$alliance.' LIMIT 1'); - if ($db2->nextRecord()) { - //friendly planet - $planet = 1; - //get level (start at 0) - $level = 0; - $db2->query('SELECT * FROM planet_has_building WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - while ($db2->nextRecord()) { - $level += $db2->getField('amount'); - } - } - else { - //unfriendly/enemy - $planet = 2; - //unknown level - $level = 0; - } - } - else { - //no planet - $planet = 0; - $level = 0; - } - if ($planet > 0 || $race > 0) - $file .= addbyte(($planet + $race)); - if ($planet > 0) - $file .= addbyte($level); - $db3->query('SELECT * FROM warp WHERE game_id = '.$game_id.' AND (sector_id_1 = '.$sector_id.' OR sector_id_2 = '.$sector_id.') LIMIT 1'); - if ($db3->nextRecord()) - $CurrByte = 128; - else $CurrByte = 0; - // locations - $db2->query('SELECT * FROM location NATURAL JOIN location_type WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' LIMIT 1'); - $CurrByte += $db2->getNumRows(); - $file .= addbyte($CurrByte); - // warp - $db3->query('SELECT * FROM warp WHERE game_id = '.$game_id.' AND (sector_id_1 = '.$sector_id.' OR sector_id_2 = '.$sector_id.') LIMIT 1'); - if ($db3->nextRecord()) { - $warp_id = ($db3->getField('sector_id_1') == $sector_id) ? $db3->getField('sector_id_2') : $db3->getField('sector_id_1'); - $file .= add2bytes($warp_id); - } - - while ($db2->nextRecord()) { - $file .= add2bytes($db2->getField('mgu_id')); - } -} - -$size = strlen($file); - -header('Pragma: public'); -header('Expires: 0'); -header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); -header('Cache-Control: private',false); -header('Content-Type: application/force-download'); -header('Content-Disposition: attachment; filename="$game_name.cmf"'); -header('Content-Transfer-Encoding: binary'); -header('Content-Length: '.$size); - -echo $file; - -?> diff --git a/engine/Default/mgu_create_full.php b/engine/Default/mgu_create_full.php deleted file mode 100644 index f55d4c9a5..000000000 --- a/engine/Default/mgu_create_full.php +++ /dev/null @@ -1,178 +0,0 @@ -getSector(); - -$game_id = $player->getGameID(); -//init file so we can get a size later -$file = ''; -//function for writing a ushort -function add2bytes($int) { - $temp = pack('c', $int % 256); - $temp .= pack('c', $int / 256); - return $temp; - -} -function addbyte($int) { - return pack('c', $int); -} -//generate the players alliance list... -$alliance = '(0'; -$db->query('SELECT * FROM player WHERE alliance_id = ' . $db->escapeNumber($player->getAllianceID()) . ' AND alliance_id != 0'); -while ($db->nextRecord()) { - $alliance .= ','; - $alliance .= $db->getField('account_id'); -} -$alliance .= ')'; -$db->query('SELECT * FROM game WHERE game_id = '.$game_id); -if ($db->nextRecord()) - $game_name = $db->getField('game_name'); - -$file .= 'CMF by ^V^ Productions ©2004 '; -//get number of galaxies -$galaxies =& SmrGalaxy::getGameGalaxies($game_id); -$file .= addbyte(count($galaxies)); -//get galaxy name length -foreach ($galaxies as &$galaxy) { - //gal name - $file .= addbyte(strlen($galaxy->getName())); - $file .= $galaxy->getName(); - //gal owner - $file .= addbyte(0); - //$file .= addbyte(33); - //$file .= 'Not Supported By SMR Download Yet'; - //default port owner - if ($db->getField('galaxy_id') <= 8) - $file .= addbyte($galaxy->getGalaxyID()); - else - $file .= addbyte(9); - //gal size - $file .= addbyte($galaxy->getWidth()); - $file .= addbyte($galaxy->getHeight()); -} unset($galaxy); -//planet definitions (num of, [size of name, name]) -$file .= addbyte(2); -$file .= addbyte(8); -$file .= 'Friendly'; -$file .= addbyte(5); -$file .= 'Enemy'; -//done with all header info - -$db2 = new SmrMySqlDatabase(); -$db3 = new SmrMySqlDatabase(); - -$db->query('SELECT * FROM sector WHERE game_id = '.$game_id.' ORDER BY sector_id'); -while ($db->nextRecord()) { - $sector_id = $db->getField('sector_id'); - - // link infos - $CurrByte = 0; - if ($db->getField('link_up') > 0) $CurrByte += 128; - if ($db->getField('link_right') > 0) $CurrByte += 64; - if ($db->getField('link_down') > 0) $CurrByte += 32; - if ($db->getField('link_left') > 0) $CurrByte += 16; - //do we have a planet here? - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - if ($db2->nextRecord()) { - $CurrByte += 8; - } - //do we have a port here? - $db2->query('SELECT * FROM port WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - if ($db2->nextRecord()) { - $CurrByte += 4; - } - //sector friendliness - $db2->query('SELECT * FROM sector_has_forces WHERE sector_id = '.$sector_id.' AND mines > 0 AND owner_id IN '.$alliance); - if ($db2->getNumRows() > 0) { - //we want a green 'friendly' sector - $CurrByte += 1; - } - else { - //we want a blue 'neutral' sector - $CurrByte += 0; - } - $file .= addbyte($CurrByte); - $db2->query('SELECT * FROM port WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - $race = 0; - $has_port = FALSE; - if ($db2->nextRecord()) { - $has_port = TRUE; - $race = $db2->getField('race_id'); - if ($race == 1) $race = 9; - else $race -= 1; - //3 bytes total... - $db2->query('SELECT * FROM good ORDER BY good_id'); - for ($i=0;$i<=2;$i++) { - $CurrByte = 0; - $CurrAdd = 128; - for ($j=0;$j<=3;$j++) { - $db2->nextRecord(); - $good_id = $db2->getField('good_id'); - $db3->query('SELECT * FROM port_has_goods WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' AND good_id = '.$good_id); - if ($db3->nextRecord()) - if ($db3->getField('transaction') == 'Sell') - $CurrByte += $CurrAdd; - else - $CurrByte += $CurrAdd / 2; - $CurrAdd /= 4; - } - $file .= addbyte($CurrByte); - } - } - //add port race byte... - $race = $race * 16; - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - if ($db2->nextRecord()) { - $db2->query('SELECT * FROM planet WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id.' AND owner_id IN '.$alliance); - if ($db2->nextRecord()) { - //friendly planet - $planet = 1; - //get level (start at 0) - $level = 0; - $db2->query('SELECT * FROM planet_has_building WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - while ($db2->nextRecord()) { - $level += $db2->getField('amount'); - } - } - else { - //unfriendly/enemy - $planet = 2; - //unknown level - $level = 0; - } - } - else { - //no planet - $planet = 0; - $level = 0; - } - if ($planet > 0 || $race > 0) - $file .= addbyte(($planet + $race)); - if ($planet > 0) - $file .= addbyte($level); - $db3->query('SELECT * FROM warp WHERE game_id = '.$game_id.' AND (sector_id_1 = '.$sector_id.' OR sector_id_2 = '.$sector_id.')'); - if ($db3->nextRecord()) - $CurrByte = 128; - else $CurrByte = 0; - // locations - $db2->query('SELECT * FROM location NATURAL JOIN location_type WHERE game_id = '.$game_id.' AND sector_id = '.$sector_id); - $CurrByte += $db2->getNumRows(); - $file .= addbyte($CurrByte); - // warp - $db3->query('SELECT * FROM warp WHERE game_id = '.$game_id.' AND (sector_id_1 = '.$sector_id.' OR sector_id_2 = '.$sector_id.')'); - if ($db3->nextRecord()) { - $warp_id = ($db3->getField('sector_id_1') == $sector_id) ? $db3->getField('sector_id_2') : $db3->getField('sector_id_1'); - $file .= add2bytes($warp_id); - } - - while ($db2->nextRecord()) { - $file .= add2bytes($db2->getField('mgu_id')); - } -} - -header('Content-type: application/octet-stream'.EOL); -header('Content-Disposition: attachment; filename='.$game_name.'.cmf'.EOL); -header('Content-transfer-encoding: binary'.EOL); -$size = strlen($file); -header('Content-Length: '.$size); -echo($file); - -?> \ No newline at end of file diff --git a/engine/Default/mgu_create_new.php b/engine/Default/mgu_create_new.php deleted file mode 100644 index 919644ca8..000000000 --- a/engine/Default/mgu_create_new.php +++ /dev/null @@ -1,437 +0,0 @@ -getGameID(); - -// Game name -$db->query( - 'SELECT game_name FROM game WHERE game_id=' . $game_id . ' LIMIT 1' -); - -$db->nextRecord(); -$game_name = $db->getField('game_name'); -$total_sectors = 0; - -// Build the galaxy array. -$galaxies =& SmrGalaxy::getGameGalaxies($game_id); -foreach ($galaxies as &$galaxy) { - $total_sectors += $galaxy->getSize(); -} unset($galaxy); - -// Fill the sectors array with visited sectors -$db->query( - 'SELECT sector_id,galaxy_id,link_up,link_left,link_right,link_down ' . - 'FROM sector WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND sector_id NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) ' -); - -while($db->nextRecord()) { - $sectors[$db->getField('sector_id')] = array( - 'up' => $db->getField('link_up'), - 'left' => $db->getField('link_left'), - 'right' => $db->getField('link_right'), - 'down' => $db->getField('link_down') - ); -} - -// Locations -$db->query( - 'SELECT ' . - 'location.sector_id as sector_id,' . - 'location_type.mgu_id as mgu_id ' . - 'FROM location,location_type ' . - 'WHERE location.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND location.location_type_id = location_type.location_type_id ' . - 'AND location.sector_id NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) ' -); - -// Adjust the sectors array -while($db->nextRecord()) { - $sectors[$db->getField('sector_id')]['location'][] = $db->getField('mgu_id'); -} - -// Warps -$db->query( - 'SELECT ' . - 'sector_id_1,sector_id_2 ' . - 'FROM warp ' . - 'WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND ((sector_id_1 NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ))' . - ' OR (sector_id_2 NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ))' . - ') ' -); - -// Adjust the sectors array -while($db->nextRecord()) { - if(isset($sectors[$db->getField('sector_id_1')])) { - $sectors[$db->getField('sector_id_1')]['warp'] = $db->getField('sector_id_2'); - } - if(isset($sectors[$db->getField('sector_id_2')])) { - $sectors[$db->getField('sector_id_2')]['warp'] = $db->getField('sector_id_1'); - } -} - -// Grab the information for any ports the player has knowledge of -$ports = array(); -$db->query( - 'SELECT ' . - 'port.race_id as race_id,' . - 'port.sector_id as sector_id, ' . - 'player_visited_port.port_info as port_info ' . - 'FROM player_visited_port,port ' . - 'WHERE port.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND player_visited_port.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND port.sector_id = player_visited_port.sector_id ' . - 'AND player_visited_port.account_id=' . $db->escapeNumber($player->getAccountID()) -); - -// Adjust the sectors array -while($db->nextRecord()) { - // Adjust races for MGU - $race = $db->getField('race_id'); - if($race == 1) { - $race = 9; - } - else { - --$race; - } - $sectors[$db->getField('sector_id')]['port'] = array( - 'info' => $db->getField('port_info'), - 'race' => $race - ); -} - -// Grab the 'safe' sectors (Those with a friendly mine in) -$safe = array(); -$query = - 'SELECT sector_has_forces.sector_id as sector_id ' . - 'FROM sector_has_forces,player ' . - 'WHERE sector_has_forces.owner_id = player.account_id ' . - 'AND '; - -if($player->getAllianceID()) { - $query .= '(player.alliance_id = ' . $db->escapeNumber($player->getAllianceID()) . ' OR ' . - 'sector_has_forces.owner_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) '; -} -else { - $query .= 'sector_has_forces.owner_id = ' . $db->escapeNumber($player->getAccountID()) . ' '; -} - -$query .= - 'AND player.game_id = sector_has_forces.game_id ' . - 'AND sector_has_forces.game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND sector_has_forces.mines > 0 ' . - 'AND sector_has_forces.sector_id NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) ' . - 'GROUP BY sector_has_forces.sector_id'; - -$db->query($query); - -// Adjust the sectors array -while($db->nextRecord()) { - $sectors[$db->getField('sector_id')]['safe'] = true; -} - -// Grab the planets -$planets=array(); -$db->query( - 'SELECT sector_id ' . - 'FROM planet ' . - 'WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND sector_id NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) ' -); - -// Adjust the sectors array -while($db->nextRecord()) { - $sectors[$db->getField('sector_id')]['planet'] = true; -} - -// Determine level of player/alliance owned planets -$query = - 'SELECT ' . - 'SUM(planet_has_building.amount) as level,' . - 'planet_has_building.sector_id as sector_id ' . - 'FROM planet_has_building,planet,player ' . - 'WHERE planet.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND planet_has_building.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND player.game_id=' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND planet_has_building.sector_id = planet.sector_id ' . - 'AND player.account_id = planet.owner_id ' . - 'AND planet_has_building.sector_id NOT IN ( ' . - 'SELECT sector_id FROM player_visited_sector ' . - 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' ' . - 'AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) ' . - 'AND '; - -if($player->getAllianceID()) { - $query .= '(player.alliance_id = ' . $db->escapeNumber($player->getAllianceID()) . ' OR ' . - 'planet.owner_id = ' . $db->escapeNumber($player->getAccountID()) . ' ) '; -} -else { - $query .= 'planet.owner_id = ' . $db->escapeNumber($player->getAccountID()) . ' '; -} - -$query .= 'GROUP BY sector_id'; - -$db->query($query); - -// Adjust the sectors array (The cast is important, we test against it later) -while($db->nextRecord()) { - $sectors[$db->getField('sector_id')]['planet'] = (int)$db->getField('level'); -} - -/* - * Build the output file - */ -$file = 'CMF by ^V^ Productions ©2004 '; - -// Number of galaxies -$file .= pack('C',count($galaxies)); - -// Galaxies -foreach($galaxies as $galaxy_id => $galaxy) { - // Names - $file .= pack('C',strlen($galaxy->getName())); - $file .= $galaxy->getName(); - $file .= pack('C', 0); - // Race - if($galaxy_id < 9) { - $file .= pack('C', $galaxy_id); - } - else { - $file .= pack('C', 9); - } - // Height/Width - $file .= pack('C', $galaxy->getWidth()); - $file .= pack('C', $galaxy->getHeight()); -} - -$file .= pack('C', 2); -$file .= pack('C', 8); -$file .= 'Friendly'; -$file .= pack('C', 5); -$file .= 'Enemy'; - -$max = $total_sectors + 1; - -$galaxy_ids = array_keys($galaxies); -$galaxy_index = 0; -$current_galaxy = $galaxy_ids[$galaxy_index]; - -for($i=1;$i<$max;++$i) { - - $byte = 0; - - if($i > $galaxies[$current_galaxy]['end']) { - ++$galaxy_index; - $current_galaxy = $galaxy_ids[$galaxy_index]; - } - - if(isset($sectors[$i])) { - // Sector is known, all information is pulled from the $sectors array - if($sectors[$i]['up']) { - $byte |= 128; - } - if($sectors[$i]['right']) { - $byte |= 64; - } - if($sectors[$i]['down']) { - $byte |= 32; - } - if($sectors[$i]['left']) { - $byte |= 16; - } - if(isset($sectors[$i]['planet'])) { - $byte |= 8; - } - if(isset($sectors[$i]['port'])) { - $byte |= 4; - } - if(isset($sectors[$i]['safe'])) { - $byte |= 1; - } - - $file .= pack('C', $byte); - - $byte = 0; - - if(isset($sectors[$i]['port'])) { - $info = unserialize(gzuncompress($sectors[$i]['port']['info'])); - for($j=0;$j<3;++$j) { - $byte = 0; - for($k=0;$k<4;++$k) { - $good_id = (4 * $j) + $k + 1; - if($info->hasGood($good_id)) { - $good = $info->getGood($good_id); - if ($good['TransactionType'] == 'Sell') { - $byte |= 1 << (2*(4 - $k) - 1); - } - else { - $byte |= 1 << (2*(4 - $k) - 2); - } - } - - } - $file .= pack('C', $byte); - } - - // Port race byte is combined with planet byte - $byte = $sectors[$i]['port']['race'] << 4; - - } - - if(isset($sectors[$i]['planet'])) { - if(is_int($sectors[$i]['planet'])) { - // Friendly planet; - $file .= pack('C', ($byte | 1)); - $file .= pack('C', $sectors[$i]['planet']); - } - else { - $file .= pack('C', ($byte | 2)); - $file .= pack('C', 0); - } - } - else if(isset($sectors[$i]['port'])) { - $file .= pack('C', $byte); - } - - $byte = 0; - - if(isset($sectors[$i]['warp'])) { - $byte |= 128; - } - - if(isset($sectors[$i]['location'])) { - $byte |= count($sectors[$i]['location']); - } - - $file .= pack('C', $byte); - - if(isset($sectors[$i]['warp'])) { - $file .= pack('v', $sectors[$i]['warp']); - } - - if(isset($sectors[$i]['location'])) { - foreach($sectors[$i]['location'] as $mgu_id) { - $file .= pack('v', $mgu_id); - } - } - } - else { - // We generate unvisited sectors manually - $byte += 3; - - // Ok, first we want to know where we are. - // Find X and Y inside the universe. - $base = $i - $galaxies[$current_galaxy]['start']; - $y = floor($base/$galaxies[$current_galaxy]['width']); - $x = $base % $galaxies[$current_galaxy]['width']; - - // Check for a visited sector up. - $check_x = $x; - $check_y = $y - 1; - if($check_y < 0) $check_y += $galaxies[$current_galaxy]['height']; - $check_sector = - $check_x + ($check_y * $galaxies[$current_galaxy]['width']) + - $galaxies[$current_galaxy]['start']; - - if(isset($sectors[$check_sector]) && $sectors[$check_sector]['down']) { - $byte |= 128; - } - - // Check for a visited sector right. - $check_x = $x + 1; - $check_y = $y; - if($check_x >= $galaxies[$current_galaxy]['width']) $check_x = 0; - $check_sector = - $check_x + ($check_y * $galaxies[$current_galaxy]['width']) + - $galaxies[$current_galaxy]['start']; - - if(isset($sectors[$check_sector]) && $sectors[$check_sector]['left']) { - $byte |= 64; - } - - // Check for a visited sector down. - $check_x = $x; - $check_y = $y + 1; - if($check_y >= $galaxies[$current_galaxy]['height']) $check_y = 0; - $check_sector = - $check_x + ($check_y * $galaxies[$current_galaxy]['width']) + - $galaxies[$current_galaxy]['start']; - - if(isset($sectors[$check_sector]) && $sectors[$check_sector]['up']) { - $byte |= 32; - } - - // Check for a visited sector left. - $check_x = $x - 1; - $check_y = $y; - if($check_x < 0) $check_x += $galaxies[$current_galaxy]['width']; - $check_sector = - $check_x + ($check_y * $galaxies[$current_galaxy]['width']) + - $galaxies[$current_galaxy]['start']; - - if(isset($sectors[$check_sector]) && $sectors[$check_sector]['right']) { - $byte |= 16; - } - - $file .= pack('C', $byte); - $file .= pack('C', 0); - - continue; - } -} - -$size = strlen($file); - -header('Pragma: public'); -header('Expires: 0'); -header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); -header('Cache-Control: private',false); -header('Content-Type: application/force-download'); -header('Content-Disposition: attachment; filename="'.$game_name.'.cmf"'); -header('Content-Transfer-Encoding: binary'); -header('Content-Length: '.$size); - -echo $file; -exit; -//var_dump($sectors); - -?>