/** * @see Page::readData */ public function readData() { parent::readData(); //echo "."; $this->fleetQueue = new FleetQueue(0); $this->readTarget(); $this->specs = Spec::getBySpecType(3); $this->fleets = Fleet::getByUserID(WCF::getUser()->userID); foreach ($this->fleets as $fleetID => $fleet) { $this->fleets[$fleetID]->navalFormation = NavalFormation::getByFleetID($fleetID); } // backlink if (isset($_REQUEST['backlink'])) { $this->backlink = StringUtil::trim($_REQUEST['backlink']); } $array = array(); preg_match('/^(https?:\\/\\/[^\\/]*\\/)?(.*)$/i', $this->backlink, $array); $this->fleetQueue->backlink = $this->backlink = isset($array[2]) ? $array[2] : ''; //echo "."; // TODO: clean this one up $sql = "DELETE FROM ugml_galactic_jump_queue\n\t\t\t\tWHERE userID = " . WCF::getUser()->userID; WCF::getDB()->registerShutdownUpdate($sql); $sql = "INSERT INTO ugml_galactic_jump_queue (userID, startPlanetID, state, time)\n\t\t\t\tVALUES(" . WCF::getUser()->userID . ", " . LWCore::getPlanet()->planetID . ", 1, " . TIME_NOW . ")"; WCF::getDB()->registerShutdownUpdate($sql); }
/** * View system */ public function view() { global $lang, $user; includeLang('galaxy'); for ($i = 0; $i < 15; $i++) { $position = $i + 1; $lang['echo_galaxy'] .= $this->viewPositionRow($position); } $lang['dpath'] = !$user["dpath"] ? DEFAULT_SKINPATH : $user["dpath"]; $lang['galaxy'] = $this->galaxy; $lang['system'] = $this->system; $lang['tg'] = LWCore::getPlanet()->galaxy; $lang['ts'] = LWCore::getPlanet()->system; $lang['tp'] = LWCore::getPlanet()->planet; $lang['tpt'] = LWCore::getPlanet()->planet_type; $lang['planet_count'] = $this->planetCount(); $lang['iraks'] = LWCore::getPlanet()->interplanetary_misil; $lang['max_slots'] = LWCore::getUser()->computer_tech + 1; $lang['recycler'] = LWCore::getPlanet()->recycler; $lang['probes'] = LWCore::getPlanet()->spy_sonde; $lang['spio_anz'] = $user['spio_anz']; $lang['phalanx_costs'] = floor($this->getPhalanxCosts()); $fleets = Fleet::getByUserID(WCF::getUser()->userID); $lang['slots'] = count($fleets); $lang['Solar_system_at'] = str_replace('%g', $this->galaxy, $lang['Solar_system_at']); $lang['Solar_system_at'] = str_replace('%s', $this->system, $lang['Solar_system_at']); display(parsetemplate(gettemplate('galaxy_body'), $lang), '', false); }
/** * Validates all values. */ public function validate() { // TODO: dont use game_config here global $game_config; EventHandler::fireAction($this, 'validate'); // TODO: integrate in wcf eventlistener validate@FleetQueue if ($this->missionID == 11) { require_once LW_DIR . 'lib/data/fleet/NavalFormation.class.php'; $formation = new NavalFormation($this->formationID); $currentImpactDiff = $formation->impactTime - microtime(true); if ($this->getDuration() > $currentImpactDiff * (100 + NavalFormation::MAX_TIME_MOVEMENT) / 100) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.navalFormation.tooLate')); } } if (!count($this->ships)) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.noShips')); } if (WCF::getUser()->urlaubs_modus) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.global.vacation.error')); } if ($this->galaxy > GALAXIES || $this->galaxy < 1 || $this->system > 499 || $this->system < 1 || $this->planet > 15 || $this->planet < 1) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.illegalPlanet')); } $availableMissions = $this->getMissions(); if (!isset($availableMissions[$this->missionID])) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.mission.notAvailable')); } if ($this->getTargetPlanet()->planetID) { $selectedMission = $availableMissions[$this->missionID]; if ($game_config['noobProtection'] && $selectedMission['noobProtection'] && WCF::getUser()->points > $this->getTargetPlanet()->noobProtectionLimit() && $this->getTargetPlanet()->getOwner()->onlinetime > TIME_NOW - 60 * 60 * 24 * 7) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.noobProtection')); } if ($this->getTargetPlanet()->getOwner()->authlevel && !WCF::getUser()->authlevel) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.protectedOfiara')); } if ($this->getTargetPlanet()->planetID == LWCore::getPlanet()->planetID) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.samePlanet')); } $sql = "SELECT urlaubs_modus\r\n\t\t\t\t\tFROM ugml_users\r\n\t\t\t\t\tWHERE id = " . $this->getTargetPlanet()->id_owner; $row = WCF::getDB()->getFirstRow($sql); if ($row['urlaubs_modus'] && $this->getTargetPlanet()->planetKind != 2) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.vacationError')); } } if ($this->getConsumption() > LWCore::getPlanet()->deuterium) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.tooMuchResources')); } if ($this->metal > LWCore::getPlanet()->metal || $this->crystal > LWCore::getPlanet()->crystal || $this->deuterium > LWCore::getPlanet()->deuterium - $this->getConsumption()) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.tooMuchResources')); } if ($this->metal + $this->crystal + $this->deuterium + $this->getConsumption() > $this->getCapacity()) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.capacityError')); } $fleets = Fleet::getByUserID(WCF::getUser()->userID); if (WCF::getUser()->computer_tech < count($fleets)) { require_once WCF_DIR . 'lib/system/exception/NamedUserException.class.php'; throw new NamedUserException(WCF::getLanguage()->get('wot.fleet.start.insufficientSlots')); } }
/** * Reads the data for the backup from the db and saves it to the file. * * @param array coordinates changes of the planets */ public function backup($coordChanges) { global $resource; // create file $file = $this->getZipFile(false); // write headers $head = "-- WOT Game\n"; $head .= "-- database: " . WCF::getDB()->getDatabaseName() . "\n"; $head .= "-- Private BackUp " . $this->pbuID . " of user: "******"\n"; $head .= "-- generated at " . date('r') . "\n\n"; $head .= "-- DO NOT EDIT THIS FILE\n\n"; $head .= "-- WCF DATABASE CHARSET\n"; $head .= "SET NAMES " . WCF::getDB()->getCharset() . ";\n\n"; $file->write($head); // read currently flying fleets $fleetObjs = Fleet::getByUserID($this->userID); foreach ($fleetObjs as $fleetObj) { foreach ($fleetObj->fleet as $specID => $count) { $fleets[$fleetObj->startPlanetID][$resource[$specID]] = $count; } } $inserted = false; $planets = array(); $planetCount = 0; $mainPlanetCount = 0; $coordsToPlanetID = array(); foreach (self::$backupTables as $tableArray) { $table = $tableArray[0]; $col = $tableArray[1]; $sql = "SELECT *\n\t\t\t\t\tFROM `" . $table . "`\n\t\t\t\t\tWHERE `" . $col . "` = " . $this->userID; // order moon directly after planet if ($table == 'ugml_planets') { $sql .= " ORDER BY galaxy,\n\t\t\t\t\t\t\tsystem,\n\t\t\t\t\t\t\tplanet,\n\t\t\t\t\t\t\tplanet_type"; } $result = WCF::getDB()->sendQuery($sql); if (WCF::getDB()->countRows($result)) { if ($inserted) { $file->write("\n\n\n"); } // check column types $sql = "SHOW COLUMNS FROM `" . $table . "`"; $result2 = WCF::getDB()->sendQuery($sql); $escapeColumns = array(); while ($row = WCF::getDB()->fetchArray($result2)) { // skip columns manually if (isset(self::$skipColumns[$table]) && in_array($row['Field'], self::$skipColumns[$table])) { $escapeColumns[$row['Field']] = 2; continue; } // escape string if (strpos($row['Type'], 'int') === false) { $escapeColumns[$row['Field']] = 1; continue; } // skip auto_increment automatically /*if($row['Extra'] == 'auto_increment') { $escapeColumns[$row['Field']] = 2; continue; }*/ // change planet coords if (($table == 'ugml_planets' || $table == 'ugml_users') && ($row['Field'] == 'galaxy' || $row['Field'] == 'system' || $row['Field'] == 'planet')) { $escapeColumns[$row['Field']] = 3; continue; } // change main planet id if ($table == 'ugml_users' && ($row['Field'] == 'id_planet' || $row['Field'] == 'current_planet')) { $escapeColumns[$row['Field']] = 4; continue; } // do not escape (integer) $escapeColumns[$row['Field']] = 0; } $inserted = false; // escape columns with backticks $columns = array(); foreach ($escapeColumns as $column => $escape) { if ($escape != 2) { $columns[] = "`" . $column . "`"; } } // we could use "INSERT INTO table VALUES ..." // but if there would be added some columns // after the backup and before the restore, the // count of columns would not be the same anymore // and MySQL would throw a error. so we better // use "INSERT INTO table ... VALUES ..." $tableStr = "INSERT INTO `" . $table . "`"; $tableStr .= "\n (" . implode(",", $columns) . ")"; $tableStr .= "\nVALUES"; while ($row = WCF::getDB()->fetchArray($result)) { if ($inserted) { $file->write("\n\n"); } $file->write($tableStr); // set coord variables if needed ... $changeCoords = false; if ($table == 'ugml_planets') { // ... for planet rows (planet) if ($row['planet_type'] == 1 && isset($coordChanges[$row['id']])) { $changeCoords = true; $galaxy = $coordChanges[$row['id']]['galaxy']; $system = $coordChanges[$row['id']]['system']; $planet = $coordChanges[$row['id']]['planet']; } else { if ($row['planet_type'] == 3) { // last planet row was the planet with this moon, // so we can take the "old" coord variables $system = new System($row['galaxy'], $row['system']); $planet = $system->getPlanet($row['planet'], 1); if (isset($coordChanges[$planet->planetID])) { $changeCoords = true; } echo 'checked moon coord change ...'; var_Dump($changeCoords); } } // register planet count for main planet correction (referential integrity) if ($row['id'] == $this->getUser()->id_planet) { $mainPlanetCount = $planetCount; } } else { if ($table == 'ugml_users') { // ... for user row (main planet) if (isset($coordChanges[$row['id_planet']])) { $changeCoords = true; $galaxy = $coordChanges[$row['id_planet']]['galaxy']; $system = $coordChanges[$row['id_planet']]['system']; $planet = $coordChanges[$row['id_planet']]['planet']; } } } foreach ($row as $column => $value) { switch ($escapeColumns[$column]) { // escape strings case 1: $row[$column] = "'" . escapeString($value) . "'"; continue 2; // remove // remove case 2: unset($row[$column]); ${$column} = $value; continue 2; // replace coordinates // replace coordinates case 3: if ($changeCoords) { $row[$column] = ${$column}; } continue 2; // replace main planet id // replace main planet id case 4: $row[$column] = "@pid" . $mainPlanetCount; continue 2; // escape empty vars // escape empty vars default: if (empty($value) && !is_numeric($value)) { $row[$column] = "''"; } continue 2; } } // add currently flying fleets if ($table == 'ugml_planets' && isset($fleets[$id])) { foreach ($fleets[$id] as $column => $count) { $row[$column] += $count; } } // write $file->write(" (" . implode(",", $row) . ");"); if ($table == 'ugml_planets') { $file->write("\nSET @pid" . $planetCount . " = LAST_INSERT_ID();"); ++$planetCount; } $inserted = true; } } } }