Location: PHPKode > scripts > Some Chess > some-chess/game.php
<?php 
//		Some Chess, a PHP multi-player chess server.
//		Copyright (C) 2006 Jon Link
session_start(); 
require_once('loginon.php');
require_once('config.php');
include_once('languages/'.$lang.'_main.php');
include_once('constants.php');
include_once('standard.php');
$id					 	= validate($_SESSION['id']);
$now			 		= date(YmdHi);
$do						= $_POST['do'];
if(!$do) $do			= $_GET['do'];
$status					= validate($_GET['status']);
$gameID				 	= validate($_POST['gameID']);
if(!$gameID) $gameID	= validate($_GET['gameID']);
$vsName				 	= $_GET['vs'];
$queryOnline = 'UPDATE players SET online="1", timeOnline="'.$now.'" WHERE id="'.$id.'" LIMIT 1';
mysql_query($queryOnline) or die('<div class="error">'.errorDBStr.'player</div>');
echo'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<title>Some Chess</title>
	<link rel="stylesheet" type="text/css" href="somechess.css">
	</head>
	<body>	
<div id="menu">Some Chess <span id="ver">',version,'</span><br />',$menu,'</div>';
if($status !== 'view'){
	echo'<iframe src="board.php?gameID=',$gameID,'&amp;do=',$do,'&amp;vs=',$vsName,'" frameborder="0" id="board">
	<h3>'.$gameStr[0].'</h3>
	</iframe>';
}else{
	if($_GET['move'])$move		= '&amp;move='.$_GET['move'];
	if($_GET['player'])$player	= '&amp;player='.$_GET['player'];
	echo'<iframe src="view.php?gameID=',$gameID,'&amp;status=',$status,$move,$player,'" frameborder="0" id="board">
	<h3>'.$gameStr[0].'</h3>
	</iframe>';
}
if(!$status && $showChat == 1){
	echo'<iframe src="chat.php?gameID=',$gameID,'" frameborder="0" id="chat">
		<h3>'.$gameStr[1].'</h3>
	</iframe>';
	echo'</div>
	<form action="game.php?do=display&amp;gameID=',$gameID,'&amp;vs=',$vsName,'" method="post" id="chatter">
		<input type="text" name="chat" autocomplete="off" id="chatIn" />
		<input type="hidden" name="gameID" value="',$gameID,'" />
		<input type="hidden" name="act" value="chat" />
		<input type="submit" value="Chat" class="gButt" />
	</form>
	</div>';
}
$act			= $_POST['act'];
if($act == 'chat'){
	$chat		= validate($_POST['chat']);
	$name		= validate($_SESSION['name']);	
	$queryChat	= 'SELECT gameID FROM chat WHERE gameID="'.$gameID.'"'; 
	$resultChat	= mysql_query($queryChat) or die('<div class="error">'.errorDBStr.'chat</div>');	
	$nextChat	= mysql_num_rows($resultChat)+1;	
	$queryChat	= 'INSERT INTO chat (gameID,playerName,num,text) VALUES ("'.$gameID.'","'.$name.'","'.$nextChat.'","'.$chat.'")';
	$resultChat	= mysql_query($queryChat) or die('<div class="error">'.errorDBStr.'chat</div>'.$queryChat);	
}
$vsName			= str_replace('_',' ',$vsName);
if($showPlayerImg && $status !=='view'){
	$queryVS			= 'SELECT * FROM players WHERE name="'.$vsName.'" LIMIT 1';
	$resultVS			= mysql_query($queryVS) or die('<div class="error">'.errorDBStr.'players</div>');
	$VSpic				= mysql_result($resultVS,0,'pic');
	if(!$VSpic)$VSpic	= 'default.png';
	$vsPad				= 45;
}
$query				 = 'SELECT * FROM games WHERE gameID="'.$gameID.'" LIMIT 1';
$result				 = mysql_query($query) or die('<div class="error">'.errorDBStr.'game</div>');	
$bID				 = mysql_result($result,0,'blackPlayerID');
$wID				 = mysql_result($result,0,'whitePlayerID');
if($id == $bID){$playerColor = 'black';$oppColor='white';}elseif($id == $wID){$playerColor = 'white';$oppColor='black';}

if(!$showChat){
	echo '<div id="picframeB">';
}elseif(!$status){
	echo '<div id="picframeA">';
}
if($status !=='view'){
	echo'<div class="name">';
	if($showPlayerImg) echo'<img src="'.$playerImgDir.'/'.$_SESSION['pic'].'" alt="" class="pic" />';
	echo'<p>'.$_SESSION['name'].'</p>('.$playerColor.')
	</div>
	<div style="padding:0'.$vsPad.'px 15px 0 15px;float:left;font-weight:700;">
	Vs. 
	</div>
	<div class="name">';
	if($showPlayerImg) echo'<img src="'.$playerImgDir.'/'.$VSpic.'" alt="" class="pic" />';
	echo'<p>'.$vsName.'</p>('.$oppColor.')
		</div>
	</div>';
}else{
	$queryNames		= 'SELECT whitePlayerID, blackPlayerID FROM games WHERE gameID="'.$gameID.'"';
	$resultNames	= mysql_query($queryNames)or die('<div class="error">'.errorDBStr.'game</div>');
	$whiteID		= mysql_result($resultNames,0,'whitePlayerID');
	$blackID		= mysql_result($resultNames,0,'blackPlayerID');
	$queryNames		= 'SELECT name FROM players WHERE id="'.$whiteID.'"';
	$resultNames	= mysql_query($queryNames)or die('<div class="error">'.errorDBStr.'game</div>');
	$whiteName		= mysql_result($resultNames,0,'name');
	$queryNames		= 'SELECT name FROM players WHERE id="'.$blackID.'"';
	$resultNames	= mysql_query($queryNames)or die('<div class="error">'.errorDBStr.'game</div>');
	$blackName		= mysql_result($resultNames,0,'name');
	echo '<div id="picframeC"><b>'.$whiteName.'</b> (white)<br />VS.<br /> <b>'.$blackName.'</b> (black)</div>';
}
?>
</body>
</html>
Return current item: Some Chess