<? @session_start(); include "conn.php";

$q=mysql_fetch_array(mysql_query("select * from member where id='$_SESSION[cid]' and id<>''"));

if(
$_GET[ck]==1)
{
$zp=mysql_fetch_array(mysql_query("select x from map where id='zombie'"));
$mp=mysql_fetch_array(mysql_query("select x from map where id='man'"));


if(
$zp[x]==10)
{
echo(
"WIN : ZOMBIE<br>");
mysql_query("update map set x=0 where id='man'");
$myb=mysql_fetch_array(mysql_query("select sum(bat) from batlist where id='$q[id]' and t='zombie'"));
$myb=$myb[0]+round($myb[0]/5);

if(
$myb && $myb>0)
{

if(
rand(1,2)==1)
{
$bo=mysql_fetch_array(mysql_query("select sum(bat) from batlist where t='zombie'"));
$bo=round($bo[0]/10);
$myb=$myb+$bo;
}

mysql_query("update member set gold=gold+$myb where id='$q[id]'");
mysql_query("delete from batlist where id='$q[id]' and id<>'admin'");
echo(
"<meta http-equiv=refresh content=0;url=index.php>");
}
}

if(
$mp[x]==10)
{
echo(
"WIN : MAN<br>");
mysql_query("update map set x=0 where id='zombie'");
$myb=mysql_fetch_array(mysql_query("select sum(bat) from batlist where id='$q[id]' and t='man'"));
$myb=$myb[0]+round($myb[0]/5);

if(
$myb && $myb>0)
{

if(
rand(1,2)==1)
{
$bo=mysql_fetch_array(mysql_query("select sum(bat) from batlist where t='man'"));
$bo=round($bo[0]/10);
$myb=$myb+$bo;
}

mysql_query("update member set gold=gold+$myb where id='$q[id]'");
mysql_query("delete from batlist where id='$q[id]'");
echo(
"<meta http-equiv=refresh content=0;url=index.php>");
}
}



$tm=date('i',time());

$tm=round($tm%2);

if(
$tm==1)
{
$ttm=date('s',time());
$ttm=60-$ttm;
echo(
"<h1><b>count down : $ttm</b></h1>");

if(
$zp[x]==10 || $mp[x]==10)
{
if(
$zp[x]==10$win="zombie";
if(
$mp[x]==10$win="human";

mysql_query("delete from batlist");
$tm=time();
mysql_query("delete from chat");
mysql_query("insert into chat values('admin','$tm','WIN : $win')");
echo(
"<meta http-equiv=refresh content=0;url=index.php>");
}


mysql_query("update map set x=0");
}

if(
$tm==0)
{
$ttm=date('s',time());
$ttm=60-$ttm;
echo(
"timeout : $ttm");
$rnd1=rand(1,20);
$rnd2=rand(1,20);

if(
$rnd1==1mysql_query("update map set x=x+1 where id='zombie' and x<10");
if(
$rnd2==1mysql_query("update map set x=x+1 where id='man' and x<10");


}

echo(
"<table border=1 align=center><tr>");

for(
$i=0;$i<=10;$i++)
{
$v="&nbsp;";
if(
$zp[x]==$i$v="<img src='images/zombie.bmp'>";
if(
$i==10 && $zp[x]!=10$v="GOAL";
echo(
"<td width=50 height=50>$v</td>");
}
echo(
"</tr><tr>");

for(
$i=0;$i<=10;$i++)
{
$v="&nbsp;";
if(
$mp[x]==$i$v="<img src='images/man.bmp'>";
if(
$i==10 && $mp[x]!=10$v="GOAL";
echo(
"<td width=50 height=50>$v</td>");


}
echo(
"</tr>");

$b1=mysql_fetch_array(mysql_query("select sum(bat) from batlist where t='zombie'"));
$b2=mysql_fetch_array(mysql_query("select sum(bat) from batlist where t='man'"));

echo(
"<tr><td colspan=11>zombie : ".number_format($b1[0])."<br>human : ".number_format($b2[0])."</td></tr></table>");



$ck=mysql_query("select * from chat order by tm desc limit 0,20");

echo(
"<table border=0><tr>");
while(
$d=mysql_fetch_array($ck))
{
$tt=date('H:i:s',$d[tm]);
$d[id]=str_replace("<","&lt;",$d[id]);
$d[id]=str_replace(">","&gt;",$d[id]);
$d[msg]=str_replace("<","&lt;",$d[msg]);
$d[msg]=str_replace(">","&gt;",$d[msg]);
$d[msg]=substr($d[msg],0,100);

if(
$d[id]!="admin") echo("<tr><td><b>&lt;$tt&gt;</b></td><td>[$d[id]]</td><td width=1000>$d[msg]</td></tr>");
if(
$d[id]=="admin") echo("<tr><td colspan=3 align=left><h3>$d[msg]</h3></td></tr>");
}
echo(
"</table>");

exit();
}

 
?>
<html>
<head>
<title>game</title>
</head>
<? if($_SESSION[cid]) { echo("<body onload=msgfrm.msg.focus();>"); } else echo("<body>"); ?>

<?
$mip
=md5("$_SERVER[REMOTE_ADDR]",true);


if(
$_GET[mode]=="logout")
{
$_SESSION[cid]="";
exit(
"<meta http-equiv=refresh content=0;url=index.php>");
}

if(
$_GET[mode]=="del" && $_SESSION[cid])
{
mysql_query("delete from member where id='$q[id]' and id<>'admin'");
mysql_query("delete from batlist where id='$q[id]'");
exit(
"<meta http-equiv=refresh content=0;url=index.php>");
}

if(
$q[id])
{

if(
$_POST[msg])
{
$tm=time();
mysql_query("insert into chat values('$q[id]','$tm','$_POST[msg]')");
}

echo(
"<script src='jquery-1.7.2.min.js'></script>");
echo(
"<h1><b>[$q[id]]</b> GOLD : $q[gold]/2147483647<br></h1><a href=?mode=logout>logout</a>&nbsp;&nbsp;<a href=?mode=del>delete</a><hr>");

if(
$q[gold]>=2147483647)
{
$pw="????";
echo(
"password is $pw<br>");
}


echo(
"<div id=game>Loading. . . </div><hr>");

?>

<script>

function ck()
{

$.ajax({
  type: "POST",
  url: "index.php?ck=1",
  data: "",
  success: function(gg){ if(gg!=0) game.innerHTML=gg; }
});

setTimeout('ck()',1000);

}

setTimeout('ck()',100);
</script>
<form method=post action=index.php name=msgfrm>
msg : <input type=text name=msg size=50 maxlength=50><input type=submit>
</form>



<?

$cck
=mysql_fetch_array(mysql_query("select count(x) from map where x=0"));

if(
$cck[0]==2)
{
echo(
"batting : <form name=batfrm><input type=text name=bat value='$q[gold]' size=10><br><img src='images/zombie.bmp' border=5 onclick=location.href='?bat=1&gold='+batfrm.bat.value></a>
<img border=5 src='images/man.bmp' onclick=location.href='?bat=2&gold='+batfrm.bat.value></a></form>"
);

if(
$_GET[bat]==&& $_GET[gold]<=$q[gold] && !eregi("[^0-9]",$_GET[gold]) && $q[gold]>0)
{
mysql_query("update member set gold=gold-$_GET[gold] where id='$q[id]' and id<>'admin'");
mysql_query("insert into batlist values('$q[id]','zombie','$_GET[gold]')");
echo(
"<meta http-equiv=refresh content=0;url=index.php>");
}

if(
$_GET[bat]==&& $_GET[gold]<=$q[gold] && !eregi("[^0-9]",$_GET[gold]) && $q[gold]>0)
{
mysql_query("update member set gold=gold-$_GET[gold] where id='$q[id]' and id<>'admin'");
mysql_query("insert into batlist values('$q[id]','man','$_GET[gold]')");
echo(
"<meta http-equiv=refresh content=0;url=index.php>");
}


}



}

if(!
$q[id] && $_POST[id] && $_POST[ip])
{

if(
md5("$_POST[ip]",true)==md5("61.42.25.12",true)) exit("Access Denied");

$mpw=md5("$_POST[ip]",true);

$q=mysql_fetch_array(mysql_query("select * from member where id='$_POST[id]' and ip='$mpw'"));

if(
$q[id])
{

$_SESSION[cid]="$q[id]";
}
exit(
"<meta http-equiv=refresh content=0;url=index.php>");
}


if(!
$q[id])
{

if(
$_POST[jid])
{
$ck=mysql_fetch_array(mysql_query("select * from member where id='$_POST[jid]'"));
$ck2=mysql_fetch_array(mysql_query("select * from member where ip='$mip'"));
if(
$ck[id]) exit("<meta http-equiv=refresh content=0;url=index.php>");
if(
$ck2[id]) exit("<meta http-equiv=refresh content=0;url=index.php>");
mysql_query("insert into member values('$mip','$_POST[jid]',1000,0,0)");
echo(
"<script>alert('done');</script>");
exit(
"<meta http-equiv=refresh content=0;url=index.php>");
}

echo(
"<form method=post action=index.php><br>
<table border=1><tr><td>login</td><td>id</td><td><input type=text name=id></td><td>ip</td><td><input type=text name=ip value='
$_SERVER[REMOTE_ADDR]'></td><td><input type=submit value='login'></td></tr>
<tr><td>join</td><td>id</td><td><input type=text name=jid></td><td><input type=submit value='join'></td></tr></table></form>"
);
exit();
}

?>
<a href=index.phps>source</a>
</body>
</html>