public function write($key, $value, $forceDb = false)
 {
     if ($forceDb) {
         return $this->writeToDb($key, $value);
     }
     if (!isUsingLocalStorage()) {
         // should probably throw exception here. just leave it as false for now.
         return false;
     }
     list($namespace, $group, $item) = $this->config->parseKey($key);
     $path = base_path("userdata/.env.php");
     $content = '';
     if (file_exists($path)) {
         $content = file_get_contents($path);
     }
     $array = eval('?>' . $content);
     // convert . to _ since some configs don't like . in env vars
     $key = str_replace('.', '_', $key);
     $array[$key] = $value;
     $string = "<?php\n\nreturn " . var_export($array, true) . ";";
     file_put_contents($path, $string);
     //put the value into the environment at run time
     $_ENV[$key] = $value;
     //reload the configuration with the changes to the environment
     \Config::reload($group, $namespace);
 }
Example #2
0
function ShowUniversePage()
{
    global $LNG, $USER;
    $template = new template();
    $action = HTTP::_GP('action', '');
    $universe = HTTP::_GP('uniID', 0);
    switch ($action) {
        case 'open':
            $config = Config::get($universe);
            $config->game_disable = 1;
            $config->save();
            break;
        case 'closed':
            $config = Config::get($universe);
            $config->game_disable = 0;
            $config->save();
            break;
        case 'delete':
            if (!empty($universe) && $universe != ROOT_UNI && $universe != Universe::current()) {
                $GLOBALS['DATABASE']->query("DELETE FROM " . ALLIANCE . ", " . ALLIANCE_RANK . ", " . ALLIANCE_REQUEST . " \n\t\t\t\tUSING " . ALLIANCE . " \n\t\t\t\tLEFT JOIN " . ALLIANCE_RANK . " ON " . ALLIANCE . ".id = " . ALLIANCE_RANK . ".allianceID\n\t\t\t\tLEFT JOIN " . ALLIANCE_REQUEST . " ON " . ALLIANCE . ".id = " . ALLIANCE_REQUEST . " .allianceID\n\t\t\t\tWHERE ally_universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . BANNED . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . BUDDY . ", " . BUDDY_REQUEST . "\n\t\t\t\tUSING " . BUDDY . "\n\t\t\t\tLEFT JOIN " . BUDDY_REQUEST . " ON " . BUDDY . ".id = " . BUDDY_REQUEST . ".id\n\t\t\t\tWHERE " . BUDDY . ".universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . CONFIG . " WHERE uni = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . DIPLO . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . FLEETS . ", " . FLEETS_EVENT . ", " . AKS . ", " . LOG_FLEETS . "\n\t\t\t\tUSING " . FLEETS . "\n\t\t\t\tLEFT JOIN " . FLEETS_EVENT . " ON " . FLEETS . ".fleet_id = " . FLEETS_EVENT . ".fleetID\n\t\t\t\tLEFT JOIN " . AKS . " ON " . FLEETS . ".fleet_group = " . AKS . ".id\n\t\t\t\tLEFT JOIN " . LOG_FLEETS . " ON " . FLEETS . ".fleet_id = " . LOG_FLEETS . ".fleet_id\n\t\t\t\tWHERE " . FLEETS . ".fleet_universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . MESSAGES . " WHERE message_universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . NOTES . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . PLANETS . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . STATPOINTS . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . TICKETS . ", " . TICKETS_ANSWER . "\n\t\t\t\tUSING " . TICKETS . "\n\t\t\t\tLEFT JOIN " . TICKETS_ANSWER . " ON " . TICKETS . ".ticketID = " . TICKETS_ANSWER . ".ticketID\n\t\t\t\tWHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . TOPKB . " WHERE universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . USERS . ", " . USERS_ACS . ", " . USERS_AUTH . ", " . TOPKB_USERS . ", " . SESSION . ", " . SHORTCUTS . ", " . RECORDS . "\n\t\t\t\tUSING " . USERS . "\n\t\t\t\tLEFT JOIN " . USERS_ACS . " ON " . USERS . ".id = " . USERS_ACS . ".userID\n\t\t\t\tLEFT JOIN " . USERS_AUTH . " ON " . USERS . ".id = " . USERS_AUTH . ".id\n\t\t\t\tLEFT JOIN " . TOPKB_USERS . " ON " . USERS . ".id = " . TOPKB_USERS . ".uid\n\t\t\t\tLEFT JOIN " . SESSION . " ON " . USERS . ".id = " . SESSION . ".userID\n\t\t\t\tLEFT JOIN " . SHORTCUTS . " ON " . USERS . ".id = " . SHORTCUTS . ".ownerID\n\t\t\t\tLEFT JOIN " . RECORDS . " ON " . USERS . ".id = " . RECORDS . ".userID\n\t\t\t\tLEFT JOIN " . LOSTPASSWORD . " ON " . USERS . ".id = " . LOSTPASSWORD . ".userID\n\t\t\t\tWHERE " . USERS . ".universe = " . $universe . ";");
                $GLOBALS['DATABASE']->query("DELETE FROM " . USERS_VALID . " WHERE universe = " . $universe . ";");
                if (Universe::getEmulated() == $universe) {
                    Universe::setEmulated(Universe::current());
                }
                if (count(Universe::availableUniverses()) == 2) {
                    // Hack The Session
                    setcookie(session_name(), session_id(), SESSION_LIFETIME, HTTP_BASE, NULL, HTTPS, true);
                    HTTP::redirectTo("../admin.php?reload=r");
                }
            }
            break;
        case 'create':
            $universeCount = count(Universe::availableUniverses());
            // Check Multiuniverse Support
            $ch = curl_init();
            if ($universeCount == 1) {
                curl_setopt($ch, CURLOPT_URL, PROTOCOL . HTTP_HOST . HTTP_BASE . "uni" . ROOT_UNI . "/");
            } else {
                curl_setopt($ch, CURLOPT_URL, PROTOCOL . HTTP_HOST . HTTP_BASE);
            }
            curl_setopt($ch, CURLOPT_HTTPGET, true);
            curl_setopt($ch, CURLOPT_AUTOREFERER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; 2Moons/" . Config::get()->VERSION . "; +http://2moons.cc)");
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"));
            curl_exec($ch);
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            if ($httpCode != 302) {
                $template = new template();
                $template->message(str_replace(array('{NGINX-CODE}'), array('rewrite /(.*)/?uni[0-9]+/?(.*) /$1/$2 break;'), $LNG->getTemplate('createUniverseInfo')) . '<a href="javascript:window.history.back();"><button>' . $LNG['uvs_back'] . '</button></a>' . '<a href="javascript:window.location.reload();"><button>' . $LNG['uvs_reload'] . '</button></a>');
                exit;
            }
            $config = Config::get();
            $configSQL = array();
            foreach (Config::getGlobalConfigKeys() as $basicConfigKey) {
                $configSQL[] = '`' . $basicConfigKey . '` = "' . $config->{$basicConfigKey} . '"';
            }
            $configSQL[] = '`uni_name` = "' . $LNG['fcm_universe'] . ' ' . ($universeCount + 1) . '"';
            $configSQL[] = '`close_reason` = ""';
            $configSQL[] = '`OverviewNewsText` = "' . $GLOBALS['DATABASE']->escape($config->OverviewNewsText) . '"';
            $GLOBALS['DATABASE']->query("INSERT INTO " . CONFIG . " SET " . implode(', ', $configSQL) . ";");
            $newUniverse = $GLOBALS['DATABASE']->GetInsertID();
            Config::reload();
            list($userID, $planetID) = PlayerUtil::createPlayer($newUniverse, $USER['username'], '', $USER['email'], $USER['lang'], 1, 1, 1, NULL, AUTH_ADM);
            $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET password = '******'password'] . "' WHERE id = " . $userID . ";");
            if ($universeCount === 1) {
                // Hack The Session
                setcookie(session_name(), session_id(), SESSION_LIFETIME, HTTP_ROOT . 'uni' . $USER['universe'] . '/', NULL, HTTPS, true);
                HTTP::redirectTo("uni" . $USER['universe'] . "/admin.php?reload=r");
            }
            break;
    }
    $uniList = array();
    $uniResult = $GLOBALS['DATABASE']->query("SELECT uni, users_amount, game_disable, energySpeed, halt_speed, resource_multiplier, fleet_speed, game_speed, uni_name, COUNT(DISTINCT inac.id) as inactive, COUNT(planet.id) as planet\n\tFROM " . CONFIG . " conf\n\tLEFT JOIN " . USERS . " as inac ON uni = inac.universe AND inac.onlinetime < " . (TIMESTAMP - INACTIVE) . "\n\tLEFT JOIN " . PLANETS . " as planet ON uni = planet.universe\n\tGROUP BY conf.uni, inac.universe, planet.universe\n\tORDER BY uni ASC;");
    while ($uniRow = $GLOBALS['DATABASE']->fetch_array($uniResult)) {
        $uniList[$uniRow['uni']] = $uniRow;
    }
    $template->assign_vars(array('uniList' => $uniList, 'SID' => session_id()));
    $template->show('UniversePage.tpl');
}