/** * Displays the planet search result. * * @return Bengine_Game_Controller_Search */ protected function planetSearch() { $sr = array(); $i = 0; $select = array("u.userid", "u.username", "u.usertitle", "u.points", "u.last as useractivity", "u.umode", "u.level", "u.hp", "b.to", "p.planetid", "p.planetname", "p.ismoon", "g.galaxy", "g.system", "g.position", "a.aid", "a.tag", "a.name", "gm.galaxy as moongala", "gm.system as moonsys", "gm.position as moonpos"); $joins = "LEFT JOIN " . PREFIX . "user u ON (p.userid = u.userid)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy g ON (g.planetid = p.planetid)"; $joins .= "LEFT JOIN " . PREFIX . "galaxy gm ON (gm.moonid = p.planetid)"; $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)"; $result = Core::getQuery()->select("planet p", $select, $joins, Core::getDB()->quoteInto("p.planetname LIKE ? AND u.username IS NOT NULL", $this->searchItem->get()), "p.planetname ASC, u.username ASC", "25", "u.userid"); foreach ($result->fetchAll() as $row) { $sr[$i] = $row; if ($row["planetid"] == $row["hp"]) { $p_addition = " (HP)"; } else { if ($row["ismoon"]) { $p_addition = " (" . Core::getLanguage()->getItem("MOON") . ")"; } else { $p_addition = ""; } } $sr[$i]["planetname"] = $row["planetname"] . $p_addition; $i++; } $result->closeCursor(); $UserList = new Bengine_Game_User_List(); $UserList->setByArray($sr); Hook::event("SearchResultPlanet", array($UserList)); Core::getTPL()->addLoop("result", $UserList->getArray()); Core::getTPL()->addLoop("searchSuggestions", $this->getSimilarWords($this->searchItem, "planet")); $this->setTemplate("search/player"); 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; }
/** * Displays player ranking table. * * @param integer $type Type of ranking (Fleet, Research, Points) * @param integer $pos Position to start ranking * * @return Bengine_Game_Controller_Ranking */ protected function playerRanking($type, $pos) { $where = Core::getDB()->quoteInto("(`username` < ? AND `{$type}` >= {points}) OR `{$type}` > {points}", array(Core::getUser()->get("username"))); $where = str_replace("{points}", (double) Core::getUser()->get($type), $where); $result = Core::getQuery()->select("user", array("COUNT(`userid`)+1 AS rank"), "", $where, "", 1); $rank = (int) $result->fetchColumn(); $currentPage = ceil($rank / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); $result = Core::getQuery()->select("user u", "userid", "", "u.userid > '0'"); $pages = ceil($result->rowCount() / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); if (!is_numeric($pos)) { $pos = $currentPage; } else { if ($pos > $pages) { $pos = $pages; } else { if ($pos < 1) { $pos = 1; } } } $ranks = ""; for ($i = 0; $i < $pages; $i++) { $n = $i * Core::getOptions()->get("USER_PER_PAGE") + 1; if ($i + 1 == $pos) { $s = 1; } else { $s = 0; } if ($i + 1 == $currentPage) { $c = "ownPosition"; } else { $c = ""; } $ranks .= createOption($i + 1, fNumber($n) . " - " . fNumber($n + Core::getOptions()->get("USER_PER_PAGE") - 1), $s, $c); } Core::getTPL()->assign("rankingSel", $ranks); $rank = abs(($pos - 1) * Core::getOptions()->get("USER_PER_PAGE")); $max = Core::getOptions()->get("USER_PER_PAGE"); $select = array("u.userid", "u.username", "u.usertitle", "u.last as useractivity", "u.umode", "u.level", "g.galaxy", "g.system", "g.position", "a.aid", "a.tag", "a.name", "b.to"); if ($type != "level") { $orderType = "points"; if ($this->average) { $select[] = "(u." . $type . "/(('" . TIME . "' - u.regtime)/60/60/24)) AS points"; } else { $select[] = "u." . $type . " AS points"; } } else { $orderType = "u.level"; $select[] = "u.points"; } $joins = "LEFT JOIN " . PREFIX . "galaxy g ON u.hp = g.planetid "; $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 . "')"; $result = Core::getQuery()->select("user u", $select, $joins, "u.userid > '0'", "{$orderType} DESC, u.username ASC", $rank . ", " . $max, "u.userid"); // Creating the user list object to handle the output $UserList = new Bengine_Game_User_List($result, $rank); Hook::event("ShowRankingPlayer", array($UserList)); Core::getTPL()->addLoop("ranking", $UserList->getArray()); $this->setTemplate("ranking/player"); return $this; }