Esempio n. 1
0
 public function Colony($value = "")
 {
     if (empty($value)) {
         return $this->_colony;
     } else {
         Helper::checkType($this, $value, "Colony");
         $this->_colony =& $value;
     }
 }
Esempio n. 2
0
 public function Target($value = "")
 {
     if (empty($value)) {
         return $this->_target;
     } else {
         Helper::checkType($this, $value, "Coordinates");
         $this->_target =& $value;
     }
 }
Esempio n. 3
0
 public function Defender($value = "")
 {
     if (empty($value)) {
         return $this->_defender;
     } else {
         Helper::checkType($this, $value, "Fleet");
         $this->_defender =& $value;
     }
 }
 public function Owner($value = "")
 {
     if (empty($value)) {
         return $this->_owner;
     } else {
         Helper::checkType($this, $value, "User");
         $this->_owner =& $value;
     }
 }
Esempio n. 5
0
 public static function AddToDatabase($u, $plainPassword)
 {
     Helper::checkType(get_called_class(), $u, "User");
     // Generate a 50-character random salt and salt the plain password with it
     $random_salt_value = substr(md5(uniqid(mt_rand(), true)), 0, 50);
     $hashedPassword = sha1($random_salt_value . $plainPassword);
     $query = "INSERT INTO user ";
     $query .= "(username, password, randomsalt, authorisationID, primary_email, secondary_email, ";
     $query .= "registration_time, last_online, is_banned, banned_until) ";
     $query .= "VALUES('" . $u->Username() . "', '" . $hashedPassword . "', '" . $random_salt_value . "', " . $u->AuthorisationLevel();
     $query .= ", '" . $u->PrimaryEmail() . "', '" . $u->SecondaryEmail() . "', " . $u->RegistrationTime() . ", " . $u->LastOnline();
     $query .= ", " . $u->IsBanned() . ", " . $u->BannedUntil() . ");";
     return Database::Instance()->ExecuteQuery($query, "INSERT");
 }
 public function UpdateDatabase()
 {
     $colonyID = $this->Colony()->ID();
     $query = "";
     // Iterate over the build list
     foreach ($this->Members() as $item) {
         // Check if we're getting a correct object
         Helper::checkType($this, $item, "BuildItem");
         if ($item->Amount() < 1) {
             $this->DeleteItemFromDatabase($item);
             continue;
         }
         $newPositionInList = $item->PositionInList();
         $oldPositionInList = $item->OldPositionInList();
         $itemID = $item->ID();
         $level = $item->Level();
         $query .= "UPDATE production_building SET build_list_position = {$newPositionInList}, level = {$level} ";
         $query .= "WHERE colonyID = {$colonyID} AND resource_type_being_built = {$itemID} AND build_list_position = {$oldPositionInList};";
     }
     if ($query != "") {
         // Lop off the last semicolon because otherwise you get an SQL error
         $fixedQuery = substr($query, 0, strlen($query) - 1);
         Database::Instance()->ExecuteQuery($fixedQuery, "MULTI");
     }
 }
 public function UpdateDatabase()
 {
     $colonyID = $this->BuildList()->Colony()->ID();
     $query = "";
     // We'll want to keep track of how many fields we'll use up
     $usedFields = 0;
     // Get current time
     $currentTime = time();
     // Iterate over the build list and only update the items that were changed
     foreach ($this->BuildList()->Members() as $item) {
         // Check if we're getting a correct object
         Helper::checkType($this, $item, "BuildItem");
         $itemName = $item->Name();
         $amountRequested = $item->Amount();
         // TODO: uncommented for testing purposes
         if ($amountRequested === 0) {
             $this->BuildList()->DeleteItemFromDatabase($item);
             continue;
         }
         $usedFields += $amountRequested;
         $newPositionInList = $item->PositionInList();
         $oldPositionInList = $item->OldPositionInList();
         $itemID = $item->ID();
         $scheduledTime = $item->FirstBuildTime() + $currentTime;
         $query .= "UPDATE production SET amount_requested = {$amountRequested}, build_list_position = {$newPositionInList}, scheduled_time = {$scheduledTime} ";
         $query .= "WHERE colonyID = {$colonyID} AND resource_type_being_built = {$itemID} AND build_list_position = {$oldPositionInList};";
     }
     if ($query != "") {
         // Lop off the last semicolon because otherwise you get an SQL error
         $fixedQuery = substr($query, 0, strlen($query) - 1);
         Database::Instance()->ExecuteQuery($fixedQuery, "MULTI");
         // Update UsedFields
         $colonyUsedFields = $this->BuildList()->Colony()->UsedFields();
         $this->BuildList()->Colony()->UsedFields($colonyUsedFields + $usedFields);
         $itemsToBeUpdated = array("used_build_fields");
         $this->BuildList()->Colony()->UpdateDatabaseProperties($itemsToBeUpdated);
     }
 }
Esempio n. 8
0
 public function DeductFromFleet(ShipFleet $otherFleet)
 {
     Helper::checkType($this, $otherFleet, "ShipFleet");
     $this->VerifySameColonyAndMission($otherFleet, true);
     $newFleet = Helper::deductUnits($this->Members(), $otherFleet->Members());
     $this->Members($newFleet);
     if (Helper::containsNegative($newFleet)) {
         // Should never ever happen
         throw new Exception("Fleet contains negative units! (in ShipFleet::DeductFromFleet)");
     }
 }
Esempio n. 9
0
 public static function AddToDatabase(Colony $c)
 {
     // TODO: (not a real todo) VERY IMPORTANT: get_called_class ONLY WORKS ABOVE 5.3.0!!
     Helper::checkType(get_called_class(), $c, "Colony");
     // If this is a home colony, check if one already exists.
     if ($c->HomeColony()) {
         $ownerID = $c->Owner()->ID();
         $query = "SELECT ID FROM colony WHERE userID = {$ownerID} AND is_home_colony = 1;";
         $result = Database::Instance()->ExecuteQuery($query, "SELECT");
         if ($result != NULL) {
             throw new Exception("The user {$ownerID} already has a home colony!");
         }
     }
     // Insert a row in the colony table
     $query = "INSERT INTO colony ";
     $query .= "(name, userID, is_home_colony, is_moon, galaxy_position, system_position, planet_position, last_updated) ";
     $query .= "VALUES ('" . $c->Name() . "', " . $c->Owner()->ID() . ", " . $c->HomeColony() . ", " . $c->IsMoon() . ", " . $c->Coordinates()->Galaxy() . ", " . $c->Coordinates()->System() . ", " . $c->Coordinates()->Planet() . ", " . $c->LastUpdated() . ");";
     $colonyID = Database::Instance()->ExecuteQuery($query, "INSERT");
     $c->ID($colonyID);
     // Prepare rows in the other colony tables
     // colony_defences
     $query = "INSERT INTO colony_defences VALUES( {$colonyID}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );";
     Database::Instance()->ExecuteQuery($query, "INSERT");
     // colony_properties
     $query = "INSERT INTO colony_properties VALUES( {$colonyID}, 0, " . $c->MaxFields() . ", " . $c->UsedFields() . ", " . $c->PlanetData()->MinTemperature() . ", ";
     $query .= $c->PlanetData()->GenerateMaxTemperature() . ", '" . $c->PlanetData()->GroundType() . "', '" . $c->PlanetData()->Image() . "', ";
     $query .= $c->Diameter() . ", 0, " . $c->PlanetType()->ID() . ")";
     Database::Instance()->ExecuteQuery($query, "INSERT");
     // colony_resources
     $query = "INSERT INTO colony_resources VALUES( {$colonyID}, " . $c->CurrentResources()->Metal() . ", 0, " . $c->MetalStorage();
     $query .= ", " . $c->CurrentResources()->Crystal() . ", 0, " . $c->CrystalStorage();
     $query .= ", " . $c->CurrentResources()->Deuterium() . ", 0, " . $c->DeuteriumStorage();
     $query .= ", " . $c->CurrentResources()->Energy() . ", " . $c->CurrentResources()->Energy();
     $query .= ", 0, 0, 0, 0, 0, 0 );";
     Database::Instance()->ExecuteQuery($query, "INSERT");
     // fleet table
     $c->Fleet()->AddToDatabase();
     // colony_structures
     $query = "INSERT INTO colony_structures VALUES( {$colonyID}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );";
     Database::Instance()->ExecuteQuery($query, "INSERT");
     // Update Colony object
     $c->ID($colonyID);
     return $colonyID;
 }