Beispiel #1
0
 public function moveVillage($x, $y)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Moving village ' . $this->village->getName());
     $profiler->message('Desired location: (' . $x . ',' . $y . ')');
     $location = $this->getValidLocation($x, $y);
     if ($location) {
         list($x, $y) = $location;
         $profiler->message('Actual location: (' . $x . ',' . $y . ')');
         $tc = $this->village->buildings->getTownCenterLocation();
         $profiler->message('Current castle location: (' . $tc[0] . ',' . $tc[1] . ')');
         // First, calculate the relative position
         $profiler->start('Calculating relative position.');
         $dx = $x - $tc[0];
         $dy = $y - $tc[1];
         $profiler->message('Relative position: (' . $dx . ',' . $dy . ')');
         $profiler->stop();
         $profiler->start('Moving buildings');
         // Fetch all thze buildings & move 'em.
         $buildings = $this->village->buildings->getBuildings();
         foreach ($buildings as $v) {
             // Fetch original location
             list($ox, $oy) = $v->getLocation();
             $nx = $ox + $dx;
             $ny = $oy + $dy;
             $profiler->start('Moving ' . $v->getName() . ' from (' . $ox . ',' . $oy . ') to (' . $nx . ',' . $ny . ')');
             $v->setLocation($nx, $ny);
             $profiler->stop();
         }
         $profiler->stop();
     }
     $profiler->stop();
 }
Beispiel #2
0
 public static function getDistance($loc1, $loc2, $portals, $ignoreImpassable = true)
 {
     if ($loc1[0] == $loc2[0] && $loc1[1] == $loc2[1]) {
         return 0;
     }
     // Show the route
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Calculating map distance between ' . $loc1[0] . ',' . $loc1[1] . ' and ' . $loc2[0] . ',' . $loc2[1]);
     $locations = array();
     foreach ($portals as $v) {
         $l1 = $v->getCasterLocation();
         $l2 = $v->getTargetLocation();
         $locations[$v->getId()] = array($l1, $l2);
     }
     $profiler->message('Straight line distance: ' . round(self::calculateDistance($loc1[0], $loc1[1], $loc2[0], $loc2[1])));
     // Debug portals
     $profiler->start('Available portals');
     foreach ($locations as $k => $v) {
         list($l1, $l2) = $v;
         $profiler->message('Portal ' . $k . ' goes from ' . $l1[0] . ',' . $l1[1] . ' to ' . $l2[0] . ',' . $l2[1]);
     }
     $profiler->stop();
     $distance = self::getShortestDistance($loc1, $loc2, $portals, $ignoreImpassable);
     if ($distance === false) {
         return false;
     }
     $pd = 0;
     $profiler->start('Route debug... this is what we did');
     foreach ($distance[1] as $v) {
         $profiler->message('Arriving at ' . $v[0] . ',' . $v[1] . ' (' . round($v['d']) . ').');
     }
     $profiler->stop();
     $profiler->stop();
     return $distance[0];
 }
Beispiel #3
0
 public function getObjects($squarePoints, $radius)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Let's replace this :)
     $out = array();
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($squarePoints, max($radius, 3));
     $objects = array();
     foreach ($buildingSQL as $buildingV) {
         $profiler->start('Initializing building');
         $profiler->start('Fetching building race object');
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $profiler->stop();
         $profiler->start('Fetching building object');
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $profiler->stop();
         $profiler->start('Setting data');
         $b->setData($buildingV['bid'], $buildingV);
         if ($buildingV['destroyDate'] > 0 && $buildingV['destroyDate'] < NOW) {
             $b->setDestroyed(true);
         }
         $profiler->stop();
         $profiler->start('Assigning building to array');
         //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
         $objects[] = new Dolumar_Map_Object($b);
         $profiler->stop();
         $profiler->stop();
     }
     return $objects;
 }
Beispiel #4
0
 public function processBattles($now)
 {
     // Check if it has been checked for this
     if ($now <= $this->iLastBattleCheck) {
         return;
     }
     $this->iLastBattleCheck = $now;
     // To not replace all this shit.
     $villageId = $this->objProfile->getId();
     // Start profiler & stuff
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Calculating battles for village ' . $villageId . ' (' . $now . ')');
     // The lock will make sure that every battle will only be calculated one time.
     $lock = Neuron_Core_Lock::__getInstance();
     // First: make sure this village hasn't been calculated yet
     /*
     if ($lock->setSoftLock ('battle_village', $villageId.'_'.$now))
     {
     */
     $dbi = Neuron_DB_Database::getInstance();
     $villageId = intval($villageId);
     $battles = $dbi->query("\n\t\t\t\tSELECT\n\t\t\t\t\tbattleId\n\t\t\t\tFROM\n\t\t\t\t\tbattle\n\t\t\t\tWHERE\n\t\t\t\t\t(vid = {$villageId} OR targetId = {$villageId})\n\t\t\t\t\tAND (\n\t\t\t\t\t\t(fightDate < {$now} AND isFought = '0') OR\n\t\t\t\t\t\tendDate < {$now}\n\t\t\t\t\t)\n\t\t\t\tORDER BY\n\t\t\t\t\tfightDate ASC,\n\t\t\t\t\tendDate ASC,\n\t\t\t\t\tbattleId ASC\n\t\t\t");
     $profiler->start('Processing ' . count($battles) . ' battles.');
     foreach ($battles as $bdata) {
         $profiler->start('Processing battle ' . $bdata['battleId']);
         // Only process every battle ones
         if ($lock->setLock('battle', $bdata['battleId'])) {
             $profiler->start('Lock set, process battles.');
             $battle = Dolumar_Battle_Battle::getBattle($bdata['battleId']);
             //$battle->setData ($aBattle, $this->objProfile);
             // Check for fight execution
             if ($battle->getFightDate() <= $now && !$battle->isFought()) {
                 $profiler->start('Executing battle #' . $battle->getId());
                 // Execute battle
                 $battle->execute();
                 $profiler->stop();
             }
             // Check for fight removal
             if ($battle->getEndDate() <= $now && $battle->isFought()) {
                 $profiler->start('Removing battle #' . $battle->getId());
                 // Do finish battle stuff
                 $battle->removeBattle();
                 $profiler->stop();
             }
             //$battle->__destruct ();
             unset($battle);
             //}
             $lock->releaseLock('battle', $bdata['battleId']);
             $profiler->stop();
             $this->objProfile->reloadData();
             reloadEverything();
         } else {
             $profiler->start('Battle is already locked, not doing anything.');
             $profiler->stop();
         }
         $profiler->stop();
     }
     $profiler->stop();
     $profiler->stop();
 }
 public function sendMessage($channelId, $message, Neuron_GameServer_Player $player)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Here we *must* update the last channelId message
     $id = parent::sendMessage($channelId, $message, $player);
     $cName = $this->sPrefix . 'lastmessage_' . $channelId;
     $profiler->message('Setting ' . $cName . ' to ' . $id);
     //echo 'setting ' . $cName . ' to ' . $id;
     $this->objCache->setCache($cName, $id);
     return $id;
 }
Beispiel #6
0
 private function generateSquare($x, $y)
 {
     // Clear some space:
     $this->randCache = array();
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Generating perlin noise square (' . $x . ',' . $y . ')');
     $lx = ($x + 1) * self::PAR_FILE;
     $ly = ($y + 1) * self::PAR_FILE;
     for ($i = $x * self::PAR_FILE; $i < $lx; $i++) {
         for ($j = $y * self::PAR_FILE; $j < $ly; $j++) {
             self::getOneSingleLocation($i, $j);
         }
     }
     $profiler->stop();
 }
Beispiel #7
0
 /**
  * Return all data from one given order ID
  */
 public function speedupBuild($id, $amount)
 {
     $db = Neuron_DB_Database::getInstance();
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Speeding up training of ' . $id . ' with ' . $amount . ' seconds.');
     $data = $this->getTrainingStatus($id);
     if ($data) {
         $timeLeft = $data['timeLeft'];
         if ($amount > $timeLeft) {
             $amount = $timeLeft;
         }
     }
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages_units\n\t\t\tSET\n\t\t\t\tendTraining = endTraining - {$amount}\n\t\t\tWHERE\n\t\t\t\tuid = {$id}\n\t\t");
     $profiler->stop();
     return;
 }
Beispiel #8
0
 protected function calculateIncome($level = null)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     if (!isset($level)) {
         $level = $this->getLevel();
     }
     // 40 for every level
     $income = $this->INCOME * GAME_SPEED_RESOURCES * 1.1 * $level;
     // Manipulated by honour!
     $profiler->start('Fetching honour');
     $income *= $this->getVillage()->honour->getHonour() / 100;
     $profiler->stop();
     // Bonusses (in resources)
     $profiler->start('Fetching locations');
     $bonus = $this->loadNearebyLocation();
     if (isset($bonus[$this->RESOURCE])) {
         $income += $income / 100 * $bonus[$this->RESOURCE];
     }
     $profiler->stop();
     //$income = (floor ($income * 4 * GAME_SPEED_RESOURCES) / 4);
     $income = floor($income);
     return $income;
 }
Beispiel #9
0
 private function loadBuildings()
 {
     if (!isset($this->buildings)) {
         $profiler = Neuron_Profiler_Profiler::__getInstance();
         $profiler->start('Loading buildings');
         $db = Neuron_Core_Database::__getInstance();
         $buildingsDBData = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tmap_buildings\n\t\t\t\tWHERE\n\t\t\t\t\tvillage = '" . $this->objMember->getId() . "'\n\t\t\t\t\tAND (destroyDate = 0 OR destroyDate > " . NOW . ")\n\t\t\t"));
         $this->buildings = array();
         $this->buildingCount = array();
         $this->buildingCount_all = array();
         $this->buildingLevelSum = array();
         foreach ($buildingsDBData as $v) {
             $b = Dolumar_Buildings_Building::getBuilding($v['buildingType'], $this->objMember->getRace(), $v['xas'], $v['yas']);
             $b->setData($v['bid'], $v);
             $b->setVillage($this->objMember);
             $this->buildings[$v['bid']] = $b;
             if ($b->isFinishedBuilding()) {
                 // Count the buildings
                 if (!isset($this->buildingCount[$v['buildingType']])) {
                     $this->buildingCount[$v['buildingType']] = 0;
                 }
                 $this->buildingCount[$v['buildingType']]++;
                 if (!isset($this->buildingLevelSum[$v['buildingType']])) {
                     $this->buildingLevelSum[$v['buildingType']] = 0;
                 }
                 $this->buildingLevelSum[$v['buildingType']] += $v['bLevel'];
             }
             // Count the buildings
             if (!isset($this->buildingCount_all[$v['buildingType']])) {
                 $this->buildingCount_all[$v['buildingType']] = 0;
             }
             $this->buildingCount_all[$v['buildingType']]++;
         }
         $profiler->stop();
     }
 }
Beispiel #10
0
 public static function getBuildingsFromLocations($points = array(), $range = 5)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Loading buildings from multiple points');
     $db = Neuron_Core_Database::__getInstance();
     $select = "FALSE ";
     foreach ($points as $v) {
         $select .= "OR ( xas < '" . ($v[0] + $range) . "' AND xas > '" . ($v[0] - $range) . "' AND yas < '" . ($v[1] + $range) . "' AND yas > '" . ($v[1] - $range) . "') ";
     }
     $sql = "\n\t\t\tSELECT\n\t\t\t\tmap_buildings.*,\n\t\t\t\tvillages.race\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tLEFT JOIN\n\t\t\t\tvillages ON map_buildings.village = villages.vid\n\t\t\tWHERE\n\t\t\t\t(\n\t\t\t\t\tmap_buildings.destroyDate = '0'\n\t\t\t\t\tOR map_buildings.destroyDate > '" . (time() - RUINS_DURATION) . "'\n\t\t\t\t)\n\t\t\t\tAND\n\t\t\t\t(\n\t\t\t\t\t{$select}\n\t\t\t\t)\n\t\t\tORDER BY\n\t\t\t\tmap_buildings.destroyDate = '0' DESC,\n\t\t\t\tmap_buildings.destroyDate DESC\n\t\t";
     $buildingSQL = $db->getDataFromQuery($db->customQuery($sql));
     $profiler->stop();
     return $buildingSQL;
 }
 public function sendMessage($channelId, $message, Neuron_GameServer_Player $player)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $db = Neuron_DB_Database::getInstance();
     $profiler->message('Sending message');
     return $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tn_chat_messages\n\t\t\tSET\n\t\t\t\tc_c_id = '{$db->escape($channelId)}',\n\t\t\t\tc_plid = '{$player->getId()}',\n\t\t\t\tc_date = NOW(),\n\t\t\t\tc_message = '{$db->escape($message)}'\n\t\t");
 }
Beispiel #12
0
 /**
  *	Check if a move can be executed (and set the correct error if not)
  */
 private function canReach(Neuron_GameServer_Map_Location $end, $isTargetAnObject = false)
 {
     $start = $this->getLocation();
     Neuron_Profiler_Profiler::getInstance()->message('Check if we can go from ' . $start . ' to ' . $end);
     // Too far? Don't bother about anything else
     if ($this->getMap()->getMinimalDistance($start, $end) > $this->getMovePoints()) {
         $this->error = 'not_enough_movepoints';
         Neuron_Profiler_Profiler::getInstance()->message('Precheck failed');
         return false;
     }
     // Otherwise: check the path
     $path = $this->getMap()->getPath($this->getSide(), $start, $end, $this->getMovePoints() + 1, $isTargetAnObject);
     if ($path === false) {
         Neuron_Profiler_Profiler::getInstance()->message('No path found.');
         $this->error = 'no_path_found';
     } else {
         if ($path->getCost() > $this->getMovePoints()) {
             $this->error = 'not_enough_movepoints';
         } else {
             return $path;
         }
     }
     return false;
 }
Beispiel #13
0
 private function _takeResources($gold, $wood, $stone, $iron, $grain, $gems)
 {
     $db = Neuron_Core_Database::__getInstance();
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Taking resources away: ' . $gold . ' ' . $wood . ' ' . $stone . ' ' . $iron . ' ' . $grain . ' ' . $gems);
     $this->loadData();
     // Make sure this doesn't go over the capacity
     $capacity = $this->getCapacity();
     $resources = $this->getResources();
     // Build a WHERE clause according to "the positives"
     $where = "(vid = {$this->objMember->getId()} AND lastResRefresh = {$this->lastReload})";
     //echo "Taking resources:\n";
     $a = array('gold', 'wood', 'stone', 'iron', 'grain', 'gems');
     foreach ($a as $v) {
         //echo "- " . $v . " = " . $$v . " CAP " . $capacity[$v] . " ";
         //echo " CUR " . $resources[$v] . " ";
         // If $v is negative (= ADDING!) AND it's bigger then our currenct capacity
         if (${$v} < 0 && abs(${$v}) + $resources[$v] > $capacity[$v]) {
             ${$v} = 0 - max(0, $capacity[$v] - $resources[$v]);
             $profiler->start('Capacity overflow for ' . $v . ', taking ' . ${$v} . ' instead');
             $profiler->stop();
         } elseif (${$v} > 0) {
             $where .= " AND " . $v . " >= " . ${$v};
         }
         //echo "CALC " . $$v . "\n";
     }
     // Show what we got:
     $data = array($gold, $wood, $stone, $iron, $grain, $gems);
     if ($gold == 0 && $wood == 0 && $stone == 0 && $iron == 0 && $grain == 0 && $gems == 0) {
         $profiler->stop();
         return true;
     } else {
         $profiler->start('We are going to take: ' . print_r($data, true));
         // Update the database
         $a = $db->update('villages', array('gold' => $gold > 0 ? '--' . $gold : '++' . abs($gold), 'wood' => $wood > 0 ? '--' . $wood : '++' . abs($wood), 'stone' => $stone > 0 ? '--' . $stone : '++' . abs($stone), 'iron' => $iron > 0 ? '--' . $iron : '++' . abs($iron), 'grain' => $grain > 0 ? '--' . $grain : '++' . abs($grain), 'gems' => $gems > 0 ? '--' . $gems : '++' . abs($gems)), $where) == 1;
         //customMail ('*****@*****.**', 'res debug', $db->getLatestQuery ());
         $profiler->stop();
         // Cached resources
         if ($a) {
             $this->data['gold'] -= $gold;
             $this->data['wood'] -= $wood;
             $this->data['stone'] -= $stone;
             $this->data['iron'] -= $iron;
             $this->data['grain'] -= $grain;
             $this->data['gems'] -= $gems;
         }
         $profiler->stop();
         return $a;
     }
 }
Beispiel #14
0
 public function speedupBuild($amount)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Speeding up building ' . $this->getId() . ' with ' . $amount . ' seconds.');
     // Now let's check if $amount is bigger than timeleft
     if ($amount > $this->getTimeLeft()) {
         $amount = $this->getTimeLeft();
     }
     $result = $this->delayBuild(0 - $amount);
     $profiler->stop();
     return $result;
 }
Beispiel #15
0
 public function procBonusses($function, $arguments = array(), $now = NOW, $since = NOW)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Processing bonusses ' . $function);
     // If $now is lower then $since, $since is probably empty.
     if ($since > $now) {
         $since = $now;
     }
     // First: technologies
     //$this->loadTechnology ();
     /*
     if (!isset ($arguments[0]))
     {
     	$arguments[0] = array ();
     }
     */
     $profiler->start('Processing technologies');
     $profiler->start('Loading technologies');
     $technologies = $this->getTechnologies();
     $profiler->stop();
     $profiler->start('Processing technologies');
     foreach ($technologies as $technology) {
         if (method_exists($technology, $function)) {
             $arguments[0] = call_user_func_array(array($technology, $function), $arguments);
         }
     }
     $profiler->stop();
     $profiler->stop();
     // Second: spells
     // This time, the $now and $then variables are higly important. We only want spells that are
     // active between $since and $now.
     $profiler->start('Processing active effects');
     $profiler->start('Loading effects');
     $boosts = $this->getActiveBoosts($since, $now);
     $profiler->stop();
     $profiler->start('Processing effects');
     foreach ($boosts as $v) {
         if (method_exists($v, $function)) {
             $arguments[0] = call_user_func_array(array($v, $function), $arguments);
         }
     }
     $profiler->stop();
     $profiler->stop();
     $profiler->stop();
     return $arguments[0];
 }
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
define('MAP_PERLIN_NO_CACHE', true);
function color_cache($im, $color)
{
    global $color_cache;
    if (!isset($color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]])) {
        $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]] = imagecolorallocate($im, $color[0], $color[1], $color[2]);
    }
    return $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]];
}
Neuron_Profiler_Profiler::getInstance()->setForceActivate(false);
if (isset($_GET['x']) && isset($_GET['y'])) {
    $extension = 'png';
    $cache = Neuron_Core_Cache::__getInstance('worldmap/');
    $width = Neuron_Core_Tools::getInput('_GET', 'width', 'int', 250);
    $height = Neuron_Core_Tools::getInput('_GET', 'height', 'int', 250);
    $zoom = Neuron_Core_Tools::getInput('_GET', 'zoom', 'int', 0);
    $x = Neuron_Core_Tools::getInput('_GET', 'x', 'int', 0);
    $y = Neuron_Core_Tools::getInput('_GET', 'y', 'int', 0);
    // Fetch cache
    $cachename = 'gw4_' . $zoom . '_' . $x . '_' . $y . '_' . $width . 'x' . $height;
    $image = $cache->getCache($cachename, 60 * 60 * 24 * 7);
    //$image = false;
    if ($image) {
        header("Content-type: image/" . $extension);
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 12) . " GMT");
Beispiel #17
0
 private function doMeleeAttack($actor, $target, $team, $isFlank = false, $isTargetFacingEnemy = false)
 {
     $pr = Neuron_Profiler_Profiler::getInstance();
     $pr->start('Executing a melee attack.');
     // Get amount of attacking units
     $amount = $actor->getAmount() - $actor->getKillUnitsQue() + $actor->getKilledInRound();
     // Current frontage is calculated on moving.
     // except when this is a flank attack
     // In that case something weird happens: everyone
     // in the flanking unit fights to a total amount
     // of the defending frontage multiplier
     if ($isFlank) {
         // Is this a flank to flank attack?
         if ($isTargetFacingEnemy) {
             // No. Calculate the frontage based on the frontage
             // multiplier used by the target
             $multiplier = $target->getCurrentFrontage() / $target->getStat('frontage');
             $frontage = $actor->getStat('frontage') * $multiplier;
             $actor->setCurrentFrontage($frontage);
         } else {
             // Yes. Just recalculate the frontage
             $frontages = $this->getFrontages($actor, $target);
             $actor->setCurrentFrontage($frontages[0]);
             $target->setCurrentFrontage($frontages[1]);
         }
     }
     // Make sure only the first row fights
     $frontage = $actor->getCurrentFrontage();
     // Shouldn't happen, but well, just to make sure.
     $frontage = max(1, $frontage);
     $amount = min($frontage, $amount);
     // Get the amount of defending units
     $defending = $target->getAmount() - $target->getKillUnitsQue();
     // Calculate the total amount of damage
     $damage = $amount * $actor->getStat('melee');
     // Don't forget the resistance!
     $damage -= $damage * $target->getStat($actor->getAttackType()) / 100;
     // Now how many units is that?
     $casualties = min($defending, $damage / $target->getStat('hp'));
     $casualties = $target->queKillUnits($casualties);
     // Log this action
     $this->objLogger->addLog_casualties($actor, $target, $casualties, 'melee', $team);
     $pr->stop();
 }
Beispiel #18
0
 public function setLocationCache($x, $y, $data)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Setting cache for (' . $x . ',' . $y . ')');
     $this->dbObj->query("\n\t\t\tINSERT INTO\n\t\t\t\tb_tiles\n\t\t\t(\n\t\t\t\tt_ix, t_iy, t_tile, t_random, t_height\n\t\t\t)\n\t\t\tVALUES\n\t\t\t(\n\t\t\t\t'{$x}',\n\t\t\t\t'{$y}',\n\t\t\t\t'{$data[0]}',\n\t\t\t\t'{$data[1]}',\n\t\t\t\t'{$data[2]}'\n\t\t\t)\n\t\t");
     $this->aTiles[$x][$y] = $data;
     $profiler->stop();
 }
 private function getOpenWindows()
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $out = array();
     // List all open windows
     $updatewindows = isset($_POST['updatewindow']) ? $_POST['updatewindow'] : null;
     if (is_array($updatewindows)) {
         $profiler->start('Ordering windows on priority');
         // Order window on input (put input first)
         $aantal = count($updatewindows);
         for ($i = 0; $i < $aantal; $i++) {
             $vervangen = $i;
             // Loop trough last, fine the one with more input.
             for ($j = $i + 1; $j < $aantal; $j++) {
                 if (isset($updatewindows[$j]['sInputData']) && strlen($updatewindows[$j]['sInputData']) > strlen($updatewindows[$vervangen]['sInputData'])) {
                     $vervangen = $j;
                 }
             }
             // Vervangen
             $temp = $updatewindows[$i];
             $updatewindows[$i] = $updatewindows[$vervangen];
             $updatewindows[$vervangen] = $temp;
         }
         $profiler->stop();
         //foreach ($updatewindows as $v)
         for ($i = 0; $i < count($updatewindows); $i++) {
             $v = $updatewindows[$i];
             if (is_array($v) && count($v) == 4) {
                 // Put everything in a big TRY
                 $profiler->start('Loading window ' . $v['sWindowId']);
                 try {
                     $window = $this->getWindow($v['sWindowId']);
                     if ($window) {
                         $window->setDivId($v['sDialogId']);
                         // Set request data
                         if (isset($v['sRequestData'])) {
                             $window->setRequestData($v['sRequestData']);
                         }
                         // Set input data
                         $window->setJsonInputData($v['sInputData']);
                         // Initialize
                         $window->setSettings();
                     }
                     $out[] = $window;
                 } catch (Exception $e) {
                     // Send a mail
                     error_log((string) $e);
                     if (defined('OUTPUT_DEBUG_DATA') && OUTPUT_DEBUG_DATA) {
                         echo $e;
                     }
                 }
                 $profiler->stop();
             }
         }
     }
     return $out;
 }
Beispiel #20
0
 public function delayFightDate($duration, $pendingBattles)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Delaying fight');
     //echo 'Delaying fight '.$this->getId ().' to '.$duration."\n";
     $aproxBattleDuration = ceil(60 * 10 / GAME_SPEED_MOVEMENT);
     $pendingBattles = $pendingBattles - 1;
     $this->loadData();
     $db = Neuron_Core_Database::__getInstance();
     if ($this->data['fightDate'] <= $duration) {
         $timestamp = $duration + $aproxBattleDuration;
         $db->update('battle', array('fightDate' => $timestamp, 'endFightDate' => $timestamp + $aproxBattleDuration, 'endDate' => $timestamp + $this->data['goHomeDuration'] + 1), "battleId = " . $this->getId());
         $this->data['fightDate'] = $timestamp;
         $this->data['endDate'] = $timestamp + $this->data['goHomeDuration'];
     }
     $profiler->stop();
 }
Beispiel #21
0
 public function setLocationCache($x, $y, $data)
 {
     if (!self::USE_MYSQL) {
         return;
     }
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Setting cache for (' . $x . ',' . $y . ')');
     $x = intval($x);
     $y = intval($y);
     $this->dbObj->query("\n\t\t\tINSERT INTO\n\t\t\t\t" . $this->sTable . "\n\t\t\t(\n\t\t\t\tt_ix, t_iy, t_tile, t_random, t_height, t_distance\n\t\t\t)\n\t\t\tVALUES\n\t\t\t(\n\t\t\t\t{$x},\n\t\t\t\t{$y},\n\t\t\t\t'{$data[0]}',\n\t\t\t\t'{$data[1]}',\n\t\t\t\t'{$data[2]}',\n\t\t\t\tSQRT(({$x}*{$x})+({$y}*{$y}))\n\t\t\t)\n\t\t");
     $this->aTiles[$x][$y] = $data;
     // Now it's in mysql, we remove the memcached area.
     $this->objMemcache->removeCache($this->getCacheName($x, $y));
     $profiler->stop();
 }
 private function file_get_contents($url)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     $profiler->start('Fetching ' . $url);
     //Initialize the Curl session
     $ch = curl_init();
     //Set curl to return the data instead of printing it to the browser.
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //Set the URL
     curl_setopt($ch, CURLOPT_URL, $url);
     // Set a reasonable timeout
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
     //Execute the fetch
     $data = curl_exec($ch);
     if ($error = curl_error($ch)) {
         $profiler->message('Error: ' . $error);
     }
     //Close the connection
     curl_close($ch);
     $profiler->stop();
     return $data;
 }
            $root->appendChild($updates);
        }
    } catch (Exception $e) {
        // Send a mail
        error_log((string) $e);
        if (defined('OUTPUT_DEBUG_DATA') && OUTPUT_DEBUG_DATA) {
            echo $e;
        }
    }
    $profiler->stop();
}
$profiler->stop();
$pgen->stop();
// Database
$db = Neuron_Core_Database::__getInstance();
$profiler = Neuron_Profiler_Profiler::getInstance();
// Let's add some additional data
$run = $dom->createElement('runtime');
$run->appendChild($dom->createElement('session_id', session_id()));
$run->appendChild($dom->createElement('parsetime', $pgen->gen(4)));
$run->appendChild($dom->createElement('mysqlcount', $db->getCounter()));
$content = $dom->createCDATASection($profiler);
$element = $run->appendChild($dom->createElement('profiler'));
$element->appendChild($content);
$content = $dom->createCDATASection(print_r($_REQUEST, true));
$run->appendChild($dom->createElement('request'))->appendChild($content);
$root->appendChild($run);
// Go for alerts
if (isset($GLOBALS['javascriptAlertErrors'])) {
    foreach ($GLOBALS['javascriptAlertErrors'] as $v) {
        $alert = $dom->createCDATASection($v);
Beispiel #24
0
 private function loadBattleCounters($vilsIdOrTarget)
 {
     $profiler = Neuron_Profiler_Profiler::__getInstance();
     $profiler->start('Generating new battle counters');
     $db = Neuron_Core_Database::__getInstance();
     // Load battles
     $t = $db->select('battle', array('*'), "endDate > '" . NOW . "' {$vilsIdOrTarget}");
     $text = Neuron_Core_Text::getInstance();
     $text->setSection('status', 'statusbar');
     foreach ($t as $v) {
         $profiler->start('Loaded battle counter: ' . $v['battleId']);
         $village = Dolumar_Players_Village::getVillage($v['vid']);
         $target = Dolumar_Players_Village::getVillage($v['targetId']);
         $output = array('target' => $this->getVillageName($target));
         $battle = Dolumar_Battle_Battle::getBattle($v['battleId']);
         if ($v['arriveDate'] > NOW) {
             if ($battle->isVisible()) {
                 $txt = Neuron_Core_Tools::putIntoText($text->get('battle_sending'), $output);
                 if ($battle->canWithdraw(Neuron_GameServer::getPlayer())) {
                     $confirm = $text->get('confirmWithdraw', 'battle');
                     $txt .= ' (<a href="javascript:void(0);" class="action" ' . 'onclick="confirmAction(this,{\'action\':\'withdrawbattle\',\'battle\':' . $v['battleId'] . '},\'' . $confirm . '\');">' . $text->get('withdraw', 'battle') . '</a>)';
                 }
                 $this->addCounter($v['arriveDate'], $village, $txt, 'troops sending', true);
             }
         } elseif ($v['fightDate'] >= NOW) {
             $this->addCounter($v['fightDate'], $village, Neuron_Core_Tools::putIntoText($text->get('battle_preparing'), $output), 'troops preparing', true);
         } elseif ($v['endFightDate'] > NOW) {
             // Get my village id
             $me = Neuron_GameServer::getPlayer();
             if ($me->getId() == $village->getOwner()->getId()) {
                 $sOnClick = 'openWindow(\'battle\', {\'vid\':\'' . $village->getId() . '\',\'report\':' . $v['bLogId'] . '});';
             } else {
                 $sOnClick = 'openWindow(\'battle\', {\'vid\':\'' . $target->getId() . '\',\'report\':' . $v['bLogId'] . '});';
             }
             $this->addCounter($v['endFightDate'], $village, '<a href="javascript:void(0);" onclick="' . $sOnClick . '">' . Neuron_Core_Tools::putIntoText($text->get('battle_fighting'), $output) . '</a>.', 'troops fighting', true);
         } elseif ($v['isFought']) {
             $this->addCounter($v['endDate'], $village, Neuron_Core_Tools::putIntoText($text->get('battle_returning'), $output), 'troops returning', true);
         }
         $profiler->stop();
     }
     $profiler->stop();
 }