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 processInput() { $player = Neuron_GameServer::getPlayer(); if (!$player) { return; } $input = $this->getInputData(); if (isset($input['cancelQueue'])) { $db = Neuron_DB_Database::__getInstance(); $queue = intval($input['cancelQueue']); // Get all villages $villages = Neuron_GameServer::getPlayer()->getVillages(); if (count($villages) > 0) { $villageSelector = ''; foreach ($villages as $v) { // Make sure the battles are processed. $v->processBattles(); $villageSelector .= 'pq_vid = ' . $v->getId() . ' OR '; } $villageSelector = substr($villageSelector, 0, -3); // Make sure you can only remove your own queues $db->query("\n\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\tpremium_queue\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tpq_id = {$queue} AND\n\t\t\t\t\t\t{$villageSelector}\n\t\t\t\t"); } } elseif (isset($input['action'])) { switch ($input['action']) { case 'withdrawbattle': $battleid = isset($input['battle']) ? $input['battle'] : 0; if ($battleid) { // Fetch battle $battle = Dolumar_Battle_Battle::getBattle($battleid); if ($battle && $battle->getAttacker()->getOwner()->equals($player)) { $battle->withdraw(); } } break; } } $this->getFreshCounters(); $this->updateContent(); }