<?
	
	Error_Reporting(E_ALL & ~ E_NOTICE);
	Error_Reporting(ERROR | WARNING);
	mb_internal_encoding('UTF-8');
	@ ini_set('arg_separator.output', '&amp;');
	@ ini_set('session.use_trans_sid', '0');
	if (!isset ($rootpath))
	$rootpath = '../';

	session_name("SESID");
	session_start();

	require_once $rootpath . 'includes/db.php';
	$connect = @ mysql_connect($db_host, $db_user, $db_pass) or die('cannot connect to server');
	@ mysql_select_db($db_name) or die('cannot connect to db');
	@ mysql_query("SET NAMES 'utf8'", $connect);
	
	$req = mysql_query("SELECT * FROM `setting`;");
	$sets = array();
	while ($ress = mysql_fetch_row($req)) $sets[$ress[0]] = $ress[1];
	mysql_free_result($req);
	$home = $sets['host'];
	$title = $sets['title'];
	$maxonl = $sets['maxonl'];
	$maxtime = $sets['maxtime'];
	$xnum = $sets['xnum'];
	$ynum = $sets['ynum'];
	$lsun = $sets['lsun'];
	$quest_max = $sets['quest_max'];
    $emailadmina='mobsc@bk.ru';
	$online_time=300;
	if (isset($_SESSION['uid']) && isset($_SESSION['pass']))
	{
		$use_id = $_SESSION['uid'];
		$pass = $_SESSION['pass'];
	}
	elseif (isset ($_COOKIE['uid']) && isset ($_COOKIE['pass']))
	{
		$use_id = intval(base64_decode($_COOKIE['uid']));
		$_SESSION['uid'] = $use_id;
		$pass = md5($_COOKIE['pass']);
		$_SESSION['pass'] = $pass;
		$cookauth = true;
	}
	if ($use_id && $pass)
	{
		$req = mysql_query('SELECT * FROM `users` WHERE `id` = ' .$use_id . ' LIMIT 1');
		if (mysql_num_rows($req))
		{
			$data = mysql_fetch_assoc($req);
			if ($pass === $data['password'])
			{
				$use_id = $data['id'];
				$login = $data['login'];
				$level = $data['level'];
				$diz = $data['diz'];
				$logo = $data['logo'];
				$ban = $data['ban'];
				$ban_chat = $data['ban_chat'];
				$ava = $data['ava'];
				$chat_ava = $data['chat_ava'];
				$elem = $data['elem'];
				$chat_time = $data['chat_time'];
				$rasa = $data['rasa'];
				$game = $data['game'];
				$hero = $data['hero'];
				$maxplanet = $data['planet'];
				$lvl_hero = $data['lvl_hero'];
				$marat = $data['marat'];
				$tmarat = $data['tmarat'];
				$fr = $data['fr'];
				$fr_id = $data['fr_id'];
				$fr_name = $data['fr_name'];
				$quest = $data['quest'];
				$sc_quest = $data['sc_quest'];
				$quest_set = $data['quest_set'];
				$sc = $data['sc'];
				$lasttime = $data['lasttime'];
				$newtime = $data['newtime'];
				$regtime = $data['regtime'];
				$min = round($data['min'],1);
				$gas = round($data['gas'],1);
				$metall = round($data['metall'],1);
				$water = round($data['water'],1);
				$prov = round($data['prov'],1);
				$kred = round($data['kred'],1);		

				mysql_free_result($req);
			}
			else
			{
				unset($_SESSION['uid']);
				unset($_SESSION['pass']);
				setcookie('uid', '');
				setcookie('pass', '');
				$use_id = false;
				$pass = false;
			}
		}
		else
		{
			unset($_SESSION['uid']);
			unset($_SESSION['pass']);
			setcookie('uid', '');
			setcookie('pass', '');
			$use_id = false;
			$pass = false;
		}

	}
	if($level==0)$diz=1;
	$id = isset ($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : false;
	$page = isset ($_REQUEST['page']) && $_REQUEST['page'] > 0 ? intval($_REQUEST['page']) : 1;
	$act = isset ($_GET['act']) ? trim($_GET['act']) : '';
	$set = isset ($_GET['set']) ? trim($_GET['set']) : '';

$realtime = time();
?>