/* get White's nick */
$tmpNick = mysql_query("SELECT nick FROM " . $CFG_TABLE[players] . ", " . $CFG_TABLE[games] . " WHERE playerID = whitePlayer AND gameID = " . $_SESSION['gameID']);
$whiteNick = mysql_result($tmpNick, 0);
/* get Black's nick */
$tmpNick = mysql_query("SELECT nick FROM " . $CFG_TABLE[players] . ", " . $CFG_TABLE[games] . " WHERE playerID = blackPlayer AND gameID = " . $_SESSION['gameID']);
$blackNick = mysql_result($tmpNick, 0);
/* load game */
$isInCheck = $_POST['isInCheck'] == 'true';
$isCheckMate = false;
$isPromoting = false;
$isUndoing = false;
loadHistory();
loadGame();
processMessages();
if ($isUndoing) {
    doUndo();
    saveGame();
} elseif ($_POST['promotion'] != "" && $_POST['toRow'] != "" && $_POST['toCol'] != "") {
    savePromotion();
    $board[$_POST['toRow']][$_POST['toCol']] = $_POST['promotion'] | $board[$_POST['toRow']][$_POST['toCol']] & BLACK;
    saveGame();
} elseif ($_POST['fromRow'] != "" && $_POST['fromCol'] != "" && $_POST['toRow'] != "" && $_POST['toCol'] != "") {
    /* ensure it's the current player moving				 */
    /* NOTE: if not, this will currently ignore the command...               */
    /*       perhaps the status should be instead?                           */
    /*       (Could be confusing to player if they double-click or something */
    $tmpIsValid = true;
    if ($numMoves == -1 || $numMoves % 2 == 1) {
        /* White's move... ensure that piece being moved is white */
        if (($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) != 0 || $board[$_POST['fromRow']][$_POST['fromCol']] == 0) {
            /* invalid move */
        $query = $db->Execute($sql, array($time_limit, $game_id));
        db_op_result($query, __LINE__, __FILE__);
    } else {
        $sql = $db->Prepare("UPDATE games set timeBlack=? WHERE game_id=?");
        $query = $db->Execute($sql, array($time_limit, $game_id));
        db_op_result($query, __LINE__, __FILE__);
    }
    $smarty->assign('js_checkmate_alert', "<script>alert('" . $MSG_LANG['theflaghasfallen'] . " " . $mycolor2 . $MSG_LANG['lost'] . "');  window.location='chess.php'; </script>");
    //we switch the display based on that. good reason to exit and halt execution here I guess
    exit;
}
########## RESEARCH MARKER END###########
if (!empty($_POST['from_row'])) {
    //config value needed- allow_undo Hmm dont we have it already? find out
    if ($isUndoing) {
        $do_undo = doUndo();
        //obviously this is teh undo move- we're eliminating it or making it optional
        $save_the_game = saveGame();
        //we should pass game data- screw setting stuff global
    } else {
        if ($allow_chat && isset($_POST['chat_msg']) && $chatdata) {
            if ($_POST['chat_msg'] != "") {
                //post a chat comment- public or private - depends on value of button..??
                if (!get_magic_quotes_gpc()) {
                    //Eh?/ Jeez! this is insanity - we now have function so we dont have to CARE about this crap
                    $_POST['chat_msg'] = addslashes($_POST['chat_msg']);
                    $_POST['chat_msg'] = htmlspecialchars($_POST['chat_msg']);
                    $_POST['chat_msg'] = wordwrap($_POST['chat_msg'], 35, " ", 1);
                }
                $sql = "";
                mysql_query("insert into {$db_prefix}chat (from_id,message,game_id) VALUES ('" . $_SESSION['player_id'] . "','" . $_POST['chat_msg'] . "','" . $_SESSION[game_id] . "')");