public static function bundle2text($xml, $sName = 'default')
 {
     $data = self::getTextContent($xml);
     $cache = Neuron_Core_Cache::getInstance('language/' . $sName . '/');
     foreach ($data['messages'] as $k => $v) {
         $cache->setCache($k, serialize($v));
     }
     foreach ($data['files'] as $k => $v) {
         $cache->setCache($k, $v);
     }
 }
 protected function load_file($file)
 {
     $cache = Neuron_Core_Cache::getInstance('language/' . $this->sName . '/');
     if ($data = $cache->getCache($file)) {
         $this->cache[$file] = unserialize($data);
     } else {
         Neuron_Core_MessageBundle::bundle2text($this->sUrl, $this->sName);
         // Now check again. If it not exists, enter an empty array.
         if ($data = $cache->getCache($file)) {
             $this->cache[$file] = unserialize($data);
         } else {
             $cache->setCache($file, serialize(array()));
         }
     }
 }
Пример #3
0
 public function getContent()
 {
     $player = Neuron_GameServer::getPlayer();
     if ($player && $player->isPlaying()) {
         $page = new Neuron_Core_Template();
         // Check for welcome message
         if (isset($_SESSION['welcome_html'])) {
             $page->set('welcome', $_SESSION['welcome_html']);
         }
         $server = Neuron_GameServer_Server::getInstance();
         $txt = $server->getText('headline');
         $page->set('headline', isset($txt) ? Neuron_Core_Tools::output_text($txt) : null);
         $page->set('nickname', $player->getDisplayName());
         $page->set('isPremium', $player->isPremium());
         $page->set('date', date(DATE, $player->getPremiumEndDate()));
         $page->set('isFreePremium', !$player->isProperPremium());
         $msg = Neuron_GameServer_Mappers_CachedChatMapper::getInstance();
         $messages = $msg->countUnreadMessages($player);
         $page->set('inbox', $messages);
         $clans = $player->getClans();
         $page->set('hasclan', count($clans) > 0);
         if (count($clans) > 0) {
             $objlogs = Dolumar_Players_ClanLogs::getInstance();
             $objlogs->clearMyVillages();
             foreach ($player->getVillages() as $village) {
                 $objlogs->addMyVillage($village);
             }
             $logs = $objlogs->getClanLogs($clans, 0, 3);
             foreach ($logs as $v) {
                 $page->addListValue('logs', array('date' => date(DATETIME, $v['timestamp']), 'text' => $objlogs->getLogText($v)));
             }
         }
         // Fetch thze news
         if (defined('GAMENEWS_RSS_URL')) {
             $text = Neuron_Core_Text::getInstance();
             $localized_link = str_replace('{lang}', $text->getCurrentLanguage(), GAMENEWS_RSS_URL);
             $rss = new Neuron_Core_RSSParser($localized_link);
             $rss->setCache(Neuron_Core_Cache::getInstance('newsfeed/'));
             foreach ($rss->getItems(3) as $v) {
                 $page->addListValue('gamenews', array('date' => $v['date'] ? date(DATETIME, $v['date']) : null, 'title' => $v['title'], 'url' => $v['url']));
             }
         }
         return $page->parse('dolumar/welcome/welcome.phpt');
     }
     return false;
 }
Пример #4
0
 public static function parseHelpFile($file)
 {
     $objCache = Neuron_Core_Cache::__getInstance('wiki/');
     $sKey = str_replace('/', '|', $file);
     $cache = null;
     if (self::USE_CACHE) {
         $cache = $objCache->getCache($sKey);
         //$cache = false;
         if ($cache) {
             return $cache;
         }
     }
     $t = self::parseNewFile($file);
     if ($t) {
         if (self::USE_CACHE) {
             $objCache->setCache($sKey, $t);
         }
         return $t;
     } else {
         return false;
     }
 }
 public function dispatch()
 {
     if (!isset($this->objGame)) {
         throw new Neuron_Core_Error('Neuron_GameServer did not receive a Neuron_GameServer_Game object.');
     }
     if ($this->objGame instanceof Neuron_GameServer_Interfaces_Dispatch) {
         if (!$this->getRidOfSessionID()) {
             return;
         }
         $this->objGame->dispatch();
         return;
     }
     Neuron_URLBuilder::getInstance()->setOpenCallback(array($this, 'getOpenUrl'));
     Neuron_URLBuilder::getInstance()->setUpdateCallback(array($this, 'getUpdateUrl'));
     $pgen = Neuron_Core_PGen::__getInstance();
     $pgen->start();
     // Start counter
     $sInputs = explode('/', isset($_GET['module']) ? $_GET['module'] : null);
     $sModule = $sInputs[0];
     switch ($sModule) {
         case 'openid':
             $this->openid();
             break;
         case 'gameserver':
             array_shift($sInputs);
             array_shift($sInputs);
             $assetPath = realpath(__DIR__ . '/../../assets/');
             $filename = $assetPath . '/' . implode('/', $sInputs);
             if (file_exists($filename)) {
                 $ext = explode('.', $filename);
                 $ext = array_pop($ext);
                 switch ($ext) {
                     case 'css':
                         header('Content-Type: text/css');
                         break;
                     default:
                         $finfo = finfo_open(FILEINFO_MIME_TYPE);
                         $mimetype = finfo_file($finfo, $filename);
                         finfo_close($finfo);
                         header('Content-Type: ' . $mimetype);
                         break;
                 }
                 echo file_get_contents($filename);
             } else {
                 http_response_code(404);
                 echo 'File not found: ' . implode('/', $sInputs);
             }
             break;
         case 'dialog':
             // A little overwrite
             $output = $this->objGame->getCustomOutput();
             if ($output) {
                 header("Content-Type: text/xml; charset=utf-8;");
                 echo '<?xml version="1.0" encoding="utf-8"?>';
                 echo '<root><command command="refresh"></command></root>';
                 return;
             }
             require_once self::SCRIPT_PATH . 'dialog/dialog.php';
             break;
         case 'api':
             require_once self::SCRIPT_PATH . 'api/api.php';
             break;
         case 'map':
             // Close the session (lock)
             //session_write_close ();
             require_once self::SCRIPT_PATH . 'map/map.php';
             break;
         case 'image':
             // Close the session (lock)
             session_write_close();
             require_once self::SCRIPT_PATH . 'image/image.php';
             break;
         case 'test':
             // Close the session (lock)
             session_write_close();
             // Login
             $player = Neuron_GameServer::getPlayer();
             $overwritelogin = true;
             if ((!$player || !$player->isAdmin()) && !$overwritelogin) {
                 echo 'You must login.';
             } else {
                 $file = isset($sInputs[1]) ? $sInputs[1] : null;
                 if (@(include 'scripts/tests/' . $sInputs[1] . '.php')) {
                     //include_once ('scripts/tests/' . $sInputs[1] . '.php');
                 } else {
                     if (include self::SCRIPT_PATH . 'tests/' . $file . '.php') {
                         // ok
                     } else {
                         echo "File not found: " . self::SCRIPT_PATH . 'tests/' . $file . '.php';
                     }
                 }
                 /*if (file_exists (self::SCRIPT_PATH.'tests/'.$file.'.php'))
                 		{
                 		*/
                 /*}
                 		else
                 		{
                 			echo "File not found: " . self::SCRIPT_PATH.'tests/'.$file.'.php';
                 		}*/
             }
             break;
         case 'admin':
             // Check for page
             setcookie('session_id', session_id(), 0, COOKIE_BASE_PATH . 'admin/');
             $login = Neuron_Core_Login::getInstance(1);
             if (!$login->isLogin()) {
                 $objPage = new Neuron_GameServer_Pages_Admin_Login($login);
             } else {
                 $sPage = isset($sInputs[1]) ? $sInputs[1] : 'Index';
                 $sClassname = 'Neuron_GameServer_Pages_Admin_' . ucfirst(strtolower($sPage));
                 $myself = Neuron_GameServer::getPlayer();
                 if ($myself && $myself->isChatModerator()) {
                     if ($objPage = $this->objGame->getAdminPage($sPage)) {
                     } elseif (class_exists($sClassname)) {
                         $objPage = new $sClassname();
                     } else {
                         $objPage = new Neuron_GameServer_Pages_Admin_Index();
                     }
                 } else {
                     $objPage = new Neuron_GameServer_Pages_Admin_Invalid();
                 }
             }
             echo $objPage->getHTML();
             break;
         case 'page':
             // Check for page
             $sPage = isset($sInputs[1]) ? $sInputs[1] : 'Index';
             $sClassname = 'Neuron_GameServer_Pages_' . ucfirst(strtolower($sPage));
             $myself = Neuron_GameServer::getPlayer();
             if ($objPage = $this->objGame->getPage($sPage)) {
             } else {
                 if (class_exists($sClassname)) {
                     $objPage = new $sClassname();
                 } else {
                     $objPage = new Neuron_GameServer_Pages_Index();
                 }
             }
             echo $objPage->getOutput();
             break;
         case 'time':
             echo 'time=' . round(microtime(true) * 1000);
             break;
         case '':
             $_SESSION['tmp'] = null;
             // Now, if we have a NOLOGIN_REDIRECT set, redirect here
             if (defined('NOLOGIN_REDIRECT') && !isset($_GET['DEBUG'])) {
                 $player = Neuron_GameServer::getPlayer();
                 if (!$player) {
                     header("Location: " . NOLOGIN_REDIRECT);
                     echo "Redirecting to " . NOLOGIN_REDIRECT;
                 } else {
                     $this->showIndexPage();
                 }
             } else {
                 $this->showIndexPage();
             }
             break;
         case 'favicon.ico':
         case 'favicon.icon':
             header('Content-type: image/x-icon');
             echo file_get_contents('./favicon.ico');
             break;
         default:
             //throw new Exception ('Invalid API call: module "'.$sModule.'" not found.');
             echo '<p>Invalid module: ' . $sModule . '</p>';
             break;
     }
     if (isset($profiler) && defined(USE_PROFILE) && USE_PROFILE) {
         // Dump the profiler
         if (intval($profiler->getTotalDuration()) > 2) {
             $cache = Neuron_Core_Cache::__getInstance('profiler/' . $_SERVER['REMOTE_ADDR'] . '/');
             $cache->setCache(date('dmYHis'), (string) $profiler);
         }
     }
 }
Пример #6
0
 *  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");
        echo $image;
    } else {
        $im = imagecreate($width, $height);
Пример #7
0
    $dim = IMG_WIDTH / IMG_HEIGHT;
    if ($dim > 2) {
        // Right bottom
        $dest = array(floor(IMG_WIDTH - $width) - 5, IMG_HEIGHT - 13 + $size / 2);
    } else {
        // Center bottom
        $dest = array(floor(IMG_WIDTH / 2 - $width / 2), IMG_HEIGHT - 18 + $size / 2);
    }
    imagettftext($im, $size, 0, $dest[0], $dest[1], $color, $font, $name);
}
define('IMG_WIDTH', isset($_GET['width']) ? (int) $_GET['width'] : 800);
define('IMG_HEIGHT', isset($_GET['height']) ? (int) $_GET['height'] : 400);
define('IMG_ZOOM', isset($_GET['zoom']) ? (int) $_GET['zoom'] : 100);
// Check for data
if (isset($player_id)) {
    $player = Neuron_GameServer::getPlayerFromOpenID($player_id, true);
    if ($player && $player->isFound()) {
        $village = $player->getMainVillage();
        if ($village) {
            $loc = $village->buildings->getTownCenterLocation();
            define('LOC_X', $loc[0]);
            define('LOC_Y', $loc[1]);
        } else {
            define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0);
            define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0);
        }
    } else {
        define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0);
        define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0);
    }
} else {
Пример #8
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.
 */
define('DISABLE_STATIC_FACTORY', true);
$objCache = Neuron_Core_Cache::__getInstance('general/');
$parameters = array('type' => '2d');
$usecache = isset($_GET['nocache']) ? $_GET['nocache'] != 1 : true;
if ($usecache && ($ranking = $objCache->getCache('ranking.xml', 60 * 60 * 12))) {
    header('Content-type: text/xml');
    echo $ranking;
    exit(1);
} else {
    $lock = Neuron_Core_Lock::getInstance();
    if ($lock->setLock('ranking_api', 1)) {
        header('Content-type: text/xml');
        // Fetch ALL players
        $db = Neuron_Core_Database::__getInstance();
        $players = $db->getDataFromQuery($db->customQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tn_players.*, \n\t\t\t\t\tSUM(villages.networth) AS score\n\t\t\t\tFROM\n\t\t\t\t\tn_players\n\t\t\t\tLEFT JOIN\n\t\t\t\t\tvillages ON villages.plid = n_players.plid\n\t\t\t\tWHERE\n\t\t\t\t\tn_players.plid IS NOT NULL \n\t\t\t\t\tAND villages.vid IS NOT NULL\n\t\t\t\t\tAND villages.isActive = 1\n\t\t\t\t\tAND n_players.isPlaying = '1' \n\t\t\t\t\tAND n_players.isRemoved = '0'\n\t\t\t\tGROUP BY\n\t\t\t\t\tn_players.plid\n\t\t\t\tORDER BY\n\t\t\t\t\tscore DESC,\n\t\t\t\t\tLOWER(n_players.nickname) ASC\n\t\t\t"));
        $output = '<?xml version="1.0" encoding="UTF-8"?>';
        $output .= '<browsergameshub version="1" type="2d">';
Пример #9
0
 public function setLocationCache($x, $y, $data)
 {
     parent::setCache('map' . $x . 'x' . $y, serialize($data));
 }
Пример #10
0
function getBackgroundImage($x, $y, $tilesToLoad, $usecache = true)
{
    global $color_cache;
    $cachename = 'i' . intval($_GET['x']) . 'p' . intval($_GET['y']) . $tilesToLoad . '.png';
    $cache = Neuron_Core_Cache::__getInstance('minimapbg/');
    if ($usecache && $cache->hasCache($cachename, 0)) {
        $img = $cache->getFileName($cachename);
        return imagecreatefrompng($img);
    } else {
        $color_cache = array();
        // Build the new background image.
        $tileSizeX = 8;
        $tileSizeY = $tileSizeX / 2;
        $halfTileX = floor($tileSizeX / 2);
        $halfTileY = floor($tileSizeY / 2);
        $im = imagecreate($tileSizeX * $tilesToLoad, $tileSizeY * $tilesToLoad);
        $background = imagecolorallocate($im, 0, 0, 0);
        $switchpoint = $tilesToLoad;
        $loadExtra = 1;
        $startX = ($x + $y) * $switchpoint;
        $startY = ($x - $y) * $switchpoint;
        for ($i = 0 - $loadExtra - 1; $i < $switchpoint * 2 + $loadExtra + 1; $i++) {
            if ($i > $switchpoint) {
                $offset = ($i - $switchpoint) * 2;
            } else {
                $offset = 0;
            }
            $colStart = 0 - $i + $offset - $loadExtra;
            $colEnd = $i - $offset + $loadExtra + 1;
            //$output['sq'][$sQ]['tl'][$i] = array ();
            $tx = $startX + $i;
            $white = imagecolorallocate($im, 255, 255, 255);
            for ($j = $colStart - 1; $j < $colEnd + 1; $j++) {
                $ty = $startY - $j;
                $px = round(($i - $j) * floor($tileSizeX / 2));
                $py = round(($i + $j) * floor($tileSizeY / 2));
                // Check for building
                /*
                if (isset ($buildings[$tx]) && isset ($buildings[$tx][$ty]))
                {
                	$color = color_cache ($im, $buildings[$tx][$ty][0]->getMapColor ());
                }
                			
                else
                {
                */
                $location = Dolumar_Map_Location::getLocation($tx, $ty);
                $c = $location->getHeightIntencity();
                $col = $location->getMapColor();
                $col[0] = floor($col[0] * $c);
                $col[1] = floor($col[1] * $c);
                $col[2] = floor($col[2] * $c);
                $color = color_cache($im, $col);
                //}
                $punten = array($px + $halfTileX, $py, $px + $tileSizeX, $py + $halfTileY, $px + $halfTileX, $py + $tileSizeY, $px, $py + $halfTileY);
                imagefilledpolygon($im, $punten, 4, $color);
            }
        }
        ob_start();
        imagepng($im, null);
        $cache->setCache($cachename, ob_get_clean());
        return $im;
    }
}