Файл: durak/file2.php
Строк: 128
<?
if ($game['id'] && isset($user))
{
if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
$mat=antimat($msg);
if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;
if (strlen2($msg)>512){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<1){$err='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_chat` WHERE `id_game` = '$game[id]' AND `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
elseif(!isset($err)){
mysql_query("INSERT INTO `durak_chat` (`id_user`, `time`, `msg`, `id_game`) values('$user[id]', '$time', '".my_esc($msg)."', '$game[id]')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Ваш комментарий успешно принят');
}
}
//----------------------------раздача---------------------------------//
if (isset($_GET['razdat']) && $game['status']==2)
{
$q = mysql_query("SELECT * FROM `durak_karty` ORDER BY rand() ");
$num=0;
while ($karta = mysql_fetch_assoc($q))
{
$num++;
$time++;
if ($num >= 0 && $num<=6)
mysql_query("INSERT INTO `durak_game` (`mast`, `karta`, `sila`, `id_user`, `time`, `id_game`) values('$karta[mast]', '$karta[name]', '$karta[sila]', '$avtor[id]', '$time', '$game[id]')");
else if ($num >= 7 && $num<=12)
mysql_query("INSERT INTO `durak_game` (`mast`, `karta`, `sila`, `id_user`, `time`, `id_game`) values('$karta[mast]', '$karta[name]', '$karta[sila]', '$prot[id]', '$time', '$game[id]')");
else if ($num >= 13 && $num<=35)
mysql_query("INSERT INTO `durak_game` (`mast`, `karta`, `sila`, `id_user`, `time`, `id_game`) values('$karta[mast]', '$karta[name]', '$karta[sila]', '0', '$time', '$game[id]')");
else if ($num >= 35 && $num<=36)
{
mysql_query("INSERT INTO `durak_game` ( `mast`, `karta`, `sila`, `id_user`, `time`, `id_game`) values('$karta[mast]', '$karta[name]', '$karta[sila]', '0', '$time', '$game[id]')");
mysql_query("UPDATE `durak` SET `kozar` = '$karta[mast]' WHERE `id` = '$game[id]' LIMIT 1");
}
}
mysql_query("UPDATE `durak` SET `hod` = '$prot[id]', `bit` = '$avtor[id]', `hodit` = '$prot[id]', `status` = '3' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
}
//--------------------------------------------------------------------//
$kartS = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_hod` where `id_game` = '$game[id]'"),0);
if (isset($_GET['go'])) // карта хода
$khod=mysql_fetch_assoc(mysql_query("SELECT * FROM `durak_game` WHERE `id` = '".my_esc($_GET['go'])."'"));
$activ_karta = mysql_fetch_assoc(mysql_query("SELECT * FROM `durak_game` WHERE `karta` = '$game[karta]' limit 1")); // карта активная
$sec2 = -180-$game['time']+$time;
if ($sec2>0 && $game['status']==3)
{
if ($avtor['id']==$game['hod'])
{
mysql_query("UPDATE `durak` SET `game_over` = '$prot[id]' , `read` = '0', `status` = '4' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
$game['game_over']=$prot['id'];
}
elseif ($prot['id']==$game['hod'])
{
mysql_query("UPDATE `durak` SET `game_over` = '$avtor[id]' , `read` = '0', `status` = '4' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
$game['game_over']=$avtor['id'];
}
}
//---------------------------ход первый-------------------------------//
if (isset($_GET['go']) && $game['hod']==$user['id'] && $khod['on']==0 && $khod['id_user']==$user['id'] && $game['read']==0 && $kartS<10 && $game['status']==3) // ход первый
{
mysql_query("UPDATE `durak_game` SET `on` = '1', `time` = '$time' WHERE `id` = '$khod[id]' AND `id_game` = '".$game['id']."' LIMIT 1");
mysql_query("UPDATE `durak` SET `karta` = '$khod[karta]', `read` = '1', `time` = '$time' , `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
if ($game['kozar']==$khod['mast'])$ss=1;
mysql_query("INSERT INTO `durak_hod` (`num`, `mast`, `name`, `sila`, `id_user`, `id_game`, `kozar`) values('$time', '$karta[mast]', '$khod[karta]', '$khod[sila]', '$user[id]', '$game[id]', '$ss')");
header("Location: ?");
}
//--------------------------------------------------------------------//
//----------------------------ход второй------------------------------//
if (isset($_GET['go']) && $game['hod']==$user['id'] && $khod['on']==0 && $khod['id_user']==$user['id'] && $game['read']==1 && $kartS<10 && $game['status']==3) // ход второй
{
if ($khod['sila']>$activ_karta['sila'] && $khod['mast']==$activ_karta['mast'])
{
mysql_query("UPDATE `durak_game` SET `on` = '1', `time` = '$time' WHERE `id` = '$khod[id]' AND `id_game` = '".$game['id']."' LIMIT 1");
mysql_query("UPDATE `durak` SET `karta` = '$khod[karta]',`time` = '$time', `read` = '2', `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
if ($game['kozar']==$khod['mast'])$ss=1;
mysql_query("INSERT INTO `durak_hod` (`num`, `mast`, `name`, `sila`, `id_user`, `id_game`, `kozar`) values('$time', '$khod[mast]', '$khod[karta]', '$khod[sila]', '$user[id]', '$game[id]', '$ss')");
}elseif ($khod['mast']==$game['kozar'] && $khod['mast']!=$activ_karta['mast'])
{
mysql_query("UPDATE `durak_game` SET `on` = '1', `time` = '$time' WHERE `id` = '$khod[id]' AND `id_game` = '".$game['id']."' LIMIT 1");
mysql_query("UPDATE `durak` SET `karta` = '$khod[karta]',`time` = '$time', `read` = '2', `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
if ($game['kozar']==$khod['mast'])$ss=1;
mysql_query("INSERT INTO `durak_hod` (`num`, `mast`, `name`, `sila`, `id_user`, `id_game`, `kozar`) values('$time', '$khod[mast]', '$khod[karta]', '$khod[sila]', '$user[id]', '$game[id]', '$ss')");
}
header("Location: ?");
}
//--------------------------------------------------------------------//
//----------------------------ход третий------------------------------//
if (isset($_GET['go']) && $game['hod']==$user['id'] && $khod['on']==0 && $khod['id_user']==$user['id'] && $game['read']==2 && $kartS<10 && $game['status']==3)
{
$coll = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_hod` WHERE `sila` = '$khod[sila]'"),0);
if ($coll>0)
{
mysql_query("UPDATE `durak_game` SET `on` = '1', `time` = '$time' WHERE `id` = '$khod[id]' AND `id_game` = '".$game['id']."' LIMIT 1");
mysql_query("UPDATE `durak` SET `karta` = '$khod[karta]',`time` = '$time', `read` = '1', `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
if ($game['kozar']==$khod['mast'])$ss=1;
mysql_query("INSERT INTO `durak_hod` (`num`, `mast`, `name`, `sila`, `id_user`, `id_game`, `kozar`) values('$time', '$khod[mast]', '$khod[karta]', '$karta[sila]', '$user[id]', '$game[id]', '$ss')");
}
header("Location: ?");
}
//--------------------------------------------------------------------//
//--------------------------выход-------------------------------------//
if (isset($_GET['go']) && $_GET['go']=='exit' && isset($_GET['ok']))
{
if ($game['stav']>0)
{
$p = $game['stav'];
if ($game['game_over']==$prot['id'])
mysql_query("UPDATE `user` SET `balls` = '".($prot['balls']+$p)."' WHERE `id` = '$prot[id]' LIMIT 1");
elseif ($game['game_over']==$avtor['id'])
mysql_query("UPDATE `user` SET `balls` = '".($avtor['balls']+$p)."' WHERE `id` = '$avtor[id]' LIMIT 1");
if ($game['game_over']==$prot['id'])
mysql_query("UPDATE `user` SET `balls` = '".($avtor['balls']-$p)."' WHERE `id` = '$avtor[id]' LIMIT 1");
elseif ($game['game_over']==$avtor['id'])
mysql_query("UPDATE `user` SET `balls` = '".($prot['balls']-$p)."' WHERE `id` = '$prot[id]' LIMIT 1");
}
mysql_query("DELETE FROM `durak_chat` WHERE `id_game` = '".$game['id']."'");
mysql_query("DELETE FROM `durak_hod` WHERE `id_game` = '".$game['id']."'");
mysql_query("DELETE FROM `durak_game` WHERE `id_game` = '".$game['id']."'");
mysql_query("DELETE FROM `durak` WHERE `id` = '".$game['id']."'");
header("Location: index.php?");
}
if (isset($_GET['go']) && $_GET['go']=='bito' && isset($_GET['ok']) && $game['status']==3)
{
mysql_query("UPDATE `durak` SET `karta` = '', `time` = '$time', `hodit` = '$ank2[id]', `bit` = '$user[id]', `read` = '0', `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
mysql_query("DELETE FROM `durak_hod` WHERE `id_game` = '".$game['id']."'");
mysql_query("DELETE FROM `durak_game` WHERE `on` = '1' AND `id_game` = '".$game['id']."'");
header("Location: index.php?");
}
//-------------------------------------------------------------------//
//-------------------------------забрать-----------------------------//
if ($game['hod']==$user['id'] && $game['read']==1 && isset($_GET['zabrat']) && $game['status']==3)
{
mysql_query("UPDATE `durak` SET `karta` = '', `time` = '$time', `read` = '0', `hod` = '$ank2[id]' WHERE `id` = '$game[id]' LIMIT 1");
mysql_query("DELETE FROM `durak_hod` WHERE `id_game` = '".$game['id']."'");
mysql_query("UPDATE `durak_game` SET `on` = '0', `time` = '$time', `id_user` = '$user[id]' WHERE `on` = '1' AND `id_game` = '".$game['id']."'");
header("Location: index.php?");
}
//--------------------------------------------------------------------//
$kozar=mysql_fetch_assoc(mysql_query("SELECT * FROM `durak_game` WHERE `mast` = '$game[kozar]' AND `id_game` = '$game[id]' ORDER BY `id` DESC limit 1"));
//----------------------------набрать---------------------------------//
$dy_kart = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_game` WHERE `id_user` = '$ank2[id]' AND `id_game` = '$game[id]'"),0);
$my_kart = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_game` WHERE `id_user` = '$user[id]' AND `id_game` = '$game[id]'"),0);
$cc = 6-$my_kart;
if ($game['read']==0 && $my_kart<6 && $game['status']==3)
{
mysql_query("UPDATE `durak_game` SET `id_user` = '$user[id]', `time` = '$time' WHERE `id_user` = '0' AND `id_game` = '".$game['id']."' ORDER BY `id` ASC LIMIT $cc");
}
$cc2 = 6-$dy_kart;
if ($game['read']==0 && $dy_kart<6 && $game['status']==3)
{
mysql_query("UPDATE `durak_game` SET `id_user` = '$ank2[id]', `time` = '$time' WHERE `id_user` = '0' AND `id_game` = '".$game['id']."' ORDER BY `id` ASC LIMIT $cc2");
}
//--------------------------------------------------------------------//
$my_kartS = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_game` WHERE `on` = '0' AND `id_user` = '$avtor[id]' AND `id_game` = '$game[id]'"),0);
$my_kartD = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_game` WHERE `on` = '0' AND `id_user` = '$prot[id]' AND `id_game` = '$game[id]'"),0);
if (($my_kartS==0 && $my_kartD==0 && $game['status']==3) && ($game['read']==0 || $game['read']==2))
{
mysql_query("UPDATE `durak` SET `game_over` = '0' , `read` = '0', `status` = '5' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
}
elseif (($my_kartS==0 && $game['status']==3) && ($game['read']==0 || $game['read']==2))
{
mysql_query("UPDATE `durak` SET `game_over` = '$avtor[id]' , `read` = '0', `status` = '4' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
}
elseif (($my_kartD==0 && $game['status']==3) && ($game['read']==0 || $game['read']==2))
{
mysql_query("UPDATE `durak` SET `game_over` = '$prot[id]' , `read` = '0', `status` = '4' WHERE `id` = '$game[id]' LIMIT 1");
header("Location: ?");
}
//--------------------------противника карты--------------------------------//
$qS = mysql_query("SELECT * FROM `durak_game` where `id_user` = '$ank2[id]' AND `on` = '0' AND `id_game` = '".$game['id']."' ORDER BY `time` ASC");
echo "<center>";
while ($kartaS = mysql_fetch_assoc($qS))
{
echo "<img src='mini/1.png' style='border:1px solid #fff;border-radius: 5px;padding:1px;' border='0' /> ";
}
echo "</center>";
//-------------------------------------------------------------------//
//----------------------------карты в игре----------------------------//
echo "<table style='width:100%;'>";
echo "<tr>";
echo "<td>";
if ($game['status']==4 || $game['status']==5)
{
echo "<div class='nav'>";
if ($game['status']==5)
{
echo "<b>Ничья! Победила дружба!</b>";
}
elseif ($game['game_over']==$user['id'])
{
echo "<b>Вы выиграли! Поздравляем!</b><br />";
if ($game['stav']>0)
echo "Вам будет начислено $game[stav] $sm";
}
else
{
echo "<b>Вы проиграли!</b><br />";
if ($game['stav']>0)
echo "C вас будет списано $game[stav] $sm";
}
echo "</div>";
}
$q5 = mysql_query("SELECT * FROM `durak_hod` where `id_game` = '".$game['id']."' ORDER BY `num` ASC");
$ob5 = 0;
while ($karta5 = mysql_fetch_assoc($q5))
{
$ob5++;
?>
<div class="items_spec">
<img src="<?echo "$game[koloda]/$karta5[name].jpg";?>" style="border: 2px solid #bdbdbd;border-radius: 5px; padding:0px;" class="ob<?echo $ob5;?>" border="0" />
</div>
<style>
.items_spec {
float: left;
padding: 12px 0 0 12px;
width: 1px;
height: 130px;
display: block;
position: relative;
}
span.special {
position: absolute;
right: 0;
top: 0;
}
</style>
<?
}
echo "</td>";
$colls = mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_game` WHERE `id_user` = '0' AND `id_game` = '$game[id]'"),0);
echo "<td style='text-align:right; vertical-align: top;'>";
if ($game['hod']==$user['id'] && $game['status']==3)
echo "<b>Ваш ход</b> $sec2<br />";
else if ($game['status']==3)
echo "<b>Ход противника</b> $sec2<br />";
if ($game['stav']>0)echo "Ставка: $game[stav] $sm!<br />";
if ($kozar['id'] && $colls>0)
{
echo "<img src='mini/$kozar[karta].png' style='border:1px solid #fff;border-radius: 3px; padding:0px;' border='0' />";
if ($kozar['id'] && $colls>1)
echo "<img src='mini/1.png' style='border:1px solid #fff;border-radius: 3px;'border='0' >";
echo "<br />x $colls";
}
else
{
echo "Колода пуста";
}
echo "</td>";
echo "</tr>";
echo "</table>";
//-------------------------------------------------------------------//
echo "</div>";
echo "<div class='niz'>";
//--------------------------мои карты--------------------------------//
$q = mysql_query("SELECT * FROM `durak_game` where `id_user` = '$user[id]' AND `on` = '0' AND `id_game` = '".$game['id']."' ORDER BY `sila` DESC");
echo "<center>";
while ($karta = mysql_fetch_assoc($q))
{
if ($game['hod']==$user['id'])
{
$url = "<a href='?go=$karta[id]'>";
$a = '</a>';
}else{
$url = null;
$a = null;
}
echo "$url<img src='mini/$karta[karta].png' style='border:1px solid #fff;border-radius: 3px;padding:0px;' border='0' />$a ";
}
echo "</center>";
//-------------------------------------------------------------------//
//---------------------------меню игры-------------------------------//
echo "<div class='foots2'><center>";
if ($game['hod']==$user['id'] && $game['read']==1 && $game['bit']==$user['id'])
echo "<a href='?zabrat' >Забрать</a> ";
if ($game['hodit']==$user['id'] && $game['read']==2)
echo "<a href='?go=bito&ok' >Откинуть карты</a> ";
if ($game['status']==4 || $game['status']==5)
echo "<a href='?go=exit&ok' >Закончить</a> ";
echo "<a href='?' >Обновить</a> ";
echo "</center></div>";
//-------------------------------------------------------------------//
echo "</div>";
if ($game['chat']==1)
{
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `durak_chat` WHERE `id_game` = '$game[id]'"),0);
$q=mysql_query("SELECT * FROM `durak_chat` WHERE `id_game` = '$game[id]' ORDER BY `id` DESC LIMIT 5");
echo " <div class='fons'>n";
echo " <div class='foots'>n";
echo "Комментарии:";
echo " </div>n";
echo "<form method="post" name='message' action="?">n";
echo "<textarea name="msg"></textarea><br />n";
echo "<input value="Отправить" type="submit"/>n";
echo "</form>n";
if ($k_post==0)
{
echo " <div class='foots2' style='text-align:left;'>n";
echo "Нет комментариевn";
echo " </div><br />n";
}
$nnn=0;
while ($post = mysql_fetch_assoc($q))
{
//$ank_c=mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
$ank_c=get_user($post['id_user']);
echo "<b>$ank_c[nick]</b> (".vremja($post['time']).") » n";
echo output_text($post['msg'])."";echo " <br />";
}
echo " </div>n";
}
echo " <div class='foots'>n";
echo "<center>Подкидной "Дурак"</center>";
echo " </div>n";
}
?>