/** * Start a new session and destroy old sessions. * * @return Bengine_Game_Login */ public function startSession() { if ($this->canLogin) { Core::getDB()->query("UPDATE " . PREFIX . "user SET curplanet = hp WHERE userid = ?", array($this->userid)); } return parent::startSession(); }
/** * Rebuilds a cache object. * * @param string $type * @param mixed $options * * @return void */ public static function rebuildCache($type, array $options = null) { switch ($type) { case "config": Core::getCache()->buildConfigCache(); break; case "lang": if ($options !== null && !empty($options["language"])) { $result = Core::getQuery()->select("languages", array("langcode"), "", Core::getDB()->quoteInto("languageid = ?", $options["language"])); $langcode = $result->fetchColumn(); if (!empty($options["group"])) { $result = Core::getQuery()->select("phrasesgroups", array("title"), "", Core::getDB()->quoteInto("phrasegroupid = ?", $options["group"])); $groupname = $result->fetchColumn(); Core::getCache()->cachePhraseGroup($groupname, $langcode); } else { Core::getCache()->cacheLanguage($langcode); } } else { $result = Core::getQuery()->select("languages", "langcode"); foreach ($result->fetchAll() as $row) { Core::getCache()->cacheLanguage($row["langcode"]); } } break; case "perm": Core::getCache()->buildPermissionCache(); break; } return; }
/** * Checks if the given key is ok for the userid. * * @param integer $user_id * @param string $key * * @return boolean */ public function checkKey($user_id, $key) { $where = Core::getDB()->quoteInto("user_id = ?", $user_id); $where .= Core::getDB()->quoteInto(" AND feed_key = ?", $key); $result = Core::getQuery()->select("feed_keys", array("feed_key"), "", $where); return $result->rowCount() > 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("EhRecycling", array($event, &$data, $this)); $where = Core::getDB()->quoteInto("galaxy = ? AND system = ? AND position = ?", array($data["galaxy"], $data["system"], $data["position"])); $result = Core::getQuery()->select("galaxy", array("metal", "silicon"), "", $where); if ($_row = $result->fetchRow()) { $result->closeCursor(); $capacityMetal = (int) ($data["capacity"] * 66.7 / 100); $capacitySilicon = (int) ($data["capacity"] * 33.3 / 100); $roundFix = $data["capacity"] - $capacityMetal - $capacitySilicon; if ($roundFix > 0) { $capacitySilicon += $roundFix; } $data["debrismetal"] = $_row["metal"]; $data["debrissilicon"] = $_row["silicon"]; $capacitySilicon += $capacityMetal > $_row["metal"] ? $capacityMetal - $_row["metal"] : 0; $capacityMetal += $capacitySilicon > $_row["silicon"] ? $capacitySilicon - $_row["silicon"] : 0; $data["metal"] += min($capacityMetal, $_row["metal"]); $restMetal = $_row["metal"] - min($capacityMetal, $_row["metal"]); $data["silicon"] += min($capacitySilicon, $_row["silicon"]); $restSilicon = $_row["silicon"] - min($capacitySilicon, $_row["silicon"]); $data["recycledmetal"] = abs($_row["metal"] - $restMetal); $data["recycledsilicon"] = abs($_row["silicon"] - $restSilicon); if ($_row["silicon"] != 0 || $_row["metal"] != 0) { Core::getQuery()->update("galaxy", array("metal" => $restMetal, "silicon" => $restSilicon), "galaxy = ? AND system = ? AND position = ?", array($data["galaxy"], $data["system"], $data["position"])); } } new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data); $this->sendBack($data, $data["time"] + $event["time"]); return $this; }
/** * Alliance page action. * * @return Bengine_Comm_Controller_Alliance */ public function pageAction() { Core::getLanguage()->load("Alliance"); Core::getTPL()->clearHTMLHeaderFiles(); Core::getTPL()->addHTMLHeaderFile("game.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); $tag = $this->getParam("1"); $fNumber = array("member", "points", "rpoints", "fpoints", "dpoints"); $attr = array("a.aid", "a.name", "a.tag", "a.logo", "a.textextern", "a.homepage", "a.showhomepage", "COUNT(u2a.userid) AS member", "SUM(u.points) AS points", "SUM(u.rpoints) AS rpoints", "SUM(u.fpoints) AS fpoints", "SUM(u.dpoints) AS dpoints"); $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", $attr, $joins, Core::getDB()->quoteInto("tag = ?", $tag), "", 1, "a.aid"); $row = $result->fetchRow(); if ($row) { foreach ($fNumber as $field) { $row[$field] = fNumber($row[$field]); } $parser = new Bengine_Game_Alliance_Page_Parser($row["aid"]); if (Str::length(strip_tags($row["textextern"])) > 0) { $row["textextern"] = $parser->startParser($row["textextern"]); } else { $row["textextern"] = Core::getLang()->get("WELCOME"); } $row["homepage"] = $row["homepage"] != "" ? Link::get($row["homepage"], $row["homepage"], $row["homepage"]) : ""; $row["logo"] = $row["logo"] != "" ? Image::getImage($row["logo"], "") : ""; Hook::event("ShowPublicAlliancePage", array(&$row)); $this->assign($row); $this->setIsAjax(); } else { $this->setNoDisplay(true); } return $this; }
/** * Renders the signature image. * * @return Bengine_Comm_Controller_Signature */ protected function _render() { Core::getLang()->load("Signature"); $config = $this->getConfig(); $imageConfig = $config["image"]; $user = $this->getUser(); $img = imagecreatefrompng(AD . "img/" . $imageConfig["background"]); if ($imageConfig["stats"]["show"]) { $result = Core::getQuery()->select("user", array("userid")); $totalUser = fNumber($result->rowCount()); $this->_addParamToImage($img, "stats", Core::getLang()->get("RANK") . " " . $user->getFormattedRank() . "/" . $totalUser); } if ($imageConfig["planets"]["show"]) { $result = Core::getQuery()->select("planet", array("planetid"), "", Core::getDB()->quoteInto("userid = ? AND ismoon = 0", $user->getUserid())); $planets = Core::getLang()->get("NUMBER_OF_COLONY") . " " . fNumber($result->rowCount() - 1); $this->_addParamToImage($img, "planets", $planets); } $this->_addParamToImage($img, "username", $user->getUsername()); $this->_addParamToImage($img, "gameName", Core::getConfig()->get("pagetitle")); $this->_addParamToImage($img, "planet", $user->getHomePlanet()->getPlanetname() . " [" . $user->getHomePlanet()->getCoords(false) . "]"); $this->_addParamToImage($img, "points", Core::getLang()->get("POINTS") . " " . $user->getFormattedPoints()); if ($user->getAid()) { $this->_addParamToImage($img, "alliance", Core::getLang()->get("ALLIANCE") . " " . $user->getAlliance()->getTag()); } imagepng($img, $this->getCachePath() . DIRECTORY_SEPARATOR . $this->getUserId() . self::IMAGE_FILE_EXTENSION, $imageConfig["quality"]); imagedestroy($img); return $this; }
/** * Recalculate the points. * * @return Bengine_Game_Cronjob_PointClean */ protected function cleanPoints() { Hook::event("CleanPointsBegin"); $_result = Core::getQuery()->select("user", "userid"); foreach ($_result->fetchAll() as $_row) { $points = 0; $fpoints = 0; $dpoints = 0; $result = Core::getQuery()->select("planet", "planetid", "", Core::getDB()->quoteInto("userid = ?", $_row["userid"])); foreach ($result->fetchAll() as $row) { $points += Bengine_Game_PointRenewer::getBuildingPoints($row["planetid"]); $points += Bengine_Game_PointRenewer::getFleetPoints($row["planetid"]); $fpoints += Bengine_Game_PointRenewer::getFleetPoints_Fleet($row["planetid"]); $dpoints += Bengine_Game_PointRenewer::getDefensePoints($row["planetid"]); } $result->closeCursor(); $points += Bengine_Game_PointRenewer::getResearchPoints($_row["userid"]); $points += Bengine_Game_PointRenewer::getFleetEventPoints($_row["userid"]); $fpoints += Bengine_Game_PointRenewer::getFleetEvent_Fleet($_row["userid"]); $rpoints = Bengine_Game_PointRenewer::getResearchPoints_r($_row["userid"]); Core::getQuery()->update("user", array("points" => $points, "fpoints" => $fpoints, "rpoints" => $rpoints, "dpoints" => $dpoints), "userid = ?", array($_row["userid"])); } $_result->closeCursor(); return $this; }
function buildCache() { $Data = Core::getDB()->query("SELECT userID, MAX(banTime) FROM " . BANNED . " WHERE banTime > " . TIMESTAMP . " GROUP BY userID;"); $Bans = array(); while ($Row = $Data->fetchObject()) { $Bans[$Row->userID] = $Row; } return $Bans; }
/** * Function to resort phrases. * * @package Recipe 1.2 * @author Sebastian Noll * @copyright Copyright (c) 2009, Sebastian Noll * @license Proprietary * @version $Id: SortPhrases.php 8 2010-10-17 20:55:04Z secretchampion $ */ function sortPhrases() { Core::getDB()->query("DROP TABLE IF EXISTS " . PREFIX . "buffer"); Core::getDB()->query("CREATE TABLE " . PREFIX . "buffer " . "(phraseid int(10) unsigned NOT NULL auto_increment, " . "languageid int(4) unsigned NOT NULL, " . "phrasegroupid int(4) unsigned NOT NULL, " . "title varchar(128) NOT NULL, " . "content text NOT NULL, " . "PRIMARY KEY (phraseid), " . "KEY languageid (languageid,phrasegroupid), " . "KEY phrasegroupid (phrasegroupid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); Core::getDB()->query("INSERT INTO " . PREFIX . "buffer (languageid, phrasegroupid, title, content) SELECT languageid, phrasegroupid, title, content FROM " . PREFIX . "phrases ORDER BY languageid ASC, phrasegroupid ASC, title ASC"); Core::getDB()->query("TRUNCATE TABLE " . PREFIX . "phrases"); Core::getDB()->query("INSERT INTO " . PREFIX . "phrases (phraseid, languageid, phrasegroupid, title, content) SELECT phraseid, languageid, phrasegroupid, title, content FROM " . PREFIX . "buffer ORDER BY phraseid ASC"); Core::getDB()->query("DROP TABLE IF EXISTS " . PREFIX . "buffer"); }
/** * (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) { $result = Core::getQuery()->select("events", array("eventid", "planetid", "destination", "start"), "", Core::getDB()->quoteInto("parent_id = ?", $event->get("eventid"))); foreach ($result->fetchAll() as $row) { Core::getQuery()->update("events", array("mode" => 20, "planetid" => $row["destination"], "destination" => $row["planetid"], "time" => TIME + (TIME - $row["start"])), "eventid = ?", array($row["eventid"])); } $this->sendBack($data); return $this; }
/** * @param integer $adId * @return Bengine_Admin_Controller_Commercial */ protected function editAction($adId) { if ($this->isPost()) { $this->save($this->getParam("ad_id"), $this->getParam("name"), $this->getParam("position"), $this->getParam("max_views"), $this->getParam("enabled", 0), $this->getParam("html_code")); } $result = Core::getQuery()->select("ad", array("*"), "", Core::getDB()->quoteInto("ad_id = ?", $adId)); $row = $result->fetchRow(); $row["html_code"] = htmlspecialchars($row["html_code"]); Core::getTPL()->assign($row); return $this; }
/** * @param string $grouptitle * @param array $perms * @return Bengine_Admin_Controller_Usergroups */ protected function add($grouptitle, array $perms) { Core::getQuery()->insert("usergroup", array("grouptitle" => $grouptitle, "standard" => 0)); $groupid = Core::getDB()->lastInsertId(); if (count($perms) > 0) { foreach ($perms as $permid) { if ($permid > 0) { Core::getQuery()->insert("group2permission", array("permissionid" => $permid, "groupid" => $groupid, "value" => 1)); } } } Admin::rebuildCache("perm"); return $this; }
/** * Loads all menu items. * * @return Bengine_Comm_CMS */ protected function loadMenuItems() { $result = Core::getQuery()->select("page", array("position", "title", "label", "link"), "", Core::getDB()->quoteInto("languageid = ?", $this->langid), "displayorder ASC"); foreach ($result->fetchAll() as $row) { $position = $row["position"]; if (!empty($row["link"])) { $this->menuItems[$position][]["link"] = Link::get($row["link"], $row["title"], $row["title"]); } else { $this->menuItems[$position][]["link"] = Link::get(LANG . "index/" . $row["label"], $row["title"], $row["title"]); } } Hook::event("CommLoadMenu", array(&$this->menuItems, $this)); return $this; }
/** * @param int|Bengine_Game_Model_User $user * @param int $mode * @return Bengine_Game_Model_Collection_Assault */ public function addParticipantFilter($user, $mode = null) { if ($user instanceof Bengine_Game_Model_User) { $user = $user->get("userid"); } $on = Core::getDB()->quoteInto("pa.assaultid = a.assaultid AND pa.userid = ?", (int) $user); if (null !== $mode) { $on .= Core::getDB()->quoteInto(" AND pa.mode = ?", (int) $mode); } $this->getSelect()->join(array("pa" => "assaultparticipant"), $on)->where("pa.userid", (int) $user); if (null !== $mode) { $this->getSelect()->where("pa.mode = ?", (int) $mode); } return $this; }
/** * (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("EhDowngradeBuilding", array($event, &$data, $this)); if (!$event->getPlanetid()) { return $this; } $points = ($data["metal"] + $data["metal"] + $data["metal"]) / 1000; if ($data["level"] > 0) { Core::getQuery()->update("building2planet", array("level" => $data["level"]), "buildingid = '" . $data["buildingid"] . "' AND planetid = ?", array($event->getPlanetid())); } else { Core::getQuery()->delete("building2planet", "buildingid = ? AND planetid = ?", null, null, array($data["buildingid"], $event->getPlanetid())); } Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ? WHERE userid = ?", array($points, $event->getUserid())); return $this; }
/** * @return Bengine_Admin_Controller_Index */ protected function indexAction() { Core::getLanguage()->load("AI_Overview"); $this->assign("DBType", Core::getDB()->getDatabaseType()); $this->assign("DBVersion", Core::getDB()->getClientVersion()); $this->assign("DBServer", Core::getDB()->getServerVersion()); $this->assign("PHPVersion", phpversion()); $this->assign("IPAddress", IPADDRESS); $this->assign("Host", HTTP_HOST); $this->assign("ServerIP", $_SERVER["SERVER_ADDR"]); $this->assign("RecipeVersion", Core::versionToString()); $meta = Admin::getMeta(); $this->assign("RecipeAIVersion", $meta["packages"]["bengine"]["admin"]["version"]); $this->assign("ServerSoftware", $_SERVER["SERVER_SOFTWARE"]); return $this; }
/** * (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("EbUpgradeResearch", array($event, &$data, $this)); $points = ($data["metal"] + $data["silicon"] + $data["hydrogen"]) / 1000; $select = new Recipe_Database_Select(); $select->from("research2user")->attributes(array("level"))->where("buildingid = ?", $data["buildingid"])->where("userid = ?", $event->getUserid()); if ($row = $select->getStatement()->fetchRow()) { Core::getQuery()->update("research2user", array("level" => $data["level"]), "buildingid = ? AND userid = ?", array($data["buildingid"], $event->getUserid())); Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid())); } else { if ($data["level"] == 1) { Core::getQuery()->insert("research2user", array("buildingid" => $data["buildingid"], "userid" => $event->getUserid(), "level" => 1)); Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid())); } } return $this; }
/** * Activates an account, if key exists. * Starts log in on success. * * @return Bengine_Game_Account_Activation */ protected function activateAccount() { if (!empty($this->key)) { $result = Core::getQuery()->select("user u", array("u.userid", "u.username", "p.password", "temp_email"), "LEFT JOIN " . PREFIX . "password p ON (p.userid = u.userid)", Core::getDB()->quoteInto("u.activation = ?", $this->getKey())); if ($row = $result->fetchRow()) { $result->closeCursor(); Hook::event("ActivateAccount", array($this)); Core::getQuery()->update("user", array("activation" => "", "email" => $row["temp_email"]), "userid = ?", array($row["userid"])); $login = new Bengine_Game_Login($row["username"], $row["password"], "game", "trim"); $login->setCountLoginAttempts(false); $login->checkData(); $login->startSession(); return $this; } $result->closeCursor(); } Recipe_Header::redirect("?error=ACTIVATION_FAILED", false); return $this; }
/** * @return Bengine_Admin_Controller_Globalmail */ protected function send() { $subject = Str::validateXHTML($this->getParam("subject")); $message = richtext(nl2br($this->getParam("message"))); if (Str::length($message) < 10) { Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT")); $error = true; } if (Str::length($subject) == 0) { Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT")); $error = true; } if (!empty($error)) { return $this; } $sql = "INSERT INTO `" . PREFIX . "message` (`mode`, `time`, `sender`, `receiver`, `subject`, `message`, `read`) SELECT ?, ?, NULL, " . PREFIX . "user.userid, ?, ?, ? FROM " . PREFIX . "user"; Core::getDB()->query($sql, array(1, TIME, $subject, $message, 0)); return $this; }
/** * (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("EhTransport", array($event, &$data, $this)); $this->_production($event); Core::getDB()->query("UPDATE " . PREFIX . "planet SET metal = metal + ?, silicon = silicon + ?, hydrogen = hydrogen + ? WHERE planetid = ?", array($data["metal"], $data["silicon"], $data["hydrogen"], $event["destination"])); $data["targetplanet"] = $event["destination_planetname"]; $data["targetuser"] = $event["destination_user_id"]; $data["startplanet"] = $event["planetname"]; $data["startuser"] = $event["username"]; if ($event["userid"] == $data["targetuser"]) { new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data); } else { new Bengine_Game_AutoMsg(21, $event["userid"], $event["time"], $data); } $data["metal"] = 0; $data["silicon"] = 0; $data["hydrogen"] = 0; $this->sendBack($data, $data["time"] + $event["time"]); return $this; }
/** * (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("EhReturn", array($event, &$data, $this)); $this->_production($event); foreach ($data["ships"] as $ship) { $where = Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($ship["id"], $event["destination"])); $result = Core::getQuery()->select("unit2shipyard", "unitid", "", $where); if ($result->rowCount() > 0) { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity + ? WHERE unitid = ? AND planetid = ?", array($ship["quantity"], $ship["id"], $event["destination"])); } else { Core::getQuery()->insert("unit2shipyard", array("unitid" => $ship["id"], "planetid" => $event["destination"], "quantity" => $ship["quantity"])); } } $data["destination"] = $event["destination"]; Core::getDB()->query("UPDATE " . PREFIX . "planet SET metal = metal + ?, silicon = silicon + ?, hydrogen = hydrogen + ? WHERE planetid = ?", array($data["metal"], $data["silicon"], $data["hydrogen"], $event["destination"])); if (!isset($data["nomessage"])) { new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data); } return $this; }
/** * 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; }
/** * Returns formation data. * * @return array|bool */ public function getSpecialData() { if ($this->_formations === null) { $this->_formations = false; if (!empty($this->_target)) { $joins = "LEFT JOIN " . PREFIX . "events e ON (e.eventid = fi.eventid)"; $joins .= "LEFT JOIN " . PREFIX . "attack_formation af ON (e.eventid = af.eventid)"; $select = array("af.eventid", "af.time"); $where = Core::getDB()->quoteInto("fi.userid = ? AND af.time > ? AND e.destination = ?", array(Core::getUser()->get("userid"), TIME, $this->_target["planetid"])); if (!empty($this->_target["formation"])) { $where .= Core::getDB()->quoteInto(" AND e.eventid = ?", $this->_target["formation"]); } $result = Core::getQuery()->select("formation_invitation fi", $select, $joins, $where); if ($row = $result->fetchRow()) { $this->_formations = $row; } $result->closeCursor(); } } return $this->_formations; }
/** * Formats the message. * * @param Bengine_Game_Model_Message $message * * @return Bengine_Game_MessageFolder_Combat */ protected function _format(Bengine_Game_Model_Message $message) { if (!$message->get("sender")) { $message->set("sender", Core::getLanguage()->getItem("FLEET_COMMAND")); } $assault = Application::getModel("game/assault")->load((int) $message->get("message")); if ($assault->get("assaultid")) { if (!$assault->get("galaxy")) { $statement = Core::getQuery()->select("assaultparticipant ap", array("data"), "", Core::getDB()->quoteInto("ap.assaultid = ? && mode = 0", $assault->get("assaultid"))); $data = $statement->fetchColumn(); $tokens = explode(",", $data); foreach ($tokens as $token) { $valuePairs = explode(":", $token); if (trim($valuePairs[0]) == "galaxy") { $assault->set("galaxy", (int) $valuePairs[1]); } else { if (trim($valuePairs[0]) == "system") { $assault->set("system", (int) $valuePairs[1]); } else { if (trim($valuePairs[0]) == "position") { $assault->set("position", (int) $valuePairs[1]); } else { if (trim($valuePairs[0]) == "username") { $assault->set("planetname", Core::getLang()->get(substr($valuePairs[1], 6, -7))); } } } } } } $subject = getCoordLink($assault->get("galaxy"), $assault->get("system"), $assault->get("position")); $subject .= " " . $assault->get("planetname"); $message->set("subject", $subject); $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"; $message->set("message", "<div class=\"assault-report\" onclick=\"openWindow('" . $url . "');\">" . $label . "</div>"); } return $this; }
/** * @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; }
/** * Handles lost password requests. * * @param string $username Entered username * @param string $email Entered email address * * @return Bengine_Game_Account_Password_Lost */ public function __construct($username, $email) { $this->username = $username; $this->email = $email; $mode = 1; if (!$this->getUsername()) { $mode = 0; } if (!checkEmail($this->getEmail())) { $this->printIt("EMAIL_INVALID"); } $result = Core::getQuery()->select("user", array("userid", "username"), "", Core::getDB()->quoteInto("email = ?", $this->getEmail())); if ($result->rowCount() <= 0) { $this->printIt("EMAIL_NOT_FOUND"); } $row = $result->fetchRow(); $result->closeCursor(); Core::getLanguage()->assign("username", $row["username"]); Core::getLanguage()->assign("ipaddress", IPADDRESS); Hook::event("LostPassword", array($this, &$row)); if ($mode == 0) { $this->message = new Recipe_Email_Template("lost_password_username"); } else { if (Str::compare($this->getUsername(), $row["username"])) { $reactivate = BASE_URL . Core::getLang()->getOpt("langcode") . "/signup/activation/key:" . $this->getSecurityKey(); $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/password/set/key:" . $this->getSecurityKey() . "/user:"******"userid"]; Core::getTemplate()->assign("newPasswordUrl", $url); Core::getTemplate()->assign("reactivationUrl", $reactivate); $this->message = new Recipe_Email_Template("lost_password_password"); $this->setNewPw(); } else { $this->printIt("USERNAME_DOES_NOT_EXIST"); } } $this->sendMail($mode); return; }
/** * (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; }
/** * Removes inactive users. * * @return Bengine_Game_Cronjob_RemoveInactiveUser */ protected function removeInactiveUsers() { $deleteTime = TIME - Core::getConfig()->get("USER_DELETE_TIME") * 86400; $where = Core::getDB()->quoteInto("(u.last < ? OR (u.`delete` < '" . TIME . "' AND u.`delete` > '0')) AND ((u2g.usergroupid != '2' AND u2g.usergroupid != '4') OR u2g.usergroupid IS NULL)", $deleteTime); $result = Core::getQuery()->select("user u", "u.userid", "LEFT JOIN " . PREFIX . "user2group u2g ON (u2g.userid = u.userid)", $where); foreach ($result->fetchAll() as $row) { $userid = $row["userid"]; $_result = Core::getQuery()->select("planet", array("planetid", "ismoon"), "", Core::getDB()->quoteInto("userid = ?", $userid)); foreach ($_result->fetchAll() as $_row) { if (!$_row["ismoon"]) { deletePlanet($_row["planetid"], $userid, false); } } $_result->closeCursor(); $_result = Core::getQuery()->select("alliance", "aid", "", Core::getDB()->quoteInto("founder = ?", $userid)); if ($_row = $_result->fetchRow()) { deleteAlliance($_row["aid"]); } $_result->closeCursor(); Core::getQuery()->delete("user", "userid = ?", null, null, array($userid)); } $result->closeCursor(); return $this; }
/** * Switch to user account. * * @return Bengine_Game_Controller_Moderator */ protected function switchUserAction() { Core::getUser()->checkPermissions(array("CAN_SWITCH_USER")); $result = Core::getQuery()->select("user u", array("u.username", "p.password"), "LEFT JOIN " . PREFIX . "password p ON p.userid = u.userid", Core::getDB()->quoteInto("u.userid = ?", $this->userid)); if ($row = $result->fetchRow()) { $result->closeCursor(); $login = new Bengine_Game_Login($row["username"], $row["password"], "game", "trim"); $login->setCountLoginAttempts(false); $login->checkData(); $login->startSession(); } $result->closeCursor(); return $this; }
/** * Loads all research labs. * * @return void */ public static function loadReasearchLabs() { if (self::$labsLoaded) { return; } $where = Core::getDB()->quoteInto("p.userid = ?", Core::getUser()->get("userid")); $where .= Core::getDB()->quoteInto(" AND b2p.buildingid = ? AND ", 12); $where .= Core::getDB()->quoteInto("b2p.planetid != ?", Core::getUser()->get("curplanet")); $result = Core::getQuery()->select("building2planet b2p", array("b2p.level", "b2p.planetid"), "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = b2p.planetid)", $where, "b2p.level DESC"); foreach ($result->fetchAll() as $row) { self::$researchLabs[] = $row["level"]; } $result->closeCursor(); self::$labsLoaded = true; Hook::event("GameLoadResearchLabs", array(&self::$researchLabs)); return; }