/** * Displays the profile page for an user. * * @param integer $user_id * * @return Bengine_Game_Controller_Profile */ protected function pageAction($user_id) { $user = Game::getModel("game/user")->load($user_id); $profile = Game::getCollection("game/profile"); $profile->addUserFilter($user_id)->addSortIndex()->addListFilter(); $avatar = Game::getModel("game/profile")->loadByCode("AVATAR", $user_id); $about = Game::getModel("game/profile")->loadByCode("ABOUT_ME", $user_id); $this->assign("user", $user); $this->assign("aboutMe", $about->getData()); $this->assign("avatar", $avatar->getData()); $this->assign("username", $user->getUsername()); $this->assign("points", $user->getFormattedPoints()); $this->assign("status", $user->getStatusString()); $this->assign("rank", $user->getFormattedRank()); $this->assign("regdate", $user->getFormattedRegDate()); $this->assign("pm", $user->getPmLink()); $this->assign("moderate", $user->getModerateLink()); $this->assign("addToBuddylist", $user->getFriendLink()); $this->assign("pm", $user->getPmLink()); $this->assign("allianceName", $user->getAid() ? $user->getAlliance()->getPageLink() : " "); Core::getTPL()->addLoop("profile", $profile); $this->assign("canEdit", Core::getUser()->get("userid") == $user_id || Core::getUser()->ifPermissions(array("CAN_EDIT_PROFILES"))); $this->assign("editLink", Link::get("game/" . SID . "/Profile/Edit/" . $user_id, Core::getLang()->get("EDIT_PROFILE"))); Core::getLang()->assign("profileUsername", $user->getUsername()); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Friends */ protected function indexAction() { Core::getLanguage()->load(array("Statistics", "Buddylist")); if ($this->isPost()) { if ($this->getParam("delete")) { $this->remove($this->getParam("remove", array())); } if ($this->getParam("accept")) { $this->acceptRequest($this->getParam("relid")); } } $bl = array(); $select = array("b.relid", "b.friend1", "b.friend2", "b.accepted", "u1.username as user1", "u1.points as points1", "u1.last as lastlogin1", "u2.points as points2", "u2.username as user2", "u2.last as lastlogin2", "a1.tag as ally1", "a1.aid as allyid1", "a2.tag as ally2", "a2.aid as allyid2", "g1.galaxy as gala1", "g1.system as sys1", "g1.position as pos1", "g2.galaxy as gala2", "g2.system as sys2", "g2.position as pos2"); $joins = "LEFT JOIN " . PREFIX . "user u1 ON (u1.userid = b.friend1)"; $joins .= "LEFT JOIN " . PREFIX . "user u2 ON (u2.userid = b.friend2)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy g1 ON (g1.planetid = u1.hp)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy g2 ON (g2.planetid = u2.hp)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a1 ON (u2a1.userid = b.friend1)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a2 ON (u2a2.userid = b.friend2)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a1 ON (a1.aid = u2a1.aid)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a2 ON (a2.aid = u2a2.aid)"; $result = Core::getQuery()->select("buddylist b", $select, $joins, Core::getDB()->quoteInto("b.friend1 = ? OR b.friend2 = ?", Core::getUser()->get("userid")), "u1.points DESC, u2.points DESC, u1.username ASC, u2.username ASC"); foreach ($result->fetchAll() as $row) { Hook::event("ShowBuddyFirst", array(&$row)); if ($row["friend1"] == Core::getUser()->get("userid")) { if ($row["lastlogin2"] > TIME - 900) { $status = Image::getImage("on.gif", getTimeTerm(TIME - $row["lastlogin2"])); } else { $status = Image::getImage("off.gif", getTimeTerm(TIME - $row["lastlogin2"])); } $username = Link::get("game/" . SID . "/MSG/Write/" . rawurlencode($row["user2"]), Image::getImage("pm.gif", Core::getLanguage()->getItem("WRITE_MESSAGE"))) . " " . Link::get("game/" . SID . "/Profile/Page/" . $row["friend2"], $row["user2"]); $points = $row["points2"]; $position = getCoordLink($row["gala2"], $row["sys2"], $row["pos2"]); $ally = Link::get("game/" . SID . "/Alliance/Page/" . $row["allyid2"], $row["ally2"]); } else { if ($row["lastlogin1"] > TIME - 900) { $status = Image::getImage("on.gif", getTimeTerm(TIME - $row["lastlogin1"])); } else { $status = Image::getImage("off.gif", getTimeTerm(TIME - $row["lastlogin1"])); } $username = Link::get("game/" . SID . "/MSG/Write/" . rawurlencode($row["user1"]), Image::getImage("pm.gif", Core::getLanguage()->getItem("WRITE_MESSAGE"))) . " " . Link::get("game/" . SID . "/Profile/Page/" . $row["friend1"], $row["user1"]); $points = $row["points1"]; $position = getCoordLink($row["gala1"], $row["sys1"], $row["pos1"]); $ally = Link::get("game/" . SID . "/Alliance/Page/" . $row["allyid1"], $row["ally1"]); } $bl[$row["relid"]]["f1"] = $row["friend1"]; $bl[$row["relid"]]["f2"] = $row["friend2"]; $bl[$row["relid"]]["relid"] = $row["relid"]; $bl[$row["relid"]]["username"] = $username; $bl[$row["relid"]]["accepted"] = $row["accepted"]; $bl[$row["relid"]]["points"] = fNumber($points); $bl[$row["relid"]]["status"] = $status; $bl[$row["relid"]]["position"] = $position; $bl[$row["relid"]]["ally"] = $ally; Hook::event("ShowBuddyLast", array($row, &$bl)); } $result->closeCursor(); Core::getTPL()->addLoop("buddylist", $bl); return $this; }
/** * @param integer $groupid * @return Bengine_Admin_Controller_Usergroups */ protected function editAction($groupid) { if ($this->isPost() && $this->getParam("save_usergroup")) { $this->save($this->getParam("groupid"), $this->getParam("grouptitle"), $this->getParam("permissions", array())); } $permissions = array(); $result = Core::getQuery()->select("group2permission g2p", array("g2p.permissionid", "g2p.value", "g.grouptitle"), "LEFT JOIN " . PREFIX . "usergroup g ON (g.usergroupid = g2p.groupid)", Core::getDB()->quoteInto("g2p.groupid = ?", $groupid)); foreach ($result->fetchAll() as $row) { $grouptitle = $row["grouptitle"]; if ($row["value"]) { $permissions[] = $row["permissionid"]; } } if (empty($grouptitle)) { $grouptitle = ""; $result = Core::getQuery()->select("usergroup", "grouptitle", "", Core::getDB()->quoteInto("usergroupid = ?", $groupid)); if ($row = $result->fetchRow()) { $grouptitle = $row["grouptitle"]; } } Core::getTPL()->assign("grouptitle", $grouptitle); Core::getTPL()->assign("perms", $permissions); Admin::rebuildCache("perm"); 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; }
/** * 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; }
/** * Displays a message and shut program down. * * @param string $message Message to log * @param string $mode Log mode * * @return void */ public static function dieMessage($message, $mode = "error") { Core::getLanguage()->load("error"); $message = Core::getLanguage()->getItem($message); Core::getTPL()->addLogMessage("<div class=\"" . $mode . "\">" . $message . "</div>"); Core::getTemplate()->display("error"); exit; }
/** * Shows the pillory as Atom feed. * * @return Bengine_Comm_Controller_Pillory */ public function atomAction() { $this->assign("selfUrl", BASE_URL . "pillory/atom"); $this->assign("alternateUrl", BASE_URL . "pillory"); $this->assign("title", Core::getLang()->get("PILLORY")); Core::getTPL()->addLoop("feed", $this->getBans(0, self::MAX_FEED_ITEMS)); $this->setTemplate("atom"); return $this; }
/** * Sends a remote request. * * @param string $url Universe url * @param string $username Username * @param string $password Password * @param string $email E-Mail address * * @return Bengine_Comm_Controller_Password */ protected function _sendRemoteRequest($url, $username, $password, $email) { $url .= Core::getLang()->getOpt("langcode") . "/signup/checkuser"; $request = new Recipe_HTTP_Request($url, "Curl"); $request->getSession()->setRequestType("POST")->setPostArgs(array("username" => $username, "password" => $password, "email" => $email)); Core::getTPL()->sendHeader(); terminate($request->getResponse()); return $this; }
/** * 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; }
/** * Runs the community application. * * @return void */ public function run() { parent::run(); Core::getUser()->removeTheme(); Core::getTPL()->addHTMLHeaderFile("admin.css", "css"); Core::getLang()->load(array("AI_Global")); $menu = new Bengine_Admin_Menu(); Core::getTPL()->addLoop("menu", $menu->getMenu()); $this->dispatch(); return; }
/** * @return Bengine_Admin_Controller_Permissions */ protected function indexAction() { if ($this->getParam("add_permission")) { $this->add($this->getParam("permission")); } else { if ($this->getParam("update_permission")) { $this->update($this->getParam("delete"), $this->getParam("perm")); } } $perms = Core::getQuery()->select("permissions", array("permissionid", "permission"), "", "", "permission ASC"); Core::getTPL()->addLoop("perms", $perms->fetchAll()); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Resource */ protected function indexAction() { Hook::event("ShowResourcesBefore", array($this)); Core::getTPL()->addLoop("data", $this->data); $productFactor = (double) Core::getConfig()->get("PRODUCTION_FACTOR"); $isMoon = (bool) Game::getPlanet()->getData("ismoon"); // Basic prod $basicMetal = $isMoon ? 0 : Core::getOptions()->get("METAL_BASIC_PROD"); Core::getTPL()->assign("basicMetal", fNumber($basicMetal * $productFactor)); $basicSilicon = $isMoon ? 0 : Core::getOptions()->get("SILICON_BASIC_PROD"); Core::getTPL()->assign("basicSilicon", fNumber($basicSilicon * $productFactor)); $basicHydrogen = $isMoon ? 0 : Core::getOptions()->get("HYDROGEN_BASIC_PROD"); Core::getTPL()->assign("basicHydrogen", fNumber($basicHydrogen * $productFactor)); Core::getTPL()->assign("sats", Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID)); if (Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID) > 0) { Core::getTPL()->assign("satsNum", fNumber(Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID))); $solarSatProduction = Game::getPlanet()->getBuildingProd("energy", Bengine_Game_Planet::SOLAR_SAT_ID); Core::getTPL()->assign("satsProd", fNumber($solarSatProduction)); Core::getLang()->assign("prodPerSat", floor($solarSatProduction / Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID))); Core::getTPL()->assign("solar_satellite_prod", Game::getPlanet()->getData("solar_satellite_prod")); } // Storage capacity Core::getTPL()->assign("storageMetal", fNumber(Game::getPlanet()->getStorage("metal") / 1000) . "k"); Core::getTPL()->assign("storageSilicon", fNumber(Game::getPlanet()->getStorage("silicon") / 1000) . "k"); Core::getTPL()->assign("sotrageHydrogen", fNumber(Game::getPlanet()->getStorage("hydrogen") / 1000) . "k"); // Total prod Core::getTPL()->assign("totalMetal", fNumber(Game::getPlanet()->getProd("metal"))); Core::getTPL()->assign("totalSilicon", fNumber(Game::getPlanet()->getProd("silicon"))); Core::getTPL()->assign("totalHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen"))); Core::getTPL()->assign("totalEnergy", fNumber(Game::getPlanet()->getEnergy())); // Daily prod Core::getTPL()->assign("dailyMetal", fNumber(Game::getPlanet()->getProd("metal") * 24)); Core::getTPL()->assign("dailySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 24)); Core::getTPL()->assign("dailyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 24)); // Weekly prod Core::getTPL()->assign("weeklyMetal", fNumber(Game::getPlanet()->getProd("metal") * 168)); Core::getTPL()->assign("weeklySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 168)); Core::getTPL()->assign("weeklyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 168)); // Monthly prod Core::getTPL()->assign("monthlyMetal", fNumber(Game::getPlanet()->getProd("metal") * 720)); Core::getTPL()->assign("monthlySilicon", fNumber(Game::getPlanet()->getProd("silicon") * 720)); Core::getTPL()->assign("monthlyHydrogen", fNumber(Game::getPlanet()->getProd("hydrogen") * 720)); $selectBox = ""; for ($i = 10; $i >= 0; $i--) { $selectBox .= createOption($i * 10, $i * 10, 0); } Core::getTPL()->assign("selectProd", $selectBox); Hook::event("ShowResourcesAfter"); $this->assign("updateAction", BASE_URL . "game/" . SID . "/Resource/Update"); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Changelog */ protected function indexAction() { Core::getLang()->load("Main"); $meta = Game::getMeta(); define("BENGINE_REVISION", $meta["packages"]["bengine"]["game"]["revision"]); $ip = rawurlencode($_SERVER["SERVER_ADDR"]); $host = rawurlencode(HTTP_HOST); // Fetching changelog data from remote server $json = file_get_contents(VERSION_CHECK_PAGE . "?ip=" . $ip . "&host=" . $host . "&vers=" . Game::getVersion()); $data = json_decode($json, true); $latestVersion = $data["releases"][0]["versionNumber"]; $latestRevision = $data["releases"][0]["versionCode"]; Core::getTPL()->assign("latestVersion", $latestVersion); Core::getTPL()->assign("latestRevision", $latestRevision); Core::getTPL()->addLoop("releases", $data["releases"]); Core::getTPL()->assign("languageKey", Core::getLang()->getOpt("langcode")); 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; }
/** * Starts the application. * * @return void */ public function run() { Hook::event("PreRun"); self::loadMeta(); Core::getTPL()->assign("charset", CHARACTER_SET); Core::getTPL()->assign("langcode", Core::getLang()->getOpt("langcode")); Core::getTPL()->assign("formaction", Core::getRequest()->getRequestedUrl()); $pageTitle = array(); if ($titlePrefix = Core::getConfig()->get("TITLE_PREFIX")) { $pageTitle[] = $titlePrefix; } $pageTitle[] = Core::getConfig()->get("pagetitle"); if ($titleSuffix = Core::getConfig()->get("TITLE_SUFFIX")) { $pageTitle[] = $titleSuffix; } Core::getTPL()->assign("pageTitle", implode(Core::getConfig()->get("TITLE_GLUE"), $pageTitle)); Hook::event("PostRun"); return; }
/** * @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; }
/** * 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; }
/** * Starts the controller. * * @return Recipe_Controller_Abstract */ public function run() { $action = $this->_action; $method = $action . $this->getActionNameSuffix(); if (!method_exists($this, $method)) { $method = "noroute" . $this->getActionNameSuffix(); } $args = array(); for ($i = 1; $i < 5; $i++) { $args[] = $this->getParam(strval($i)); } call_user_func_array(array($this, $method), $args); if (!$this->_noDisplay) { Core::getTPL()->display($this->getTemplate($action), $this->_isAjax); } return $this; }
/** * 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; }
/** * Index action. * * @return Bengine_Game_Controller_Galaxy */ protected function indexAction() { if ($this->isPost()) { $this->setCoordinatesByPost($this->getParam("galaxy"), $this->getParam("system"), $this->getParam("submittype")); } $this->validateInputs()->subtractHydrogen(); // Star surveillance $canMonitorActivity = false; if (Game::getPlanet()->getBuilding("STAR_SURVEILLANCE") > 0) { $range = pow(Game::getPlanet()->getBuilding("STAR_SURVEILLANCE"), 2) - 1; $diff = abs(Game::getPlanet()->getData("system") - $this->system); if ($this->galaxy == Game::getPlanet()->getData("galaxy") && $range >= $diff) { $canMonitorActivity = true; } } Core::getTPL()->assign("canMonitorActivity", $canMonitorActivity); // Images $rockimg = Image::getImage("rocket.gif", Core::getLanguage()->getItem("ROCKET_ATTACK")); // Get sunsystem data $select = array("g.planetid", "g.position", "g.destroyed", "g.metal", "g.silicon", "g.moonid", "p.picture", "p.planetname", "p.last as planetactivity", "u.username", "u.usertitle", "u.userid", "u.points", "u.last as useractivity", "u.umode", "u.level", "m.planetid AS moon", "m.picture AS moonpic", "m.planetname AS moonname", "m.diameter AS moonsize", "m.temperature", "m.last as moonactivity", "a.tag", "a.name", "a.showmember", "a.homepage", "a.showhomepage", "u2a.aid", "b.to"); $joins = "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = g.planetid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = p.userid)"; $joins .= "LEFT JOIN " . PREFIX . "planet m ON (m.planetid = g.moonid)"; $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.userid = u.userid)"; $joins .= "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "ban_u b ON (b.userid = u.userid AND b.to > '" . TIME . "')"; $where = Core::getDB()->quoteInto("g.galaxy = ? AND g.system = ?", array($this->galaxy, $this->system)); $result = Core::getQuery()->select("galaxy g", $select, $joins, $where); $UserList = new Bengine_Game_User_List(); $UserList->setKey("position"); $UserList->setNewbieProtection(true); $UserList->setFetchRank(true); $UserList->setTagAsLink(false); $UserList->load($result); $sys = $UserList->getArray(); Hook::event("SolarSystemDataBefore", array($this, &$sys)); for ($i = 1; $i <= 15; $i++) { if (isset($sys[$i]) && !$sys[$i]["destroyed"]) { $sys[$i]["systempos"] = $i; if ($sys[$i]["tag"] != "") { $sys[$i]["allydesc"] = sprintf(Core::getLanguage()->getItem("GALAXY_ALLY_HEADLINE"), $sys[$i]["tag"], $sys[$i]["alliance_rank"]); } $sys[$i]["metal"] = fNumber($sys[$i]["metal"]); $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]); $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30); $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]); $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]); $sys[$i]["moonpicture"] = $sys[$i]["moonpic"] != "" ? Image::getImage("planets/small/s_" . $sys[$i]["moonpic"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["moonname"], 22, 22) : ""; $sys[$i]["moon"] = sprintf(Core::getLanguage()->getItem("MOON_DESC"), $sys[$i]["moonname"]); $sys[$i]["moonsize"] = fNumber($sys[$i]["moonsize"]); $sys[$i]["moontemp"] = fNumber($sys[$i]["temperature"]); if ($sys[$i]["moonactivity"] > $sys[$i]["planetactivity"]) { $activity = $sys[$i]["moonactivity"]; } else { $activity = $sys[$i]["planetactivity"]; } if ($activity > TIME - 900 && $sys[$i]["userid"] != Core::getUser()->get("userid")) { $sys[$i]["activity"] = "(*)"; } else { if ($activity > TIME - 3600 && $sys[$i]["userid"] != Core::getUser()->get("userid")) { $sys[$i]["activity"] = "(" . floor((TIME - $activity) / 60) . " min)"; } else { $sys[$i]["activity"] = ""; } } if (Game::getPlanet()->getBuilding("ROCKET_STATION") > 3 && $sys[$i]["userid"] != Core::getUser()->get("userid") && $this->inMissileRange()) { $sys[$i]["rocketattack"] = Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["planetid"], $rockimg); $sys[$i]["moonrocket"] = "<tr><td colspan=\"3\" class=\"center\">" . Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["moonid"] . "/1", Core::getLanguage()->getItem("ROCKET_ATTACK")) . "</td></tr>"; } else { $sys[$i]["rocketattack"] = ""; $sys[$i]["moonrocket"] = ""; } $sys[$i]["allypage"] = Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Page/" . $sys[$i]["aid"], Core::getLanguage()->getItem("ALLIANCE_PAGE"), 1)); if (($sys[$i]["showhomepage"] || $sys[$i]["aid"] == Core::getUser()->get("aid")) && $sys[$i]["homepage"] != "") { $sys[$i]["homepage"] = "<tr><td>" . Str::replace("'", "\\'", Link::get($sys[$i]["homepage"], Core::getLanguage()->getItem("HOMEPAGE"), 2)) . "</td></tr>"; } else { $sys[$i]["homepage"] = ""; } if ($sys[$i]["showmember"]) { $sys[$i]["memberlist"] = "<tr><td>" . Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Memberlist/" . $sys[$i]["aid"], Core::getLanguage()->getItem("SHOW_MEMBERLIST"), 3)) . "</td></tr>"; } $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25); } else { if (empty($sys[$i]["destroyed"])) { $sys[$i] = array(); $sys[$i]["destroyed"] = false; $sys[$i]["metal"] = 0; $sys[$i]["silicon"] = 0; $sys[$i]["debris"] = ""; $sys[$i]["picture"] = ""; $sys[$i]["planetname"] = ""; $sys[$i]["planetid"] = ""; } else { $sys[$i]["metal"] = fNumber($sys[$i]["metal"]); $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]); $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25); $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30); $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]); $sys[$i]["planetname"] = Core::getLanguage()->getItem("DESTROYED_PLANET"); $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]); } $sys[$i]["systempos"] = $i; $sys[$i]["userid"] = null; $sys[$i]["moon"] = ""; $sys[$i]["moonid"] = ""; $sys[$i]["username"] = ""; $sys[$i]["alliance"] = ""; $sys[$i]["activity"] = ""; $sys[$i]["moonpicture"] = ""; $sys[$i]["user_status_long"] = ""; } } ksort($sys); Hook::event("SolarSystemDataAfter", array($this, &$sys)); Core::getTPL()->assign("sendesp", Image::getImage("esp.gif", Core::getLanguage()->getItem("SEND_ESPIONAGE_PROBE"))); Core::getTPL()->assign("monitorfleet", Image::getImage("binocular.gif", Core::getLanguage()->getItem("MONITOR_FLEET_ACTIVITY"))); Core::getTPL()->assign("moon", Str::replace("\"", "", Image::getImage("planets/mond" . Core::getConfig()->get("PLANET_IMG_EXT"), Core::getLanguage()->getItem("MOON"), 75, 75))); Core::getTPL()->addLoop("sunsystem", $sys); Core::getTPL()->assign("debris", Str::replace("\"", "", Image::getImage("debris.jpg", Core::getLanguage()->getItem("DEBRIS"), 75, 75))); Core::getTPL()->assign("galaxy", $this->galaxy); Core::getTPL()->assign("system", $this->system); return $this; }
/** * Index action. * * @param integer $id Construction ID * * @return Bengine_Game_Controller_Construction_Edit */ protected function indexAction($id) { if ($this->isPost()) { if ($this->getParam("addreq")) { $this->addRequirement($id, $this->getParam("level"), $this->getParam("needs")); } if ($this->getParam("saveconstruction")) { $this->saveConstruction($this->getParam("name"), $this->getParam("name_id"), $this->getParam("allow_on_moon"), $this->getParam("desc"), $this->getParam("full_desc"), $this->getParam("prod_what"), $this->getParam("prod"), $this->getParam("cons_what"), $this->getParam("consumption"), $this->getParam("special"), $this->getParam("basic_metal"), $this->getParam("basic_silicon"), $this->getParam("basic_hydrogen"), $this->getParam("basic_energy"), $this->getParam("charge_metal"), $this->getParam("charge_silicon"), $this->getParam("charge_hydrogen"), $this->getParam("charge_energy")); } } $select = array("c.name AS name_id", "p.content AS name", "c.special", "c.allow_on_moon", "c.basic_metal", "c.basic_silicon", "c.basic_hydrogen", "c.basic_energy", "c.prod_metal", "c.prod_silicon", "c.prod_hydrogen", "c.prod_energy", "c.cons_metal", "c.cons_silicon", "c.cons_hydrogen", "c.cons_energy", "c.charge_metal", "c.charge_silicon", "c.charge_hydrogen", "c.charge_energy"); $joins = "LEFT JOIN " . PREFIX . "phrases p ON (p.title = c.name)"; $result = Core::getQuery()->select("construction c", $select, $joins, Core::getDB()->quoteInto("c.buildingid = ? AND p.languageid = ?", array($id, Core::getLanguage()->getOpt("languageid")))); if ($row = $result->fetchRow()) { $result->closeCursor(); Hook::event("EditUnitDataLoaded", array(&$row)); // Set production $prodWhat = ""; if (!empty($row["prod_metal"])) { $row["prod"] = $row["prod_metal"]; $prodWhat = "metal"; } else { if (!empty($row["prod_silicon"])) { $row["prod"] = $row["prod_silicon"]; $prodWhat = "silicon"; } else { if (!empty($row["prod_hydrogen"])) { $row["prod"] = $row["prod_hydrogen"]; $prodWhat = "hydrogen"; } else { if (!empty($row["prod_energy"])) { $row["prod"] = $row["prod_energy"]; $prodWhat = "energy"; } } } } // Set Consumption $consWhat = ""; if (!empty($row["cons_metal"])) { $row["consumption"] = $row["cons_metal"]; $consWhat = "metal"; } else { if (!empty($row["cons_silicon"])) { $row["consumption"] = $row["cons_silicon"]; $consWhat = "silicon"; } else { if (!empty($row["cons_hydrogen"])) { $row["consumption"] = $row["cons_hydrogen"]; $consWhat = "hydrogen"; } else { if (!empty($row["cons_energy"])) { $row["consumption"] = $row["cons_energy"]; $consWhat = "energy"; } } } } Core::getTPL()->assign("prodWhat", $this->getResourceSelect($prodWhat)); Core::getTPL()->assign("consWhat", $this->getResourceSelect($consWhat)); Core::getTPL()->assign($row); $result = Core::getQuery()->select("phrases", "content", "", Core::getDB()->quoteInto("languageid = ? AND title = ?", array(Core::getLanguage()->getOpt("languageid"), $row["name_id"] . "_DESC"))); $_row = $result->fetchRow(); $result->closeCursor(); Core::getTPL()->assign("description", Str::replace("<br />", "", $_row["content"])); $result = Core::getQuery()->select("phrases", "content", "", Core::getDB()->quoteInto("languageid = ? AND title = ?", array(Core::getLanguage()->getOpt("languageid"), $row["name_id"] . "_FULL_DESC"))); $_row = $result->fetchRow(); $result->closeCursor(); Core::getTPL()->assign("full_description", Str::replace("<br />", "", $_row["content"])); $req = array(); $i = 0; $result = Core::getQuery()->select("requirements r", array("r.requirementid", "r.needs", "r.level", "p.content"), "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = r.needs) LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", Core::getDB()->quoteInto("r.buildingid = ? AND p.languageid = ?", array($id, Core::getLanguage()->getOpt("languageid")))); foreach ($result->fetchAll() as $row) { $req[$i]["delete"] = Link::get("game/sid:" . SID . "/Construction_Edit/DeleteRequirement/" . $row["requirementid"] . "/" . $id, "[" . Core::getLanguage()->getItem("DELETE") . "]"); $req[$i]["name"] = Link::get("game/" . SID . "/Construction_Edit/Index/" . $row["needs"], $row["content"]); $req[$i]["level"] = $row["level"]; $i++; } Core::getTPL()->addLoop("requirements", $req); $const = array(); $i = 0; $result = Core::getQuery()->select("construction b", array("b.buildingid", "p.content"), "LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", "(b.mode = '1' OR b.mode = '2' OR b.mode = '5') AND p.languageid = " . Core::getDB()->quote(Core::getLanguage()->getOpt("languageid")), "p.content ASC"); foreach ($result->fetchAll() as $row) { $const[$i]["name"] = $row["content"]; $const[$i]["id"] = $row["buildingid"]; $i++; } $result->closeCursor(); Core::getTPL()->addLoop("constructions", $const); } return $this; }
/** * Generic template assignments. * * @return void */ protected static function globalTPLAssigns() { // JavaScript & CSS Core::getTPL()->addHTMLHeaderFile("game.css", "css"); // TODO: change to responsive Core::getTPL()->addHTMLHeaderFile("jquery-ui.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); Core::getTPL()->addHTMLHeaderFile("lib/jquery-ui.js", "js"); Core::getTPL()->addHTMLHeaderFile("main.js", "js"); // Set planets for right menu and fill planet stack. $planets = array(); $i = 0; $order = "p.sort_index ASC, p.planetid ASC"; $joins = "LEFT JOIN " . PREFIX . "galaxy g ON (g.planetid = p.planetid)"; $joins .= "LEFT JOIN " . PREFIX . "planet m ON (g.moonid = m.planetid)"; $atts = array("p.planetid", "p.ismoon", "p.planetname", "p.picture", "g.galaxy", "g.system", "g.position", "m.planetid AS moonid", "m.planetname AS moon", "m.picture AS mpicture"); $where = Core::getDB()->quoteInto("p.userid = ?", Core::getUser()->get("userid")); $where .= Core::getDB()->quoteInto(" AND p.ismoon = ?", 0); $result = Core::getQuery()->select("planet p", $atts, $joins, $where, $order); unset($order); foreach ($result->fetchAll() as $row) { $planets[$i] = $row; $coords = $row["galaxy"] . ":" . $row["system"] . ":" . $row["position"]; $coords = "[" . $coords . "]"; $planets[$i]["coords"] = $coords; $planets[$i]["picture"] = Image::getImage("planets/small/s_" . $row["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $row["planetname"] . " " . $coords, 60, 60); if ($row["moonid"]) { $planets[$i]["mpicture"] = Image::getImage("planets/small/s_" . $row["mpicture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $row["moon"] . " " . $coords, 20, 20); } self::$planetStack[] = $row["planetid"]; $i++; } $result->closeCursor(); Hook::event("GamePlanetList", array(&$planets)); Core::getTPL()->addLoop("planetHeaderList", $planets); // Menu Core::getTPL()->addLoop("navigation", new Bengine_Game_Menu("Menu")); // Assignments $planet = self::getPlanet(); Core::getTPL()->assign("themePath", Core::getUser()->get("theme") ? Core::getUser()->get("theme") : HTTP_HOST . REQUEST_DIR); Core::getTPL()->assign("planetImageSmall", Image::getImage("planets/small/s_" . $planet->getData("picture") . Core::getConfig()->get("PLANET_IMG_EXT"), $planet->getData("planetname"), 88, 88)); Core::getTPL()->assign("currentPlanet", Link::get("game/" . SID . "/Index/PlanetOptions", $planet->getData("planetname"))); Core::getTPL()->assign("currentCoords", $planet->getCoords()); // Show message if user is in vacation or deletion mode. $delete = false; if (Core::getUser()->get("delete") > 0) { $delete = Core::getLanguage()->getItem("ACCOUNT_WILL_BE_DELETED"); } $umode = false; if (Core::getUser()->get("umode")) { $umode = Core::getLanguage()->getItem("UMODE_ENABLED"); } Core::getTPL()->assign("delete", $delete); Core::getTPL()->assign("umode", $umode); return; }
/** * Shows all building information. * * @param integer $id * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Constructions */ protected function infoAction($id) { $select = array("name", "demolish", "basic_metal", "basic_silicon", "basic_hydrogen", "basic_energy", "prod_metal", "prod_silicon", "prod_hydrogen", "prod_energy", "special", "cons_metal", "cons_silicon", "cons_hydrogen", "cons_energy", "charge_metal", "charge_silicon", "charge_hydrogen", "charge_energy"); $result = Core::getQuery()->select("construction", $select, "", Core::getDB()->quoteInto("buildingid = ? AND (mode = '1' OR mode = '2' OR mode = '5')", $id)); if ($row = $result->fetchRow()) { $result->closeCursor(); Core::getLanguage()->load("info,Resource"); Hook::event("BuildingInfoBefore", array(&$row)); // Assign general building data Core::getTPL()->assign("buildingName", Core::getLanguage()->getItem($row["name"])); Core::getTPL()->assign("buildingDesc", Core::getLanguage()->getItem($row["name"] . "_FULL_DESC")); Core::getTPL()->assign("buildingImage", Image::getImage("buildings/" . $row["name"] . ".gif", Core::getLanguage()->getItem($row["name"]), null, null, "leftImage")); Core::getTPL()->assign("edit", Link::get("game/" . SID . "/Construction_Edit/Index/" . $id, "[" . Core::getLanguage()->getItem("EDIT") . "]")); // Production and consumption of the building $prodFormula = false; if (!empty($row["prod_metal"])) { $prodFormula = $row["prod_metal"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_silicon"])) { $prodFormula = $row["prod_silicon"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_hydrogen"])) { $prodFormula = $row["prod_hydrogen"]; $baseCost = $row["basic_hydrogen"]; } else { if (!empty($row["prod_energy"])) { $prodFormula = $row["prod_energy"]; $baseCost = $row["basic_energy"]; } else { if (!empty($row["special"])) { $prodFormula = $row["special"]; $baseCost = 0; } } } } } $consFormula = false; if (!empty($row["cons_metal"])) { $consFormula = $row["cons_metal"]; } else { if (!empty($row["cons_silicon"])) { $consFormula = $row["cons_silicon"]; } else { if (!empty($row["cons_hydrogen"])) { $consFormula = $row["cons_hydrogen"]; } else { if (!empty($row["cons_energy"])) { $consFormula = $row["cons_energy"]; } } } } // Production and consumption chart $chartType = false; if ($prodFormula != false || $consFormula != false) { $chart = array(); $chartType = "cons_chart"; if ($prodFormula && $consFormula) { $chartType = "prod_and_cons_chart"; } else { if ($prodFormula) { $chartType = "prod_chart"; } } if (Game::getPlanet()->getBuilding($id) - 7 < 0) { $start = 7; } else { $start = Game::getPlanet()->getBuilding($id); } $productionFactor = (double) Core::getConfig()->get("PRODUCTION_FACTOR"); if (!empty($row["prod_energy"])) { $productionFactor = 1; } $currentProduction = 0; if ($prodFormula) { $currentProduction = parseFormula($prodFormula, $baseCost, Game::getPlanet()->getBuilding($id)) * $productionFactor; } $currentConsumption = 0; if ($consFormula) { $currentConsumption = parseFormula($consFormula, 0, Game::getPlanet()->getBuilding($id)); } for ($i = $start - 7; $i <= Game::getPlanet()->getBuilding($id) + 7; $i++) { $chart[$i]["level"] = $i; $chart[$i]["s_prod"] = $prodFormula ? parseFormula($prodFormula, $baseCost, $i) * $productionFactor : 0; $chart[$i]["s_diffProd"] = $prodFormula ? $chart[$i]["s_prod"] - $currentProduction : 0; $chart[$i]["s_cons"] = $consFormula ? parseFormula($consFormula, 0, $i) : 0; $chart[$i]["s_diffCons"] = $consFormula ? $currentConsumption - $chart[$i]["s_cons"] : 0; $chart[$i]["prod"] = fNumber($chart[$i]["s_prod"]); $chart[$i]["diffProd"] = fNumber($chart[$i]["s_diffProd"]); $chart[$i]["cons"] = fNumber($chart[$i]["s_cons"]); $chart[$i]["diffCons"] = fNumber($chart[$i]["s_diffCons"]); } Hook::event("BuildingInfoProduction", array(&$chart)); Core::getTPL()->addLoop("chart", $chart); } if ($chartType) { Core::getTPL()->assign("chartType", "game/constructions/" . $chartType); } // Show demolish function $factor = floatval($row["demolish"]); if (Game::getPlanet()->getBuilding($id) > 0 && $factor > 0.0) { Core::getTPL()->assign("buildingLevel", Game::getPlanet()->getBuilding($id)); Core::getTPL()->assign("demolish", true); $metal = ""; $_metal = 0; $silicon = ""; $_silicon = 0; $hydrogen = ""; $_hydrogen = 0; if ($row["basic_metal"] > 0) { $_metal = 1 / $factor * parseFormula($row["charge_metal"], $row["basic_metal"], Game::getPlanet()->getBuilding($id)); $metal = Core::getLanguage()->getItem("METAL") . ": " . fNumber($_metal); } Core::getTPL()->assign("metal", $metal); if ($row["basic_silicon"] > 0) { $_silicon = 1 / $factor * parseFormula($row["charge_silicon"], $row["basic_silicon"], Game::getPlanet()->getBuilding($id)); $silicon = Core::getLanguage()->getItem("SILICON") . ": " . fNumber($_silicon); } Core::getTPL()->assign("silicon", $silicon); if ($row["basic_hydrogen"] > 0) { $_hydrogen = 1 / $factor * parseFormula($row["charge_hydrogen"], $row["basic_hydrogen"], Game::getPlanet()->getBuilding($id)); $hydrogen = Core::getLanguage()->getItem("HYDROGEN") . ": " . fNumber($_hydrogen); } Core::getTPL()->assign("hydrogen", $hydrogen); $time = getBuildTime($_metal, $_silicon, self::BUILDING_CONSTRUCTION_TYPE); Core::getTPL()->assign("dimolishTime", getTimeTerm($time)); $showLink = Game::getPlanet()->getData("metal") >= $_metal && Game::getPlanet()->getData("silicon") >= $_silicon && Game::getPlanet()->getData("hydrogen") >= $_hydrogen; if ($id == 12 && Game::getEH()->getResearchEvent()) { $showLink = false; } $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize(); if (($id == 8 || $id == 7) && $shipyardSize > 0) { $showLink = false; } Core::getTPL()->assign("showLink", $showLink && !$this->event && !Core::getUser()->get("umode")); Core::getTPL()->assign("demolishNow", Link::get("game/" . SID . "/Constructions/Demolish/{$id}", Core::getLanguage()->getItem("DEMOLISH_NOW"))); } else { Core::getTPL()->assign("demolish", false); } Hook::event("BuildingInfoAfter", array(&$row)); } else { $result->closeCursor(); throw new Recipe_Exception_Generic("Unkown building. You'd better don't manipulate the URL. We see everything ;)"); } return $this; }
/** * Add new page * * @return Bengine_Admin_Controller_Cms */ protected function newPageAction() { if ($this->getParam("add_page")) { $this->addPageAction($this->getParam("position"), $this->getParam("languageid"), $this->getParam("displayorder"), $this->getParam("title"), $this->getParam("label"), $this->getParam("link"), $this->getParam("content")); } $result = Core::getQuery()->select("languages", array("languageid", "title"), "", "", "title ASC"); Core::getTPL()->addLoop("langselection", $result->fetchAll()); return $this; }
/** * Shows form for planet options. * * @return Bengine_Game_Controller_Index */ protected function planetOptionsAction() { if ($this->isPost() && $this->getParam("changeplanetoptions")) { $this->changePlanetOptions($this->getParam("planetname"), $this->getParam("abandon"), $this->getParam("password")); } Core::getTPL()->assign("position", Game::getPlanet()->getCoords()); Core::getTPL()->assign("planetName", Game::getPlanet()->getData("planetname")); Hook::event("SHOW_PLANET_OPTIONS"); return $this; }
/** * 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; }
/** * 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; }
/** * @param integer $langid * @param integer $groupid * @return Bengine_Admin_Controller_Language */ protected function showfromgroupAction($langid, $groupid) { if ($this->getParam("save_phrases")) { $this->savePhrases($this->getParam("phraseid")); } $langs = array(); $result = Core::getQuery()->select("languages", array("languageid", "title"), "ORDER BY title ASC"); foreach ($result->fetchAll() as $row) { $id = $row["languageid"]; $langs[$id]["title"] = $row["title"]; } $groups = array(); $result = Core::getQuery()->select("phrasesgroups", array("phrasegroupid", "title"), "ORDER BY title ASC"); foreach ($result->fetchAll() as $row) { $id = $row["phrasegroupid"]; $groups[$id]["title"] = $row["title"]; } $phrases = array(); $where = Core::getDB()->quoteInto("p.languageid = ? AND p.phrasegroupid = ?", array($langid, $groupid)); $result = Core::getQuery()->select("phrases p", array("p.phraseid", "p.languageid", "p.phrasegroupid", "p.title", "p.content"), "", $where); foreach ($result->fetchAll() as $row) { $id = $row["phraseid"]; $phrases[$id]["phraseid"] = $id; $phrases[$id]["title"] = $row["title"]; $phrases[$id]["content"] = $row["content"]; $phrases[$id]["delete"] = Link::get("admin/language/deletephrase/" . $langid . "/" . $groupid . "/" . $id . "/", Core::getLanguage()->getItem("Delete")); $phrases[$id]["lang"] = ""; foreach ($langs as $key => $value) { $phrases[$id]["lang"] .= createOption($key, $value["title"], $key == $row["languageid"] ? 1 : 0); } $phrases[$id]["groups"] = ""; foreach ($groups as $key => $value) { $phrases[$id]["groups"] .= createOption($key, $value["title"], $key == $row["phrasegroupid"] ? 1 : 0); } } Core::getTPL()->addLoop("vars", $phrases); return $this; }
/** * Shows all sessions for the user. * * @return Bengine_Game_Controller_Moderator */ protected function sessionsAction() { /* @var Bengine_Game_Model_Collection_SessionLog $sessionLog */ $sessionLog = Game::getCollection("game/sessionLog"); $sessionLog->addTimeOrder(); if ($ip = $this->getParam("ip")) { $sessionLog->addIpFilter($ip); } else { if ($id = $this->getParam("id")) { $sessionLog->addUserFilter($id); } else { $this->redirect("game/" . SID . "/Index"); } } Core::getTPL()->addLoop("sessionLog", $sessionLog); return $this; }
/** * @param integer $cronid * @return Bengine_Admin_Controller_Cronjob */ protected function editAction($cronid) { $result = Core::getQuery()->select("cronjob", array("class", "month", "day", "weekday", "hour", "minute"), "", Core::getDB()->quoteInto("cronid = ?", $cronid)); if ($row = $result->fetchRow()) { if ($this->getParam("edit_cronjob")) { $this->save($cronid, $this->getParam("month"), $this->getParam("day"), $this->getParam("weekday"), $this->getParam("hour"), $this->getParam("minute"), $this->getParam("class")); } $selMin = explode(",", $row["minute"]); $selHour = explode(",", $row["hour"]); $selWD = explode(",", $row["weekday"]); $selDay = explode(",", $row["day"]); $selMon = explode(",", $row["month"]); $minute = ""; $hour = ""; $weekday = ""; $day = ""; $month = ""; $i = 0; while ($i < 60) { $minute .= createOption($i, $i, in_array($i, $selMin) ? 1 : 0); $i += 5; } for ($i = 0; $i < 24; $i++) { $hour .= createOption($i, $i, in_array($i, $selHour) ? 1 : 0); } $wds = array(1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"); for ($i = 1; $i <= 7; $i++) { $weekday .= createOption($i, $wds[$i], in_array($i, $selWD) ? 1 : 0); } for ($i = 1; $i <= 31; $i++) { $day .= createOption($i, $i, in_array($i, $selDay) ? 1 : 0); } for ($i = 1; $i <= 12; $i++) { $month .= createOption($i, $i, in_array($i, $selMon) ? 1 : 0); } Core::getTPL()->assign("minute", $minute); Core::getTPL()->assign("hour", $hour); Core::getTPL()->assign("weekday", $weekday); Core::getTPL()->assign("day", $day); Core::getTPL()->assign("month", $month); Core::getTPL()->assign("class", $row["class"]); } return $this; }