/** * (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; }
/** * 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; }
/** * 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; }
/** * Combat report action. * * @return Bengine_Comm_Controller_Combat */ public function reportAction() { if (!defined("SID")) { define("SID", ""); } Core::getLanguage()->load(array("info", "AssaultReport")); Core::getTPL()->clearHTMLHeaderFiles(); Core::getTPL()->addHTMLHeaderFile("game.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); $select = new Recipe_Database_Select(); $select->from(array("a" => "assault"))->join(array("p" => "planet"), "p.planetid = a.planetid")->attributes(array("a" => array("report"), "p" => array("planetname")))->where(array("a" => "assaultid"), $this->getParam("1"))->where(array("a" => "key"), $this->getParam("2")); $result = $select->getStatement(); $row = $result->fetchRow(); if ($row) { $report = $row["report"]; $report = preg_replace_callback("/\\{lang}([^\"]+)\\{\\/lang}/siU", function ($matches) { return Core::getLanguage()->getItem($matches[1]); }, $report); $report = preg_replace_callback("/\\{embedded\\[([^\"]+)]}(.*)\\{\\/embedded}/siU", function ($matches) { return sprintf(Core::getLanguage()->getItem($matches[1]), $matches[2]); }, $report); Hook::event("ShowCombatReport", array(&$report, &$row)); $this->assign("report", $report); $this->assign("planetName", $row["planetname"]); $this->setIsAjax(); } else { $this->setNoDisplay(true); } return $this; }
/** * Initialize a cURL session. * * @return Recipe_HTTP_Session_Curl */ protected function init() { $this->resource = @curl_init(); if (!$this->resource) { throw new Recipe_Exception_Generic("Connection faild via cURL request."); } Hook::event("HttpRequestInitFirst", array($this)); @curl_setopt($this->resource, CURLOPT_RETURNTRANSFER, true); @curl_setopt($this->resource, CURLOPT_TIMEOUT, self::TIMEOUT); $url = $this->webpage; if (count($this->getGetArgs()) > 0) { $url .= "?" . $this->getGetArgs(false); } @curl_setopt($this->resource, CURLOPT_URL, $url); if ($this->getRequestType() == "GET") { @curl_setopt($this->resource, CURLOPT_HTTPGET, true); } else { if ($this->getRequestType() == "POST") { @curl_setopt($this->resource, CURLOPT_POST, true); @curl_setopt($this->resource, CURLOPT_POSTFIELDS, $this->getPostArgs(false)); } else { if ($this->getRequestType() == "PUT") { @curl_setopt($this->resource, CURLOPT_PUT, true); } } } $this->response = curl_exec($this->resource); $this->errorNo = curl_errno($this->resource); if ($this->errorNo) { $this->error = curl_error($this->resource); throw new Recipe_Exception_Generic("There is an error occured in cURL session (" . $this->errorNo . "): " . $this->error); } Hook::event("HttpRequestInitLast", array($this)); return $this; }
/** * Formats a message. * * @param string $message Raw log message * @param string $mode Log mode * * @return string Formatted message */ public static function getMessageField($message, $mode = "error") { Core::getLanguage()->load("error"); $message = Core::getLanguage()->getItem($message); $message = "<span class=\"field_" . $mode . "\">" . $message . "</span>"; Hook::event("MessageField", array(&$message)); return $message; }
/** * 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; }
/** * Constructor: Set basic variables. * * @return \Recipe_Cache */ public function __construct() { $this->cacheDir = APP_ROOT_DIR . "var/cache/"; $this->setLanguageCacheDir("language/"); $this->setTemplateCacheDir("templates/"); $this->setSessionCacheDir("sessions/"); $this->setPermissionCacheDir("permissions/"); $this->cacheFileClose = "\n\n// Cache-Generator finished\n?>"; Hook::event("CacheConstruct", array($this)); return; }
/** * Overriding no route action to check for CMS pages. * * @return Bengine_Comm_Controller_Index */ protected function norouteAction() { if ($row = Comm::getCMS()->getPage($this->_action)) { Hook::event("ShowCMSPage", array(&$row)); $this->assign("page", $row["title"]); $this->assign("content", $row["content"]); $this->setTemplate("cms_page"); } else { parent::norouteAction(); } 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("EhAttack", array($event, &$data, $this)); $statement = Core::getQuery()->select("assault", array("assaultid"), "", "planetid = ? AND running = 1", "", "", "", "", array($event->get("destination"))); if ($statement->fetchRow()) { $event->set("prev_rc", null); $event->save(); return $this; } $assault = new Bengine_Game_Assault($event["destination"], $event["destination_user_id"], $event); $assault->addParticipant(1, $event["userid"], $event["planetid"], $event["time"], $data)->startAssault($data["galaxy"], $data["system"], $data["position"])->finish(); 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; }
/** * Generates the menu items. * * @return Bengine_Game_Menu */ protected function generateMenu() { $this->menu = array(); uasort($this->data, array($this, "sort")); foreach ($this->data as $first) { uasort($first["items"], array($this, "sort")); $subMenu = array(); foreach ($first["items"] as $second) { $subMenu[] = array("attributes" => isset($second["attributes"]) ? $this->getHtmlAttributesFromArray($second["attributes"]) : "", "link" => $this->getLink($second)); } $this->menu[] = array("attributes" => isset($first["attributes"]) ? $this->getHtmlAttributesFromArray($first["attributes"]) : "", "link" => isset($first["label"]) ? $this->getLabel($first["label"]) : "", "children" => $subMenu); } Hook::event("GenerateMenu", array(&$this->menu, $this)); 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; }
/** * (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("EhAllianceAttack", array($event, &$data, $this)); $assault = new Bengine_Game_Assault($event->getDestination(), $event->getDestinationUserId(), $event); $assault->addParticipant(Bengine_Game_Assault_Participant::ATTACKER_MODE, $event->getUserid(), $event->getPlanetid(), $event->getTime(), $data); // Load allied fleets $allies = Application::getCollection("game/event")->addParentIdFilter($event->getEventid()); foreach ($allies as $ally) { $assault->addParticipant(Bengine_Game_Assault_Participant::ATTACKER_MODE, $ally->getUserid(), $ally->getPlanetid(), $event->getTime(), $ally->getData()); } $assault->startAssault($event->getGalaxy2(), $event->getSystem2(), $event->getPosition2())->finish(); Core::getQuery()->delete("formation_invitation", "eventid = ?", null, null, array($event->getEventid())); Core::getQuery()->delete("attack_formation", "eventid = ?", null, null, array($event->getEventid())); return $this; }
/** * Perfom log out proccess. * * @return Bengine_Game_Controller_Logout */ protected function indexAction() { Hook::event("DoLogout"); Core::getCache()->cleanUserCache(Core::getUser()->get("userid")); Core::getQuery()->update("sessions", array("logged" => 0), "userid = ?", array(Core::getUser()->get("userid"))); if (Core::getConfig()->exists("SESSION_SAVING_DAYS")) { $days = (int) Core::getConfig()->get("SESSION_SAVING_DAYS"); } else { $days = self::SESSION_SAVING_DAYS; } $deleteTime = TIME - 86400 * $days; Core::getQuery()->delete("sessions", "time < ?", null, null, array($deleteTime)); Game::unlock(); $this->redirect(BASE_URL); 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; }
/** * Index action. * * @return Bengine_Game_Controller_Statistics */ protected function indexAction() { Hook::event("StatisticsStart"); $this->loadTotalUnits(Bengine_Game_Controller_Shipyard::FLEET_CONSTRUCTION_TYPE); $this->loadTotalUnits(Bengine_Game_Controller_Shipyard::DEFENSE_CONSTRUCTION_TYPE); $statistics = array("totalMetal" => $this->fetchTotalMetal(), "totalSilicon" => $this->fetchTotalSilicon(), "totalHydrogen" => $this->fetchTotalHydrogen(), "totalPlayers" => fNumber($this->fetchTotalPlayers()), "totalPlanets" => fNumber($this->fetchTotalPlanets()), "totalMoons" => fNumber($this->fetchTotalPlanets(1)), "totalOnline" => fNumber($this->fetchOnlinePlayers()), "totalDebrisFields" => fNumber($this->fetchDebrisFields()), "totalRecentAssaults" => fNumber($this->fetchRecentAssaults())); $totalRessources = $statistics["totalSilicon"] + $statistics["totalHydrogen"] + $statistics["totalMetal"]; $statistics["percentMetal"] = fNumber($statistics["totalMetal"] / $totalRessources * 100, 2); $statistics["percentSilicon"] = fNumber($statistics["totalSilicon"] / $totalRessources * 100, 2); $statistics["percentHydrogen"] = fNumber($statistics["totalHydrogen"] / $totalRessources * 100, 2); $statistics["totalMetal"] = fNumber($statistics["totalMetal"] / 1000000, 2); $statistics["totalSilicon"] = fNumber($statistics["totalSilicon"] / 1000000, 2); $statistics["totalHydrogen"] = fNumber($statistics["totalHydrogen"] / 1000000, 2); Hook::event("StatisticsFinished", array(&$statistics)); Core::getTPL()->assign($statistics); Core::getTPL()->addLoop("ships", $this->unitCount); return $this; }
/** * Search in database for expired cron tasks and execute them. * * @throws Recipe_Exception_Generic * @return Recipe_Cron */ public function exeCron() { $select = array("cronid", "class", "month", "day", "weekday", "hour", "minute", "xtime", "active"); $_result = Core::getQuery()->select("cronjob", $select, "", "(xtime <= " . TIME . " OR xtime IS NULL) AND active = '1'"); foreach ($_result->fetchAll() as $_row) { $class = explode("/", $_row["class"]); $class = $class[0] . "/cronjob_" . $class[1]; $cronjobObj = Application::factory($class); if ($cronjobObj instanceof Recipe_CronjobAbstract) { Hook::event("ExecuteCronjob", array($this, &$_row, $cronjobObj)); $cronjobObj->execute($_row["cronid"], $_row["xtime"], $this->calcNextExeTime($_row)); } else { throw new Recipe_Exception_Generic("Cannot execute cron job \"{$_row["class"]}\"."); } } $_result->closeCursor(); 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; }
/** * Deletes old sessions. * * @param integer $deletionDays Deletion time in days * @return Bengine_Game_Cronjob_CleanSessions */ protected function clearSessions($deletionDays) { $deletionDays = (int) $deletionDays; Hook::event("CleanSessionsBegin"); // Delete all contents from session cache $sessionCache = APP_ROOT_DIR . "var/cache/sessions/"; File::rmDirectoryContent($sessionCache); // Disable sessions Core::getQuery()->update("sessions", array("logged" => 0), "logged = '1'"); // Delete old sessions $deleteTime = TIME - $deletionDays * 86400; Core::getQuery()->delete("sessions", "time < ?", null, null, array($deleteTime)); // Log user count $sql = "INSERT INTO `" . PREFIX . "user_counter`\r\n\t\t(`count`, `day`, `week`, `day_of_week`, `month`, `day_of_month`, `year`, `time`) VALUES\r\n\t\t((SELECT COUNT(`userid`) FROM `" . PREFIX . "user` LIMIT 1), DAYOFYEAR(CURDATE()), WEEK(CURDATE()), DAYOFWEEK(CURDATE()), MONTH(CURDATE()), DAYOFMONTH(CURDATE()), YEAR(CURDATE()), UNIX_TIMESTAMP())"; Core::getDatabase()->query($sql); // Clean combats running flag Core::getQuery()->update("assault", array("running" => 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; }
/** * @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; }
/** * 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; }
/** * (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; }
/** * @param Bengine_Game_Model_Event $event * @param array $data * @return Bengine_Game_EventHandler_Handler_Construct_Shipyard */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EhAddShip", array($event, &$data, $this)); if (!$event->getPlanetid()) { return $this; } // >>> This ensures compatibility with 0.42 and older. Will be removed in 0.50. if (empty($data["one"])) { return $this->_executeOld($event, $data); } // <<< End 0.42 compatibility $timespan = TIME - $event->get("time"); $quantity = floor($timespan / $data["one"]) + 1; $quantity = min($quantity, $data["quantity"]); $data["quantity"] -= $quantity; $points = $data["points"] * $quantity; $result = Core::getQuery()->select("unit2shipyard", "quantity", "", Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($data["buildingid"], $event->getPlanetid()))); if ($result->rowCount() > 0) { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity + ? WHERE planetid = ? AND unitid = ?", array($quantity, $event->getPlanetid(), $data["buildingid"])); } else { Core::getQuery()->insert("unit2shipyard", array("unitid" => $data["buildingid"], "planetid" => $event->getPlanetid(), "quantity" => $quantity)); } $result->closeCursor(); $fpoints = $quantity; $dpoints = 0; if ($event["mode"] == 5) { $fpoints = 0; $dpoints = $quantity; } Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, fpoints = fpoints + ?, dpoints = dpoints + ? WHERE userid = ?", array($points, $fpoints, $dpoints, $event->getUserid())); if ($data["quantity"] > 0) { $event->set(array("start" => TIME, "time" => $event->get("time") + $data["one"] * $quantity, "prev_rc" => null, "data" => $data)); $event->save(); } return $this; }
/** * 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; }
/** * 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; }