//****************************************************************************** $wake_up_sent = false; if (isset($_POST['wakeID']) && $_SESSION['game_id'] == $_POST['wakeID']) { call("webchessMail('wakeup',{$_SESSION['opponent']['p_email']},'',{$_SESSION['username']},{$_SESSION['game_id']})"); $wake_up_sent = webchessMail('wakeup', $_SESSION['opponent']['p_email'], '', $_SESSION['username'], $_SESSION['game_id']); } //*/ //****************************************************************************** // load game from database for display //****************************************************************************** // get FEN array $query = "\n\tSELECT h_fen\n\tFROM " . T_HISTORY . "\n\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\tORDER BY h_time\n"; $FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__); $num_moves = count($FENarray) - 1; // remove one for initpos loadGame(); // sets up board using last entry in ".T_HISTORY." table (chessdb.inc.php) // convert the current FEN array to an array of standard moves FENtomoves(); // (chessutils.inc.php) // find out if it's the current player's turn $FENitems = explode(' ', $FENarray[$num_moves]); $curTurn = $colorArray[$FENitems[1]]; $isPlayersTurn = $curTurn == $_SESSION['player']['p_color'] ? true : false; //*/ // set the display to show whos turn, or shared if ($_SESSION['shared']) { $turn = "Shared"; } elseif ($isPlayersTurn) { $turn = "Your Move"; } else {
function api_query_user($aParameter) { $aUsers = getParamFrom($aParameter, 'users', ''); $aGames = getParamFrom($aParameter, 'games', ''); $aCurrent = getParamFrom($aParameter, 'current', false); $aUTF8 = getParamFrom($aParameter, 'utf8', false); // load gameconfigs $GameFiles = scandir(dirname(__FILE__) . '/../../themes/games'); $Games = array(); foreach ($GameFiles as $GameFileName) { if (substr($GameFileName, -4) === '.xml') { $Game = loadGame(substr($GameFileName, 0, -4)); $Games[$Game['GameId']] = $Game; } } // Build query $Parameters = array(); $Conditions = array(); // Filter users if (!$aCurrent && $aUsers != '') { $Users = explode(',', $aUsers); foreach ($Users as &$UserId) { $UserId = intval($UserId); } if (count($Users) == 1) { array_push($Conditions, 'UserId=?'); array_push($Parameters, $Users[0]); } else { array_push($Conditions, 'UserId IN (' . implode(',', $Users) . ')'); } } if ($aCurrent) { $Session = Session::get(); if ($Session === null) { return array(); } // no user logged in array_push($Conditions, 'UserId=?'); array_push($Parameters, $Session->getUserId()); } // Filter games if ($aGames != '') { $Games = explode(',', $aGames); $GameOptions = array(); foreach ($Games as $Game) { array_push($GameOptions, 'Game=?'); array_push($Parameters, $Game); } array_push($Conditions, $GameOptions); } // Build where clause $WhereString = ''; if (count($Conditions) > 0) { foreach ($Conditions as &$Part) { if (is_array($Part)) { $Part = '(' . implode(' OR ', $Part) . ')'; } } $WhereString = 'WHERE ' . implode(' AND ', $Conditions) . ' '; } // Run query $Connector = Connector::getInstance(); $UserQuery = $Connector->prepare('SELECT `' . RP_TABLE_PREFIX . 'User`.UserId AS _UserId, `' . RP_TABLE_PREFIX . 'Character`.* FROM `' . RP_TABLE_PREFIX . 'User` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(UserId) ' . $WhereString . 'ORDER BY UserId,Name,Game'); foreach ($Parameters as $Index => $Value) { //Out::getInstance()->pushValue('query', $Value); if (is_numeric($Value)) { $UserQuery->bindValue($Index + 1, $Value, PDO::PARAM_INT); } else { $UserQuery->bindValue($Index + 1, $Value, PDO::PARAM_STR); } } // Resolve result $Result = array(); $LastUserId = 0; $User = array(); $UserQuery->loop(function ($UserRow) use(&$LastUserId, &$Result, &$User, &$Games, $aUTF8) { if ($LastUserId != $UserRow['_UserId']) { if (count($User) > 0) { array_push($Result, $User); } $LastUserId = $UserRow['_UserId']; $User = array('Id' => $LastUserId, 'Characters' => array()); } if ($UserRow['CharacterId'] != null) { $Game = $Games[$UserRow['Game']]; $Classes = explode(':', $UserRow['Class']); $Roles = array(); if ($Game['ClassMode'] == 'single') { // Single class mode -> Roles are in database array_push($Roles, $UserRow['Role1']); if ($UserRow['Role1'] != $UserRow['Role2']) { array_push($Roles, $UserRow['Role2']); } } else { // Multi class mode -> Roles are attached to class foreach ($Classes as $ClassId) { foreach ($Game['Classes'][$ClassId]['roles'] as $RoleId) { if (!in_array($RoleId, $Roles)) { array_push($Roles, $RoleId); } } } } array_push($User['Characters'], array('Name' => $aUTF8 ? xmlToUTF8($UserRow['Name']) : $UserRow['Name'], 'Game' => $UserRow['Game'], 'IsMainChar' => $UserRow['Mainchar'] == 'true', 'Classes' => $Classes, 'Roles' => $Roles)); } }); if (count($User) > 0) { array_push($Result, $User); } return $Result; }
//OK let's get this sucker loaded. if (!empty($_POST['is_in_check'])) { $is_in_check = $_POST['is_in_check']; } else { $is_in_check = false; } //initialize the variables - let's keep em organized as well.... $isCheckMate = false; $isPromoting = false; $isUndoing = false; if (empty($game_id)) { $game_id = $_SESSION['game_id']; } $load_history = loadHistory($game_id); //should be load_history($game_id) and return value is history array, better than globaling everything $load_game = loadGame($game_id); //dont know - should this return a true or false we can check? or does it return specific data? $sql = $db->Prepare("SELECT * from {$db_prefix}games WHERE game_id=?"); $query = $db->Execute($sql, array($game_id)); db_op_result($query, __LINE__, __FILE__); $row = $query->fields; if (empty($row)) { //this is rather silly, really .. let's instead show a notice "game deleted" and have done with it :) //offer options such as pgn download, review, kibbitz, etc - the game cleanup script will archive saved games //The game was deleted //echo "<script>window.location='mainmenu.php'</script>"; //exit; } $white = $row['white_player']; $black = $row['black_player']; $timeLimit = $row['time_limit'];
function loadGameSettings() { global $gSite; global $gGame; if ($gGame != null) { return; } // ### return, already initialized ### loadSiteSettings(); $Out = Out::getInstance(); $gGame = loadGame($gSite['GameConfig']); }
function getGameInfo($id_game = 0, $raw = false) { global $scripturl, $txt, $db_prefix, $user_info, $smcFunc, $modSettings, $context; $id_game = loadGame($id_game); if ($id_game === false) { return false; } if ($raw) { return $context['arcade']['game_data'][$id_game]; } $game =& $context['arcade']['game_data'][$id_game]; // Is game installed in subdirectory /*if ($game['game_directory'] != '') $gameurl = $modSettings['gamesUrl'] . '/' . $game['game_directory'] . '/'; // It is in main directory else $gameurl = $modSettings['gamesUrl'] . '/';*/ $description = parse_bbc($game['description']); $help = parse_bbc($game['help']); if (!empty($game['real_name'])) { $player_name = $game['real_name']; $guest = empty($game['id_member']); } else { $player_name = $txt['guest']; $guest = true; } return array('id' => $game['id_game'], 'url' => array('play' => $scripturl . '?action=arcade;sa=play;game=' . $game['id_game'], 'highscore' => $scripturl . '?action=arcade;sa=highscore;game=' . $game['id_game'], 'favorite' => $context['arcade']['can_favorite'] ? $game['is_favorite'] == 0 ? $scripturl . '?action=arcade;sa=favorite;game=' . $game['id_game'] : $scripturl . '?action=arcade;sa=favorite;remove;game=' . $game['id_game'] : '#'), 'extra_data' => !empty($game['extra_data']) ? unserialize($game['extra_data']) : array(), 'category' => array('id' => $game['id_cat'], 'name' => $game['cat_name'], 'link' => $scripturl . '?action=arcade;category=' . $game['id_cat']), 'internal_name' => $game['internal_name'], 'name' => $game['game_name'], 'class' => $game['class'], 'description' => $description, 'help' => $help, 'rating' => $game['game_rating'], 'rating2' => round($game['game_rating']), 'thumbnail' => !empty($game['thumbnail']) ? $gameurl . $game['thumbnail'] : '', 'thumbnail_small' => !empty($game['thumbnail_small']) ? $gameurl . $game['thumbnail_small'] : '', 'is_champion' => $game['id_score'] > 0, 'champion' => array('id' => $game['id_member'], 'name' => $player_name, 'score_id' => $game['id_score'], 'link' => !$guest ? '<a href="' . $scripturl . '?action=profile;u=' . $game['id_member'] . '">' . $player_name . '</a>' : $player_name, 'score' => comma_format((double) $game['champ_score']), 'time' => $game['champion_time']), 'is_personal_best' => !$user_info['is_guest'] && $game['id_pb'] > 0, 'personal_best' => !$user_info['is_guest'] ? comma_format((double) $game['personal_best']) : 0, 'personal_best_score' => !$user_info['is_guest'] ? $game['personal_best'] : 0, 'score_type' => $game['score_type'], 'highscore_support' => $game['score_type'] != 2, 'is_favorite' => $context['arcade']['can_favorite'] ? $game['is_favorite'] > 0 : false, 'favorite' => $game['num_favorites'], 'member_groups' => isset($game['member_groups']) ? explode(',', $game['member_groups']) : array()); }
function ExportGameInfo() { global $scripturl, $txt, $db_prefix, $modSettings, $context, $sourcedir, $smcFunc, $boarddir; $id = loadGame((int) $_REQUEST['game'], true); if ($id === false) { fatal_lang_error('arcade_game_not_found', false); } $game =& $context['arcade']['game_data'][$id]; ob_end_clean(); if (!empty($modSettings['enableCompressedOutput'])) { @ob_start('ob_gzhandler'); } else { ob_start(); } $game['extra_data'] = unserialize($game['extra_data']); $extra = ''; if (isset($game['extra_data']['flash_version'])) { $extra = ' <flash> <version>' . $game['extra_data']['flash_version'] . '</version> <width>' . $game['extra_data']['width'] . '</width> <height>' . $game['extra_data']['height'] . '</height> <bgcolor>' . strtoupper(implode('', array_map('dechex', $game['extra_data']['background_color']))) . '</bgcolor> </flash>'; } header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); printf('<?xml version="1.0"?> <!-- Generated with SMF Arcade %s --> <game-info> <id>%s</id> <name><![CDATA[%s]]></name> <description><![CDATA[%s]]></description> <help><![CDATA[%s]]></help> <thumbnail>%s</thumbnail> <thumbnail-small>%s</thumbnail-small> <file>%s</file> <scoring>%d</scoring> <submit>%s</submit>%s </game-info>', SMFArcade::VERSION, $game['internal_name'], htmlspecialchars($game['game_name']), htmlspecialchars($game['description']), htmlspecialchars($game['help']), htmlspecialchars($game['thumbnail']), htmlspecialchars($game['thumbnail_small']), $game['game_file'], $game['score_type'], $game['submit_system'], $extra); obExit(false); }