Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
0
 public static function getVillage($id, $syncBattle = NOW, $cronStuff = false, $noStatic = false)
 {
     $in = self::$instances;
     $id = intval($id);
     if (empty($id) || $id == 0) {
         return new Dolumar_Players_DummyVillage();
     }
     $lock = Neuron_Core_Lock::__getInstance();
     if (!defined('DISABLE_STATIC_FACTORY') && !$noStatic) {
         // Initialize the village
         if (!isset($in[$id]) || !$in[$id]->isInitialized) {
             $in[$id] = new Dolumar_Players_Village($id, $cronStuff);
         }
         $village = $in[$id];
     } else {
         $village = new Dolumar_Players_Village($id, $cronStuff);
     }
     $village->setBattleProcessData($syncBattle);
     return $village;
 }
Ejemplo n.º 3
0
 private static function getArmyId(Dolumar_Underworld_Models_Mission $mission, Dolumar_Underworld_Models_Army $army, $forceUpdate = false)
 {
     $db = Neuron_DB_Database::getInstance();
     $data = $db->query("\n\t\t\tSELECT\n\t\t\t\tul_a_vid,\n\t\t\t\tul_a_id,\n\t\t\t\tul_a_version\n\t\t\tFROM\n\t\t\t\tunderworld_log_armies\n\t\t\tWHERE\n\t\t\t\tua_id = {$army->getId()}\n\t\t\tORDER BY\n\t\t\t\tul_a_version DESC\n\t\t\tLIMIT 1\n\t\t");
     if ($forceUpdate || count($data) === 0) {
         if (count($data) > 0) {
             $logArmyId = $data[0]['ul_a_id'];
             $version = $data[0]['ul_a_version'] + 1;
         } else {
             $lock = Neuron_Core_Lock::getInstance();
             if ($lock->setLock('underworld_army_id', 1)) {
                 $chk = $db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tMAX(ul_a_id) AS id\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tunderworld_log_armies\n\t\t\t\t\t");
                 $logArmyId = intval($chk[0]['id']) + 1;
                 $version = 1;
                 $lock->releaseLock('underworld_army_id', 1);
             }
         }
         $id = self::createArmy($mission, $army, $logArmyId, $version);
     } else {
         $id = $data[0]['ul_a_vid'];
     }
     return $id;
 }
Ejemplo n.º 4
0
<?php

session_write_close();
$action = isset($_GET['action']) ? $_GET['action'] : null;
$lockid = isset($_GET['lock']) ? $_GET['lock'] : time();
if ($action == 'lock') {
    $lock = Neuron_Core_Lock::getInstance('test');
    if ($lock->setLock('test', $lockid)) {
        usleep(2 * 1000000);
        echo 'Here I am!';
        usleep(2 * 1000000);
        $lock->releaseLock('test', $lockid);
    } else {
        echo 'Was locked :(';
    }
    echo '<br />Lock ID: ' . $lockid;
} else {
    for ($i = 0; $i < 20; $i++) {
        echo '<iframe src="' . ABSOLUTE_URL . 'test/locks/?action=lock&lock=' . $lockid . '"></iframe>';
    }
}
Ejemplo n.º 5
0
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  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.
 */
require_once 'bootstrap/bootstrap.php';
$lock = Neuron_Core_Lock::getInstance();
if (!defined('CRONJOB_OUTPUT')) {
    define('CRONJOB_OUTPUT', true);
}
if (CRONJOB_OUTPUT) {
    header('Content-type: text/text');
}
function runCronjobFile($file)
{
    if (!CRONJOB_OUTPUT) {
        ob_start();
        include $file;
        ob_end_clean();
    } else {
        echo 'Running ' . $file . "\n";
        echo '----------------------' . "\n";
Ejemplo n.º 6
0
 private function processTransfers()
 {
     if ($this->areTransfersProcessed) {
         return true;
     }
     $db = Neuron_DB_Database::getInstance();
     $this->areTransfersProcessed = true;
     $transfers = $db->query("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tvillages_transfers\n\t\t\tWHERE\n\t\t\t\tto_vid = {$this->objMember->getId()} AND\n\t\t\t\tt_date_received < FROM_UNIXTIME(" . NOW . ") AND\n\t\t\t\tt_isReceived = '0'\n\t\t");
     if (count($transfers) > 0) {
         $objLock = Neuron_Core_Lock::__getInstance();
         if ($objLock->setLock('prcTransfer', $this->objMember->getId())) {
             try {
                 // Reload the transfers (lock bestendig)
                 $transfers = $db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tvillages_transfers\n\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t\tvillages_transfers_items USING(t_id)\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tto_vid = {$this->objMember->getId()} AND\n\t\t\t\t\t\t\tt_date_received < FROM_UNIXTIME(" . NOW . ") AND\n\t\t\t\t\t\t\tt_isReceived = '0'\n\t\t\t\t\t");
                 $resources = array();
                 $runes = array();
                 $equipment = array();
                 $transactions = array();
                 foreach ($transfers as $v) {
                     switch ($v['ti_type']) {
                         case 'RESOURCE':
                             if (isset($resources[$v['ti_key']])) {
                                 $resources[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $resources[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                         case 'RUNE':
                             if (isset($runes[$v['ti_key']])) {
                                 $runes[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $runes[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                         case 'EQUIPMENT':
                             if (isset($equipment[$v['ti_key']])) {
                                 $equipment[$v['ti_key']] += $v['ti_amount'];
                             } else {
                                 $equipment[$v['ti_key']] = $v['ti_amount'];
                             }
                             break;
                     }
                     $transactions[$v['t_id']] = true;
                 }
                 foreach (array_keys($transactions) as $v) {
                     // Now make sure we don't give these resources again
                     $db->query("\n\t\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t\tvillages_transfers\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tt_isReceived = '1'\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tt_id = {$v}\n\t\t\t\t\t\t");
                 }
             } catch (Exception $error) {
                 error_log("Transfer error: " . $error->getMessage());
             }
             $objLock->releaseLock('prcTransfer', $this->objMember->getId());
             $logcontainer = new Dolumar_Logable_GeneralContainer();
             // Now let's add 'em resources
             if (count($resources) > 0) {
                 $logcontainer->add(new Dolumar_Logable_ResourceContainer($resources));
                 $this->giveResources($resources);
             }
             if (count($runes) > 0) {
                 $logcontainer->add(new Dolumar_Logable_RuneContainer($runes));
                 $this->giveRunes($runes);
             }
             if (count($equipment) > 0) {
                 $this->giveEquipment($equipment);
             }
             // Now we just need to log it
             $objLogs = Dolumar_Players_Logs::__getInstance();
             $objLogs->addCompleteTransferLog($this->objMember, $logcontainer);
         } else {
             error_log("Could not lock for transfers: " . $this->objMember->getId());
         }
     }
 }
Ejemplo n.º 7
0
 public function doUpgradeBuilding()
 {
     $res = $this->getUpgradeCost($this->getVillage());
     $objLock = Neuron_Core_Lock::__getInstance();
     if ($objLock->setLock('upgradebuilding', $this->getId())) {
         $return = false;
         $duration = $this->getUpgradeTime($this->getVillage());
         // Check some stuff
         if (!$this->isFinished()) {
             $this->sError = 'unfinished';
         } elseif (!$this->getVillage()->readyToBuild()) {
             $this->sError = 'busy';
         } elseif (!$this->getVillage()->resources->takeResourcesAndRunes($res)) {
             $this->sError = $this->getVillage()->resources->getError();
         } else {
             $db = Neuron_Core_Database::__getInstance();
             // Reload buildings & runes
             $this->getVillage()->buildings->reloadBuildings();
             $this->getVillage()->resources->reloadRunes();
             $this->getVillage()->buildings->increaseBuildingLevel($this, $this->getLevel() + 1);
             // Update duration
             $db->update('map_buildings', array('lastUpgradeDate' => time() + $duration, 'bLevel' => '++'), "bid = '" . $this->id . "'");
             // Reload windows
             if (isset($this->objWindow)) {
                 reloadEverything();
                 reloadStatusCounters();
                 $loc = $this->getLocation();
                 $this->objWindow->reloadLocation($loc[0], $loc[1]);
             }
             $runes = array();
             if (isset($res['runeId']) && isset($res['runeAmount'])) {
                 $runes[$res['runeId']] = $res['runeAmount'];
             }
             unset($res['runeId']);
             unset($res['runeAmount']);
             $this->addUsedResources($res, $runes);
             $this->getVillage()->onUpgrade($this);
             $return = true;
         }
         $objLock->releaseLock('upgradebuilding', $this->getId());
         return $return;
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 public function onWin(Dolumar_Underworld_Models_Side $side)
 {
     // Add log
     $lock = Neuron_Core_Lock::getInstance();
     $lockname = 'uw_fin';
     if ($lock->setLock($lockname, $this->getMission()->getId())) {
         // Reload mission, just to be sure
         $mission = Dolumar_Underworld_Mappers_MissionMapper::getFromId($this->getMission()->getId());
         if ($mission) {
             // Logger
             $this->getMission()->getLogger()->win($side);
             // Do whatever we need to do
             $this->winnerBenefits($side);
             // Start removing mission
             $mission->destroy();
             // Release the lock
             $lock->releaseLock($lockname, $this->getMission()->getId());
         }
     }
 }