Файл: gonki.us/gonki.php
Строк: 122
<?php
require_once('system/incfiles/core.php');
if(empty($user)) header('Location: /auth.php');
if(isset($_GET['gonshik'])){
$gonk = $db->query("SELECT * FROM `gonki` WHERE `sopernik` = '$_GET[gonshik]' AND `us` = '$user[id]' AND `time` > ".($time-3600)."")->num_rows;
$gauto = $db->query("SELECT * FROM `my_auto` WHERE `id_us` = '$_GET[gonshik]'")->fetch_array();
$gus = $db->query('SELECT * FROM `user` WHERE `auto` = "'.$gauto['id'].'"')->fetch_array();
if(empty($_GET['gonshik']) or $gus['id'] == NULL) header('Location: /gonki.php');
if($user['benzin'] < 10) $err .= '<div class="error">Недостаточно бензина для гонки!</div>';
if($user['money'] < 100) $err .= '<div class="error">Недостаточно монет для гонки!</div>';
if($gonk >= 3) $err .= '<div class="error">Данный гонщик устал! Приходите через час.</div>';
if(empty($err)){
$rand = mt_rand(0, 5);
if(($gauto['ls']+$gus['ls']) > ($user['ls']+$usauto['ls']+$rand)){
$db->query('UPDATE `user` SET `benzin` = "'.($user['benzin']-10).'", `money` = "'.($user['money']-100).'", `opyt` = "'.($user['opyt']-2).'" WHERE `id` = "'.$user['id'].'"');
$status = 'err';
$_SESSION['status'] = $status;
$db->query("INSERT INTO `gonki` SET `time` = '$time', `sopernik` = '$_GET[gonshik]', `us` = '$user[id]', `status` = '$status'");
header('Location: /gonki.php');
}
if(($gauto['ls']+$gus['ls']) <= ($user['ls']+$usauto['ls']+$rand)){
$db->query('UPDATE `user` SET `benzin` = "'.($user['benzin']-10).'", `money` = "'.($user['money']+500).'", `opyt` = "'.($user['opyt']-2).'" WHERE `id` = "'.$user['id'].'"');
$status = 'ok';
$_SESSION['status'] = $status;
$db->query("INSERT INTO `gonki` SET `time` = '$time', `sopernik` = '$_GET[gonshik]', `us` = '$user[id]', `status` = '$status'");
header('Location: /gonki.php');
}
}
}
if(isset($_GET['session'])){
unset($_SESSION['status']);
header('Location: /gonki.php');
}
$title = $copy.': Гонки';
require_once(ROOT.'system/incfiles/header.php');
echo '<div class="razd5">Гонки</div>';
if(isset($err)) echo $err;
if($user['auto'] == 0){
echo '<div class="menu_j"><a href="/magazin.php" class="top_menu_j"><img src="/system/design/img/ind.png" alt="*"/> Купить тачку!</a></div>';
require_once(ROOT.'system/incfiles/footer.php');
exit;
}
if($_SESSION['status'] == 'ok'){
echo '<div class="ok"><span style="float:right"><a href="?session">X</a></span><b>Победа!</b><hr />Награда: <font color="green">+</font><img src="/system/design/ico/money.png" alt="" /> <font color="white">500</font>, <font color="green">+</font><img src="/system/design/ico/opyt.png" alt="" /><font color="white">2</font>,
<font color="red">-</font><img src="/system/design/ico/bak.png" alt="" /><font color="yellow">10</font></div>';
}
if($_SESSION['status'] == 'err'){
echo '<div class="error"><span style="float:right"><a href="?session">X</a></span><b>Поражение!</b><hr />Награда: <font color="red">-</font><img src="/system/design/ico/money.png" alt="" /> <font color="white">100</font>, <font color="green">+</font><img src="/system/design/ico/opyt.png" alt="" /><font color="white">2</font>, <font color="red">-</font><img src="/system/design/ico/benzin.png" alt="" /><font color="yellow">10</font></div>';
}
$q = $db->query('SELECT * FROM `my_auto` WHERE `id_us` NOT LIKE "'.$user['id'].'" AND `ls` > "'.$usauto['ls'].'" OR `id_us` NOT LIKE "'.$user['id'].'" AND `ls` = "'.$usauto['ls'].'" ORDER BY `ls` ASC LIMIT 10');
while($post = $q->fetch_array()){
echo '<div class="menu_j"><a href="?gonshik='.$post['id_us'].'" class="top_menu_j"><span style="float:right">'.user($post['id_us']).'<br /><img src="/system/design/ico/ls.png" alt=""/> <font color="darkorange">'.$post['ls'].'л.с. </font></span><img src="'.$post['img'].'" alt="" style="width:100px"/><br /><img src="'.$post['neon'].'" alt="" style="width:100px; margin-top:-17px;"/></a></div>';
}
require_once(ROOT.'system/incfiles/footer.php');
?>