/** * Recalculate the points. * * @return Bengine_Game_Cronjob_PointClean */ protected function cleanPoints() { Hook::event("CleanPointsBegin"); $_result = Core::getQuery()->select("user", "userid"); foreach ($_result->fetchAll() as $_row) { $points = 0; $fpoints = 0; $dpoints = 0; $result = Core::getQuery()->select("planet", "planetid", "", Core::getDB()->quoteInto("userid = ?", $_row["userid"])); foreach ($result->fetchAll() as $row) { $points += Bengine_Game_PointRenewer::getBuildingPoints($row["planetid"]); $points += Bengine_Game_PointRenewer::getFleetPoints($row["planetid"]); $fpoints += Bengine_Game_PointRenewer::getFleetPoints_Fleet($row["planetid"]); $dpoints += Bengine_Game_PointRenewer::getDefensePoints($row["planetid"]); } $result->closeCursor(); $points += Bengine_Game_PointRenewer::getResearchPoints($_row["userid"]); $points += Bengine_Game_PointRenewer::getFleetEventPoints($_row["userid"]); $fpoints += Bengine_Game_PointRenewer::getFleetEvent_Fleet($_row["userid"]); $rpoints = Bengine_Game_PointRenewer::getResearchPoints_r($_row["userid"]); Core::getQuery()->update("user", array("points" => $points, "fpoints" => $fpoints, "rpoints" => $rpoints, "dpoints" => $dpoints), "userid = ?", array($_row["userid"])); } $_result->closeCursor(); return $this; }
/** * Checks if the given key is ok for the userid. * * @param integer $user_id * @param string $key * * @return boolean */ public function checkKey($user_id, $key) { $where = Core::getDB()->quoteInto("user_id = ?", $user_id); $where .= Core::getDB()->quoteInto(" AND feed_key = ?", $key); $result = Core::getQuery()->select("feed_keys", array("feed_key"), "", $where); return $result->rowCount() > 0; }
/** * Deletes old combats. * * @param integer $days Storing time of combats * * @return integer Number of delteted combats */ protected function cleanCombats($days) { $days = (int) $days; $time = TIME - 86400 * $days; Core::getQuery()->delete("assault", "time <= ?", null, null, array($time)); return Core::getDatabase()->affectedRows(); }
/** * Rebuilds a cache object. * * @param string $type * @param mixed $options * * @return void */ public static function rebuildCache($type, array $options = null) { switch ($type) { case "config": Core::getCache()->buildConfigCache(); break; case "lang": if ($options !== null && !empty($options["language"])) { $result = Core::getQuery()->select("languages", array("langcode"), "", Core::getDB()->quoteInto("languageid = ?", $options["language"])); $langcode = $result->fetchColumn(); if (!empty($options["group"])) { $result = Core::getQuery()->select("phrasesgroups", array("title"), "", Core::getDB()->quoteInto("phrasegroupid = ?", $options["group"])); $groupname = $result->fetchColumn(); Core::getCache()->cachePhraseGroup($groupname, $langcode); } else { Core::getCache()->cacheLanguage($langcode); } } else { $result = Core::getQuery()->select("languages", "langcode"); foreach ($result->fetchAll() as $row) { Core::getCache()->cacheLanguage($row["langcode"]); } } break; case "perm": Core::getCache()->buildPermissionCache(); break; } return; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EhRecycling", array($event, &$data, $this)); $where = Core::getDB()->quoteInto("galaxy = ? AND system = ? AND position = ?", array($data["galaxy"], $data["system"], $data["position"])); $result = Core::getQuery()->select("galaxy", array("metal", "silicon"), "", $where); if ($_row = $result->fetchRow()) { $result->closeCursor(); $capacityMetal = (int) ($data["capacity"] * 66.7 / 100); $capacitySilicon = (int) ($data["capacity"] * 33.3 / 100); $roundFix = $data["capacity"] - $capacityMetal - $capacitySilicon; if ($roundFix > 0) { $capacitySilicon += $roundFix; } $data["debrismetal"] = $_row["metal"]; $data["debrissilicon"] = $_row["silicon"]; $capacitySilicon += $capacityMetal > $_row["metal"] ? $capacityMetal - $_row["metal"] : 0; $capacityMetal += $capacitySilicon > $_row["silicon"] ? $capacitySilicon - $_row["silicon"] : 0; $data["metal"] += min($capacityMetal, $_row["metal"]); $restMetal = $_row["metal"] - min($capacityMetal, $_row["metal"]); $data["silicon"] += min($capacitySilicon, $_row["silicon"]); $restSilicon = $_row["silicon"] - min($capacitySilicon, $_row["silicon"]); $data["recycledmetal"] = abs($_row["metal"] - $restMetal); $data["recycledsilicon"] = abs($_row["silicon"] - $restSilicon); if ($_row["silicon"] != 0 || $_row["metal"] != 0) { Core::getQuery()->update("galaxy", array("metal" => $restMetal, "silicon" => $restSilicon), "galaxy = ? AND system = ? AND position = ?", array($data["galaxy"], $data["system"], $data["position"])); } } new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data); $this->sendBack($data, $data["time"] + $event["time"]); return $this; }
/** * Alliance page action. * * @return Bengine_Comm_Controller_Alliance */ public function pageAction() { Core::getLanguage()->load("Alliance"); Core::getTPL()->clearHTMLHeaderFiles(); Core::getTPL()->addHTMLHeaderFile("game.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); $tag = $this->getParam("1"); $fNumber = array("member", "points", "rpoints", "fpoints", "dpoints"); $attr = array("a.aid", "a.name", "a.tag", "a.logo", "a.textextern", "a.homepage", "a.showhomepage", "COUNT(u2a.userid) AS member", "SUM(u.points) AS points", "SUM(u.rpoints) AS rpoints", "SUM(u.fpoints) AS fpoints", "SUM(u.dpoints) AS dpoints"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid) "; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u2a.userid = u.userid) "; $result = Core::getQuery()->select("alliance a", $attr, $joins, Core::getDB()->quoteInto("tag = ?", $tag), "", 1, "a.aid"); $row = $result->fetchRow(); if ($row) { foreach ($fNumber as $field) { $row[$field] = fNumber($row[$field]); } $parser = new Bengine_Game_Alliance_Page_Parser($row["aid"]); if (Str::length(strip_tags($row["textextern"])) > 0) { $row["textextern"] = $parser->startParser($row["textextern"]); } else { $row["textextern"] = Core::getLang()->get("WELCOME"); } $row["homepage"] = $row["homepage"] != "" ? Link::get($row["homepage"], $row["homepage"], $row["homepage"]) : ""; $row["logo"] = $row["logo"] != "" ? Image::getImage($row["logo"], "") : ""; Hook::event("ShowPublicAlliancePage", array(&$row)); $this->assign($row); $this->setIsAjax(); } else { $this->setNoDisplay(true); } return $this; }
/** * Renders the signature image. * * @return Bengine_Comm_Controller_Signature */ protected function _render() { Core::getLang()->load("Signature"); $config = $this->getConfig(); $imageConfig = $config["image"]; $user = $this->getUser(); $img = imagecreatefrompng(AD . "img/" . $imageConfig["background"]); if ($imageConfig["stats"]["show"]) { $result = Core::getQuery()->select("user", array("userid")); $totalUser = fNumber($result->rowCount()); $this->_addParamToImage($img, "stats", Core::getLang()->get("RANK") . " " . $user->getFormattedRank() . "/" . $totalUser); } if ($imageConfig["planets"]["show"]) { $result = Core::getQuery()->select("planet", array("planetid"), "", Core::getDB()->quoteInto("userid = ? AND ismoon = 0", $user->getUserid())); $planets = Core::getLang()->get("NUMBER_OF_COLONY") . " " . fNumber($result->rowCount() - 1); $this->_addParamToImage($img, "planets", $planets); } $this->_addParamToImage($img, "username", $user->getUsername()); $this->_addParamToImage($img, "gameName", Core::getConfig()->get("pagetitle")); $this->_addParamToImage($img, "planet", $user->getHomePlanet()->getPlanetname() . " [" . $user->getHomePlanet()->getCoords(false) . "]"); $this->_addParamToImage($img, "points", Core::getLang()->get("POINTS") . " " . $user->getFormattedPoints()); if ($user->getAid()) { $this->_addParamToImage($img, "alliance", Core::getLang()->get("ALLIANCE") . " " . $user->getAlliance()->getTag()); } imagepng($img, $this->getCachePath() . DIRECTORY_SEPARATOR . $this->getUserId() . self::IMAGE_FILE_EXTENSION, $imageConfig["quality"]); imagedestroy($img); return $this; }
/** * Prepares expired events. * * @param string $raceConditionKey Race condition key * @param int $max Maximum events to select * * @return Bengine_Game_Model_Collection_Event */ public function addRaceConditionFilter($raceConditionKey, $max = self::MAX_EVENT_EXECUTION) { $max = (int) $max; Core::getQuery()->update("events", array("prev_rc" => $raceConditionKey), "prev_rc IS NULL AND time <= '" . TIME . "' ORDER BY eventid ASC LIMIT " . $max); $this->getSelect()->where(array("e" => "prev_rc"), $raceConditionKey); $this->addTimeOrder(); return $this; }
/** * Removes galaxy garbage. * * @return Bengine_Game_Cronjob_RemoveGalaxyGarbage */ protected function removeGalaxyGarbage() { $result = Core::getQuery()->select("galaxy g", array("g.planetid"), "LEFT JOIN " . PREFIX . "events e ON (e.destination = g.planetid OR e.planetid = g.planetid)", "g.destroyed = '1' AND e.eventid IS NULL"); foreach ($result->fetchAll() as $row) { Core::getQuery()->delete("planet", "planetid = ?", null, null, array($row["planetid"])); } $result->closeCursor(); return $this; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_remove($event, $data) */ protected function _remove(Bengine_Game_Model_Event $event, array $data) { $result = Core::getQuery()->select("events", array("eventid", "planetid", "destination", "start"), "", Core::getDB()->quoteInto("parent_id = ?", $event->get("eventid"))); foreach ($result->fetchAll() as $row) { Core::getQuery()->update("events", array("mode" => 20, "planetid" => $row["destination"], "destination" => $row["planetid"], "time" => TIME + (TIME - $row["start"])), "eventid = ?", array($row["eventid"])); } $this->sendBack($data); return $this; }
/** * @param array $delete * @param array $perms * @return Bengine_Admin_Controller_Permissions */ protected function update(array $delete, array $perms) { foreach ($delete as $pid) { Core::getQuery()->delete("permissions", "permissionid = ?", null, null, array($pid)); } foreach ($perms as $pid) { Core::getQuery()->update("permissions", array("permission" => Core::getRequest()->getPOST("perm_" . $pid)), "permissionid = ?", array($pid)); } return $this; }
/** * Function to clear old sessions. * * @package Recipe 1.2 * @author Sebastian Noll * @copyright Copyright (c) 2009, Sebastian Noll * @license Proprietary * @version $Id: ClearSessions.php 8 2010-10-17 20:55:04Z secretchampion $ * * @param integer Delete sessions older than "days" * * @return void */ function clearSessions($days = 0) { if ($days > 0) { $deldate = $days * 86400; $and = " AND time < '" . $deldate . "'"; } else { $and = ""; } Core::getQuery()->delete("sessions", "logged = '0'" . $and); return; }
/** * Executes expired events. * * @return Bengine_Game_EventHandler */ protected function goThroughEvents() { /* @var Bengine_Game_Model_Collection_Event $collection */ $collection = Game::getModel("game/event")->getCollection(); $collection->addRaceConditionFilter($this->raceConditionKey); $collection->executeAll(); if ($collection->count() > 0) { Core::getQuery()->delete("events", "prev_rc = ?", null, null, array($this->raceConditionKey)); } return $this; }
/** * Saves the user data for the profile. * * @return Bengine_Game_Model_Profile */ protected function _afterSave() { if ($this->getUserId()) { if ($this->getIsNew()) { Core::getQuery()->insert("profile2user", array("profile_id" => $this->getProfileId(), "user_id" => $this->getUserId(), "data" => $this->getData())); } else { Core::getQuery()->update("profile2user", array("data" => $this->getData()), "profile_id = ? AND user_id = ?", array($this->getProfileId(), $this->getUserId())); } } return parent::_afterSave(); }
/** * Returns the rank for this user. * * @return integer */ public function getRank() { if (!$this->exists("rank")) { $where = "(`username` < ? AND `points` >= {points}) OR `points` > {points}"; $where = str_replace("{points}", (double) $this->get("points", 0), $where); $result = Core::getQuery()->select("user", array("COUNT(`userid`)+1 AS rank"), "", $where, "", 1, "", "", array($this->get("username"))); $this->set("rank", (int) $result->fetchColumn()); $result->closeCursor(); } return $this->get("rank"); }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EhAttack", array($event, &$data, $this)); $statement = Core::getQuery()->select("assault", array("assaultid"), "", "planetid = ? AND running = 1", "", "", "", "", array($event->get("destination"))); if ($statement->fetchRow()) { $event->set("prev_rc", null); $event->save(); return $this; } $assault = new Bengine_Game_Assault($event["destination"], $event["destination_user_id"], $event); $assault->addParticipant(1, $event["userid"], $event["planetid"], $event["time"], $data)->startAssault($data["galaxy"], $data["system"], $data["position"])->finish(); return $this; }
/** * Executes all events that are queued, but max 1000 events. * * @return Bengine_Game_Cronjob_EventExecution */ protected function _execute() { require_once "Bengine/Game.php"; $raceConditionKey = Str::substring(md5(microtime(true)), 0, 16); /* @var Bengine_Game_Model_Collection_Event $collection */ $collection = Application::getModel("game/event")->getCollection(); $collection->addRaceConditionFilter($raceConditionKey, Core::getConfig()->get("CRONJOB_MAX_EVENT_EXECUTION")); $collection->executeAll(); if ($collection->count() > 0) { Core::getQuery()->delete("events", "prev_rc = ?", null, null, array($raceConditionKey)); } return $this; }
/** * Loads all menu items. * * @return Bengine_Comm_CMS */ protected function loadMenuItems() { $result = Core::getQuery()->select("page", array("position", "title", "label", "link"), "", Core::getDB()->quoteInto("languageid = ?", $this->langid), "displayorder ASC"); foreach ($result->fetchAll() as $row) { $position = $row["position"]; if (!empty($row["link"])) { $this->menuItems[$position][]["link"] = Link::get($row["link"], $row["title"], $row["title"]); } else { $this->menuItems[$position][]["link"] = Link::get(LANG . "index/" . $row["label"], $row["title"], $row["title"]); } } Hook::event("CommLoadMenu", array(&$this->menuItems, $this)); return $this; }
/** * Fetches all bans. * * @param int $offset * @param int $count * @return array */ protected function getBans($offset, $count) { $offset = (int) $offset; $count = (int) $count; $bans = array(); $attr = array("b.`banid`", "b.`from`", "b.`to`", "b.`reason`", "u.`username`", "m.`username` AS moderator"); $joins = "LEFT JOIN `" . PREFIX . "user` u ON (u.`userid` = b.`userid`) "; $joins .= "LEFT JOIN `" . PREFIX . "user` m ON (m.`userid` = b.`modid`)"; $result = Core::getQuery()->select("ban_u b", $attr, $joins, "", "b.`from` DESC, b.`banid` DESC", $offset . ", " . $count); foreach ($result->fetchAll() as $row) { $bans[] = array("counter" => $row["banid"], "from" => Date::timeToString(1, $row["from"]), "to" => Date::timeToString(1, $row["to"]), "reason" => $row["reason"], "username" => $row["username"], "moderator" => $row["moderator"], "date" => Date::timeToString(3, $row["from"], "D, d M Y H:i:s O", false), "author" => $row["moderator"], "title" => $row["username"], "text" => $row["username"] . " – " . $row["reason"], "link" => "", "date_atom" => Date::timeToString(3, $row["from"], "c", false), "guid" => md5($row["from"])); } return $bans; }
/** * Changes a configuration parameter. * * @param string $var Variable name * @param string $value New value of the variable * @param boolean $renewcache Turn off auto-caching * * @return Recipe_Options */ public function setValue($var, $value, $renewcache = false) { Hook::event("SetOptionVariable", array($this, &$var, &$value)); if ($this->hasVariable($var, false)) { Core::getQuery()->update("config", array("value" => $value), "var = ?", array($var)); } else { $spec = array("var" => $var, "value" => $value, "type" => "char", "groupid" => 1, "islisted" => 1); Core::getQuery()->insert("config", $spec); } $this->item[$var] = $value; if ($this->cacheActive && $renewcache) { Core::getCache()->buildConfigCache(); } return $this; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EhDowngradeBuilding", array($event, &$data, $this)); if (!$event->getPlanetid()) { return $this; } $points = ($data["metal"] + $data["metal"] + $data["metal"]) / 1000; if ($data["level"] > 0) { Core::getQuery()->update("building2planet", array("level" => $data["level"]), "buildingid = '" . $data["buildingid"] . "' AND planetid = ?", array($event->getPlanetid())); } else { Core::getQuery()->delete("building2planet", "buildingid = ? AND planetid = ?", null, null, array($data["buildingid"], $event->getPlanetid())); } Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ? WHERE userid = ?", array($points, $event->getUserid())); return $this; }
/** * 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; }
/** * 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; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EbUpgradeResearch", array($event, &$data, $this)); $points = ($data["metal"] + $data["silicon"] + $data["hydrogen"]) / 1000; $select = new Recipe_Database_Select(); $select->from("research2user")->attributes(array("level"))->where("buildingid = ?", $data["buildingid"])->where("userid = ?", $event->getUserid()); if ($row = $select->getStatement()->fetchRow()) { Core::getQuery()->update("research2user", array("level" => $data["level"]), "buildingid = ? AND userid = ?", array($data["buildingid"], $event->getUserid())); Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid())); } else { if ($data["level"] == 1) { Core::getQuery()->insert("research2user", array("buildingid" => $data["buildingid"], "userid" => $event->getUserid(), "level" => 1)); Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points + ?, rpoints = rpoints + '1' WHERE userid = ?", array($points, $event->getUserid())); } } return $this; }
/** * @param Bengine_Game_Model_User $user * @param Bengine_Game_Model_Planet $planet * @return Bengine_Game_Model_Achievement */ public function unlockForUser(Bengine_Game_Model_User $user, Bengine_Game_Model_Planet $planet = null) { Core::getQuery()->insert("achievement2user", array("achievement_id" => $this->get("achievement_id"), "user_id" => $user->get("userid"), "date" => TIME)); $this->set("user_id", $user->get("userid")); $user->addXP($this->get("xp")); if (count($this->getRewards()) > 0) { if (null === $planet) { $planet = $user->getHomePlanet(); } foreach ($this->getRewards() as $rewardModel) { /* @var Bengine_Game_Model_AchievementReward $rewardModel */ $reward = $rewardModel->getRewardObject(); $reward->setUser($user)->setPlanet($planet); $reward->reward(); } } return $this; }
/** * Search in database for expired cron tasks and execute them. * * @throws Recipe_Exception_Generic * @return Recipe_Cron */ public function exeCron() { $select = array("cronid", "class", "month", "day", "weekday", "hour", "minute", "xtime", "active"); $_result = Core::getQuery()->select("cronjob", $select, "", "(xtime <= " . TIME . " OR xtime IS NULL) AND active = '1'"); foreach ($_result->fetchAll() as $_row) { $class = explode("/", $_row["class"]); $class = $class[0] . "/cronjob_" . $class[1]; $cronjobObj = Application::factory($class); if ($cronjobObj instanceof Recipe_CronjobAbstract) { Hook::event("ExecuteCronjob", array($this, &$_row, $cronjobObj)); $cronjobObj->execute($_row["cronid"], $_row["xtime"], $this->calcNextExeTime($_row)); } else { throw new Recipe_Exception_Generic("Cannot execute cron job \"{$_row["class"]}\"."); } } $_result->closeCursor(); return $this; }
/** * Activates an account, if key exists. * Starts log in on success. * * @return Bengine_Game_Account_Activation */ protected function activateAccount() { if (!empty($this->key)) { $result = Core::getQuery()->select("user u", array("u.userid", "u.username", "p.password", "temp_email"), "LEFT JOIN " . PREFIX . "password p ON (p.userid = u.userid)", Core::getDB()->quoteInto("u.activation = ?", $this->getKey())); if ($row = $result->fetchRow()) { $result->closeCursor(); Hook::event("ActivateAccount", array($this)); Core::getQuery()->update("user", array("activation" => "", "email" => $row["temp_email"]), "userid = ?", array($row["userid"])); $login = new Bengine_Game_Login($row["username"], $row["password"], "game", "trim"); $login->setCountLoginAttempts(false); $login->checkData(); $login->startSession(); return $this; } $result->closeCursor(); } Recipe_Header::redirect("?error=ACTIVATION_FAILED", false); return $this; }
/** * Deletes old sessions. * * @param integer $deletionDays Deletion time in days * @return Bengine_Game_Cronjob_CleanSessions */ protected function clearSessions($deletionDays) { $deletionDays = (int) $deletionDays; Hook::event("CleanSessionsBegin"); // Delete all contents from session cache $sessionCache = APP_ROOT_DIR . "var/cache/sessions/"; File::rmDirectoryContent($sessionCache); // Disable sessions Core::getQuery()->update("sessions", array("logged" => 0), "logged = '1'"); // Delete old sessions $deleteTime = TIME - $deletionDays * 86400; Core::getQuery()->delete("sessions", "time < ?", null, null, array($deleteTime)); // Log user count $sql = "INSERT INTO `" . PREFIX . "user_counter`\r\n\t\t(`count`, `day`, `week`, `day_of_week`, `month`, `day_of_month`, `year`, `time`) VALUES\r\n\t\t((SELECT COUNT(`userid`) FROM `" . PREFIX . "user` LIMIT 1), DAYOFYEAR(CURDATE()), WEEK(CURDATE()), DAYOFWEEK(CURDATE()), MONTH(CURDATE()), DAYOFMONTH(CURDATE()), YEAR(CURDATE()), UNIX_TIMESTAMP())"; Core::getDatabase()->query($sql); // Clean combats running flag Core::getQuery()->update("assault", array("running" => 0)); return $this; }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data) */ protected function _execute(Bengine_Game_Model_Event $event, array $data) { Hook::event("EhReturn", array($event, &$data, $this)); $this->_production($event); foreach ($data["ships"] as $ship) { $where = Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($ship["id"], $event["destination"])); $result = Core::getQuery()->select("unit2shipyard", "unitid", "", $where); if ($result->rowCount() > 0) { Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity + ? WHERE unitid = ? AND planetid = ?", array($ship["quantity"], $ship["id"], $event["destination"])); } else { Core::getQuery()->insert("unit2shipyard", array("unitid" => $ship["id"], "planetid" => $event["destination"], "quantity" => $ship["quantity"])); } } $data["destination"] = $event["destination"]; Core::getDB()->query("UPDATE " . PREFIX . "planet SET metal = metal + ?, silicon = silicon + ?, hydrogen = hydrogen + ? WHERE planetid = ?", array($data["metal"], $data["silicon"], $data["hydrogen"], $event["destination"])); if (!isset($data["nomessage"])) { new Bengine_Game_AutoMsg($event["mode"], $event["userid"], $event["time"], $data); } return $this; }
/** * @throws Recipe_Exception_Generic * @return bool */ protected function _reward() { switch ($this->getType()) { case "metal": $this->getPlanet()->addMetal($this->getValue()); break; case "silicon": $this->getPlanet()->addSilicon($this->getValue()); break; case "hydrogen": $this->getPlanet()->addHydrogen($this->getValue()); break; default: throw new Recipe_Exception_Generic("Invalid resource type '{$this->getType()}'"); break; } $value = (int) $this->getValue(); Core::getQuery()->update("planet", array($this->getType() => new Recipe_Database_Expr("{$this->getType()} + {$value}")), "planetid = ?", array($this->getPlanet()->get("planetid"))); return true; }