Ejemplo n.º 1
0
 public static function getFromId($id)
 {
     $id = explode('|', $id);
     $uid = $id[0];
     $village = Dolumar_Players_Village::getFromId($id[1]);
     $race = Dolumar_Races_Race::getFromId($id[2]);
     return self::getUnitFromId($uid, $race, $village);
 }
Ejemplo n.º 2
0
 public static function getFromId($id)
 {
     // Load building from ID (takes a mysql query)
     $db = Neuron_DB_Database::__getInstance();
     $id = intval($id);
     $data = $db->query("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tWHERE\n\t\t\t\tbid = '{$id}'\n\t\t");
     if (count($data) == 1) {
         $village = Dolumar_Players_Village::getFromId($data[0]['village']);
         if ($village) {
             $building = self::getBuilding($data[0]['buildingType'], $village->getRace(), $data[0]['xas'], $data[0]['yas']);
             $building->setData($data[0]['bid'], $data[0]);
             return $building;
         } else {
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public function getBody()
 {
     $player = Neuron_GameServer::getPlayer();
     if (!$player->isModerator()) {
         return '<p>You don\'t have the rights to access the player logs.</p>';
     }
     $page = new Neuron_Core_Template();
     // Let's find the players
     $input = Neuron_Core_Tools::getInput('_GET', 'players', 'varchar');
     $playerids = explode('|', $input);
     $players = array();
     $villages = array();
     $ids = array();
     $i = 0;
     foreach ($playerids as $v) {
         $player = Neuron_GameServer::getPlayer($v);
         if ($player) {
             $players[] = $player;
             $villages = array_merge($villages, $player->getVillages());
             $ids[$player->getId()] = $i;
             $page->addListValue('players', array('key' => $i, 'id' => $player->getId(), 'name' => $player->getName(), 'url' => $this->getUrl('user', array('id' => $player->getId()))));
             $i++;
         }
     }
     $pageid = max(0, intval(Neuron_Core_Tools::getInput('_GET', 'page', 'int', 1)) - 1);
     $objLogs = Dolumar_Players_Logs::getInstance();
     $logs = $objLogs->getLogs($villages, $pageid * 250, 250, 'DESC');
     foreach ($logs as $v) {
         $player = Dolumar_Players_Village::getFromId($v['village'])->getOwner();
         // Check if this is an important log.
         $bImportant = $this->isImportantLog($players, $v);
         $page->addListValue('logs', array('action' => $objLogs->getLogText($v, false), 'date' => date(DATETIME, $v['timestamp']), 'player' => $player->getName(), 'url' => $this->getUrl('user', array('id' => $player->getId())), 'key' => $ids[$player->getId()], 'important' => $bImportant ? 'important' : null));
     }
     $page->set('page', $pageid + 1);
     if (count($logs) == 250) {
         $page->set('nextpage', $this->getUrl('gamelogs', array('players' => $input, 'page' => $pageid + 2)));
     }
     if ($pageid > 0) {
         $page->set('previouspage', $this->getUrl('gamelogs', array('players' => $input, 'page' => $pageid)));
     }
     return $page->parse('pages/admin/gamelogs.phpt');
 }
Ejemplo n.º 4
0
 public function getBody()
 {
     $timeframe = Neuron_Core_Tools::getInput('_GET', 'timeframe', 'int', 60 * 60 * 48);
     $page = new Neuron_Core_Template();
     $page->set('timeframe', $timeframe);
     $objLogs = Dolumar_Players_Logs::getInstance();
     $objLogs->setTimeInterval(NOW - $timeframe, NOW);
     $pageid = Neuron_Core_Tools::getInput('_GET', 'page', 'int', 1);
     $limit = Neuron_Core_Tools::splitInPages($page, $objLogs->getSuspiciousLogsCounter(), $pageid, self::SUSPICIOUS_TRANSACTIONS_PERPAGE, 7, array('timeframe' => $timeframe), 'multis');
     //print_r ($limit);
     //$logs = $objLogs->getSuspiciousLogs ();
     $logs = $objLogs->getSuspiciousLogs($limit['start'], $limit['perpage'], 'DESC');
     foreach ($logs as $v) {
         $player = Dolumar_Players_Village::getFromId($v['village'])->getOwner();
         $page->addListValue('logs', array('action' => $objLogs->getLogText($v, false), 'date' => date(DATETIME, $v['timestamp']), 'player' => $player->getDisplayName()));
     }
     // Output the shizzle
     $html = $page->parse('dolumar/pages/admin/multis/dangeroustransactions.phpt');
     $html .= parent::getBody();
     return $html;
 }
Ejemplo n.º 5
0
 /**
  *	Get all clan portal buildings
  */
 public function getClanportals()
 {
     $db = Neuron_DB_Database::getInstance();
     $villages = array();
     foreach ($this->getMembers() as $player) {
         foreach ($player->getVillages() as $v) {
             $villages[] = $v->getId();
         }
     }
     $list = "(" . implode($villages, ",") . ")";
     $data = $db->query("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tmap_buildings\n\t\t\tWHERE\n\t\t\t\tbuildingType = 61 AND\n\t\t\t\tvillage IN {$list} AND\n\t\t\t\t(destroyDate = 0 OR destroyDate > " . NOW . ")\n\t\t");
     $out = array();
     foreach ($data as $v) {
         $village = Dolumar_Players_Village::getFromId($v['village']);
         $building = Dolumar_Buildings_Building::getFromId($v['bid'], $village->getRace(), $v['xas'], $v['yas']);
         $building->setData($v['bid'], $v);
         $building->setVillage($village);
         $out[] = $building;
     }
     return $out;
 }
Ejemplo n.º 6
0
 private function getSpeedUpTraining($data)
 {
     $text = Neuron_Core_Text::getInstance();
     $inputData = $this->getInputData();
     $village = isset($data['village']) ? $data['village'] : null;
     $unit = isset($data['unit']) ? $data['unit'] : null;
     $id = isset($data['order']) ? $data['order'] : null;
     $village = Dolumar_Players_Village::getFromId($village);
     $troop = Dolumar_Units_Unit::getFromId($unit);
     $order = $village->units->getTrainingStatus($id);
     if (!$troop || !$id || !$village || !$order) {
         return '<p>Order not found.</p>';
     }
     $price = PREMIUM_SPEEDUP_TRAINING_PRICE;
     $unit = PREMIUM_SPEEDUP_TRAINING_UNIT;
     if (isset($inputData['duration'])) {
         $selected = abs(intval($inputData['duration']));
         $desc = Neuron_Core_Tools::putIntoText($text->get('confdesc_training', 'speedup', 'statusbar'), array('unit' => $troop->getName(), 'amount' => Neuron_Core_Tools::getDurationText($selected * $unit)));
         return $this->getConfirm($price, $unit, $selected, $desc);
     }
     $time = $order['timeLeft'];
     return $this->getSpeedUpHTML('training', $time, $price, $unit);
 }
Ejemplo n.º 7
0
 private function getTradeContent()
 {
     $text = Neuron_Core_Text::__getInstance();
     // Can we do it already?
     if ($this->countMaximumTransfers() <= $this->countOutgoingTransfers()) {
         return $this->getMarketBusy();
     }
     if (isset($this->aInput['target'])) {
         $objVillage = Dolumar_Players_Village::getFromId($this->aInput['target']);
         if ($objVillage) {
             $this->objTarget = $objVillage;
             if ($this->objTarget->equals($this->getVillage())) {
                 $msgs[] = array($text->get('error_ownvillage', 'market', 'buildings'), false);
                 return $this->getChooseTarget($msgs);
             }
             /*
             if (!$this->isValidTarget ($objVillage))
             {
             	return $this->getChooseTarget 
             	(
             		array
             		(
             			array 
             			(
             				Neuron_Core_Tools::putIntoText
             				(
             					$text->get ($this->sError, 'market', 'buildings', $this->sError), 
             					array
             					(
             						'percentage' => self::MAX_PERCENTAGE
             					)
             				),
             				false
             			)
             		)
             	);
             }
             */
             // Check for selected resources
             $resources = $this->getResourcesFromInput();
             $runes = $this->getRunesFromInput();
             $equipment = $this->getEquipmentFromInput();
             $confirmed = isset($this->aInput['confirmed']);
             if ($this->isFilled($resources) || $this->isFilled($runes) || count($equipment) > 0) {
                 if ($confirmed) {
                     return $this->getDonateResources($objVillage, $resources, $runes, $equipment);
                 } else {
                     return $this->getConfirmDonation($objVillage, $resources, $runes, $equipment);
                 }
             } else {
                 return $this->getChooseAmount($objVillage);
             }
         }
     }
     return $this->getChooseTarget();
 }
Ejemplo n.º 8
0
 public function useCredit($amount, $data)
 {
     $action = isset($data['action']) ? $data['action'] : null;
     $logs = Dolumar_Players_Logs::getInstance();
     switch ($action) {
         case 'buyrunes':
             $runes = array_keys($this->getMainVillage()->resources->getInitialRunes());
             $out = array();
             foreach ($runes as $v) {
                 if (isset($data[$v])) {
                     $out[$v] = intval($data[$v]);
                 }
             }
             $village = isset($data['village']) ? $data['village'] : null;
             $village = $this->getMyVillage($village);
             if ($village) {
                 $village->resources->giveRunes($out);
                 $logs->addPremiumRunesBoughtLog($village, $out);
             }
             break;
         case 'movevillage':
             $village = isset($data['village']) ? $data['village'] : null;
             $village = $this->getMyVillage($village);
             list($ox, $oy) = $village->buildings->getTownCenterLocation();
             $x = isset($data['x']) ? $data['x'] : null;
             $y = isset($data['y']) ? $data['y'] : null;
             if ($village && isset($x) && isset($y)) {
                 $village->movevillage->moveVillage($x, $y);
                 $logs->addPremiumMoveVillage($village, $x, $y, $ox, $oy);
             }
             break;
         case 'movebuilding':
             $building = isset($data['building']) ? $data['building'] : null;
             $village = isset($data['village']) ? $data['village'] : null;
             $village = $this->getMyVillage($village);
             $x = isset($data['x']) ? intval($data['x']) : null;
             $y = isset($data['y']) ? intval($data['y']) : null;
             if ($village && isset($x) && isset($y) && isset($building)) {
                 $building = $village->buildings->getBuilding($building);
                 if ($building && $building->checkBuildLocation($village, $x, $y)) {
                     list($ox, $oy) = $building->getLocation();
                     $building->setLocation($x, $y);
                     $logs->addPremiumMoveBuilding($building, $x, $y, $ox, $oy);
                 }
             }
             break;
         case 'bonusbuilding':
             $village = isset($data['village']) ? $data['village'] : null;
             $village = $this->getMyVillage($village);
             $x = isset($data['x']) ? intval($data['x']) : null;
             $y = isset($data['y']) ? intval($data['y']) : null;
             $building = isset($data['building']) ? intval($data['building']) : null;
             $building = Dolumar_Buildings_Building::getBuilding($building, $village->getRace());
             $extra = isset($data['tile']) ? intval($data['tile']) : null;
             $chk = $building->checkBuildLocation($village, $x, $y);
             if ($chk[0]) {
                 $building = $building->build($village, $x, $y, $extra);
                 $logs->addPremiumBonusBuilding($building, $x, $y);
             }
             break;
         case 'speedup':
             $type = isset($data['type']) ? $data['type'] : null;
             $duration = isset($data['duration']) ? $data['duration'] : null;
             switch ($type) {
                 case 'building':
                     $id = isset($data['building']) ? $data['building'] : null;
                     $building = Dolumar_Buildings_Building::getFromId($id);
                     $building->speedupBuild($duration);
                     // Reload the status bar
                     $player = $building->getVillageForced()->getOwner();
                     $player->updates->setFlag('refresh-statusbar');
                     break;
                 case 'training':
                     $id = isset($data['order']) ? $data['order'] : null;
                     $village = isset($data['village']) ? $data['village'] : null;
                     $village = Dolumar_Players_Village::getFromId($village);
                     $village->units->speedupBuild($id, $data['duration']);
                     $player = $village->getOwner();
                     $player->updates->setFlag('refresh-statusbar');
                     break;
                 case 'scouting':
                     $id = isset($data['scoutid']) ? $data['scoutid'] : null;
                     $village = isset($data['village']) ? $data['village'] : null;
                     $village = Dolumar_Players_Village::getFromId($village);
                     $village->speedupScouting($id, $data['duration']);
                     $player = $village->getOwner();
                     $player->updates->setFlag('refresh-statusbar');
                     break;
             }
             break;
         case 'buyresources':
             $village = isset($data['village']) ? $data['village'] : null;
             $resource = isset($data['resource']) ? $data['resource'] : null;
             $village = $this->getMyVillage($village);
             if ($village) {
                 if ($resource === 'all') {
                     $village->resources->fillAll();
                 } else {
                     $village->resources->fill($resource);
                 }
             }
             break;
         default:
             $this->extendPremiumAccount(60 * 60 * 24 * 15);
             break;
     }
 }
Ejemplo n.º 9
0
 /**
  *	@prcTransfers: Should we also process the "unprocessed" transfers?
  */
 public function getOngoingTransfers($prcTransfers = true)
 {
     $db = Neuron_DB_Database::getInstance();
     if ($prcTransfers) {
         $this->processTransfers();
     }
     $data = $db->query("\n\t\t\tSELECT\n\t\t\t\t*,\n\t\t\t\tUNIX_TIMESTAMP(t_date_sent) AS sentdate,\n\t\t\t\tUNIX_TIMESTAMP(t_date_received) AS receiveddate\n\t\t\tFROM\n\t\t\t\tvillages_transfers t\n\t\t\tLEFT JOIN\n\t\t\t\tvillages_transfers_items i USING(t_id)\n\t\t\tWHERE\n\t\t\t\tt.t_isReceived = '0' AND\n\t\t\t\t(t.from_vid = {$this->objMember->getId()} OR t.to_vid = {$this->objMember->getId()})\n\t\t");
     $toProcess = array();
     $transfers = array();
     foreach ($data as $v) {
         // Group on t_id
         if (!isset($transfers[$v['t_id']])) {
             $from = Dolumar_Players_Village::getFromId($v['from_vid']);
             $to = Dolumar_Players_Village::getFromId($v['to_vid']);
             if ($from->equals($this->objMember)) {
                 $type = 'outgoing';
                 if (!isset($toProcess[$to->getId()]) && $v['receiveddate'] < NOW) {
                     $toProcess[$to->getId()] = $to;
                     // Well, if we need to process this anyway,
                     // there is no use in continueing to load stuff.
                     continue;
                 }
             } else {
                 $type = 'incoming';
             }
             $transfers[$v['t_id']] = array('from' => $from, 'to' => $to, 'type' => $type, 'senddate' => $v['sentdate'], 'receiveddate' => $v['receiveddate']);
         }
         // Now add 'em resources
         $restype = strtolower($v['ti_type']);
         if (!isset($transfers[$v['t_id']][$restype])) {
             $transfers[$v['t_id']][$restype] = array();
         }
         $transfers[$v['t_id']][$restype][$v['ti_key']] = $v['ti_amount'];
     }
     // Now, if we still need to process some,
     // we'll have to go trough this again...
     if ($prcTransfers && count($toProcess) > 0) {
         foreach ($toProcess as $v) {
             $v->resources->processTransfers();
         }
         // beware of the loop.
         return $this->getOngoingTransfers(false);
     }
     return array_values($transfers);
 }
Ejemplo n.º 10
0
 private function loadQueues($vilsId)
 {
     $text = Neuron_Core_Text::__getInstance();
     // Replace the selector with a proper one for this table
     $vilsId = str_replace('vid', 'pq_vid', $vilsId);
     // Cancel confirmation
     $cancel = $text->get('cancel', 'queue', 'statusbar');
     $confirm = addslashes($text->get('confirm', 'queue', 'statusbar'));
     $db = Neuron_DB_Database::__getInstance();
     $row = $db->query("\n\t\t\tSELECT\n\t\t\t\tpq_id,\n\t\t\t\tpq_vid,\n\t\t\t\tpq_action,\n\t\t\t\tpq_data\n\t\t\tFROM\n\t\t\t\tpremium_queue\n\t\t\tWHERE\n\t\t\t\tTRUE {$vilsId}\n\t\t");
     foreach ($row as $v) {
         $village = Dolumar_Players_Village::getFromId($v['pq_vid']);
         $data = json_decode($v['pq_data'], true);
         $txt = array('cancel' => '<a href="javascript:void(0);" onclick="confirmAction(this,{\'cancelQueue\':' . $v['pq_id'] . '}, \'' . $confirm . '\');">' . $cancel . '</a>');
         // Find the right queues
         switch ($v['pq_action']) {
             case 'build':
                 $building = Dolumar_Buildings_Building::getBuilding($data['building'], $village->getRace());
                 $txt['building'] = $building->getName();
                 $txt['x'] = floor($data['x']);
                 $txt['y'] = floor($data['y']);
                 break;
             case 'upgrade':
                 $building = Dolumar_Buildings_Building::getFromId($data['building']);
                 $txt['building'] = $building->getName();
                 $txt['level'] = $data['level'];
                 list($txt['x'], $txt['y']) = $building->getLocation();
                 break;
             case 'training':
                 $unit = Dolumar_Units_Unit::getUnitFromId($data['unit'], $village->getRace(), $village);
                 $txt['unit'] = $unit->getName($data['amount'] > 1);
                 $txt['amount'] = $data['amount'];
                 break;
         }
         $this->addCounter(null, $village, Neuron_Core_Tools::putIntoText($text->get($v['pq_action'], 'queue', 'statusbar'), $txt), 'queue', false);
     }
 }
Ejemplo n.º 11
0
if ($lock->setLock('cron_const', 0, $locktime)) {
    //$iIdleTime = 60*15;
    $iIdleTime = 0;
    // Collect all queues of all villages
    $db = Neuron_DB_Database::__getInstance();
    $profiler = Neuron_Profiler_Profiler::getInstance();
    // Only check once every 15 minutes!
    $queues = $db->query("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\tpremium_queue\n\t\tWHERE\n\t\t\tpq_lastcheck < FROM_UNIXTIME(" . (time() - $iIdleTime) . ")\n\t\tORDER BY\n\t\t\tpq_lastcheck ASC\n\t");
    $count = 0;
    $total = count($queues);
    foreach ($queues as $queue) {
        echo "Loaded queue {$queue['pq_id']}\n";
        $profiler->start('Executing queue ' . $queue['pq_id'] . ' (' . $queue['pq_action'] . ')');
        $bRemove = true;
        $profiler->start('Loading village');
        $village = Dolumar_Players_Village::getFromId($queue['pq_vid']);
        $profiler->stop();
        if ($village && $village->isActive() && !$village->getOwner()->inVacationMode()) {
            $bRemove = $village->premium->executeQueuedAction($queue['pq_action'], json_decode($queue['pq_data'], true));
        }
        if ($bRemove) {
            echo "Removing queue {$queue['pq_id']}\n";
            // Remove the queue
            $db->query("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tpremium_queue\n\t\t\t\tWHERE\n\t\t\t\t\tpq_id = {$queue['pq_id']}\n\t\t\t");
        } else {
            echo "Updating queue {$queue['pq_id']}\n";
            // Update the queue
            $db->query("\n\t\t\t\tUPDATE\n\t\t\t\t\tpremium_queue\n\t\t\t\tSET\n\t\t\t\t\tpq_lastcheck = FROM_UNIXTIME(" . time() . ")\n\t\t\t\tWHERE\n\t\t\t\t\tpq_id = {$queue['pq_id']}\n\t\t\t");
        }
        $memory = memory_get_usage();
        $count++;