<?

if ($msg=="!вопрос"||$msg=="!vopros"){
$r = mysql_query ("select * from vopros where klu4 = '1'");
$a = mysql_fetch_array($r);
$vp = $a ["question"];
$i = $a ["number"];
if ($i!=5){
$st = getmicrotime();           
$today=date ("H:i"); 
$a = @mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='room0' where id ='".$uid."'");
$rnd = rand(0,99999999);
$rs = "<b>Вопрос: </b> ";
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$rs."".$vp."', id='".$st."', towhom='', hid='0', usid='".$uid."', komu=''");         
}
}
$s = substr ($msg,0,5); 
if (($s == "stats")&&(strlen($msg) > 6)){
$stsus = substr ($msg,6,strlen($msg)-6);                          
$a = @mysql_query ("Select credits from users where user='".$stsus."'");
if (mysql_affected_rows() != 0){ 
$st = getmicrotime();           
$today=date ("H:i");
$b = mysql_fetch_array($a);
$i = $b["credits"];  
$a = @mysql_query ("Select user from users order by credits desc LIMIT 101");
$j = 1;
$b = mysql_fetch_array($a);   

while (($b["user"] != $stsus)&&($j <= 100)) {$b = mysql_fetch_array($a); $j++;}
if ($j<=100) $s= "И он занимает в рейтинге $j место";
else $s = "И его место в рейтинге за пределами первой сотни.";
$mes = "У пользователя $stsus $i правильных ответов. $s";
$rnd = rand(0,99999999);
if($towhom == $uid) $th = $id; else $th ="";
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$mes."', id='".$st."', towhom='".$th."', hid='0', usid='".$uid."', komu=''");  

$a = @mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='room0' where id ='".$uid."'");
               } else { 
$st = getmicrotime();           
$today=date ("H:i");
$mes = "Игрока с ником $stsus нет в базе данных!";
$rnd = rand(0,99999999);
if($towhom == $uid) $th = $id; else $th ="";
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$mes."', id='".$st."', towhom='".$th."', hid='0', usid='".$uid."', komu=''");  
                                     
$a = @mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='room0' where id ='".$uid."'");
}
}
$agent = htmlentities(addslashes($HTTP_USER_AGENT));
if (((strpos ($agent,"M3Gate") !== false)||(strpos ($agent,"Opera") !== false)||(strpos ($agent,"emulator") !== false)||(strpos ($agent,"WinWAP") !== false)||(strpos ($agent,"Wapsilon") !== false)||(strpos ($agent,"Mozilla") !== false)||(strpos ($agent,"M3GATE") !== false))&&($rm==0)&&($set["vict"] == 0)){
$latumnik=mysql_fetch_array(mysql_query("Select latuser from users where id='2' LIMIT 1;"));
if (($amsg == $kansw||$amsg == $tran)&&$nom!=5){
$st = time();
$today=date ("H:i");
$mes = "".$us."! Вы правильно ответили на этот вопрос. Но с компа ответы не засчитываются.";     
$rnd = rand(0,99999999);
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$mes."', id='".$st."', towhom='".$id."', hid='0', usid='".$uid."', komu='".$us."'");
}
}else{
if (($amsg == $kansw||$amsg == $tran)&&$nom!=5){{
$st = time();
$victint = $set["victint"];
$st = $st + $victint;
if ($victint=="10") $interval="10 секунд";
else if ($victint=="30") $interval="30 секунд";
else if ($victint=="60") $interval="минуту";
else $interval="2 минуты";
mysql_query ("Update vopros set number = '5', time = '".$st."', answer = ' ', tran = ' ' WHERE klu4 ='1'");
$a = @mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='room0' where id ='".$uid."'");
$a = @mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='room0' where id ='".$uid."'");
               
$p = $row["credits"];
$p++;
 mysql_query ("Update users set credits='".$p."' where id ='".$id."'");
$st = getmicrotime();           
$today=date ("H:i");
$mes = "".$us."! Ах вот он, какой, Правильный ответ. Следующий вопрос через ".$interval.".";
$rnd = rand(0,99999999);
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$mes."', id='".$st."', towhom='".$towhom."', hid='0', usid='".$uid."', komu=''");  
} 
$st = time();
$today=date ("H:i");
$mes = "Поздравляю!!!";     
$rnd = rand(0,99999999);
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$mes."', id='".$st."', towhom='".$id."', hid='0', usid='".$uid."', komu='".$us."'");
}
}
?>