<?
# Автор движка: InstalScript
# vk.com/k.karamin  - Я Вк
# bymas.ru/id3741  - Я на бумасе
# Специально для обитателей bymas.ru
# Ток на бумасе можно найти моды для данного движка
session_start();
ob_start();
require_once("mysql.php");
require_once("user.php");
require_once("user_mission_text.php");


function user($uid,$type){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));
if($user == null){$nick = 'не найден';$id = '1';}else{$nick = $user['nick'];$id = $user['id'];}
if($user['time'] >= (time() - '300')){$online = 'online';}else{$online  = 'offline';}
if($user['side'] == '0'){$side = 'empire';$sidetext = 'империя';}else{$side = 'federation';$sidetext = 'федерация';}
if($type == 'rules'){return "$user[rules]";}
if($type == 'side'){return "$side";}
if($type == 'side-text'){return "$sidetext";}
if($type == 'ava'){return "/instalscript/images/avatars/".$user['ava']."";}
if($type == '0'){return "<img src = '/instalscript/images/icons/$side.png'><a class='white' w:id='profileLink' href='/profile/".$id."/'>$nick</a>";}
if($type == '1'){return "<img src = '/instalscript/images/icons/$side.png'> $nick";}
if($type == '2'){
return "
<tr w:id='users'>
<td class='usr w100'>
<a class='white' w:id='profileLink' href='/profile/".$id."/'>
<img class='vb' src = '/instalscript/images/icons/".$side.".png'>
<img class='vb' src = '/instalscript/images/icons/".$online.".png'>
<span class='green2' w:id='login'>".$nick."</span>
<br>
</a>
</td>
</tr>
";
}



}
function trofeis($trof,$var){
if($var == '1'){
if($trof == '1'){return "flask";}
if($trof == '2'){return "helmet";}
if($trof == '3'){return "compass";}
if($trof == '4'){return "cigarcase";}
if($trof == '5'){return "mapcase";}
if($trof == '6'){return "standard";}
if($trof == '7'){return "pistol";}
if($trof == '8'){return "decoration";}
}

if($var == '2'){
if($trof == '1'){return "Фляжка";}
if($trof == '2'){return "Каска";}
if($trof == '3'){return "Компас";}
if($trof == '4'){return "Портсигар";}
if($trof == '5'){return "Планшет командира";}
if($trof == '6'){return "Боевое знамя";}
if($trof == '7'){return "Табельный пистолет";}
if($trof == '8'){return "Знак отличия";}
}


}
function trofei_battle($uid,$var){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));
$user_bon = mysql_fetch_assoc(mysql_query("SELECT * FROM `ubonus` WHERE `uid` = '".$user['id']."' AND `type` = 'vip' "));

if($var == 'battle-pve'){

if($user_bon != null){$vip = '10';}else{$vip = '15';} # vip

$rand = mt_rand(1,20);
if($rand > $vip){
$trof_rand = mt_rand(1,4);
$utrof = mysql_fetch_assoc(mysql_query("SELECT * FROM `utrofie` WHERE `trof` = '".trofeis($trof_rand,'1')."' AND `uid` = '".$uid."' "));
if($utrof == null){
mysql_query("INSERT INTO `utrofie` SET `trof` = '".trofeis($trof_rand,'1')."',`amount` = '1',`uid` = '".$uid."',`time` = '".(time())."' ")or die(mysql_error());
}else{
mysql_query("UPDATE `utrofie` SET `amount` = `amount` + '1' WHERE `id` = '".$utrof['id']."' ");
}

$utext = "Выпал трофей [span class = green2 mt10 sh_b]".trofeis($trof_rand,'2')."[/span]";
mysql_query("INSERT INTO `log` SET `text` = '".$utext."',`pid` = '".$uid."',`who` = '0',`time` = '".(time())."' ")or die(mysql_error());

}

}


}
# trofei_battle($uid,'battle-pve'); # Для теста
function utank($id,$type){

$tnk = mysql_fetch_assoc(mysql_query("SELECT * FROM `utank` WHERE `id` = '".$id."' "));
$tk = mysql_fetch_assoc(mysql_query("SELECT * FROM `tank` WHERE `id` = '".$tnk['tid']."' "));

$cannon = round((($tk['ha']/100)*10)*$tnk['cannon']); # орудие
$gold_cannon = round((($tk['ha']/100)*50)*$tnk['cannon']); # стоимость орудия

$tower = round((($tk['ha']/100)*10)*$tnk['tower']); # башня
$gold_tower = round((($tk['ha']/100)*50)*$tnk['tower']); # стоимость башни

$caterpillar = round((($tk['ha']/100)*10)*$tnk['caterpillar']); # гусеницы
$gold_caterpillar = round((($tk['ha']/100)*50)*$tnk['caterpillar']); # стоимость за урон

$machinegun = round((($tk['ha']/100)*10)*$tnk['machinegun']); # пулемет
$gold_machinegun = round((($tk['ha']/100)*50)*$tnk['machinegun']); # стоимость за пулемет

$rockets = round((($tk['ha']/100)*10)*$tnk['rockets']); # ракеты
$gold_rockets = round((($tk['ha']/100)*50)*$tnk['rockets']); # стоимость за ракеты

$frontalarmor = round((($tk['ha']/100)*10)*$tnk['frontalarmor']); # лобовая броня
$gold_frontalarmor = round((($tk['ha']/100)*50)*$tnk['frontalarmor']); # стоимость за лобовую броню

$sidearmor = round((($tk['ha']/100)*10)*$tnk['sidearmor']); # боковая броня
$gold_sidearmor = round((($tk['ha']/100)*50)*$tnk['sidearmor']); # стоимость за боковую броню



}
function tank($tid,$type){
$tnk = mysql_fetch_assoc(mysql_query("SELECT * FROM `tank` WHERE `id` = '".$tid."' "));
if($type == 'level'){return $tnk['level'];}
if($type == 'name'){return $tnk['name'];}
if($type == 'img'){return $tnk['img'];}
if($type == 'info'){return $tnk['info'];}
if($type == 'country'){return $tnk['country'];}
if($type == 'type'){return $tnk['type'];}
if($type == 'ha'){return $tnk['ha'];}
if($type == 'hb'){return $tnk['hb'];}
if($type == 'ho'){return $tnk['ho'];}
if($type == 'hc'){return $tnk['hc'];}

}


function country($country,$type){
if($type == 'img'){return "/instalscript/images/country/ico/".$country.".png";}
if($type == 'text'){
if($country == 'britain'){$countr = "Великобритания";}
elseif($country == 'china'){$countr = "Китай";}
elseif($country == 'france'){$countr = "Франция";}
elseif($country == 'germany'){$countr = "Германия";}
elseif($country == 'japan'){$countr = "Япония";}
elseif($country == 'usa'){$countr = "США";}
elseif($country == 'ussr'){$countr = "СССР";}else{$countr = "Неизвестно";}
return $countr;
}
}
function ttype($type){
if($type == "easy"){$return = "Лёгкий";}
if($type == "normal"){$return = "Средний";}
if($type == "hard"){$return = "Тяжёлый";}
if($type == "pt-sau"){$return = "ПТ-САУ";}
if($type == "sau"){$return = "САУ";}
return $return;
}
function logi($log){$_SESSION['log'] = check($log);}
function logs(){return bbcode(check($_SESSION['log']),'1');}
function logn(){$log = $_SESSION['log'];if(isset($log)){return $_SESSION['log'] = null;}}
function page($num,$str,$result){
if($num == null or $num < '1'){$num = '1';}
$num = abs($num);
$start = $str * $num - $str;
if($num >= $result){$start = '0';}
return $start;
}
function ppage($url,$num,$str,$result){
$endpage = ceil($result/$str);
if($endpage == null or $endpage < '1'){$endpage = '1';}
if($endpage < $num or empty($num)){header("location:".$url."/1/");};
if($num == null or $num < '1'){$num = '1';}
$num = abs($num);
$start = $str * $num;





if($str < $result){

echo "<div class='pgn'>";


if($num - 5 > 0){echo "<a class='simple-but gray' href = '".$url."/1/' ><span><span>«</span></span></a>";}
if($num - 4 > 0){echo "<a class='simple-but gray' href = '".$url."/".abs($num - 4)."/' title='Go to page ".abs($num - 4)."'><span><span>".abs($num - 4)."</span></span></a>";}
if($num - 3 > 0){echo "<a class='simple-but gray' href = '".$url."/".abs($num - 3)."/' title='Go to page ".abs($num - 3)."'><span><span>".abs($num - 3)."</span></span></a>";}
if($num - 2 > 0){echo "<a class='simple-but gray' href = '".$url."/".abs($num - 2)."/' title='Go to page ".abs($num - 2)."'><span><span>".abs($num - 2)."</span></span></a>";}
if($num - 1 > 0){echo "<a class='simple-but gray' href = '".$url."/".abs($num - 1)."/' title='Go to page ".abs($num - 1)."'><span><span>".abs($num - 1)."</span></span></a>";}


echo "<span class='simple-but gray' title='Go to page ".$num."'><em><span><span>".$num."</span></span></em></span>";


if($endpage >= $num + '1'){echo "<a class='simple-but gray' href = '".$url."/".abs($num + 1)."/' title='Go to page ".abs($num + 1)."'><span><span>".abs($num + 1)."</span></span></a>";}
if($endpage >= $num + '2'){echo "<a class='simple-but gray' href = '".$url."/".abs($num + 2)."/' title='Go to page ".abs($num + 2)."'><span><span>".abs($num + 2)."</span></span></a>";}
if($endpage >= $num + '3'){echo "<a class='simple-but gray' href = '".$url."/".abs($num + 3)."/' title='Go to page ".abs($num + 3)."'><span><span>".abs($num + 3)."</span></span></a>";}
if($endpage >= $num + '4'){echo "<a class='simple-but gray' href = '".$url."/".abs($num + 4)."/' title='Go to page ".abs($num + 4)."'><span><span>".abs($num + 4)."</span></span></a>";}
if($endpage >= $num + '5'){echo "<a class='simple-but gray' href = '".$url."/".abs($num + 5)."/' title='Go to page ".abs($num + 5)."'><span><span>".abs($num + 5)."</span></span></a>";}


if($num + '5' < $endpage){echo "<a class='simple-but gray' href = '".$url."/".$endpage."/'><span><span>»</span></span></a>";}




echo "</div>";
}



}
function snaryad($type,$var){
if($var == '1'){
if($type == 'snaryadBB'){return "бронебойным";}
if($type == 'snaryadOF'){return "осколочно-фугасным";}
if($type == 'snaryadKS'){return "кумулятивным";}
}

}
function clock($time){
$month_name = array('1' => 'января','2' => 'февраля','3' => 'марта','4' => 'апреля','5' => 'мая','6' => 'июня','7' => 'июля','8' => 'августа','9' => 'сентября','10' => 'октября','11' => 'ноября','12' => 'декабря');
$month = $month_name[ date( 'n' , $time ) ];
$day = date( 'j' , $time );
$year = date( 'Y' , $time );
$hour = date( 'G' , $time );
$min = date( 'i' , $time );
$date = $day . ' ' . $month . ' ' . $year . ' г. в ' . $hour . ':' . $min;
$timer = time()- $time;
if($timer<60){return $timer." сек. назад";}
elseif($timer>=60 and $timer<3600){return round($timer/60)." мин. назад";}
elseif($timer>=3600 and $timer<86400){return round($timer/3600)." ч. назад";}
else{return $date;}

}
function timer($var){
$skok = $var - time();
if($skok > '0'){
if($skok<60){return $skok." с.";}
elseif($skok>=60 && $skok<3600){return round($skok/60)." м.";}
elseif($skok>=3600 && $skok<86400){return round($skok/3600)." ч.";}
elseif($skok >= 86400){return round($skok/86400)."д.";}
}
}
function ftimer($var){
$skok = $var;
if($skok > '0'){
if($skok<60){return $skok." с.";}
elseif($skok>=60 && $skok<3600){return round($skok/60)." м.";}
elseif($skok>=3600 && $skok<86400){return round($skok/3600)." ч.";}
elseif($skok >= 86400){return round($skok/86400)."д.";}
}
}


function check($text){
$text = mysql_real_escape_string(htmlspecialchars(stripslashes(trim($text))));return $text;
} # Из DCMS
function bbcode($text,$admin){
if($admin == '1'){
$str_search = array(
"#\[div class = (.+?)\](.+?)\[\/div\]#is",
"#\[span class = (.+?)\](.+?)\[\/span\]#is",
"#/n#is",
"#\[b\](.+?)\[\/b\]#is",
"#\[i\](.+?)\[\/i\]#is",
"#\[u\](.+?)\[\/u\]#is",
"#\[code\](.+?)\[\/code\]#is",
"#\[quote\](.+?)\[\/quote\]#is",
"#\[url = (.+?)\](.+?)\[\/url\]#is",
"#\[url\](.+?)\[\/url\]#is",
"#\[img\](.+?)\[\/img\]#is",
"#\[size = (.+?)\](.+?)\[\/size\]#is",
"#\[color = (.+?)\](.+?)\[\/color\]#is",
"#\[list\](.+?)\[\/list\]#is",
"#\[listn](.+?)\[\/listn\]#is",
"#\[\*\](.+?)\[\/\*\]#"
);
$str_replace = array(
"<div class = '\\1'>\\2</div>",
"<span class = '\\1'>\\2</span>",
"<br/>",
"<b>\\1</b>",
"<i>\\1</i>",
"<span style='text-decoration:underline'>\\1</span>",
"<code class='code'>\\1</code>",
"<table width = '95%'><tr><td>Цитата</td></tr><tr><td class='quote'>\\1</td></tr></table>",
"<a href = '\\1'>\\2</a>",
"<a href = '\\1'>\\1</a>",
"<img src = '\\1' alt = 'Изображение' />",
"<span style = 'font-size:\\1%'>\\2</span>",
"<font color = '\\1'>\\2</font>",
"<ul>\\1</ul>",
"<ol>\\1</ol>",
"<li>\\1</li>"
);
return preg_replace($str_search, $str_replace, $text);
}else{return $text;}
}# Из DCMS
function vbbcode(){
echo "BB Коды:";
echo "<div class = 'hr'>[div class = hr] [/div]</div>";
echo "<div class = 'ta_l'>[div class = ta_l]текст по левой стороне[/div]</div>";
echo "<div class = 'cntr'>[div class = cntr]текс по центру[/div]</div>";
echo "<div class = 'ta_r'>[div class = ta_r]текст по правой стороне[/div]</div>";
echo "Запись с новой строки: /n";
echo "</br>[b]<b>Жирный</b>[/b]";
echo "</br>[i]<i>Курсив</i>[/i]";
echo "</br>[u]<span style='text-decoration:underline'>Подчёркнутый</span>[/u]";
echo "</br>[code]<code class='code'>маленький</code>[/code]";
echo "</br>[url = ссылка]<a href = 'ссылка'>Имя ссылки</a>[/url]";
echo "</br>[url]<a href = 'http://".$_SERVER['SERVER_NAME']."'>http://".$_SERVER['SERVER_NAME']."</a>[/url]";
echo "</br>[img]ссылка на картинку[/img]";
echo "</br>[size = 60]<span style = 'font-size:60%'>размер текста от 1 до 100</span>[/size]";
echo "</br>[color = red]<font color = 'red'>текст</font>[/color]";
echo "</br>[color = blue]<font color = 'blue'>текст</font>[/color]";
echo "</br>[color = green]<font color = 'green'>текст</font>[/color]";
echo "</br>[color = yellow]<font color = 'yellow'>текст</font>[/color]";
echo "</br>[color = 00D0FF]<font color = '00D0FF'>текст</font>[/color]";
echo "</br>[color = EE82EE]<font color = 'EE82EE'>текст</font>[/color]";
echo "</br>[color = 7cfc00]<font color = '7cfc00'>текст</font>[/color]";
echo "</br><ul>[list]текст[/list]</ul>";
echo "</br><ol>[listn]текст[/listn]</ol>";
echo "</br><li>[*]текст[/*]</li>";
}






$is = explode("/",check($_GET['is']));





if(isset($_GET['exit'])){
session_destroy();
setcookie('nick','',time()+31536000);
setcookie('pass','',time()+31536000);
header("Location:/");
exit();
}
?>