示例#1
0
 /**
  * (non-PHPdoc)
  * @see TAuthManager::onAuthorize()
  */
 public function onAuthorize($param)
 {
     $application = $this->getApplication();
     //if this is a call back function and its session timed out/invalid, then redirect the page to homepage
     if ($this->getRequest()->contains(TPage::FIELD_CALLBACK_TARGET) && !$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress())) {
         // Create a callback adapter which counstructor will set up TCallbackReponseAdapter in the HttpResponse class adapter property
         $callbackAdapter = new TActivePageAdapter(new TPage());
         // Redirect (now the adapter is not null)
         $this->Response->redirect('/');
         // Create a html writer
         $writer = $this->Response->createHtmlWriter();
         // Render the response
         $callbackAdapter->renderCallbackResponse($writer);
         //Flush the output
         $application->flushOutput();
         //exit application do not process the futher part
         exit;
     }
     parent::onAuthorize($param);
     $u = Core::getUser();
     if ($u instanceof UserAccount) {
         $r = Core::getRole();
         Core::setUser($u, $r);
     }
 }
示例#2
0
 /**
  * Checks the event for validation.
  *
  * @return boolean
  */
 protected function _isValid()
 {
     if (isset($this->_target["userid"]) && $this->_target["userid"] == Core::getUser()->get("userid") && $this->_targetType != "tf") {
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Checks the event for validation.
  *
  * @return boolean
  */
 protected function _isValid()
 {
     if (!empty($this->_target["planetid"]) && !$this->isNewbieProtected() && $this->_target["userid"] != Core::getUser()->get("userid") && $this->_targetType != "tf" && $this->_checkProbes() && !$this->_target["umode"] && !Game::attackingStoppageEnabled()) {
         return true;
     }
     return false;
 }
示例#4
0
 /**
  * Checks the event for validation.
  *
  * @return boolean
  */
 protected function _isValid()
 {
     if (!empty($this->_target["userid"]) && $this->_target["userid"] != Core::getUser()->get("userid") && $this->_targetType != "tf" && !$this->_target["umode"] && $this->_relations->hasRelation($this->_target["userid"], $this->_target["aid"])) {
         return true;
     }
     return false;
 }
示例#5
0
 /**
  * @return Bengine_Admin_Controller_Abstract
  */
 protected function init()
 {
     if ($this->getParam("controller") != "auth" && !Core::getUser()->ifPermissions(array("HAS_AI_ACCESS"))) {
         $this->redirect("admin/auth");
     }
     return parent::init();
 }
示例#6
0
 /**
  * Getting the a HTML2PDF object from an entity
  *
  * @param BaseEntityAbstract $entity
  *
  * @throws CoreException
  * @return HTML2PDF
  */
 public static function getPDF(BaseEntityAbstract $entity, $method = '')
 {
     $class = get_class($entity);
     switch ($class) {
         case 'Order':
             if (trim($method) === 'docket') {
                 $url = 'printdocket/order/' . $entity->getId() . '.html';
             } else {
                 $url = 'print/order/' . $entity->getId() . '.html';
             }
             break;
         case 'PurchaseOrder':
             $url = 'print/purchase/' . $entity->getId() . '.html';
             break;
         case 'Kit':
             $url = 'print/kit/' . $entity->getId() . '.html';
             break;
         default:
             throw new CoreException('NO such a function to covert entity:' . $class);
     }
     $url .= "?user="******"HTTP_HOST"] . '/' . $url;
     $command = '/usr/local/bin/wkhtmltopdf -B 0 -T 0 --disable-javascript "' . $url . '" ' . ($file = '/tmp/' . md5(trim(microtime()) . Core::getUser()->getId()) . '.pdf');
     $output = '';
     exec($command, $output);
     sleep(1);
     if (!is_file($file)) {
         throw new Exception('Could NOT generate pdf @' . $file . ' with command:' . $command);
     }
     return $file;
 }
示例#7
0
 /**
  * @return bool
  */
 protected function _match()
 {
     if ($this->getUser()->get("hp") == Core::getUser()->get("curplanet")) {
         return Game::getPlanet()->getData("planetname") != Core::getLang()->get("HOME_PLANET");
     }
     $planet = Game::getModel("game/planet")->load($this->getUser()->get("hp"));
     return $planet->get("planetname") != Core::getLang()->get("HOME_PLANET");
 }
示例#8
0
 /**
  * @param integer $languageId
  * @param string $title
  * @param string $text
  * @return Bengine_Admin_Controller_News
  */
 protected function add($languageId, $title, $text)
 {
     $result = Core::getQuery()->select("news", array("MAX(sort_index) AS sort_index"), "", "", "", 1);
     $sortIndex = (int) $result->fetchColumn();
     $sortIndex++;
     $spec = array("language_id" => $languageId, "title" => $title, "text" => $text, "user_id" => Core::getUser()->get("userid"), "time" => TIME, "sort_index" => $sortIndex);
     Core::getQuery()->insert("news", $spec);
     return $this;
 }
示例#9
0
 public static function show($objectId, $jsonLast = null)
 {
     $db = Core::getDb();
     $user = Core::getUser();
     $comments = array();
     $qLast = $jsonLast ? "and c.id>" . $db->escape($jsonLast) : "";
     $q = $db->buildQuery("SELECT c.id, c.body, o.ctime, u.id as local_user_id, o.user_id, c.user_connection_id, con.service, con.external_id\n      FROM comments c\n      LEFT JOIN objects o ON o.object_id=c.object_id\n      LEFT JOIN connections con ON c.user_connection_id=con.id\n\t\t\tLEFT JOIN users u ON u.id=o.user_id\n      WHERE c.in_reply_to_id=%d {$qLast}\n      ORDER BY o.ctime ASC", $objectId);
     $rs = $db->query($q);
     if ($rs && $db->numrows($rs)) {
         while ($o = $db->fetchObject($rs)) {
             $commentAuthor = ObjectCache::getByType('\\Kiki\\User', $o->user_id ? $o->user_id : $o->local_user_id);
             if ($commentAuthor) {
                 if ($o->external_id) {
                     // HACK: should not always have to load this, but this is quicker than getStoredConnections for User 0
                     $connection = User\Factory::getInstance($o->service, $o->external_id, 0);
                     // $connection = $commentAuthor->getConnection($o->service. "_". $o->external_id, true);
                     if ($connection) {
                         $serviceName = $connection->serviceName();
                         $name = $connection->name();
                         $pic = $connection->picture();
                     } else {
                         $serviceName = 'None';
                         // SNH
                         $name = $commentAuthor->name();
                         $pic = $commentAuthor->picture();
                     }
                 } else {
                     $serviceName = 'None';
                     // Kiki
                     $name = $commentAuthor->name();
                     $pic = $commentAuthor->picture();
                 }
             } else {
                 $serviceName = 'None';
                 $name = "Anonymous";
                 $pic = null;
             }
             if ($jsonLast !== null) {
                 $comments[] = Comments::showSingle($objectId, $o->id, $name, $pic, $serviceName, $o->body, $o->ctime);
             } else {
                 $comment = array('objectId' => $objectId, 'id' => $o->id, 'name' => $name, 'pic' => $pic, 'type' => $serviceName, 'body' => $o->body, 'ctime' => $o->ctime, 'dateTime' => date("c", strtotime($o->ctime)), 'relTime' => Misc::relativeTime($o->ctime));
                 $comments[] = $comment;
             }
         }
     } else {
         if ($jsonLast === null) {
             $comments[] = Comments::showDummy($objectId);
         }
     }
     if ($jsonLast !== null) {
         return $comments;
     }
     $template = new Template('parts/comments');
     $template->assign('objectId', $objectId);
     $template->assign('comments', $comments);
     return $template->fetch();
 }
示例#10
0
 /**
  * @return Bengine_Admin_Controller_Auth
  */
 protected function logoutAction()
 {
     if (Core::getUser()->getSid()) {
         Core::getCache()->cleanUserCache(Core::getUser()->get("userid"));
         Core::getRequest()->setCookie("sid", "", TIME - 1);
     }
     $this->redirect("admin/auth");
     return $this;
 }
示例#11
0
 /**
  * constructor
  */
 public function __construct()
 {
     parent::__construct();
     if (!Core::getUser() instanceof UserAccount && get_class($this) !== 'LoginController') {
         if (isset($_REQUEST['user']) && isset($_REQUEST['pass']) && in_array(get_class($this), array('OrderPrintController', 'POPrintController')) && ($userAccount = UserAccount::getUserByUsernameAndPassword(trim($_REQUEST['user']), trim($_REQUEST['pass']), true)) instanceof UserAccount) {
             Core::setUser($userAccount);
         } else {
             $this->getResponse()->Redirect('/login.html');
         }
     }
 }
示例#12
0
 /**
  * Gets the user by id or current user
  *
  * @url GET /$id
  * @url GET /current
  */
 public function getUser($id = null)
 {
     if ($id) {
         $user = UserAccount::get($id);
         // possible user loading method
     } else {
         $user = Core::getUser();
     }
     return $user instanceof UserAccount ? $user->getJson() : array();
     // serializes object into JSON
 }
示例#13
0
 /**
  * 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;
 }
示例#14
0
 /**
  * Load the userAccount from the session
  *
  * @param unknown_type $data
  * @return unknown
  */
 public function loadFromString($data)
 {
     if (!empty($data)) {
         //			var_dump(unserialize($data));
         list($coreStuff, $str) = unserialize($data);
         Core::unserialize($coreStuff);
         $this->userAccount = Core::getUser();
         return parent::loadFromString($str);
     } else {
         return $this;
     }
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 /**
  * Initializing the newbie protection status.
  *
  * @return Bengine_Game_Model_User
  */
 public function initNewbieProtectionStatus()
 {
     $isProtected = isNewbieProtected(Core::getUser()->get("points"), $this->getPoints());
     if ($isProtected == 1) {
         $this->setNewbieStatus(" <span class=\"weak-player\">n</span> ");
         $this->setUsernameClass("weak-player");
     } else {
         if ($isProtected == 2) {
             $this->setNewbieStatus(" <span class=\"strong-player\">s</span> ");
             $this->setUsernameClass("strong-player");
         } else {
             $this->setNewbieStatus("");
         }
     }
     return $this;
 }
 /**
  * Displays the ads.
  *
  * @param string $event	Event mehtod that has been called
  * @param mixed $args	Arguments [ignored]
  *
  * @return Plugin_Commercials
  */
 public function __call($event, $args = null)
 {
     if (Core::getConfig()->get("COMMERCIALS_ENABLED") && !Core::getUser()->ifPermissions("HIDE_ADS")) {
         $this->loadAds();
         $event = Str::substring($event, 2);
         if (isset($this->ads[$event])) {
             $index = array_rand($this->ads[$event]);
             $ad = $this->ads[$event][$index];
             if (Core::getConfig()->get("COUNT_AD_VIEWS")) {
                 Core::getQuery()->update("ad", array("views" => $ad["views"] + 1), "ad_id = ?", array($ad["ad_id"]));
             }
             return htmlspecialchars_decode($ad["html_code"]);
         }
     }
     return null;
 }
示例#18
0
 /**
  * validate a user providing $username and $password
  *
  * @param string $username
  * @param string $password
  * @return true, if there is such a userAccount in the database;otherwise, false;
  */
 public function validateUser($username, $password)
 {
     if (!Core::getUser() instanceof UserAccount) {
         $userAccount = UserAccount::getUserByUsernameAndPassword($username, $password);
         if (!$userAccount instanceof UserAccount) {
             return false;
         }
         $role = null;
         if (!Core::getRole() instanceof Role) {
             if (count($roles = $userAccount->getRoles()) > 0) {
                 $role = $roles[0];
             }
         }
         Core::setUser($userAccount, $role);
     }
     return true;
 }
示例#19
0
 public function onLoad($param)
 {
     parent::onLoad($param);
     if (Core::getUser() instanceof UserAccount) {
         $this->getResponse()->redirect('/');
     }
     $cScripts = BPCPageAbstract::getLastestJS(get_class($this));
     if (isset($cScripts['js']) && ($lastestJs = trim($cScripts['js'])) !== '') {
         $this->getPage()->getClientScript()->registerScriptFile('pageJs', $this->publishAsset($lastestJs));
     }
     if (isset($cScripts['css']) && ($lastestCss = trim($cScripts['css'])) !== '') {
         $this->getPage()->getClientScript()->registerStyleSheetFile('pageCss', $this->publishAsset($lastestCss));
     }
     if (!$this->IsPostBack) {
         $this->username->focus();
         $this->errorDiv->visible = false;
     }
 }
示例#20
0
 private static function _setRunningUser($preFix = '', $debug = false)
 {
     self::_log('== Set Running User : '******'', $preFix);
     Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
     self::_log('UserAccount(ID=' . Core::getUser()->getId() . ')', '', $preFix . self::TAB);
     if (!isset(self::$_api['URL']) || ($apiUrl = trim(self::$_api['URL'])) === '') {
         throw new Exception('No API URL set!');
     }
     if (!isset(self::$_api['token']) || ($token = trim(self::$_api['token'])) === '') {
         self::_log('!! no token yet, need to get token.', '', $preFix . self::TAB);
         $url = $apiUrl . 'UserAccount/login';
         $data = json_encode(array('username' => Core::getUser()->getUserName(), 'password' => Core::getUser()->getPassword()));
         self::_postJson($url, $data, $preFix . self::TAB, $debug);
         if (trim(self::$_api['token']) === '') {
             throw new Exception('Invalid token');
         }
     }
 }
示例#21
0
 public function changePersonInfo($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->firstName) || ($firstName = trim($param->CallbackParameter->firstName)) === '') {
             throw new Exception("Invalid firstName!");
         }
         if (!isset($param->CallbackParameter->lastName) || ($lastName = trim($param->CallbackParameter->lastName)) === '') {
             throw new Exception("Invalid lastName!");
         }
         Core::getUser()->getPerson()->setFirstName($firstName)->setLastName($lastName)->save();
         Core::setUser(UserAccount::get(Core::getUser()->getId()), Core::getRole());
         $results['succ'] = true;
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
示例#22
0
 /**
  * Generate image tag in HTML.
  *
  * @param string $url		Image URL
  * @param string $title		Additional title
  * @param integer $width	Image width
  * @param integer $height	Image height
  * @param string $cssClass	Additional CSS class designation
  *
  * @return string			Image tag
  */
 public static function getImage($url, $title, $width = null, $height = null, $cssClass = "")
 {
     $isExternal = Link::isExternal($url);
     if (Core::getUser()->get("theme") != "" && !$isExternal) {
         $url = Core::getUser()->get("theme") . "img/" . $url;
     }
     if (!$isExternal) {
         $url = BASE_URL . "img/" . $url;
     } else {
         $url = BASE_URL . "img/remote.php?file=" . $url;
     }
     if (Str::length($cssClass) == 0) {
         $cssClass = self::IMAGE_CSS_CLASS;
     }
     $width = !is_null($width) ? " width=\"" . $width . "\"" : "";
     $height = !is_null($height) ? " height=\"" . $height . "\"" : "";
     $img = "<img src=\"" . $url . "\" title=\"" . $title . "\" alt=\"" . $title . "\"" . $width . $height . " class=\"" . $cssClass . "\" />";
     return $img;
 }
示例#23
0
 /**
  * @return Bengine_Game_Controller_Achievements
  */
 public function indexAction()
 {
     Core::getLanguage()->load(array("Achievements"));
     /* @var Bengine_Game_Model_User $user */
     $user = Application::getModel("game/user")->load(Core::getUser()->get("userid"));
     /* @var Bengine_Game_Model_Planet $planet */
     $planet = Application::getModel("game/planet")->load(Core::getUser()->get("curplanet"));
     /* @var Bengine_Game_Model_Collection_Achievement $achievements */
     $achievements = Application::getCollection("game/achievement");
     $achievements->addUserJoin(Core::getUser()->get("userid"))->addDefaultSorting();
     Core::getTemplate()->addLoop("achievements", $achievements);
     $unlocked = $achievements->checkForUnlockedAchievements($user, $planet);
     Core::getTemplate()->addLoop("unlocked", $unlocked);
     Core::getLanguage()->assign("leftXP", $user->getLeftXPForNextLevel());
     Core::getLanguage()->assign("nextLevel", $user->get("level") + 1);
     Core::getTemplate()->assign("user", $user);
     Core::getLang()->assign("xp", $user->get("xp"));
     Core::getLang()->assign("level", $user->get("level"));
     return $this;
 }
示例#24
0
 /**
  * Formats the message.
  *
  * @param Bengine_Game_Model_Message $message
  *
  * @return Bengine_Game_MessageFolder_Alliance
  */
 protected function _format(Bengine_Game_Model_Message $message)
 {
     $senderName = $message->get("username");
     $sender = !empty($senderName) ? Core::getLanguage()->getItem("ALLIANCE_GLOBAL_MAIL") . " (" . $senderName . ")" : Core::getLanguage()->getItem("ALLIANCE");
     $message->set("sender", $sender);
     $this->replaceForeignSessionId($message);
     if (Core::getUser()->get("aid")) {
         $subject = "RE: " . preg_replace("#((RE|FW):\\s)+#is", "\\1", $message->get("subject"));
         $subject = rawurlencode($subject);
         $linkUrl = "game/";
         if (URL_SESSION) {
             $linkUrl .= SID . "/";
         }
         $linkUrl .= "Alliance/GlobalMail/" . $subject;
         if (!empty($senderName)) {
             $replyImg = Image::getImage("pm.gif", Core::getLanguage()->getItem("REPLY_ALLIANCE_MAIL"));
             $message->set("reply_link", Link::get($linkUrl, $replyImg));
         }
     }
     return $this;
 }
示例#25
0
 /**
  * Returns formation data.
  *
  * @return array|bool
  */
 public function getSpecialData()
 {
     if ($this->_formations === null) {
         $this->_formations = false;
         if (!empty($this->_target)) {
             $joins = "LEFT JOIN " . PREFIX . "events e ON (e.eventid = fi.eventid)";
             $joins .= "LEFT JOIN " . PREFIX . "attack_formation af ON (e.eventid = af.eventid)";
             $select = array("af.eventid", "af.time");
             $where = Core::getDB()->quoteInto("fi.userid = ? AND af.time > ? AND e.destination = ?", array(Core::getUser()->get("userid"), TIME, $this->_target["planetid"]));
             if (!empty($this->_target["formation"])) {
                 $where .= Core::getDB()->quoteInto(" AND e.eventid = ?", $this->_target["formation"]);
             }
             $result = Core::getQuery()->select("formation_invitation fi", $select, $joins, $where);
             if ($row = $result->fetchRow()) {
                 $this->_formations = $row;
             }
             $result->closeCursor();
         }
     }
     return $this->_formations;
 }
示例#26
0
 /**
  * Switch to user account.
  *
  * @return Bengine_Game_Controller_Moderator
  */
 protected function switchUserAction()
 {
     Core::getUser()->checkPermissions(array("CAN_SWITCH_USER"));
     $result = Core::getQuery()->select("user u", array("u.username", "p.password"), "LEFT JOIN " . PREFIX . "password p ON p.userid = u.userid", Core::getDB()->quoteInto("u.userid = ?", $this->userid));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $login = new Bengine_Game_Login($row["username"], $row["password"], "game", "trim");
         $login->setCountLoginAttempts(false);
         $login->checkData();
         $login->startSession();
     }
     $result->closeCursor();
     return $this;
 }
示例#27
0
 /**
  * Getting the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function actionTask($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->taskId) || !($task = Task::get(trim($param->CallbackParameter->taskId))) instanceof Task) {
             throw new Exception('Invalid Task provided!');
         }
         if (!isset($param->CallbackParameter->method) || ($method = trim(trim($param->CallbackParameter->method))) === '' || !method_exists($task, $method)) {
             throw new Exception('Invalid Action Method!');
         }
         $comments = isset($param->CallbackParameter->comments) ? trim($param->CallbackParameter->comments) : '';
         $results['item'] = $task->{$method}(Core::getUser(), $comments)->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
示例#28
0
 /**
  * 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;
 }
示例#29
0
 /**
  * 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;
 }
示例#30
0
 /**
  * @return Bengine_Game_Controller_Shipyard
  */
 protected function cancelAction()
 {
     $events = Core::getRequest()->getPOST("shipyard_events");
     foreach ($events as $eventId) {
         $event = Game::getModel("game/event")->load((int) $eventId);
         if ($event->get("userid") == Core::getUser()->get("userid")) {
             Game::getEH()->removeEvent($event);
         }
     }
     $this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller"));
     return $this;
 }