public function getBody() { $timeframe = Neuron_Core_Tools::getInput('_GET', 'timeframe', 'int', 60 * 60 * 48); $db = Neuron_DB_Database::__getInstance(); $page = new Neuron_Core_Template(); $page->set('timeframe', $timeframe); // Fetch all doubles $data = $db->query("\n\t\t\tSELECT\n\t\t\t\tn_login_log.l_ip,\n\t\t\t\t\n\t\t\t\tGROUP_CONCAT(DISTINCT n_login_log.l_plid) AS plids,\n\t\t\t\tGROUP_CONCAT(DISTINCT n_players.nickname) AS nicknames,\n\t\t\t\t\n\t\t\t\tGROUP_CONCAT(c.pac_plid1) AS cleared_1,\n\t\t\t\tGROUP_CONCAT(c.pac_plid2) AS cleared_2,\n\t\t\t\tGROUP_CONCAT(c.pac_reason) AS cleared_reason,\n\t\t\t\t\n\t\t\t\tCOUNT(DISTINCT l_plid) AS aantal\n\t\t\tFROM\n\t\t\t\tn_login_log\n\t\t\tLEFT JOIN\n\t\t\t\tn_players ON n_login_log.l_plid = n_players.plid\n\t\t\tLEFT JOIN\n\t\t\t\tn_players_admin_cleared c ON (c.pac_plid1 = n_login_log.l_plid OR c.pac_plid2 = n_login_log.l_plid)\n\t\t\tWHERE\n\t\t\t\tn_login_log.l_datetime > FROM_UNIXTIME(" . (NOW - $timeframe) . ") AND\n\t\t\t\tn_players.isPlaying = 1\n\t\t\tGROUP BY\n\t\t\t\tl_ip\n\t\t\tHAVING\n\t\t\t\taantal > 1\n\t\t"); foreach ($data as $row) { $plids = explode(',', $row['plids']); $nicknames = explode(',', $row['nicknames']); // Check clearances. $clearances = $this->getClearancesFromRow($row); $players = array(); $combinedlogs = ""; foreach ($plids as $k => $v) { $players[] = array('id' => $plids[$k], 'name' => isset($nicknames[$k]) ? $nicknames[$k] : 'no-nickname-set', 'url' => $this->getUrl('user', array('id' => $plids[$k])), 'logs_url' => $this->getUrl('gamelogs', array('players' => $plids[$k]))); $combinedlogs .= $plids[$k] . "|"; } // Check for cleared accounts $allcleared = true; foreach ($players as $k => $v) { $players[$k]['cleared'] = $this->isCleared($clearances, $v, $players); if ($allcleared && !$players[$k]['cleared']) { $allcleared = false; } } $combinedlogs = substr($combinedlogs, 0, -1); $page->addListValue('players', array('ip' => $row['l_ip'], 'players' => $players, 'combined_logs_url' => $this->getUrl('gamelogs', array('players' => $combinedlogs)), 'clearmultis' => $this->getUrl('clearmultis', array('players' => $combinedlogs)), 'cleared' => $allcleared, 'amount' => $row['aantal'])); } $page->usortList('players', array($this, 'sortcompare')); return $page->parse('pages/admin/multis.phpt'); }
public function withdrawHonour($amount) { $db = Neuron_DB_Database::__getInstance(); $amount *= -1; // A village gets 1 honour every hour: $duration = abs($amount) * 60 * 60; // Duration should take longer depending on the current honour $duration += min(0, 100 - $this->getHonour()) * 60 * 60; $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tvillages_morale\n\t\t\tSET\n\t\t\t\tm_vid = " . $this->objProfile->getId() . ",\n\t\t\t\tm_amount = " . $amount . ",\n\t\t\t\tm_start = FROM_UNIXTIME(" . NOW . "),\n\t\t\t\tm_end = FROM_UNIXTIME(" . (NOW + ceil($duration)) . ")\n\t\t"); // Clean the mess $db->query("\n\t\t\tDELETE FROM\n\t\t\t\tvillages_morale\n\t\t\tWHERE\n\t\t\t\tm_end < FROM_UNIXTIME(" . NOW . ")\n\t\t"); // Reset the honour $this->honour = null; }
public function addQueueAction($sAction, $aData) { $owner = $this->village->getOwner(); if (!$owner->isPremium()) { $this->error = 'not_premium'; return false; } $db = Neuron_DB_Database::__getInstance(); // Check for maximum $chk = $db->query("\n\t\t\tSELECT\n\t\t\t\tCOUNT(pq_id) AS aantal\n\t\t\tFROM\n\t\t\t\tpremium_queue\n\t\t\tWHERE\n\t\t\t\tpq_vid = {$this->village->getId()}\n\t\t"); if (count($chk) == 1 && $chk[0]['aantal'] < 3) { $result = $db->query("\n\t\t\t\tINSERT INTO\n\t\t\t\t\tpremium_queue\n\t\t\t\tSET\n\t\t\t\t\tpq_vid = {$this->village->getId()},\n\t\t\t\t\tpq_action = '{$db->escape($sAction)}',\n\t\t\t\t\tpq_data = '" . $db->escape(json_encode($aData)) . "',\n\t\t\t\t\tpq_date = FROM_UNIXTIME(" . time() . ")\n\t\t\t"); return $result > 0; } else { $this->error = 'queuelimit'; return false; } }
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; }
public static function timestampToMysqlDatetime($time = null) { if ($time == null) { $time = time(); } $db = Neuron_DB_Database::__getInstance(); return $db->fromUnixtime($time); //return self::datetimeToMysql (date ('d', $time), date ('m', $time), date ('Y', $time), // date ('H', $time), date ('i', $time), date ('s', $time)); }
public function getHTML($error = null) { $page = new Neuron_Core_Template(); $page->setTextSection('chooseTarget', 'main'); $page->set('canTargetSelf', $this->bTargetSelf); $page->set('vid', $this->objVillage->getId()); // Return action if (isset($this->sReturnAction)) { $page->set('returnUrl', $this->sReturnAction); $page->set('returnText', $this->sReturnText); } $sQuery = null; if (isset($this->aInput['sVillageName'])) { $sQuery = $this->aInput['sVillageName']; unset($this->aInput['sVillageName']); } $page->set('input', $this->aInput); $page->set('query', Neuron_Core_Tools::output_varchar($sQuery)); // Fetch all troops if (!empty($sQuery)) { $db = Neuron_Core_Database::__getInstance(); $page->set('hasSearched', true); $l = $db->getDataFromQuery($db->customQuery("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\tvillages\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tvname LIKE '%" . $db->escape($sQuery) . "%'\n\t\t\t\t\t\tAND isActive = 1\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tFIELD(vname, '" . $db->escape($sQuery) . "', vname),\n\t\t\t\t\t\tvname ASC\n\t\t\t\t\tLIMIT 10\n\t\t\t\t")); if (count($l) > 0) { foreach ($l as $v) { $village = Dolumar_Players_Village::getVillage($v['vid'], false); $village->setData($v); $tc = $village->buildings->getTownCenter(); if ($tc) { $loc = $tc->getLocation(); $page->addListValue('results', array('id' => $village->getId(), 'name' => Neuron_Core_Tools::output_varchar($village->getName()), 'location' => $loc[0] . ',' . $loc[1])); } } } } elseif ($this->bShowTargets) { $db = Neuron_DB_Database::__getInstance(); // Popular targets /* $l = $db->getDataFromQuery ( $db->customQuery (" SELECT l_vid, villages.* FROM game_log LEFT JOIN villages ON game_log.l_vid = villages.vid WHERE (l_action = 'attack' OR l_action = 'defend') AND l_vid != ".$this->objVillage->getId ()." AND l_subId = ".$this->objVillage->getId ()." AND isActive = 1 GROUP BY l_vid ORDER BY l_date ASC LIMIT 10 ") ); */ $l = $this->objVillage->visits->getLastVisits(); if (count($l) > 0) { foreach ($l as $village) { // Only add active villages if ($village->isActive()) { $tc = $village->buildings->getTownCenter(); if ($tc) { $loc = $tc->getLocation(); $page->addListValue('results', array('id' => $village->getId(), 'name' => Neuron_Core_Tools::output_varchar($village->getName()), 'location' => $loc[0] . ',' . $loc[1])); } } } } } if (isset($error)) { $page->set('external_error', $error); } return $page->parse('neuron/structure/chooseTarget.phpt'); }
public function leaveClan($user, $action = 'leave') { $db = Neuron_DB_Database::__getInstance(); $db->query("\n\t\t\tUPDATE\n\t\t\t\tclan_members\n\t\t\tSET\n\t\t\t\tcm_active = 0\n\t\t\tWHERE\n\t\t\t\tc_id = " . $this->getId() . " AND \n\t\t\t\tplid = " . $user->getId() . "\n\t\t"); $logs = Dolumar_Players_Logs::getInstance(); $logs->addLeaveClanLog($user, $this, $action); $this->recalculateFullness(); // Also destroy all clan buildings foreach ($user->getVillages() as $v) { foreach ($v->buildings->getBuildings() as $vv) { $vv->onClanLeave(); } } }
public function sendToVillage($target) { // For now: quick & dirty "instant arrival" $db = Neuron_DB_Database::__getInstance(); // Take a look: is this squad traveling at the moment? $current = $db->query("\n\t\t\tSELECT\n\t\t\t\tUNIX_TIMESTAMP(s_start) AS vertrek,\n\t\t\t\tUNIX_TIMESTAMP(s_end) AS aankomst\n\t\t\tFROM\n\t\t\t\tsquad_commands\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t\tAND s_end > FROM_UNIXTIME(" . NOW . ")\n\t\t\tORDER BY\n\t\t\t\ts_end DESC\n\t\t\tLIMIT 1\n\t\t"); if (count($current) > 0) { // This squad is currently travelling, this is a recall. // Moveing back takes as long as moving overthere. $duration = NOW - $current[0]['vertrek']; // Remove all others $db->query("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tsquad_commands\n\t\t\t\tWHERE\n\t\t\t\t\ts_end < FROM_UNIXTIME(" . NOW . ") OR\n\t\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t"); } else { // Calculate the distance & speed $speed = $this->getSpeed(); $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getCurrentLocation(), $target); $duration = $distance * 60 * 10 / ($speed * GAME_SPEED_MOVEMENT); } // Do the actual move $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages_squads\n\t\t\tSET\n\t\t\t\ts_village = " . $target->getId() . "\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t"); // Update the defense slots $db->query("\n\t\t\tUPDATE\n\t\t\t\tsquad_units\n\t\t\tSET\n\t\t\t\ts_slotId = 0,\n\t\t\t\ts_priority = 0\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t"); // Add the commands $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tsquad_commands\n\t\t\tSET\n\t\t\t\ts_id = " . $this->getId() . ",\n\t\t\t\ts_action = 'move',\n\t\t\t\ts_start = FROM_UNIXTIME(" . NOW . "),\n\t\t\t\ts_end = FROM_UNIXTIME(" . (NOW + $duration) . "),\n\t\t\t\ts_from = " . $this->getCurrentLocation()->getId() . ",\n\t\t\t\ts_to = " . $target->getId() . "\n\t\t"); reloadStatusCounters(); reloadEverything(); }
public static function getClassId($object) { $name = get_class($object); $classes = self::getClasses(); $classnames = $classes['names']; // Check if isset! if (!isset($classnames[$name])) { // Insert a new ID $db = Neuron_DB_Database::__getInstance(); $db->query("\n\t\t\t\tINSERT INTO\n\t\t\t\t\tn_logables\n\t\t\t\tSET\n\t\t\t\t\tl_name = '" . $name . "'\n\t\t\t"); /* $id = $db->getInsertId (); $classes['names'][$name] = $id; $classes['ids'][$id] = $name; */ $classes = self::getClasses(true); } return $classes['names'][$name]; }
public static function endVacationMode(Neuron_GameServer_Player $player) { $db = Neuron_DB_Database::__getInstance(); // Remove the vacation mode $db->query("\n\t\t\tUPDATE\n\t\t\t\tn_players\n\t\t\tSET\n\t\t\t\tstartVacation = NULL\n\t\t\tWHERE\n\t\t\t\tplid = {$player->getId()}\n\t\t"); }
private function doesHonourCount() { // Check if attacker (or one of attackers friends) have been // under attack within the last 48 hours (REAL TIME, no game time.) $owner = $this->attackingVillage->getOwner(); if ($owner) { $clans = $owner->getClans(); // No clans: only your own village counts. if (self::CLANMEMBERS_MAY_ATTACK_SMALL_OFFENDERS || count($clans) == 0) { $sWhere = "targetId = " . $this->attackingVillage->getId(); } else { $sWhere = ""; foreach ($clans as $clan) { foreach ($clan->getMembers() as $player) { foreach ($player->getVillages() as $v) { $sWhere .= "targetId = " . $v->getId() . " OR "; } } } $sWhere = substr($sWhere, 0, -4); } } else { $sWhere = "targetId = " . $this->attackingVillage->getId(); } // Use this where to find out if these players has been under attack $db = Neuron_DB_Database::__getInstance(); $startdate = $this->data['startDate']; $chk = $db->query("\n\t\t\tSELECT\n\t\t\t\treportId\n\t\t\tFROM\n\t\t\t\tbattle_report\n\t\t\tWHERE\n\t\t\t\tfromId = " . $this->defendingVillage->getId() . " AND \n\t\t\t\texecDate > FROM_UNIXTIME(" . ($startdate - 60 * 60 * 24 * 1) . ") AND\n\t\t\t\t({$sWhere})\n\t\t"); return count($chk) == 0; }
protected function doEndVacationMode() { $db = Neuron_DB_Database::__getInstance(); // Reset all resource times $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages\n\t\t\tSET\n\t\t\t\tlastResRefresh = '" . time() . "'\n\t\t\tWHERE\n\t\t\t\tplid = {$this->getId()} AND\n\t\t\t\tisActive = '1'\n\t\t"); parent::doEndVacationMode(); }
private function loadSpecialUnits() { if ($this->specialUnits === null) { $buildings = $this->buildings->getBuildings(); $db = Neuron_Core_Database::__getInstance(); $db2 = Neuron_DB_Database::__getInstance(); $l = $db->select('battle_specialunits', array('*'), "bsu_vid = " . $this->getId()); $inBattle = array(); foreach ($l as $v) { $inBattle[$v['bsu_vsu_id']] = true; } $l = $db->select('villages_specialunits', array('*'), "v_id = " . $this->getId() . " AND vsu_tEndDate < " . time()); $this->specialUnits = array('all' => array(), 'available' => array()); foreach ($l as $v) { if (isset($buildings[$v['vsu_bid']])) { $obj = $buildings[$v['vsu_bid']]->getSpecialUnit(); $obj->setId(intval($v['vsu_id'])); // Set current location if (intval($v['vsu_location']) > 0) { $obj->setLocation(self::getVillage($v['vsu_location']), $db2->toUnixtime($v['vsu_moveStart']), $db2->toUnixtime($v['vsu_moveEnd'])); } $this->specialUnits['all'][$v['vsu_id']] = $obj; if (!isset($inBattle[$v['vsu_id']])) { $this->specialUnits['available'][$v['vsu_id']] = $obj; } } else { // Building is gone, destroy unit $db->remove('villages_specialunits', "vsu_id = " . $v['vsu_id']); } } } }
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(); }
public function getOpenIDs() { $db = Neuron_DB_Database::__getInstance(); $openids = Neuron_GameServer_Mappers_PlayerMapper::getOpenIDs($this, false); $out = array(); foreach ($openids as $v) { $out[] = $v['openid_url']; } return $out; }
$game = new Dolumar_Game(); $server = Neuron_GameServer::bootstrap(); $server->setGame($game); $game = new Dolumar_Game(); $server = Neuron_GameServer::getInstance(); $server->setGame($game); $lock = Neuron_Core_Lock::getInstance(); // Unlock after 30 minutes. $locktime = 60 * 30; $maxmemory = return_bytes(ini_get('memory_limit')) * 0.9; $starttime = time(); 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)); }