Example #1
0
 /**
  * Starts the search.
  *
  * @param string $what	The search item
  * @param string $where	The search mode
  *
  * @return Bengine_Game_Controller_Search
  */
 protected function seek($what, $where)
 {
     Core::getLanguage()->load("Statistics");
     $this->searchItem = new String($what);
     $this->searchItem->trim()->prepareForSearch();
     if (!$this->searchItem->validSearchString) {
         $this->searchItem->set("");
         if (!empty($what)) {
             Logger::addMessage("NO_VALID_SEARCH", "warning");
         }
     }
     Core::getTPL()->assign("what", $what);
     switch ($where) {
         case 1:
             Core::getTPL()->assign("players", " selected=\"selected\"");
             $this->playerSearch();
             break;
         case 2:
             Core::getTPL()->assign("planets", " selected=\"selected\"");
             $this->planetSearch();
             break;
         case 3:
             Core::getTPL()->assign("allys", " selected=\"selected\"");
             $this->allianceSearch();
             break;
     }
     return $this;
 }
Example #2
0
/**
 * Forward to login page.
 *
 * @param string $errorid	Error id to output
 *
 * @return void
 */
function forwardToLogin($errorid)
{
    if (LOGIN_REQUIRED) {
        $login = BASE_URL . "?error=" . $errorid;
        Hook::event("ForwardToLoginPage", array(&$login, $errorid));
        doHeaderRedirection($login, false);
    }
    Logger::addMessage($errorid);
    Core::getTPL()->display("login");
    return;
}
Example #3
0
 /**
  * Executes this event.
  *
  * @return Bengine_Game_Model_Event
  */
 public function execute()
 {
     try {
         $this->getEventHandler()->execute();
     } catch (Exception $e) {
         $this->set("prev_rc", "error");
         $this->save();
         Logger::addMessage($e->getMessage());
     }
     return $this;
 }
Example #4
0
 /**
  * @param Bengine_Game_Model_Event $event
  * @param array $data
  * @return Bengine_Game_EventHandler_Handler_Fleet_Colonize
  */
 protected function _add(Bengine_Game_Model_Event $event, array $data)
 {
     if ($data["metal"] > 0 || $data["silicon"] > 0 || $data["hydrogen"] > 0) {
         Logger::addMessage("COLONIZE_RESOURCE_WARNING", "info");
     }
     $data["metal"] = 0;
     $data["silicon"] = 0;
     $data["hydrogen"] = 0;
     $event->setData($data);
     $this->prepareFleet($data);
     return $this;
 }
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Constructions
  */
 protected function indexAction()
 {
     Core::getLanguage()->load(array("info", "buildings"));
     $mode = self::BUILDING_CONSTRUCTION_TYPE;
     $moonType = Game::getPlanet()->getData("ismoon") ? self::MOON_CONSTRUCTION_TYPE : null;
     if (!Game::getPlanet()->planetFree()) {
         Logger::addMessage("PLANET_FULL", "info");
     }
     $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize();
     Core::getTPL()->assign("shipyardSize", $shipyardSize);
     Core::getLang()->assign("maxFields", fNumber(Game::getPlanet()->getMaxFields()));
     Core::getLang()->assign("occupiedFields", Game::getPlanet()->getFields(true));
     /* @var Bengine_Game_Model_Collection_Construction $collection */
     $collection = Application::getCollection("game/construction");
     $collection->addTypeFilter($mode, $moonType ? true : false, $moonType)->addPlanetJoin(Core::getUser()->get("curplanet"))->addDisplayOrder();
     Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js");
     Hook::event("ConstructionsLoaded", array($collection));
     Core::getTPL()->addLoop("constructions", $collection);
     Core::getTPL()->assign("event", $this->event);
     return $this;
 }
Example #6
0
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Research
  */
 protected function indexAction()
 {
     Core::getLanguage()->load(array("info", "buildings"));
     /* @var Bengine_Game_Model_Collection_Construction $collection */
     $collection = Application::getCollection("game/construction");
     $collection->addTypeFilter(self::RESEARCH_CONSTRUCTION_TYPE, Game::getPlanet()->getData("ismoon"))->addUserJoin(Core::getUser()->get("userid"))->addDisplayOrder();
     if (!Game::getPlanet()->getBuilding("RESEARCH_LAB") || !count($collection)) {
         Logger::dieMessage("RESEARCH_LAB_REQUIRED");
     }
     Hook::event("ResearchLoaded", array($collection));
     Core::getTPL()->addLoop("constructions", $collection);
     Core::getTPL()->assign("event", $this->event);
     $canResearch = true;
     if (!Game::getEH()->canReasearch()) {
         Logger::addMessage("RESEARCH_LAB_UPGRADING", "info");
         $canResearch = false;
     }
     Core::getTPL()->assign("canResearch", $canResearch);
     Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js");
     return $this;
 }
Example #7
0
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Shipyard
  */
 protected function indexAction()
 {
     Core::getLanguage()->load(array("info", "buildings"));
     $this->setTemplate("shipyard/index");
     /* @var Bengine_Game_Model_Collection_Construction $collection */
     $collection = Application::getCollection("game/construction", "game/unit");
     $collection->addTypeFilter($this->mode, Game::getPlanet()->getData("ismoon"))->addShipyardJoin(Core::getUser()->get("curplanet"))->addDisplayOrder();
     if (Game::getPlanet()->getBuilding("SHIPYARD") == 0) {
         Logger::dieMessage("SHIPYARD_REQUIRED");
     }
     if ($this->mode == self::FLEET_CONSTRUCTION_TYPE) {
         Core::getTPL()->assign("shipyard", Core::getLanguage()->getItem("SHIP_CONSTRUCTION"));
     } else {
         Core::getTPL()->assign("shipyard", Core::getLanguage()->getItem("DEFENSE"));
     }
     if (!$this->canBuildUnits) {
         Logger::addMessage("SHIPYARD_UPGRADING", "info");
     }
     $missions = Game::getEH()->getShipyardEvents();
     if (count($missions)) {
         Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js");
         /* @var Bengine_Game_Model_Event $event */
         $event = $missions->getFirstItem();
         Core::getTPL()->assign("remainingTime", $event->getTimeLeft());
         Core::getTPL()->assign("currentWork", Core::getLanguage()->getItem($event->getData("mission")));
         Core::getTPL()->assign("currentMissionImage", BASE_URL . "img/buildings/" . $event->getData("mission") . ".gif");
         Core::getLang()->assign("unitName", Core::getLanguage()->getItem($event->getData("mission")));
     }
     Core::getTPL()->addLoop("events", $missions);
     Core::getTPL()->addLoop("units", $collection);
     Core::getTPL()->assign("canBuildUnits", $this->canBuildUnits);
     Core::getTPL()->assign("canBuildRockets", $this->canBuildRockets);
     $this->assign("orderAction", BASE_URL . "game/" . SID . "/" . $this->getParam("controller") . "/Order");
     $this->assign("cancelAction", BASE_URL . "game/" . SID . "/" . $this->getParam("controller") . "/Cancel");
     return $this;
 }
Example #8
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;
 }
Example #9
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;
 }
Example #10
0
 /**
  * Add the message to logger.
  *
  * @return void
  */
 public function printError()
 {
     Logger::addMessage($this->message);
     return;
 }
Example #11
0
 /**
  * @param array $month
  * @param array $day
  * @param array $weekday
  * @param integer $hour
  * @param integer $minute
  * @param string $class
  * @return Bengine_Admin_Controller_Cronjob
  */
 protected function add($month, $day, $weekday, $hour, $minute, $class)
 {
     if (is_array($month) && is_array($day) && is_array($weekday) && !empty($class)) {
         $month = implode(",", $month);
         $day = implode(",", $day);
         $weekday = implode(",", $weekday);
         $spec = array("class" => $class, "month" => $month, "day" => $day, "weekday" => $weekday, "hour" => $hour, "minute" => $minute, "xtime" => TIME, "last" => 0, "active" => 0);
         Core::getQuery()->insert("cronjob", $spec);
     } else {
         Logger::addMessage("InvalidInformation");
     }
     return $this;
 }
Example #12
0
 /**
  * Select the ships for jump.
  *
  * @param array $ships
  *
  * @return Bengine_Game_Controller_Mission
  */
 protected function starGateJump($ships)
 {
     $this->noAction = true;
     $data = array();
     Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
     $select = array("u2s.unitid", "u2s.quantity", "d.capicity", "d.speed", "d.consume", "b.name");
     $joins = "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)";
     $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet d ON (d.unitid = u2s.unitid)";
     $result = Core::getQuery()->select("unit2shipyard u2s", $select, $joins, Core::getDB()->quoteInto("b.mode = '3' AND u2s.planetid = ?", Core::getUser()->get("curplanet")));
     foreach ($result->fetchAll() as $row) {
         $id = $row["unitid"];
         if (isset($ships[$id])) {
             $quantity = _pos($ships[$id]);
             if ($quantity > $row["quantity"]) {
                 $quantity = $row["quantity"];
             }
             if ($quantity > 0) {
                 $data["ships"][$id]["quantity"] = $quantity;
                 $data["ships"][$id]["name"] = $row["name"];
             }
         }
     }
     $result->closeCursor();
     $result = Core::getQuery()->select("stargate_jump", "time", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet")), "time DESC");
     $row = $result->fetchRow();
     $result->closeCursor();
     $requiredReloadTime = (int) Core::getConfig()->get("STAR_GATE_RELOAD_TIME") * 60;
     $reloadTime = $row["time"] + $requiredReloadTime;
     if (count($data) > 0 && $reloadTime < TIME) {
         $moons = array();
         $select = new Recipe_Database_Select();
         $select->from(array("p" => "planet"))->attributes(array("p" => array("planetid", "planetname"), "g" => array("galaxy", "system", "position"), "sj" => array("time")));
         $select->join(array("b2p" => "building2planet"), array("b2p" => "planetid", "p" => "planetid"))->join(array("g" => "galaxy"), array("g" => "moonid", "p" => "planetid"))->join(array("sj" => "stargate_jump"), array("sj" => "planetid", "p" => "planetid"))->where(array("p" => "userid"), Core::getUser()->get("userid"))->where(array("p" => "ismoon"), 1)->where(array("p" => "planetid", "!="), Core::getUser()->get("curplanet"))->where(array("b2p" => "buildingid"), 56)->where("IFNULL(sj.time, 0) + ? < UNIX_TIMESTAMP()", $requiredReloadTime)->group(array("p" => "planetid"))->order(array("g" => "galaxy"))->order(array("g" => "system"))->order(array("g" => "position"));
         $result = $select->getStatement();
         foreach ($result->fetchAll() as $row) {
             $moons[] = $row;
             $data["moons"][] = $row["planetid"];
         }
         $result->closeCursor();
         Hook::event("ShowStarGates", array(&$moons, &$data));
         Core::getTPL()->addLoop("moons", $moons);
         $data = serialize($data);
         Core::getQuery()->insert("temp_fleet", array("planetid" => Core::getUser()->get("curplanet"), "data" => $data));
         $this->setTemplate("mission/stargatejump");
     } else {
         if ($reloadTime < TIME) {
             $reloadTime = TIME;
         }
         Core::getLanguage()->assign("reloadTime", fNumber(($reloadTime - TIME) / 60), 2);
         Logger::addMessage("RELOADING_STAR_GATE");
     }
     return $this;
 }
Example #13
0
 /**
  * Deletes messages.
  *
  * @param integer $folder	Folder id
  * @param integer $option	Mode to delete content
  * @param array $msgs		Messages
  *
  * @return Bengine_Game_Controller_MSG
  */
 protected function deleteMessages($folder, $option, array $msgs)
 {
     $pagination = $this->getPagination($folder);
     $deltime = 604800;
     if (is_numeric(Core::getOptions()->get("DEL_MESSAGE_DAYS")) && Core::getOptions()->get("DEL_MESSAGE_DAYS") > 0) {
         $deltime = (int) Core::getOptions()->get("DEL_MESSAGE_DAYS") * 86400;
     }
     $deltime = TIME - $deltime;
     Core::getQuery()->delete("message", "time <= ?", null, null, array($deltime));
     switch ($option) {
         case 1:
             foreach ($msgs as $msgid) {
                 Core::getQuery()->delete("message", "msgid = ? AND receiver = ?", null, null, array($msgid, Core::getUser()->get("userid")));
             }
             break;
         case 2:
             $where = Core::getDB()->quoteInto("receiver = ? AND mode = ?", array(Core::getUser()->get("userid"), $folder));
             $result = Core::getQuery()->select("message", "msgid", "", $where, "time DESC", $pagination->getStart() . ", " . Core::getOptions()->get("MAX_PMS"));
             foreach ($result->fetchAll() as $row) {
                 if (!in_array($row["msgid"], $msgs)) {
                     Core::getQuery()->delete("message", "msgid = ?", null, null, array($row["msgid"]));
                 }
             }
             $result->closeCursor();
             break;
         case 3:
             $where = Core::getDB()->quoteInto("receiver = ? AND mode = ?", array(Core::getUser()->get("userid"), $folder));
             $result = Core::getQuery()->select("message", array("msgid"), "", $where, "time DESC", $pagination->getStart() . ", " . Core::getOptions()->get("MAX_PMS"));
             foreach ($result->fetchAll() as $row) {
                 Core::getQuery()->delete("message", "msgid = ?", null, null, array($row["msgid"]));
             }
             break;
         case 4:
             Core::getQuery()->delete("message", "receiver = ? AND mode = ?", null, null, array(Core::getUser()->get("userid"), $folder));
             break;
         case 5:
             $reports = array();
             $modId = Game::getRandomModerator();
             foreach ($msgs as $msgid) {
                 $where = Core::getDB()->quoteInto("m.msgid = ? AND m.receiver = ?", array($msgid, Core::getUser()->get("userid")));
                 $result = Core::getQuery()->select("message m", array("m.sender", "m.mode", "m.message", "m.time", "u.username"), "LEFT JOIN " . PREFIX . "user u ON (u.userid = m.sender)", $where);
                 if ($row = $result->fetchRow()) {
                     if (($row["sender"] > 0 || $row["mode"] == 5) && $row["sender"] != $modId) {
                         $reports[] = $row;
                     }
                 }
             }
             if (count($reports) > 0) {
                 Core::getLang()->assign("reportSender", Core::getUser()->get("username"));
                 foreach ($reports as $report) {
                     Core::getLang()->assign("reportMessage", $report["message"]);
                     Core::getLang()->assign("reportUser", $report["username"]);
                     Core::getLang()->assign("reportSendTime", Date::timeToString(1, $report["time"], "", false));
                     if ($report["mode"] == 5) {
                         $assault = Game::getModel("game/assault")->load((int) $report["message"]);
                         $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/combat/report/" . $assault->get("assaultid") . "/" . $assault->get("key");
                         $gentime = $assault->get("gentime") / 1000;
                         $label = Core::getLanguage()->getItem("ASSAULT_REPORT") . " (A: " . fNumber($assault->get("lostunits_attacker")) . ", D: " . fNumber($assault->get("lostunits_defender")) . ") " . $gentime . "s";
                         Core::getLang()->assign("reportLink", "<span class=\"assault-report\" onclick=\"window.open('" . $url . "')\">" . $label . "</span>");
                         $message = Core::getDB()->escape(Core::getLang()->get("MODERATOR_REPORT_COMBAT"));
                     } else {
                         richText($message = Core::getLang()->get("MODERATOR_REPORT_MESSAGE"));
                     }
                     $subject = Core::getLang()->get("MODERATOR_REPORT_SUBJECT");
                     $spec = array("sender" => null, "mode" => 1, "subject" => $subject, "message" => $message, "receiver" => $modId, "time" => TIME, "read" => 0);
                     Core::getQuery()->insert("message", $spec);
                 }
                 Logger::addMessage("MESSAGES_REPORTED", "success");
             }
             break;
     }
     return $this;
 }
Example #14
0
 /**
  * Starts the assault.
  *
  * @param int $galaxy
  * @param int $system
  * @param int $position
  * @return Bengine_Game_Assault
  */
 public function startAssault($galaxy = 0, $system = 0, $position = 0)
 {
     Hook::event("StartAssaultFirst", array($this, $this->owner, $galaxy, $system, $position));
     // Include database access
     $database = array();
     $cs = array();
     require APP_ROOT_DIR . "etc/Config.inc.php";
     // Run java
     $jrePath = $cs["jre"];
     $jarPath = APP_ROOT_DIR . "app/Assault.jar";
     $cmd = $jrePath . ' -jar "' . $jarPath . '" "' . $cs["host"] . '" "' . $cs["user"] . '" "' . $cs["userpw"] . '" "' . $database["databasename"] . '" "' . $database["tableprefix"] . '" ' . escapeshellarg($this->assaultid) . ' 2>&1';
     $output = array();
     $commandResult = null;
     if (function_exists("exec")) {
         exec($cmd, $output, $commandResult);
     } else {
         $output[] = "Function exec() disabled.";
     }
     $result = Core::getQuery()->select("assault", array("result", "moonchance", "moon", "accomplished", "lostunits_defender"), "", Core::getDB()->quoteInto("assaultid = ?", $this->assaultid));
     $row = $result->fetchRow();
     $result->closeCursor();
     $this->data = $row;
     if ($commandResult !== 0 || !$row["accomplished"]) {
         $output = implode("<br/>", $output);
         Logger::addMessage("Sorry, could not start battle <strong>" . $this->assaultid . "</strong>:<br/>" . $output);
     }
     Hook::event("StartAssaultLast", array($this, &$row, $this->owner));
     if ($row["moon"]) {
         new Bengine_Game_Planet_Creator($this->owner, $galaxy, $system, $position, 1, $row["moonchance"]);
     }
     return $this;
 }
Example #15
0
 /**
  * @param string $var
  * @param string $type
  * @param string $options
  * @param string $description
  * @param integer $groupid
  * @return Bengine_Admin_Controller_Config
  */
 protected function saveVariable($var, $type, $options, $description, $groupid)
 {
     $options = $this->serialize($options);
     $spec = array("type" => $type, "options" => $options, "description" => Str::validateXHTML($description), "groupid" => $groupid);
     Core::getQuery()->update("config", $spec, "var = ?", array($var));
     Logger::addMessage("Saving_Successful", "success");
     return $this;
 }
Example #16
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;
 }