<?php
error_reporting(0);
date_default_timezone_set('Europe/Moscow');
/* 
Определяем текущий домен сайта. 
Дальнейшее использование 
echo $set['site'];
*/
$set['site'] = htmlspecialchars($_SERVER['HTTP_HOST']); 
/* 
$http_host = check($_SERVER['HTTP_HOST']);
Записываем в константу полный путь до корня сайта. 
Я обычно использую в функции require_once, т.к при указании полного пути до файла, файл находится быстрее 
*/
define("H", $_SERVER["DOCUMENT_ROOT"].'/');
/*
==========================
Подключение к базе
==========================
*/
ob_start();
$db = mysql_connect('localhost','db1425141307','1349973');
mysql_query('SET NAMES`utf8`',$db); 
// Устанавливаем кодировку по умолчанию 
mysql_select_db('db1425141307',$db);
// Загрузка остальных плагинов из папки "core/function/"
$opdirbase = opendir(H.'core/function/');
while ($filebase = readdir($opdirbase))
{
if (preg_match('#\.php$#i', $filebase))
{
require_once(H.'core/function/' . $filebase);
}
}

$get_id = num($_GET['id']);
$get_parent_id = num($_GET['parent_id']);
$get_invite_id = num($_GET['invite']);
$get_attack = num($_GET['attack']);
$get_action = rawurlencode($_GET['action']);
$get_page = num($_GET['page']);
$post_id = num($_POST['id']);
$post_text = check($_POST['text']);
$post_page = num($_POST['page']);
$get_build = num($_GET['build']);
$get_accelerate = num($_GET['accelerate']);
$get_upgrade = num($_GET['upgrade']);

function smiles($text){
$text = rawuridecode($text);
$text = htmlspecialchars($text);
$aa = mysql_query("SELECT name,adres FROM `smiles` order by `id` desc");
while($ba = mysql_fetch_assoc($aa)){
$text =str_replace($ba['name'],'<img src="'.$ba['adres'].'" alt="smile" />', $text);
}
return nl2br($text);
}
 
function moder_smiles($moder){
$moder=rawuridecode($moder);
$moder = htmlspecialchars($moder);
$smile = mysql_query("SELECT name,adres FROM `smiles` order by `id` desc");
while($while_smile = mysql_fetch_assoc($smile)){
$moder=str_replace($while_smile['name'],'<img src="'.$while_smile['adres'].'" alt="smile" />', $moder);
}
$bbcode = array(
'/\[i\](.+)\[\/i\]/isU' => '<em>$1</em>',
'/\[b\](.+)\[\/b\]/isU' => '<span class="b-bbcode">$1</span>',
'/\[u\](.+)\[\/u\]/isU' => '<span style="text-decoration:underline;">$1</span>',
'/\[big\](.+)\[\/big\]/isU' => '<span style="font-size:large;">$1</span>',
'/\[center\](.+)\[\/center\]/isU' => '<div class="center">$1</div>',
'/\[small\](.+)\[\/small\]/isU' => '<span style="font-size:xx-small;">$1</span>',
'/\[right\](.+)\[\/right\]/isU' => '<div class="right">$1</div>',
'/\[hr\]/isU' => '<hr />',
'/\[br\]/isU' => '<br />',
'/\[color=(.+)\](.+)\[\/color\]/isU' => '<span style="color:$1;">$2</span>',
'/\[li\](.+)\[\/li\]/isU' => '<li class="bbcode_li">$1</li>'
);
$moder = preg_replace(array_keys($bbcode), array_values($bbcode), $moder);
$moder = preg_replace('/\[img=(.+)\](.+)\[\/img\]/isU', '<img style="max-width:250px;" height="$1" src="http://glad.keo.su/$2">', $moder);
//$moder = preg_replace('/\[color=(.+)\](.+)\[\/color\]/isU', '<font color="$1">$2</font>', $moder);
$moder = preg_replace('/\[url=(.+)\](.+)\[\/url\]/isU', '<a style="text-decoration:underline;color:0;" href="http://glad.keo.su/$1">$2</a>', $moder);
return nl2br($moder);
}

/*
========================
Куки
========================
*/
session_start();
if(mysql_result(mysql_query("SELECT count(id) from `ipban` where `ip` = '".check($_SERVER['REMOTE_ADDR'])."'"),0) >= 1){
echo'Ваш IP заблокирован.'; exit;
}
if(isset($_COOKIE['nick'])  && isset($_COOKIE['pass'])) {
$usernick = check($_COOKIE['nick']);
$userpass = check($_COOKIE['pass']);
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `nick` = '$usernick' && `pass` = '$userpass' LIMIT 1"));
if($user['bonus_sila'] > time()) {
    $user['sila'] += 300;
    $user['max_health'] += 300;
    $user['lovk'] += 300;
    $user['zashit'] += 300;
    $user['mana'] += 300;
}
// http://stateika.com/php/5-round-ceil-floor.html
/*if ($user['max_heath'] != ceil($user['max_health'])) {
mysql_query("UPDATE `user` SET `max_health` = '".ceil($user['max_health'])."'");
}   
if ($user['max_heath'] != ceil($user['sila'])) {
mysql_query("UPDATE `user` SET `sila` = '".ceil($user['sila'])."'");
}   
if ($user['max_heath'] != ceil($user['max_health'])) {
mysql_query("UPDATE `user` SET `max_mana` = '".ceil($user['max_mana'])."'");
}   
if ($user['max_heath'] != ceil($user['zashit'])) {
mysql_query("UPDATE `user` SET `zashit` = '".ceil($user['zashit'])."'");
}   
if ($user['max_heath'] != ceil($user['lovk'])) {
mysql_query("UPDATE `user` SET `lovk` = '".ceil($user['lovk'])."'");
}   
*/

} 
//////////////Функция BANNED/////////////////
if($user['banned'] > time() or $user['banned'] != 0){

 function ban_time($tl){
$d=3600*24;
$day=floor($tl/$d);
$tl=$tl-($d*$day);

$hour=floor($tl/3600);
$tl=$tl-(3600*$hour);

$minute=floor($tl/60);
$tl=$tl-(60*$minute);

$second=floor($tl);

$dayt="".($day>0?"$day д. ":null)."";
$hourt="".($hour>0?"$hour ч. ":null)."";
$minutet="".($minute>0?"$minute м. ":null)."";
$secondt="".($second>0?"$second с. ":null)."";
if($day>0)
{
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0)
{
$secondt=NULL;
$dayt=NULL;
}
return "$dayt$hourt$minutet$secondt";
     }
     

include 'head.php';
?>

	<div class='player center'>
	
	<center> Профиль заблокирован! <br/>
	Причина: <?=$user['prich'];?><br/>
	Окончание блокировки через: <?=ban_time($user['banned']-time());?>
	
	</div>
</div>





<?include 'foot.php';

?>
</div>

</body>
</html>
     <?
     
     if($user['banned'] < time()) {
     if($user['banned'] != 0){
         mysql_query("update `user` set `banned` = '0', `prich` = '' where `id` = '$user[id]'");
         header("location: ?");
     }
}
     
     exit;
}
// Дальнейшее обращение к пользователю $user['nick']
if(mysql_result(mysql_query("SELECT count(*) from `us_ban` where `type` = 'game' and `usid` = '$user[id]' and `time` > '".time()."'"),0) == true){
$user_ban = mysql_fetch_assoc(mysql_query("Select * from `us_ban` where `usid` = '$user[id]'"));
$banner = mysql_fetch_assoc(mysql_query("Select * from `user` where `id` = '$user_ban[usban]'"));
setcookie('nick', '', time() - 100, '/');
setcookie('pass', '', time() - 100, '/');
header('Location: /');
$_SESSION['err'] = 'Вы были заблокированы<br />Причина: "'.$user_ban['prich'].'"<br /> Заблокировал: '.$banner['nick'].' <br />Осталось: '.bansec2time($user_ban['time'] - time()).'';

exit();
}
$act = isset($_GET['act']) ? htmlspecialchars($_GET['act']) : '';
$buy = isset($_GET['buy']) ? htmlspecialchars($_GET['buy']) : '';
// Постраничная навигация
if ($user['set_p_str']!=NULL)
$set['p_str'] = $user['set_p_str'];
mysql_query("update `user` set `online` = '".time()."' where  (`id` = '".$user['id']."') LIMIT 1");
include_once H.'core/var.php';
$param = $user[sila] + $user[lovk] + $user[zashit] + $user[max_health];
mysql_query("UPDATE `user` SET `param` = '$param' WHERE `id` = '$user[id]' LIMIT 1");
if($user[health] < 0)mysql_query("UPDATE `user` SET `health` = '0' WHERE `id` = '$user[id]' LIMIT 1");
$ip=htmlspecialchars(stripslashes($_SERVER['REMOTE_ADDR']));
$user_agent =htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));
mysql_query("UPDATE `user` SET `ip` = '$ip', `user_agent` = '$user_agent' WHERE `id` = '$user[id]' LIMIT 1");
$user_clan = mysql_fetch_assoc(mysql_query("SELECT * FROM `clans` WHERE `id` = '".$user['clan_id']."'"));

$exp_bonus = $exp/100*$user_clan['exp_perc_bonus']+$exp;

function pagenav($base_url, $start, $max_value, $num_per_page) {
    ////////////////////////////////////////////////////////////
    // Функция постраничной навигации                         //
    ////////////////////////////////////////////////////////////
    // За основу взята аналогичная функция от форума SMF2.0   //
    ////////////////////////////////////////////////////////////
    $pgcont = 4;
    $pgcont = (int)($pgcont - ($pgcont % 2)) / 2;
    if ($start >= $max_value)
        $start = max(0, (int)$max_value - (((int)$max_value % (int)$num_per_page) == 0 ? $num_per_page : ((int)$max_value % (int)$num_per_page)));
    else
        $start = max(0, (int)$start - ((int)$start % (int)$num_per_page));
    $base_link = '<a href="' . strtr($base_url, array ('%' => '%%')) . 'starts=%d' . '">%s</a> ';
    $pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '&lt;&lt;');
    if ($start > $num_per_page * $pgcont)
        $pageindex .= sprintf($base_link, 0, '1');
    if ($start > $num_per_page * ($pgcont + 1))
        $pageindex .= '<span style="font-weight: small;"> ... </span>';
    for ($nCont = $pgcont; $nCont >= 1; $nCont--)
        if ($start >= $num_per_page * $nCont) {
            $tmpStart = $start - $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    $pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
    $tmpMaxPages = (int)(($max_value - 1) / $num_per_page) * $num_per_page;
    for ($nCont = 1; $nCont <= $pgcont; $nCont++)
        if ($start + $num_per_page * $nCont <= $tmpMaxPages) {
            $tmpStart = $start + $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
        $pageindex .= '<span style="font-weight: small;"> ... </span>';
    if ($start + $num_per_page * $pgcont < $tmpMaxPages)
        $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
    if ($start + $num_per_page < $max_value) {
        $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
        $pageindex .= sprintf($base_link, $display_page, '&gt;&gt;');
    }
    return $pageindex;
}

foreach($_GET as $ad){
  if(is_numeric($ad)){
$ad = abs(intval($ad));
}
 if(preg_match('/\include|asc|--|select|union|update|from|where|eval|glob|include|require|script|shell|BENCHMARK|CONCAT|INSERT\b/i', $ad) && !isset($_GET['execute'])){

$source = 'USER: '.$_SERVER['REMOTE_ADDR'].' | FILE: '.htmlspecialchars($_SERVER["REQUEST_URI"]).'
';
$file = htmlspecialchars($_SERVER['DOCUMENT_ROOT']).'/logs/log91.txt';
$Saved_File = fopen($file, 'a+');
fwrite($Saved_File, $source);
fclose($Saved_File);

header("Refresh: 2;url=/index.php".SID);
 exit('Защита by MrDeath');
 }

 $ad = htmlspecialchars(mysql_real_escape_string($ad));

 }
 foreach($_POST as $key => $value){

     if ($key = 'id' || $key = 'parent_id' || $key = 'invite' || $key = 'attack' || $key = 'page' || $key = 'build')
     {
        $_POST[$key] = num($value);
     }
     else
     {
        $_POST[$key] = addslashes(mysql_real_escape_string(htmlspecialchars($value)));
    } 
}
 foreach($_SESSION as $key => $value){
 
     if ($key = 'id' || $key = 'parent_id' || $key = 'invite' || $key = 'attack' || $key = 'page' || $key = 'build')
     {
        $_SESSION[$key] = num($value);
     }
     else
     {
        $_SESSION[$key] = addslashes(mysql_real_escape_string(htmlspecialchars($value)));
    } 
 }
 foreach($_COOKIE as $key => $value){
 
     if ($key = 'id' || $key = 'parent_id' || $key = 'invite' || $key = 'attack' || $key = 'page' || $key = 'build')
     {
        $_COOKIE[$key] = num($value);
     }
     else
     {
        $_COOKIE[$key] = addslashes(mysql_real_escape_string(htmlspecialchars($value)));
    } 
 }
 foreach ($_GET as $key => $value)
 {
     if ($key = 'id' || $key = 'parent_id' || $key = 'invite' || $key = 'attack' || $key = 'page' || $key = 'build')
     {
        $_GET[$key] = num($value);
     }
     else
     {
        $_GET[$key] = addslashes(mysql_real_escape_string(htmlspecialchars($value)));
    } 
}
 $id = isset($_GET['id'])?abs(intval($_GET['id'])):NULL;

?>