示例#1
0
 /**
  * Index action.
  *
  * @return Bengine_Comm_Controller_Signup
  */
 public function indexAction()
 {
     $this->assign("page", Core::getLang()->getItem("REGISTRATION"));
     $this->assign("userCheck", sprintf(Core::getLanguage()->getItem("USER_CHECK"), Core::getOptions()->get("MIN_USER_CHARS"), Core::getOptions()->get("MAX_USER_CHARS")));
     $this->assign("passwordCheck", sprintf(Core::getLanguage()->getItem("PASSWORD_CHECK"), Core::getOptions()->get("MIN_PASSWORD_LENGTH"), Core::getOptions()->get("MAX_PASSWORD_LENGTH")));
     return $this;
 }
示例#2
0
 /**
  * Runs the community application.
  *
  * @return Comm
  */
 public function run()
 {
     parent::run();
     Hook::event("CommStart");
     define("LANG", Core::getLang()->getOpt("langcode") . "/");
     Core::getLang()->load("Registration");
     self::setCMS();
     self::initUniverses();
     self::initLanguage();
     Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js");
     Core::getTPL()->addHTMLHeaderFile("lib/bootstrap.js", "js");
     Core::getTPL()->addHTMLHeaderFile("main.js", "js");
     Core::getTPL()->addHTMLHeaderFile("sign.js", "js");
     Core::getTPL()->addHTMLHeaderFile("style.css", "css");
     Core::getTPL()->assign("containerClass", "content");
     Core::getTPL()->addLoop("headerMenu", self::getCMS()->getMenu("h"));
     $userCheck = sprintf(Core::getLanguage()->getItem("USER_CHECK"), Core::getOptions()->get("MIN_USER_CHARS"), Core::getOptions()->get("MAX_USER_CHARS"));
     $passwordCheck = sprintf(Core::getLanguage()->getItem("PASSWORD_CHECK"), Core::getOptions()->get("MIN_PASSWORD_LENGTH"), Core::getOptions()->get("MAX_PASSWORD_LENGTH"));
     Core::getTPL()->assign("userCheck", $userCheck);
     Core::getTPL()->assign("passwordCheck", $passwordCheck);
     Core::getTPL()->assign("uniSelection", self::getUnisAsOptionList());
     Hook::event("CommTemplateAssign");
     $this->dispatch();
     Hook::event("CommEnd");
     return $this;
 }
示例#3
0
 /**
  * Index action.
  *
  * @return Bengine_Comm_Controller_Index
  */
 public function indexAction()
 {
     Hook::event("CommIndexStart", array($this));
     $this->assign("errorMsg", Core::getRequest()->getGET("error"));
     if ($this->isPost()) {
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         $login = new Bengine_Game_Login($this->getParam("username"), $this->getParam("password"), "game", $encryption);
         $login->setRedirectOnFailure(false)->checkData();
         if ($login->getCanLogin()) {
             Hook::event("PreLogin", array($login));
             $login->startSession();
             Hook::event("PostLogin", array($login));
         } else {
             $this->assign("errorMsg", $login->getErrors()->getFirst());
         }
     }
     if ($this->errorMsg != "") {
         Core::getLang()->load("error");
         $this->assign("errorMsg", Core::getLang()->get($this->errorMsg));
     }
     $this->assign("page", Core::getLang()->getItem("LOGIN"));
     if ($cmsPage = Comm::getCMS()->getPage("index")) {
         $this->assign("page", $cmsPage["title"]);
         $this->assign("content", $cmsPage["content"]);
         $this->setTemplate("cms_page");
     } else {
         $this->assign("showDefaultContent", true);
     }
     Hook::event("CommIndexEnd", array($this));
     return $this;
 }
示例#4
0
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Resource
  */
 protected function indexAction()
 {
     Hook::event("ShowResourcesBefore", array($this));
     Core::getTPL()->addLoop("data", $this->data);
     $productFactor = (double) Core::getConfig()->get("PRODUCTION_FACTOR");
     $isMoon = (bool) Game::getPlanet()->getData("ismoon");
     // Basic prod
     $basicMetal = $isMoon ? 0 : Core::getOptions()->get("METAL_BASIC_PROD");
     Core::getTPL()->assign("basicMetal", fNumber($basicMetal * $productFactor));
     $basicSilicon = $isMoon ? 0 : Core::getOptions()->get("SILICON_BASIC_PROD");
     Core::getTPL()->assign("basicSilicon", fNumber($basicSilicon * $productFactor));
     $basicHydrogen = $isMoon ? 0 : Core::getOptions()->get("HYDROGEN_BASIC_PROD");
     Core::getTPL()->assign("basicHydrogen", fNumber($basicHydrogen * $productFactor));
     Core::getTPL()->assign("sats", Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID));
     if (Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID) > 0) {
         Core::getTPL()->assign("satsNum", fNumber(Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID)));
         $solarSatProduction = Game::getPlanet()->getBuildingProd("energy", Bengine_Game_Planet::SOLAR_SAT_ID);
         Core::getTPL()->assign("satsProd", fNumber($solarSatProduction));
         Core::getLang()->assign("prodPerSat", floor($solarSatProduction / Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID)));
         Core::getTPL()->assign("solar_satellite_prod", Game::getPlanet()->getData("solar_satellite_prod"));
     }
     // Storage capacity
     Core::getTPL()->assign("storageMetal", fNumber(Game::getPlanet()->getStorage("metal") / 1000) . "k");
     Core::getTPL()->assign("storageSilicon", fNumber(Game::getPlanet()->getStorage("silicon") / 1000) . "k");
     Core::getTPL()->assign("sotrageHydrogen", fNumber(Game::getPlanet()->getStorage("hydrogen") / 1000) . "k");
     // Total prod
     Core::getTPL()->assign("totalMetal", fNumber(Game::getPlanet()->getProd("metal")));
     Core::getTPL()->assign("totalSilicon", fNumber(Game::getPlanet()->getProd("silicon")));
     Core::getTPL()->assign("totalHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen")));
     Core::getTPL()->assign("totalEnergy", fNumber(Game::getPlanet()->getEnergy()));
     // Daily prod
     Core::getTPL()->assign("dailyMetal", fNumber(Game::getPlanet()->getProd("metal") * 24));
     Core::getTPL()->assign("dailySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 24));
     Core::getTPL()->assign("dailyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 24));
     // Weekly prod
     Core::getTPL()->assign("weeklyMetal", fNumber(Game::getPlanet()->getProd("metal") * 168));
     Core::getTPL()->assign("weeklySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 168));
     Core::getTPL()->assign("weeklyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 168));
     // Monthly prod
     Core::getTPL()->assign("monthlyMetal", fNumber(Game::getPlanet()->getProd("metal") * 720));
     Core::getTPL()->assign("monthlySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 720));
     Core::getTPL()->assign("monthlyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 720));
     $selectBox = "";
     for ($i = 10; $i >= 0; $i--) {
         $selectBox .= createOption($i * 10, $i * 10, 0);
     }
     Core::getTPL()->assign("selectProd", $selectBox);
     Hook::event("ShowResourcesAfter");
     $this->assign("updateAction", BASE_URL . "game/" . SID . "/Resource/Update");
     return $this;
 }
示例#5
0
 /**
  * @return Bengine_Admin_Controller_Auth
  */
 protected function indexAction()
 {
     $this->setIsAjax();
     $this->setMainTemplate(null);
     if ($this->isPost()) {
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         $auth = new Login($this->getParam("username"), $this->getParam("password"), "admin/index", $encryption);
         $auth->setRedirectOnFailure(false)->setCountLoginAttempts(false)->checkData();
         if ($auth->getCanLogin()) {
             $auth->startSession();
         }
         Core::getTemplate()->assign("loginErrors", $auth->getErrors());
     }
     return $this;
 }
示例#6
0
 /**
  * Key check and set new password.
  *
  * @param integer $userid
  * @param string $key Key, transmitted by email
  * @param string $newpw New password
  *
  * @return Bengine_Game_Account_Password_Changer
  */
 public function __construct($userid, $key, $newpw)
 {
     Hook::event("ChangePassword", array($userid, $key));
     if (empty($key) || Str::length($newpw) < Core::getOptions()->get("MIN_PASSWORD_LENGTH") || Str::length($newpw) > Core::getOptions()->get("MAX_PASSWORD_LENGTH")) {
         $this->printIt("PASSWORD_INVALID");
     }
     $where = Core::getDB()->quoteInto("userid = ? AND ", $userid);
     $where .= Core::getDB()->quoteInto("activation = ?", $key);
     $result = Core::getQuery()->select("user", "userid", "", $where);
     if ($result->rowCount()) {
         $result->closeCursor();
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         $newpw = Str::encode($newpw, $encryption);
         Core::getQuery()->update("password", array("password" => $newpw, "time" => TIME), "userid = ?", array($userid));
         Core::getQuery()->update("user", array("activation" => ""), "userid = ?", array($userid));
         $this->printIt("PASSWORD_CHANGED", false);
     }
     $result->closeCursor();
     $this->printIt("ERROR_PASSWORD_CHANGED");
     return;
 }
示例#7
0
 /**
  * @param Bengine_Game_Model_Event $event
  * @param array $data
  * @return Bengine_Game_EventHandler_Handler_Fleet_Colonize
  */
 protected function _execute(Bengine_Game_Model_Event $event, array $data)
 {
     $id = self::COLONY_SHIP_ID;
     Hook::event("EhColonize", array($event, &$data, $this));
     $where = Core::getDB()->quoteInto("galaxy = ? AND system = ? AND position = ? AND planetid != ?", array($data["galaxy"], $data["system"], $data["position"], 0));
     $_result = Core::getQuery()->select("galaxy", "planetid", "", $where);
     if ($_result->rowCount() == 0) {
         $_result = Core::getQuery()->select("planet", "planetid", "", Core::getDB()->quoteInto("userid = ? AND ismoon = 0", $event["userid"]));
         if ($_result->rowCount() < Core::getOptions()->get("MAX_PLANETS")) {
             $colony = new Bengine_Game_Planet_Creator($event["userid"], $data["galaxy"], $data["system"], $data["position"]);
             $colonyShip = $data["ships"][$id];
             $_result = Core::getQuery()->select("construction", array("basic_metal", "basic_silicon", "basic_hydrogen"), "", Core::getDB()->quoteInto("buildingid = ?", $colonyShip["id"]));
             $shipData = $_result->fetchRow();
             $_result->closeCursor();
             $points = ($shipData["basic_metal"] + $shipData["basic_silicon"] + $shipData["basic_hydrogen"]) * $colonyShip["quantity"] / 1000;
             $fpoints = $colonyShip["quantity"];
             Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ?, fpoints = fpoints - ? WHERE userid = ?", array($points, $fpoints, $event["userid"]));
             if ($data["ships"][$id]["quantity"] > 1) {
                 $data["ships"][$id]["quantity"]--;
             } else {
                 $data["ships"][$id] = null;
                 unset($data["ships"][$id]);
             }
             if (count($data["ships"]) > 0) {
                 foreach ($data["ships"] as $ship) {
                     Core::getQuery()->insert("unit2shipyard", array("unitid" => $ship["id"], "planetid" => $colony->getPlanetId(), "quantity" => $ship["quantity"]));
                 }
             }
         } else {
             $this->sendBack($data, $data["time"] + $event["time"], null, $event["planetid"]);
             $data["success"] = "empire";
         }
     } else {
         $this->sendBack($data, $data["time"] + $event["time"], null, $event["planetid"]);
         $data["success"] = "occupied";
     }
     new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data);
     return $this;
 }
示例#8
0
 /**
  * Maximum available fields.
  *
  * @return integer
  */
 public function getMaxFields()
 {
     $fmax = floor(pow($this->get("diameter") / 1000, 2));
     $terraFormer = $this->getBuilding("TERRA_FORMER");
     if (null !== $terraFormer) {
         $terraFormer = (int) $terraFormer->get("level");
     } else {
         $terraFormer = 0;
     }
     if ($terraFormer > 0) {
         $fmax += $terraFormer * (int) Core::getOptions()->get("TERRAFORMER_ADDITIONAL_FIELDS");
     } else {
         if ($this->data["ismoon"]) {
             $fields = (int) $this->getBuilding("MOON_BASE")->get("level") * (int) Core::getOptions()->get("MOON_BASE_FIELDS") + 1;
             if ($fields < $fmax) {
                 $fmax = $fields;
             }
         }
     }
     Hook::event("GetMaxFields", array(&$fmax, $this));
     $addition = $this->get("ismoon") ? 0 : Core::getOptions()->get("PLANET_FIELD_ADDITION");
     return $fmax + $addition;
 }
示例#9
0
 /**
  * (non-PHPdoc)
  * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data)
  */
 protected function _execute(Bengine_Game_Model_Event $event, array $data)
 {
     Hook::event("EhEspionage", array($event, &$data, $this));
     $espReport = new Bengine_Game_Espionage_Report($event["destination"], $event["userid"], $event["destination_user_id"], $event["destination_username"], $data["ships"][38]["quantity"]);
     $data["destinationplanet"] = $espReport->getPlanetname();
     $data["suser"] = $event["username"];
     $data["planetname"] = $event["planetname"];
     $data["defending_chance"] = $espReport->getChance();
     $data["probes_lost"] = $espReport->getProbesLost();
     $data["event"] = $event;
     if ($event["destination_user_id"]) {
         new Bengine_Game_AutoMsg($event["mode"], $event["destination_user_id"], $event["time"], $data);
     }
     if ($espReport->getProbesLost()) {
         $points = 0;
         $fpoints = 0;
         $tfMetal = 0;
         $tfSilicon = 0;
         $intoTF = floatval(Core::getOptions()->get("FLEET_INTO_DEBRIS"));
         foreach ($data["ships"] as $key => $ship) {
             $_result = Core::getQuery()->select("construction", array("basic_metal", "basic_silicon", "basic_hydrogen"), "", Core::getDB()->quoteInto("buildingid = ?", $key));
             $shipData = $_result->fetchRow();
             $_result->closeCursor();
             $points += ($shipData["basic_metal"] + $shipData["basic_silicon"] + $shipData["basic_hydrogen"]) * $ship["quantity"] / 1000;
             $fpoints += $ship["quantity"];
             $tfMetal = $shipData["basic_metal"] * $ship["quantity"] * $intoTF;
             $tfSilicon = $shipData["basic_silicon"] * $ship["quantity"] * $intoTF;
         }
         $what = $event->get("destination_ismoon") ? "moonid" : "planetid";
         Core::getDB()->query("UPDATE " . PREFIX . "galaxy SET metal = metal + ?, silicon = silicon + ? WHERE " . $what . " = ?", array($tfMetal, $tfSilicon, $event["destination"]));
         Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ?, fpoints = fpoints - ? WHERE userid = ?", array($points, $fpoints, $event["userid"]));
     } else {
         $data["nomessage"] = true;
         $this->sendBack($data, $data["time"] + $event["time"], $event["destination"], $event["planetid"]);
     }
     return $this;
 }
示例#10
0
 /**
  * Shows alliance ranking.
  *
  * @param integer $type	Type of ranking (Fleet, Research, Points)
  * @param integer $pos	Position to start ranking
  *
  * @return Bengine_Game_Controller_Ranking
  */
 protected function allianceRanking($type, $pos)
 {
     $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid)";
     $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid)";
     $result = Core::getQuery()->select("alliance a", "SUM(u." . $type . ") AS points", $joins, "a.aid > '0'", "", "", "a.aid", "HAVING points >= (points)");
     $oPos = $result->rowCount();
     $oPos = $oPos <= 0 ? 1 : $oPos;
     $oPos = ceil($oPos / Core::getOptions()->get("USER_PER_PAGE"));
     $result->closeCursor();
     $result = Core::getQuery()->select("alliance", "aid", "", "aid > '0'");
     $pages = ceil($result->rowCount() / Core::getOptions()->get("USER_PER_PAGE"));
     $result->closeCursor();
     if (!is_numeric($pos)) {
         $pos = $oPos;
     } else {
         if ($pos > $pages) {
             $pos = $pages;
         } else {
             if ($pos < 1) {
                 $pos = 1;
             }
         }
     }
     $ranks = "";
     for ($i = 0; $i < $pages; $i++) {
         $n = $i * Core::getOptions()->get("USER_PER_PAGE") + 1;
         if ($i + 1 == $pos) {
             $s = 1;
         } else {
             $s = 0;
         }
         if ($i + 1 == $oPos) {
             $c = "ownPosition";
         } else {
             $c = "";
         }
         $ranks .= createOption($i + 1, fNumber($n) . " - " . fNumber($n + Core::getOptions()->get("USER_PER_PAGE") - 1), $s, $c);
     }
     Core::getTPL()->assign("rankingSel", $ranks);
     $order = $this->average ? "average" : "points";
     $rank = abs(($pos - 1) * Core::getOptions()->get("USER_PER_PAGE"));
     $max = Core::getOptions()->get("USER_PER_PAGE");
     $select = array("a.aid", "a.name", "a.tag", "a.showhomepage", "a.homepage", "a.open", "COUNT(u2a.userid) AS members", "FLOOR(SUM(u." . $type . ")) AS points", "AVG(u." . $type . ") AS average");
     $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON u2a.aid = a.aid ";
     $joins .= "LEFT JOIN " . PREFIX . "user u ON u2a.userid = u.userid ";
     $result = Core::getQuery()->select("alliance a", $select, $joins, "a.aid > '0'", $order . " DESC, members DESC, a.tag ASC", $rank . ", " . $max, "a.aid");
     $AllianceList = new Bengine_Game_Alliance_List($result, $rank);
     Hook::event("ShowRankingAlliance", array($AllianceList));
     Core::getTPL()->addLoop("ranking", $AllianceList->getArray());
     $this->setTemplate("ranking/ally");
     return $this;
 }
示例#11
0
 /**
  * Setter-method for banning login time (in minutes).
  *
  * @param integer
  *
  * @return Login
  */
 public function setBannedLoginTime($bannedLoginTime = null)
 {
     $this->bannedLoginTime = $bannedLoginTime;
     if (is_null($this->bannedLoginTime) && Core::getOptions()->exists("bannedlogintime")) {
         $this->bannedLoginTime = Core::getOptions()->get("bannedlogintime");
     }
     if (!is_numeric($this->bannedLoginTime)) {
         $this->setCountLoginAttempts(false);
     }
     return $this;
 }
示例#12
0
 /**
  * Allows the user to write a global mail to all alliance member.
  *
  * @param string $reply
  * @return Bengine_Game_Controller_Alliance
  */
 protected function globalMailAction($reply)
 {
     $result = Core::getQuery()->select("user2ally u2a", array("a.founder", "ar.CAN_WRITE_GLOBAL_MAILS"), "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid) LEFT JOIN " . PREFIX . "allyrank ar ON (ar.rankid = u2a.rank)", Core::getDB()->quoteInto("u2a.userid = ?", Core::getUser()->get("userid")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         if ($row["CAN_WRITE_GLOBAL_MAILS"] || $row["founder"] == Core::getUser()->get("userid")) {
             Core::getLanguage()->load("Message");
             if ($this->isPost()) {
                 $message = richtext($this->getParam("message"));
                 $length = Str::length(strip_tags($message));
                 $subject = Str::validateXHTML(trim($this->getParam("subject")));
                 $receiver = $this->getParam("receiver");
                 if ($length > 2 && $length <= Core::getOptions()->get("MAX_PM_LENGTH") && Str::length($subject) > 0 && Str::length($subject) < 101) {
                     Hook::event("SendGlobalMail", array($subject, &$message));
                     if ($receiver == "foo") {
                         $where = Core::getDB()->quoteInto("aid = ?", $this->aid);
                     } else {
                         $where = Core::getDB()->quoteInto("rank = ? AND aid = ?", array($receiver, $this->aid));
                     }
                     $_result = Core::getQuery()->select("user2ally", "userid", "", $where);
                     foreach ($_result->fetchAll() as $_row) {
                         Core::getQuery()->insert("message", array("mode" => 6, "time" => TIME, "sender" => Core::getUser()->get("userid"), "receiver" => $_row["userid"], "message" => $message, "subject" => $subject, "read" => $_row["userid"] == Core::getUser()->get("userid") ? 1 : 0));
                     }
                     $_result->closeCursor();
                     Logger::addMessage("SENT_SUCCESSFUL", "success");
                 } else {
                     if ($length < 3) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
                     }
                     if ($length > Core::getOptions()->get("MAX_PM_LENGTH")) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_LONG"));
                     }
                     if (Str::length($subject) == 0) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
                     }
                     if (Str::length($subject) > 100) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_LONG"));
                     }
                     Core::getTPL()->assign("subject", $this->getParam("subject"))->assign("message", $this->getParam("message"));
                 }
             } else {
                 if ($reply) {
                     $reply = preg_replace("#((RE|FW):\\s)+#is", "\\1", $reply);
                     Core::getTPL()->assign("subject", $reply);
                 }
             }
             $ranks = Core::getQuery()->select("allyrank", array("rankid", "name"), "", Core::getDB()->quoteInto("aid = ?", $this->aid));
             Core::getTPL()->assign("maxpmlength", fNumber(Core::getOptions()->get("MAX_PM_LENGTH")));
             Core::getTPL()->addLoop("ranks", $ranks);
         } else {
             Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
         }
     } else {
         Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
     }
     return $this;
 }
示例#13
0
 /**
  * Validates the inputted galaxy and system.
  *
  * @return Bengine_Game_Controller_Galaxy
  */
 protected function validateInputs()
 {
     if (empty($this->galaxy)) {
         $this->galaxy = Game::getPlanet()->getData("galaxy");
     }
     if (empty($this->system)) {
         $this->system = Game::getPlanet()->getData("system");
     }
     if ($this->galaxy < 1) {
         $this->galaxy = 1;
     } else {
         if ($this->galaxy > Core::getOptions()->get("GALAXYS")) {
             $this->galaxy = Core::getOptions()->get("GALAXYS");
         }
     }
     if ($this->system < 1) {
         $this->system = 1;
     } else {
         if ($this->system > Core::getOptions()->get("SYSTEMS")) {
             $this->system = Core::getOptions()->get("SYSTEMS");
         }
     }
     return $this;
 }
示例#14
0
 /**
  * This starts the missions and shows a quick overview of the flight.
  *
  * @param integer $mode
  * @param integer $metal
  * @param integer $silicon
  * @param integer $hydrogen
  * @param integer $holdingTime
  * @throws Recipe_Exception_Generic
  * @return Bengine_Game_Controller_Mission
  */
 protected function sendFleet($mode, $metal, $silicon, $hydrogen, $holdingTime)
 {
     $this->noAction = true;
     $fleetEvents = Game::getEH()->getOwnFleetEvents();
     if ($fleetEvents && Game::getResearch(14) + 1 <= count(Game::getEH()->getOwnFleetEvents())) {
         throw new Recipe_Exception_Generic("Too many fleets on missions.");
     }
     $result = Core::getQuery()->select("temp_fleet", "data", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $temp = unserialize($row["data"]);
         if (!in_array($mode, $temp["amissions"])) {
             Logger::dieMessage("UNKNOWN_MISSION");
         }
         $data["ships"] = $temp["ships"];
         $data["galaxy"] = $temp["galaxy"];
         $data["system"] = $temp["system"];
         $data["position"] = $temp["position"];
         $data["sgalaxy"] = Game::getPlanet()->getData("galaxy");
         $data["ssystem"] = Game::getPlanet()->getData("system");
         $data["sposition"] = Game::getPlanet()->getData("position");
         $data["maxspeed"] = $temp["maxspeed"];
         $distance = Game::getDistance($data["galaxy"], $data["system"], $data["position"]);
         $data["consumption"] = Game::getFlyConsumption($temp["consumption"], $distance, $temp["speed"]);
         if (Game::getPlanet()->getData("hydrogen") - $data["consumption"] < 0) {
             Logger::dieMessage("NOT_ENOUGH_FUEL");
         }
         if ($temp["capacity"] < $data["consumption"]) {
             Logger::dieMessage("NOT_ENOUGH_CAPACITY");
         }
         $data["metal"] = (int) abs($metal);
         $data["silicon"] = (int) abs($silicon);
         $data["hydrogen"] = (int) abs($hydrogen);
         if ($data["metal"] > Game::getPlanet()->getData("metal")) {
             $data["metal"] = _pos(Game::getPlanet()->getData("metal"));
         }
         if ($data["silicon"] > Game::getPlanet()->getData("silicon")) {
             $data["silicon"] = _pos(Game::getPlanet()->getData("silicon"));
         }
         if ($data["hydrogen"] > Game::getPlanet()->getData("hydrogen") - $data["consumption"]) {
             $data["hydrogen"] = _pos(Game::getPlanet()->getData("hydrogen") - $data["consumption"]);
         }
         if ($mode == 13) {
             $data["duration"] = _pos($holdingTime);
             if ($data["duration"] > 24) {
                 $data["duration"] = 24;
             }
             $data["duration"] *= 3600;
         }
         $capa = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"];
         // Reduce used capacity automatically
         if ($capa < 0) {
             if ($capa + $data["hydrogen"] > 0) {
                 $data["hydrogen"] -= abs($capa);
             } else {
                 $capa += $data["hydrogen"];
                 $data["hydrogen"] = 0;
                 if ($capa + $data["silicon"] > 0 && $capa < 0) {
                     $data["silicon"] -= abs($capa);
                 } else {
                     if ($capa < 0) {
                         $capa += $data["silicon"];
                         $data["silicon"] = 0;
                         if ($capa + $data["metal"] && $capa < 0) {
                             $data["metal"] -= abs($capa);
                         } else {
                             if ($capa < 0) {
                                 $data["metal"] = 0;
                             }
                         }
                     }
                 }
             }
         }
         $data["capacity"] = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"];
         if ($data["capacity"] < 0) {
             Logger::dieMessage("NOT_ENOUGH_CAPACITY");
         }
         // If mission is recycling, get just the capacity of the recyclers.
         if ($mode == 9 && $data["capacity"] > 0) {
             $_result = Core::getQuery()->select("ship_datasheet", "capicity", "", "unitid = '37'");
             // It is __capacity__ and not capicity
             $_row = $_result->fetchRow();
             $_result->closeCursor();
             $recCapa = $_row["capicity"] * $temp["ships"][37]["quantity"];
             if ($data["capacity"] >= $recCapa) {
                 $data["capacity"] = $recCapa;
             }
         }
         $time = Game::getFlyTime($distance, $data["maxspeed"], $temp["speed"]);
         $data["time"] = $time;
         if ($mode == 18) {
             $data["alliance_attack"] = $temp["alliance_attack"];
             $mainFleet = Game::getEH()->getMainFormationFleet($data["alliance_attack"]["eventid"]);
             $allFleets = Game::getEH()->getFormationFleets($data["alliance_attack"]["eventid"]);
             $numFleets = 1;
             $formationUser[$mainFleet->get("user")] = true;
             /* @var Bengine_Game_Model_Fleet $oneFleet */
             foreach ($allFleets as $oneFleet) {
                 $numFleets++;
                 $formationUser[$oneFleet->get("user")] = true;
             }
             unset($formationUser[Core::getUser()->get("userid")]);
             if ($numFleets >= Core::getOptions()->get("MAX_FORMATION_FLEETS")) {
                 Logger::dieMessage("MAX_FORMATION_FLEETS_EXCEEDED");
             }
             if (count($formationUser) >= Core::getOptions()->get("MAX_FORMATION_USER")) {
                 Logger::dieMessage("MAX_FORMATION_USER_EXCEEDED");
             }
             if ($data["time"] + TIME > ($mainFleet["time"] - TIME) * (1 + Core::getOptions()->get("MAX_FORMATION_DELAY")) + TIME) {
                 Logger::dieMessage("MAX_FORMATION_DELAY_EXCEEDED");
             }
         }
         Hook::event("SendFleet", array(&$data, &$time, &$temp, $distance));
         Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
         $handler = Game::getEH()->addEvent($mode, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), isset($temp["destination"]) ? $temp["destination"] : null, $data);
         Core::getTPL()->assign("mission", Game::getMissionName($mode));
         Core::getTPL()->assign("mode", $mode);
         Core::getTPL()->assign("distance", fNumber($distance));
         Core::getTPL()->assign("speed", fNumber($temp["maxspeed"]));
         Core::getTPL()->assign("consume", fNumber($data["consumption"]));
         Core::getTPL()->assign("start", Game::getPlanet()->getCoords(false));
         Core::getTPL()->assign("target", $data["galaxy"] . ":" . $data["system"] . ":" . $data["position"]);
         Core::getTPL()->assign("arrival", Date::timeToString(1, $handler->getFinishTime()));
         if ($returnTime = $handler->getReturnTime()) {
             Core::getTPL()->assign("return", Date::timeToString(1, $returnTime));
         }
         $fleet = array();
         foreach ($data["ships"] as $key => $value) {
             $fleet[$key]["name"] = Core::getLanguage()->getItem($value["name"]);
             $fleet[$key]["quantity"] = fNumber($value["quantity"]);
         }
         Core::getTPL()->addLoop("fleet", $fleet);
         $this->setTemplate("mission/step4");
     }
     return $this;
 }
示例#15
0
 /**
  * Returns the password.
  *
  * @param boolean $encrypted	Encrypt password
  *
  * @return string
  */
 public function getPassword($encrypted = false)
 {
     if ($encrypted) {
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         return Str::encode($this->password, $encryption);
     }
     return $this->password;
 }
示例#16
0
 /**
  * Subtracts hydrogen for surveillance consumption.
  *
  * @return Bengine_Game_Controller_MonitorPlanet
  */
 protected function subtractHydrogen()
 {
     Core::getDB()->query("UPDATE " . PREFIX . "planet SET hydrogen = hydrogen - ? WHERE planetid = ?", array(Core::getOptions()->get("STAR_SURVEILLANCE_CONSUMPTION"), Core::getUser()->get("curplanet")));
     return $this;
 }
示例#17
0
 /**
  * Detects default language.
  *
  * @return Recipe_Language
  */
 public function getDefaultLang()
 {
     if (Str::length($this->langid) == 0) {
         $this->langcode = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2) : "";
         $this->langid = 0;
     } else {
         if (!is_numeric($this->langid)) {
             $this->langcode = $this->langid;
             $this->langid = 0;
         }
     }
     $where = Core::getDB()->quoteInto("languageid = ? OR ", $this->langid);
     $where .= Core::getDB()->quoteInto("langcode = ?", $this->langcode);
     $result = Core::getQuery()->select("languages", array("languageid"), "", $where, "", "1");
     if ($row = $result->fetchRow()) {
         $this->langid = $row["languageid"];
     } else {
         $this->langid = Core::getOptions()->defaultlanguage;
     }
     return $this;
 }
示例#18
0
/**
 * Checks if user is newbie protected.
 *
 * @param integer $committer	Points of requesting user
 * @param integer $target		Points of target user
 *
 * @return integer	0: no protection, 1: weak, 2: strong
 */
function isNewbieProtected($committer, $target)
{
    Hook::event("NewbieProtection", array(&$committer, &$target));
    $newbieMin = (int) Core::getOptions()->get("NEWBIE_PROTECTION_MIN");
    $newbieFactorMin = (double) Core::getOptions()->get("NEWBIE_PROTECTION_FACTOR_MIN");
    $newbieFactorMax = (double) Core::getOptions()->get("NEWBIE_PROTECTION_FACTOR_MAX");
    if ($committer <= 0 || $target <= 0) {
        if ($committer > $target) {
            return 1;
        }
        return 2;
    }
    $n = 0;
    if ($committer < $newbieMin) {
        $n += 1;
    }
    if ($target < $newbieMin) {
        $n += 1;
    }
    if ($target / $committer > $newbieFactorMin) {
        $n += 2;
    }
    if ($committer / $target > $newbieFactorMin) {
        $n += 2;
    }
    if ($committer < $target * $newbieFactorMax / 100) {
        $n += 2;
    }
    if ($target < $committer * $newbieFactorMax / 100) {
        $n += 2;
    }
    if ($n < 3) {
        return 0;
    }
    if ($committer > $target) {
        return 1;
    }
    return 2;
}
示例#19
0
 /**
  * Shows form for planet options.
  *
  * @param string $planetname
  * @param boolean $abandon
  * @param string $password
  *
  * @return Bengine_Game_Controller_Index
  */
 protected function changePlanetOptions($planetname, $abandon, $password)
 {
     $planetname = trim($planetname);
     Hook::event("SAVE_PLANET_OPTIONS", array(&$planetname, &$abandon));
     if ($abandon == 1) {
         $ok = true;
         if (Game::getEH()->getPlanetFleetEvents()) {
             Logger::addMessage("CANNOT_DELETE_PLANET");
             $ok = false;
         }
         if (Core::getUser()->get("hp") == Core::getUser()->get("curplanet")) {
             Logger::addMessage("CANNOT_DELETE_HOMEPLANET");
             $ok = false;
         }
         $result = Core::getQuery()->select("password", "password", "", Core::getDB()->quoteInto("userid = ?", Core::getUser()->get("userid")));
         $row = $result->fetchRow();
         $result->closeCursor();
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         $password = Str::encode($password, $encryption);
         if (!Str::compare($row["password"], $password)) {
             Logger::addMessage("WRONG_PASSWORD");
             $ok = false;
         }
         if ($ok) {
             deletePlanet(Game::getPlanet()->getPlanetId(), Core::getUser()->get("userid"), Game::getPlanet()->getData("ismoon"));
             Core::getQuery()->update("user", array("curplanet" => Core::getUser()->get("hp")), "userid = ?", array(Core::getUser()->get("userid")));
             Core::getUser()->rebuild();
             $this->redirect("game/" . SID . "/Index");
         }
     } else {
         if (checkCharacters($planetname)) {
             Core::getQuery()->update("planet", array("planetname" => $planetname), "planetid = ?", array(Core::getUser()->get("curplanet")));
             $this->redirect("game/" . SID . "/Index");
         } else {
             Logger::addMessage("INVALID_PLANET_NAME");
         }
     }
     return $this;
 }
示例#20
0
 /**
  * Constructor: Builds the header and starts mailer.
  *
  * @param string $receiver	The receiver's mail address [optional]
  * @param string $subject	Mail subject [optional]
  * @param string $messages	The message [optional]
  *
  * @return \Email
  */
 public function __construct($receiver = null, $subject = null, $messages = null)
 {
     if ($receiver !== null) {
         $this->setReceiver($receiver);
     }
     if ($subject !== null) {
         $this->setSubject($subject);
     }
     if ($messages !== null) {
         $this->setMessages($messages);
     }
     $options = Core::getOptions();
     $senderName = $options->get("MAIL_SENDER_NAME");
     if (!$senderName) {
         $senderName = $options->get("pagetitle");
     }
     $this->setSender($senderName);
     $this->setSenderMail($options->get("MAIL_SENDER"));
     $this->setAdapter($options->get("MAIL_ADAPTER"));
     return;
 }
示例#21
0
 /**
  * (non-PHPdoc)
  * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_remove($event, $data)
  */
 protected function _remove(Bengine_Game_Model_Event $event, array $data)
 {
     $metal = $data["quantity"] * $data["metal"] / 100 * Core::getOptions()->get("SHIPYARD_ORDER_ABORT_PERCENT");
     $silicon = $data["quantity"] * $data["silicon"] / 100 * Core::getOptions()->get("SHIPYARD_ORDER_ABORT_PERCENT");
     $hydrogen = $data["quantity"] * $data["hydrogen"] / 100 * Core::getOptions()->get("SHIPYARD_ORDER_ABORT_PERCENT");
     Core::getDB()->query("UPDATE " . PREFIX . "planet SET metal = metal + ?, silicon = silicon + ?, hydrogen = hydrogen + ? WHERE planetid = ?", array($metal, $silicon, $hydrogen, $event->getPlanetid()));
     return $this;
 }
示例#22
0
 /**
  * Write final planet informations into database.
  *
  * @return Bengine_Game_Planet_Creator
  */
 protected function createPlanet()
 {
     Hook::event("PlanetCreatorSavePlanet", array($this));
     if ($this->moon == 0) {
         $spec = array("userid" => $this->userid, "planetname" => $this->name, "diameter" => $this->size, "picture" => $this->picture, "temperature" => $this->temperature, "last" => TIME, "metal" => Core::getOptions()->get("DEFAULT_METAL"), "silicon" => Core::getOptions()->get("DEFAULT_SILICON"), "hydrogen" => Core::getConfig()->get("DEFAULT_HYDROGEN"), "solar_satellite_prod" => 100);
         Core::getQuery()->insert("planet", $spec);
         $this->planetid = Core::getDB()->lastInsertId();
         $spec = array("galaxy" => $this->galaxy, "system" => $this->system, "position" => $this->position, "planetid" => $this->planetid);
         Core::getQuery()->insert("galaxy", $spec);
     } else {
         $spec = array("userid" => $this->userid, "ismoon" => 1, "planetname" => Core::getLanguage()->getItem("MOON"), "diameter" => $this->size, "picture" => "mond", "temperature" => $this->temperature - mt_rand(15, 35), "last" => TIME, "metal" => 0, "silicon" => 0);
         Core::getQuery()->insert("planet", $spec);
         $this->planetid = Core::getDB()->lastInsertId();
         Core::getQuery()->update("galaxy", array("moonid" => $this->planetid), "galaxy = ? AND system = ? AND position = ?", array($this->galaxy, $this->system, $this->position));
     }
     return $this;
 }
示例#23
0
 /**
  * Creates a new pagination object for the given folder.
  *
  * @param integer $id	Folder id
  *
  * @return Pagination
  */
 protected function getPagination($id)
 {
     /* @var Bengine_Game_Model_Collection_Message $messages */
     $messages = Game::getCollection("game/message");
     $messages->addReceiverFilter(Core::getUser()->get("userid"))->addFolderFilter($id);
     $pagination = new Pagination(Core::getOptions()->get("MAX_PMS"), $messages->getCalculatedSize(false));
     $pagination->setMaxPagesToShow(Core::getConfig()->get("MAX_MESSAGE_PAGES"));
     return $pagination;
 }
示例#24
0
 /**
  * @return bool
  */
 public static function attackingStoppageEnabled()
 {
     if (Core::getOptions()->get("ATTACKING_STOPPAGE_END_DATE") > 0 && Core::getOptions()->get("ATTACKING_STOPPAGE_END_DATE") < TIME) {
         Core::getOptions()->setValue("ATTACKING_STOPPAGE", 0);
         Core::getOptions()->setValue("ATTACKING_STOPPAGE_END_DATE", 0, true);
     }
     return (bool) Core::getOptions()->get("ATTACKING_STOPPAGE");
 }
示例#25
0
 /**
  * Initializing method.
  *
  * @return Recipe_Email_Smtp
  */
 protected function _init()
 {
     $options = Core::getOptions();
     $this->setHost($options->get("MAIL_SMTP_HOST"))->setPort($options->get("MAIL_SMTP_PORT"))->setUser($options->get("MAIL_SMTP_USER"))->setPwd($options->get("MAIL_SMTP_PWD"))->setAuth($options->get("MAIL_SMTP_AUTH"))->setSecure($options->get("MAIL_SMTP_SECURE"));
     return $this;
 }
示例#26
0
 /**
  * Updates the moderator form.
  *
  * @param string $username
  * @param string $usertitle
  * @param string $email
  * @param int $delete
  * @param int $umode
  * @param string $activation
  * @param string $ipcheck
  * @param int $usergroupid
  * @param int $points
  * @param int $fpoints
  * @param int $dpoints
  * @param int $rpoints
  * @param string $password
  * @param int $languageid
  * @param string $templatepackage
  * @param string $theme
  * @param string $js_interface
  * @return Bengine_Game_Controller_Moderator
  */
 protected function updateUser($username, $usertitle, $email, $delete, $umode, $activation, $ipcheck, $usergroupid, $points, $fpoints, $dpoints, $rpoints, $password, $languageid, $templatepackage, $theme, $js_interface)
 {
     $select = array("userid", "username", "email");
     $result = Core::getQuery()->select("user", $select, "", Core::getDB()->quoteInto("userid = ?", $this->userid));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         Hook::event("SaveUserModeration", array(&$row));
         $delete = $delete == 1 ? 1 : 0;
         $umode = $umode == 1 ? 1 : 0;
         $activation = $activation == 1 ? "" : "1";
         $ipcheck = $ipcheck == 1 ? 1 : 0;
         $username = trim($username);
         $usertitle = trim($usertitle);
         $js_interface = trim($js_interface);
         if (Core::getUser()->ifPermissions("CAN_EDIT_USER")) {
             Core::getQuery()->delete("user2group", "userid = ?", null, null, array($this->userid));
             Core::getQuery()->insert("user2group", array("usergroupid" => $usergroupid, "userid" => $this->userid));
             Core::getQuery()->update("user", array("points" => floatval($points), "fpoints" => (int) $fpoints, "dpoints" => (int) $dpoints, "rpoints" => (int) $rpoints), "userid = ?", array($this->userid));
         }
         if ($umode) {
             setProdOfUser($this->userid, 0);
         }
         if (!Str::compare($username, $row["username"])) {
             $num = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("username = ?", $username))->rowCount();
             if ($num > 0) {
                 $username = $row["username"];
             }
         }
         if (!Str::compare($email, $row["email"])) {
             $num = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("email = ?", $email))->rowCount();
             if ($num > 0) {
                 $email = $row["email"];
             }
         }
         if (Str::length($password) > Core::getOptions()->get("MIN_PASSWORD_LENGTH")) {
             $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
             $password = Str::encode($password, $encryption);
             Core::getQuery()->update("password", array("password" => $password, "time" => TIME), "userid = ?", array($this->userid));
         }
         $spec = array("username" => $username, "usertitle" => $usertitle, "email" => $email, "delete" => $delete, "umode" => $umode, "activation" => $activation, "languageid" => $languageid, "ipcheck" => $ipcheck, "templatepackage" => $templatepackage, "theme" => $theme, "js_interface" => $js_interface);
         Core::getQuery()->update("user", $spec, "userid = ?", array($this->userid));
     }
     return $this;
 }
示例#27
0
 /**
  * Saves the entered preferences.
  *
  * @param string $username
  * @param string $usertitle
  * @param string $email
  * @param string $pw
  * @param string $theme
  * @param integer $language
  * @param string $templatepackage
  * @param integer $umode
  * @param integer $delete
  * @param integer $ipcheck
  * @param integer $esps
  * @param integer $generate_key
  * @param string $js_interface
  * @throws Recipe_Exception_Generic
  * @return Bengine_Game_Controller_Preferences
  */
 protected function updateUserData($username, $usertitle, $email, $pw, $theme, $language, $templatepackage, $umode, $delete, $ipcheck, $esps, $generate_key, $js_interface)
 {
     if (Core::getUser()->get("umode")) {
         throw new Recipe_Exception_Generic("Vacation mode is still enabled.");
     }
     Core::getLanguage()->load("Registration");
     Hook::event("SaveUserDataFirst");
     $username = trim(str_replace("  ", " ", $username));
     $usertitle = trim($usertitle);
     $js_interface = trim($js_interface);
     $language = (int) (empty($language) ? Core::getConfig()->get("defaultlanguage") : $language);
     if (!empty($theme) && !filter_var($theme, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
         $theme = "";
         Logger::addMessage("THEME_INVALID");
     }
     if (!empty($templatepackage) && !is_dir(APP_ROOT_DIR . "app/templates/" . $templatepackage)) {
         $templatepackage = Core::getUser()->get("templatepackage");
     }
     $activation = "";
     // Check language
     if (Core::getUser()->get("languageid") != $language) {
         $result = Core::getQuery()->select("languages", "languageid", "", Core::getDB()->quoteInto("languageid = ?", $language));
         if ($result->rowCount() <= 0) {
             $language = Core::getUser()->get("languageid");
         }
         $result->closeCursor();
     }
     // Check username
     if (!Str::compare($username, Core::getUser()->get("username"))) {
         $result = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("username = ?", $username));
         if ($result->rowCount() == 0) {
             $result->closeCursor();
             if (!checkCharacters($username)) {
                 $username = Core::getUser()->get("username");
                 Logger::addMessage("USERNAME_INVALID");
             } else {
                 Logger::addMessage("USERNAME_CHANGED", "success");
             }
         } else {
             $result->closeCursor();
             $username = Core::getUser()->get("username");
             Logger::addMessage("USERNAME_EXISTS");
         }
     }
     // Check user title
     if (!Str::compare($usertitle, Core::getUser()->get("usertitle"))) {
         $length = Str::length($usertitle);
         if ($length < Core::getOptions()->get("MIN_USER_CHARS") || $length > Core::getOptions()->get("MAX_USER_CHARS")) {
             $usertitle = Core::getUser()->get("usertitle");
         }
     }
     // Check email
     if (!Str::compare($email, Core::getUser()->get("email"))) {
         $result = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("email = ?", $email));
         if ($result->rowCount() == 0) {
             $result->closeCursor();
             if (!checkEmail($email)) {
                 $email = Core::getUser()->get("email");
                 Logger::addMessage("EMAIL_INVALID");
             } else {
                 $successMsg = "EMAIL_CHANGED";
                 if (Core::getConfig()->get("EMAIL_ACTIVATION_CHANGED_EMAIL")) {
                     $activation = randString(8);
                     $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/signup/activation/key:" . $activation;
                     Core::getLang()->assign("username", $username);
                     Core::getTemplate()->assign("activationUrl", $url);
                     $template = new Recipe_Email_Template("email_changed");
                     $mail = new Email($email, Core::getLanguage()->getItem("EMAIL_ACTIVATION"));
                     $template->send($mail);
                     $successMsg .= "_REVALIDATE";
                 }
                 Logger::addMessage($successMsg, "success");
             }
         } else {
             $result->closeCursor();
             Logger::addMessage("EMAIL_EXISTS");
             $email = Core::getUser()->get("email");
         }
     }
     // Check password
     $pwLength = Str::length($pw);
     if ($pwLength > 0) {
         if ($pwLength >= Core::getOptions()->get("MIN_PASSWORD_LENGTH") && $pwLength <= Core::getOptions()->get("MAX_PASSWORD_LENGTH")) {
             $successMsg = "PASSWORD_CHANGED";
             if ($activation == "" && Core::getConfig()->get("EMAIL_ACTIVATION_CHANGED_PASSWORD")) {
                 $activation = randString(8);
                 $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/signup/activation/key:" . $activation;
                 Core::getLang()->assign("username", $username);
                 Core::getTemplate()->assign("activationUrl", $url);
                 Core::getTemplate()->assign("newPassword", $pw);
                 $template = new Recipe_Email_Template("password_changed");
                 $mail = new Email($email, Core::getLanguage()->getItem("PASSWORD_ACTIVATION"));
                 $template->send($mail);
                 $successMsg .= "_REVALIDATE";
             }
             $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
             $pw = Str::encode($pw, $encryption);
             Core::getQuery()->update("password", array("password" => $pw, "time" => TIME), "userid = ?", array(Core::getUser()->get("userid")));
             Logger::addMessage($successMsg, "success");
         } else {
             Logger::addMessage("PASSWORD_INVALID");
         }
     }
     // Umode
     if ($umode == 1) {
         // Check if umode can be activated
         /* @var Bengine_Game_Model_Collection_Event $events */
         $events = Game::getCollection("game/event");
         $events->addVacationModeFilter(Core::getUser()->get("userid"));
         $eventCount = $events->getCalculatedSize();
         if ($eventCount > 0) {
             Logger::dieMessage("CANNOT_ACTIVATE_UMODE");
         }
         $umodemin = TIME + Core::getConfig()->get("MIN_VACATION_MODE");
         setProdOfUser(Core::getUser()->get("userid"), 0);
     } else {
         $umodemin = 0;
         $umode = 0;
     }
     // Deletition
     $delete = !$delete ? 0 : TIME + self::DELETE_PROTECTION_TIME;
     // Other prefs
     $ipcheck = (int) $ipcheck;
     if (!Core::getConfig()->get("USER_EDIT_IP_CHECK")) {
         $ipcheck = Core::getUser()->get("ipcheck");
     } else {
         if ($ipcheck > 0) {
             $ipcheck = 1;
         }
     }
     if ($esps > 99) {
         $esps = 99;
     } else {
         if ($esps <= 0) {
             $esps = 1;
         }
     }
     Hook::event("SaveUserDataLast", array(&$username, &$usertitle, &$email, &$templatepackage, &$theme, &$umode, &$umodemin, &$delete, $ipcheck, $esps, &$js_interface));
     // Save it
     $spec = array("username" => $username, "usertitle" => $usertitle, "email" => $email, "temp_email" => $email, "activation" => $activation, "languageid" => $language, "templatepackage" => $templatepackage, "theme" => $theme, "ipcheck" => $ipcheck, "umode" => $umode, "umodemin" => $umodemin, "delete" => $delete, "esps" => $esps, "js_interface" => $js_interface);
     // Feeds
     if ($generate_key) {
         $new_key = randString(16);
         $result = Core::getQuery()->select("feed_keys", array("feed_key"), "", Core::getDB()->quoteInto("user_id = ?", Core::getUser()->get("userid")));
         if ($result->rowCount() > 0) {
             // User has a feed key
             Core::getQuery()->update("feed_keys", array("feed_key" => $new_key), "user_id = ?", array(Core::getUser()->get("userid")));
         } else {
             Core::getQuery()->insert("feed_keys", array("user_id" => Core::getUser()->get("userid"), "feed_key" => $new_key));
         }
     }
     Core::getQuery()->update("user", $spec, "userid = ?", array(Core::getUser()->get("userid")));
     Core::getUser()->rebuild();
     return $this;
 }