<?php
#########################################
# Скрипт онлайн игры "Стритрейсинг"_____#
# Автор: -=FеST=-(СиК)__________________#
# ICQ : 345-22-23_______________________#
# Все права принадлежат автору(-=FeST=-)#
#########################################
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/adm_check.php';
include_once '../sys/inc/user.php';
$set['title']='Стритрейсинг';
include_once '../sys/inc/thead.php';
title();
err();
aut();

if(!isset($user)){
echo 'Вы неавторизованы';
include_once '../sys/inc/tfoot.php';
exit;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `racing` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `racing`(`id_u`) VALUES('".$user['id']."')");

  $arr=mysql_fetch_array(mysql_query("SELECT * FROM `racing` WHERE `id_u`='".$user['id']."'"));
   $car=mysql_fetch_array(mysql_query("SELECT * FROM `racing_car` WHERE `id`='".$arr['car']."'"));
   $all_racer=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_race` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
   $my_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_race` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
     $sop_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_race` WHERE `id_2`='".$user['id']."' AND `act`='0'"),0);

  
  if($arr['color']!='0'){
if($arr['color']==1)
$color='red_';
elseif($arr['color']==2)
$color='blue_';
elseif($arr['color']==3)
$color='green_'; 
}
if(!isset($_GET['load'])){
echo "&raquo; 
 <a href='allrace.php?load&amp;myrace'>Мои приглашения</a> ".($my_race>0 ? '+'.$my_race.'' :'')."<br/>
 &raquo; <a href='allrace.php?load&amp;oprace'>Приглашения соперников</a> ".($sop_race>0 ? '+'.$sop_race.'' :'')."<br/>
 ";
 }
 else
 {
 if(isset($_GET['oprace'])){
 
 echo "
<div class='aut'>
<img src='ico/exp.gif' alt=''/>".$arr['exp']."
<img src='ico/level.gif' alt=''/>".$arr['level']."
<img src='ico/money.gif' alt=''/>".$arr['money']."
<img src='ico/resp.gif' alt=''/>".$arr['resp']."</div>

<center><img src='car/".(isset($color) ? "".$color."".$car['screen']."" : "".$car['screen']."")."' alt=''/> <br/>".$car['name']."</center>
<br/>";
  
if($sop_race==0){
echo "Гонок нет!<br/>";
}
else
{
if(isset($_POST['submit'])){
$user_id_2=mysql_result(mysql_query("SELECT `id_1` FROM `racing_race` WHERE `id`='".intval($_GET['id_race'])."'"),0);
$arr_2=mysql_fetch_array(mysql_query("SELECT `speed`, `uprav` FROM `racing` WHERE `id_u`='".$user_id_2."'"));
$raznica_speed=$arr['speed']-$arr_2['speed'];
if($raznica_speed<0){
$raznica_speed=$arr_2['speed']-$arr['speed'];
$invers=1;
}
if($raznica_speed>16)
$invers=3;

if($raznica_speed==0)
$invers=2;

if($raznica_speed>=1 && $raznica_speed<=15)
$invers=2;

if($raznica_speed>=1 && $raznica_speed<=15 && $invers==2)
$invers=2;


if($invers==1){
$pob=rand(1,6);
if($pob!=3){

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."");

}
else
{

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."");

}}
elseif($invers==2){
$pob=rand(1,2);
if($pob!=2){

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."");
}
else
{

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."");

}



}
elseif($invers==3){
$pob=rand(1,6);
if($pob==3){

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."");

}
else
{

mysql_query("UPDATE `racing` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `racing` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
msg("Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."");
}}
mysql_query("DELETE FROM `racing_race` WHERE `id`='".intval($_GET['id_race'])."'");
echo "&laquo; 
 <a href='allrace.php?load&amp;oprace'>Назад</a><br/>";
}
else
{
$k_page=k_page($sop_race,10);
$page=page($k_page);
$start=10*$page-10;
$queryy=mysql_query("SELECT * FROM `racing_race` WHERE `id_2`='".$user['id']."' AND `act`='0' ORDER BY `id` DESC LIMIT $start,10");
while($po=mysql_fetch_array($queryy)){
$pos=mysql_fetch_array(mysql_query("SELECT * FROM `racing` WHERE `id_u`='".$po['id_1']."'"));
  $carp=mysql_fetch_array(mysql_query("SELECT * FROM `racing_car` WHERE `id`='".$pos['car']."'"));
  if($pos['color']!='0'){
if($pos['color']==1)
$color2='red_';
elseif($pos['color']==2)
$color2='blue_';
elseif($pos['color']==3)
$color2='green_'; 
}
echo "<div class='rowup'>
- Ник : <a href='/info.php?id=".$po['id_1']."'>
".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$po['id_1']."'"),0)."</a><br/>
- Поб/Пор : ".$pos['win']."/".$pos['lose']."<br/>
- Тачка : ".$carp['name']."<br/>
<img src='car/".(isset($color2) ? "".$color2."".$carp['screen']."" : "".$carp['screen']."")."' alt=''/>
<form method='post' action='allrace.php?load&amp;oprace&amp;act&amp;id_race=".$po['id']."'>
<input type='submit' name='submit' value='Принять заявку!'/></form></div>";
}
if($k_page>'1')str('?load&amp;oprace&amp;',$k_page,$page);
}}
 
 
 }
  elseif(!isset($_GET['oprace']) && isset($_GET['myrace'])){
 
 echo "
<div class='aut'>
<img src='ico/exp.gif' alt=''/>".$arr['exp']."
<img src='ico/level.gif' alt=''/>".$arr['level']."
<img src='ico/money.gif' alt=''/>".$arr['money']."
<img src='ico/resp.gif' alt=''/>".$arr['resp']."</div>
<center><img src='".($color!='0' ? "".$color."".$car['screen']."" : "".$car['screen']."")."' alt=''/> <br/>".$car['name']."</center>
<br/>";
  
if($my_race==0){
echo "Гонок нет!<br/>";
}
else
{
if(isset($_POST['submit'])){
mysql_query("DELETE FROM `racing_race` WHERE `id`='".intval($_GET['id_race'])."' LIMIT 1");
msg('Гонка успешно удалена!');
echo "&laquo; 
 <a href='allrace.php?load&amp;myrace'>Назад</a><br/>";
}
else
{
$k_page=k_page($my_race,10);
$page=page($k_page);
$start=10*$page-10;
$queryy=mysql_query("SELECT * FROM `racing_race` WHERE `id_1`='".$user['id']."' AND `act`='0' ORDER BY `id` DESC LIMIT $start,10");
while($po=mysql_fetch_array($queryy)){
$pos=mysql_fetch_array(mysql_query("SELECT * FROM `racing` WHERE `id_u`='".$po['id_2']."'"));
 if($pos['color']!='0'){
if($pos['color']==1)
$color2='red_';
elseif($pos['color']==2)
$color2='blue_';
elseif($pos['color']==3)
$color2='green_'; 
}
  $carp=mysql_fetch_array(mysql_query("SELECT * FROM `racing_car` WHERE `id`='".$pos['car']."'"));
echo "<div class='rowup'>
- Ник : <a href='/info.php?id=".$po['id_2']."'>
".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$po['id_2']."'"),0)."</a><br/>
- Поб/Пор : ".$pos['win']."/".$pos['lose']."<br/>
- Тачка : ".$carp['name']."<br/>
<img src='car/".$color2."".$carp['screen']."' alt=''/> 
<form method='post' action='allrace.php?load&amp;myrace&amp;act&amp;id_race=".$po['id']."'>
<input type='submit' name='submit' value='Удалить заявку!'/></form></div>";
}
if($k_page>'1')str('?load&amp;myrace&amp;',$k_page,$page);
}}
 
 
 }
 }
 
 


echo "<div class='rowup'>
<div class='aut'><a style='display:block;' href='index.php'><img src='ico/back.png' alt=''/> Назад</a></div>";






include_once '../sys/inc/tfoot.php';
?>