/** * @see Form::validate() */ public function validate() { parent::validate(); if ($this->action == 'rename') { if (!PlanetUtil::isValid($this->newName)) { throw new UserInputException('newName', 'notValid'); } } else { if ($this->action == 'delete') { // main planet if (LWCore::getPlanet()->planetID == WCF::getUser()->id_planet) { throw new SystemException('tried to delete main planet'); } // password if (!WCF::getUser()->checkPassword($this->password)) { throw new UserInputException('password', 'notValid'); } // check fleets (moon, if existing and planet) if (LWCore::getPlanet()->planetKind == 1 && LWCore::getPlanet()->getMoon() != null) { if (count(Fleet::getByPlanetID(LWCore::getPlanet()->getMoon()->planetID, Fleet::OFIARA | Fleet::OWNER))) { throw new UserInputException('password', 'activityMoon'); } } // check current if (count(Fleet::getByPlanetID(LWCore::getPlanet()->planetID, Fleet::OFIARA | Fleet::OWNER))) { throw new UserInputException('password', 'activity'); } } } }
/** * Creates a new planet. * * @param int galaxy * @param int system * @param int planet * @param string name * @param int user id * @param float default metal * @param float default crystal * @param float default deuterium * @param int planet type id * @param int timestamp * @param int fields * @param int max temperature * @param int package id * @return Planet */ public static function create($galaxy, $system, $planet, $name, $userID, $metal = 0, $crystal = 0, $deuterium = 0, $planetTypeID = 1, $time = TIME_NOW, $fields = null, $maxTemp = 40, $packageID = PACKAGE_ID) { // get planet type information $sql = "SELECT classPath,\n\t\t\t\t\tplanetKind,\n\t\t\t\t\tforceImage\n\t\t\t\tFROM ugml_planet_type\n\t\t\t\tWHERE planetTypeID = " . $planetTypeID; $row = WCF::getDB()->getFirstRow($sql); $classPath = $row['classPath']; $className = StringUtil::getClassName($classPath); $planetKind = $row['planetKind']; // collect other data $information = PlanetUtil::getLocationEnvironment($planet); if (empty($row['forceImage'])) { $image = $information['image']; } else { $image = $row['forceImage']; } if ($fields === null) { $fields = $information['fields']; } $diameter = PlanetUtil::getDiameter($fields); if ($maxTemp === null) { $maxTemp = $information['maxTemp']; } $minTemp = $maxTemp - 40; // insert $planetID = self::insert($galaxy, $system, $planet, $planetKind, $planetTypeID, $className, $name, $userID, $fields, $diameter, $minTemp, $maxTemp, $image, $time, $packageID); $planet = Planet::getInstance($planetID); // add resources $planet->getEditor()->changeResources($metal, $crystal, $deuterium); return $planet; }