$game_name = $baskets = $game_name_error = $baskets_error = ""; if (isset($_POST["create_game"])) { if (empty($_POST["game_name"])) { $game_name_error = "See väli on kohustuslik"; } else { $game_name = cleanInput($_POST["game_name"]); } if (empty($_POST["baskets"])) { $baskets_error = "See väli on kohustuslik"; } else { $baskets = cleanInput($_POST["baskets"]); } if ($game_name_error == "" && $baskets_error == "") { // functions.php failis käivina funktsiooni //msg on message $msg = createGame($game_name, $baskets); if ($msg != "") { //salvestamine õnnestus //teen tühjaks input väljad $game_name = ""; $baskets = ""; echo $msg; } } } // create if end //tulemuse lisamise errorid /*$par = $my_result = $par_error = $my_result_error = ""; if(isset($_POST["create"])){ if ( empty($_POST["par"]) ) {
<?php require_once "../file/access.php"; createGame();
if ($db = new mysqli($host, $username, $password, $dbname)) { } $db->set_charset("utf8"); // Fetch parameters form querystring $type = querystring("t"); $timeToJoin = querystring('ttj'); $score = querystring('l'); $gameId = querystring('gid'); $playerId = querystring('pid'); $playerName = querystring('pname'); $jsonp = $_GET['callback']; switch ($type) { case 'create': global $db; // Create random 5 char ID for new game $gameId = createGame(); // New player object $id = 1; // ID is set to 1 for the player who creates the game $player = new Player($gameId, $playerName, $score, $id); // Save player object as JSON to database $playerJsonId = 'player_1'; $playerJson = json_encode($player, JSON_UNESCAPED_UNICODE); $sql = "UPDATE game SET {$playerJsonId} = '{$playerJson}' WHERE id = '{$gameId}'"; $db->query($sql); // Player JSON to be returned to js with JSONP $response = $playerJson; break; case 'join': // Join an already created game // Create new player object
function handleMessage($tst_msg, $userSocket) { global $openGames; switch ($tst_msg->type) { case "message": $user_name = $tst_msg->name; //sender name $user_message = $tst_msg->message; //message text $user_color = $tst_msg->color; //color //prepare data to be sent to client $response_text = mask(json_encode(array('type' => 'usermsg', 'name' => $user_name, 'message' => $user_message, 'color' => $user_color))); send_message($response_text); //send data echo "User: "******"Send message " . $response_text . "<br>"; break; //exist this loop //exist this loop case "move": makeMove($tst_msg->gameID, $tst_msg->playerID, $tst_msg->oldSpot, $tst_msg->newSpot); echo "process a move from user " . $userSocket . "\n"; break; case "showOpenGames": echo "Show open games:\n"; print_r($openGames); $response_text = mask(json_encode(array('type' => 'script', 'message' => 'showGames([' . implode(",", $openGames) . '])'))); send_message($response_text); //send data break; case "startGame": startGame($tst_msg); //$response_text = mask(json_encode(array('type'=>'script', 'name'=>'nada', 'message'=>'console.log("recveive a script message")'))); //send_message($response_text); //send data break; case "join": joinGame($tst_msg, $userSocket); break; case "newGame": createGame($tst_msg->playerID, $userSocket); break; } }
<?php include_once 'procedures.php'; $echoAnswer = ""; $gameId = intval($_POST['gameId']); if (isset($_POST['createGame'])) { $answer = createGame($_POST['gameName'], $_POST['gameDescription'], $_POST['visualizerPath'], $_POST['timeLimit'], $_POST['memoryLimit']); switch ($answer) { case 0: $echoAnswer = "Игра успешно создана (вместе с визуализатором)! Не забудьте создать для игры один или несколько тестировщиков!"; break; case -1: $echoAnswer = "Игра успешно создана! Не забудьте создать для игры один или несколько тестировщиков!"; break; case 1: $echoAnswer = "Произошла ошибка во время передачи визуализатора!"; break; case 2: $echoAnswer = "Произошла ошибка во время работы с БД!"; break; case 3: $echoAnswer = "Не удалось подключиться к БД!"; break; } } else { if (isset($_POST['updateGame'])) { $answer = updateGame($_POST['gameId'], $_POST['gameName'], $_POST['gameDescription'], $_POST['visualizerPath'], $_POST['timeLimit'], $_POST['memoryLimit']); switch ($answer) { case 0: $echoAnswer = "Игра успешно обновлена (вместе с визуализатором)!"; break;
$sessionId = getParamGET('sessionId'); $statement = $db->prepare("\n SELECT\n id,\n occupied,\n created_at\n FROM fgj16_session\n WHERE id = :sessionId\n ORDER BY created_at DESC\n LIMIT 1\n "); $statement->bindValue(':sessionId', $sessionId, PDO::PARAM_STR); $statement->execute(); $gameSession = $statement->fetchAll(PDO::FETCH_ASSOC)[0]; if (!empty($gameSession)) { return $gameSession['occupied'] !== '0' ? 'occupied' : 'unoccupied'; } return "not found"; } $value = "An error has occurred"; $action = getParamGET('action'); if ($action) { switch ($action) { case "creategame": $value = createGame($db); break; case "joingame": $value = joinGame($db); break; case "addevent": $value = addEvent($db); break; case "getevents": $value = getEvents($db); break; case "getoccupied": $value = getOccupied($db); break; default: $value = "unknown command";
function installGames($games, $move_games = false) { global $scripturl, $txt, $db_prefix, $modSettings, $context, $sourcedir, $smcFunc, $boarddir, $boardurl; loadClassFile('Class-Package.php'); // SWF Reader will be needed require_once $sourcedir . '/SWFReader.php'; $swf = new SWFReader(); $status = array(); $trigger = array(); $acc = 0; $request_file = $smcFunc['db_query']('', ' SELECT game_file, status FROM {db_prefix}arcade_files WHERE status != 10'); while ($row = $smcFunc['db_fetch_assoc']($request_file)) { $trigger[$acc] = $row['game_file']; $acc++; } $smcFunc['db_free_result']($request_file); $request = $smcFunc['db_query']('', ' SELECT f.id_file, f.game_name, f.status, f.game_file, f.game_directory FROM {db_prefix}arcade_files AS f WHERE id_file IN ({array_int:games}) AND f.status = 10', array('games' => $games)); while ($row = $smcFunc['db_fetch_assoc']($request)) { $errors = array(); $failed = true; $moveFail = false; $directory = $modSettings['gamesDirectory'] . (!empty($row['game_directory']) ? '/' . $row['game_directory'] : ''); $internal_name = getInternalName($row['game_file'], $directory); foreach ($trigger as $trig) { $trig2 = strtolower($row['game_file']); $fileSuffix = array('.gif', '1.gif', '2.gif', '.php', '.ini', '.xap'); if ($trig == $row['game_file'] || $trig == $trig2) { deleteArcadeArchives($modSettings['gamesDirectory'] . '/gamedata/' . $internal_name); deleteArcadeArchives($modSettings['gamesDirectory'] . '/gamedata/' . substr($row['game_file'], 0, -4)); if ($directory != $modSettings['gamesDirectory']) { foreach ($fileSuffix as $suffix) { deleteArcadeFile($directory . '/' . $internal_name . $suffix); $similar = similar_arcade_file_exists($directory . '/' . $internal_name . $suffix); if ($similar != $directory . '/' . $internal_name . $suffix) { deleteArcadeFile($directory . '/' . $similar); } } deleteArcadeFile($directory . '/' . $row['game_file']); $similar = similar_arcade_file_exists($directory . '/' . $row['game_file']); if ($similar != $directory . '/' . $row['game_file']) { deleteArcadeFile($directory . '/' . $similar); } } else { deleteArcadeFile($directory . '/' . $row['game_file']); $similar = similar_arcade_file_exists($directory . '/' . $row['game_file']); if ($similar != $directory . '/' . $row['game_file']) { deleteArcadeFile($directory . '/' . $similar); } foreach ($fileSuffix as $suffix) { deleteArcadeFile($directory . '/' . $internal_name . $suffix); $similar = similar_arcade_file_exists($directory . '/' . $internal_name . $suffix); if ($similar != $directory . '/' . $internal_name . $suffix) { deleteArcadeFile($directory . '/' . $similar); } } } updateGameCache(); if (@is_dir($directory) && $directory != $modSettings['gamesDirectory']) { $countfile = 0; if ($handle = @opendir($directory)) { while (false !== ($file = @readdir($handle))) { if ($file != "." && $file != "..") { $countfile++; } } @closedir($handle); } if ($countfile == 0) { deleteArcadeArchives($directory); } } if (empty($status)) { $status = array(); } $file_num = (int) $row['id_file']; $status[] = array('id' => $file_num, 'name' => $txt['directory_make_exists'] . $internal_name, 'error' => false); continue 2; } } // Search for thumbnails chdir($directory); if (file_exists($directory . '/game-info.xml')) { $gameinfo = readGameInfo($directory . '/game-info.xml'); if (!isset($gameinfo['id'])) { unset($gameinfo); } } $thumbnail = glob($internal_name . '1.{png,gif,jpg}', GLOB_BRACE); if (empty($thumbnail)) { $thumbnail = glob($internal_name . '.{png,gif,jpg}', GLOB_BRACE); } $thumbnailSmall = glob($internal_name . '2.{png,gif,jpg}', GLOB_BRACE); $game = array('id_file' => $row['id_file'], 'name' => $row['game_name'], 'class' => '', 'directory' => $row['game_directory'], 'file' => $row['game_file'], 'internal_name' => $internal_name, 'thumbnail' => isset($thumbnail[0]) ? $thumbnail[0] : '', 'thumbnail_small' => isset($thumbnailSmall[0]) ? $thumbnailSmall[0] : '', 'game_settings' => array()); unset($thumbnail, $thumbnailSmall); // Get information from flash if (substr($row['game_file'], -3) == 'swf') { if (isset($gameinfo['flash'])) { if (!empty($gameinfo['flash']['width']) && is_numeric($gameinfo['flash']['width'])) { $game['game_settings']['width'] = (int) $gameinfo['flash']['width']; } if (!empty($gameinfo['flash']['height']) && is_numeric($gameinfo['flash']['height'])) { $game['game_settings']['height'] = (int) $gameinfo['flash']['height']; } if (!empty($gameinfo['flash']['version']) && is_numeric($gameinfo['flash']['version'])) { $game['game_settings']['flash_version'] = (int) $gameinfo['flash']['version']; } if (!empty($gameinfo['flash']['bgcolor']) && strlen($gameinfo['flash']['bgcolor']) == 6) { $game['game_settings']['background_color'] = array(hexdec(substr($gameinfo['flash']['bgcolor'], 0, 2)), hexdec(substr($gameinfo['flash']['bgcolor'], 2, 2)), hexdec(substr($gameinfo['flash']['bgcolor'], 4, 2))); } } // Do we need to detect at least something? if (!isset($game['game_settings']['width']) || !isset($game['game_settings']['height']) || !isset($game['game_settings']['version']) || !isset($game['game_settings']['bgcolor'])) { $swf->open($directory . '/' . $row['game_file']); // Add missing values if (!$swf->error) { $game['game_settings'] += array('width' => $swf->header['width'], 'height' => $swf->header['height'], 'flash_version' => $swf->header['version'], 'background_color' => $swf->header['background']); } $swf->close(); } } // Detect submit system if (empty($row['class'])) { if (isset($gameinfo)) { $row['class'] = $gameinfo['submit']; } elseif (substr($row['game_file'], -3) == 'xap') { $row['class'] = 'Arcade_Game_silver'; } elseif (file_exists($boarddir . '/arcade/gamedata/' . $internal_name . '/v32game.txt')) { $row['class'] = 'Arcade_Game_ibp32'; } elseif (file_exists($boarddir . '/arcade/gamedata/' . $internal_name . '/v3game.txt')) { $row['class'] = 'Arcade_Game_ibp3'; } elseif (file_exists($directory . '/' . $internal_name . '.ini')) { $row['class'] = 'Arcade_Game_pnflash'; } elseif (file_exists($directory . '/' . $internal_name . '.php')) { $file = file_get_contents($directory . '/' . $internal_name . '.php'); if (strpos($file, '$config = array(') !== false) { $row['class'] = 'Arcade_Game_ibp'; } else { $row['class'] = 'Arcade_Game_v1game'; } unset($file); } else { $row['class'] = 'Arcade_Game_v1game'; } } $game['class'] = $row['class']; $game['score_type'] = isset($gameinfo) && isset($gameinfo['scoring']) ? (int) $gameinfo['scoring'] : 0; if (!empty($gameinfo['thumbnail'])) { $game['thumbnail'] = $gameinfo['thumbnail']; } if (!empty($gameinfo['thumbnail-small'])) { $game['thumbnail_small'] = $gameinfo['thumbnail-small']; } $game_directory = $game['directory']; // Move files if necessary if ($game_directory != $internal_name && $move_games) { if (!is_dir($modSettings['gamesDirectory'] . '/' . $internal_name) && !mkdir($modSettings['gamesDirectory'] . '/' . $internal_name, 0777)) { $moveFail = true; $game['error'] = array('directory_make_failed', array($modSettings['gamesDirectory'] . '/' . $internal_name)); continue; } if (!is_writable($modSettings['gamesDirectory'] . '/' . $internal_name)) { @chmod($modSettings['gamesDirectory'] . '/' . $internal_name, 0777); } $renames = array($directory . '/' . $game['file'] => $modSettings['gamesDirectory'] . '/' . $internal_name . '/' . $game['file']); if (!empty($game['thumbnail'])) { $renames[$directory . '/' . $game['thumbnail']] = $modSettings['gamesDirectory'] . '/' . $internal_name . '/' . $game['thumbnail']; } if (!empty($game['thumbnail_small'])) { $renames[$directory . '/' . $game['thumbnail_small']] = $modSettings['gamesDirectory'] . '/' . $internal_name . '/' . $game['thumbnail_small']; } foreach ($renames as $from => $to) { if (!file_exists($from) && file_exists($to)) { continue; } if (!rename($from, $to)) { $moveFail = true; $game['error'] = array('file_move_failed', array($from, $to)); continue; } } if (!$moveFail) { $game_directory = $internal_name; $directory = $modSettings['gamesDirectory'] . '/' . $game_directory; } } if (@file_exists($modSettings['gamesDirectory'] . '/' . $game_directory . '/game-info.xml')) { $gameinfo = readGameInfo($modSettings['gamesDirectory'] . '/' . $game_directory . '/game-info.xml'); $game['description'] = !empty($gameinfo['description']) ? $gameinfo['description'] : false; } if (empty($game['description']) && @file_exists($modSettings['gamesDirectory'] . '/' . $game_directory . '/' . $game['internal_name'] . '.php')) { @(require_once $modSettings['gamesDirectory'] . '/' . $game_directory . '/' . $game['internal_name'] . '.php'); $game_info = array('gtitle', 'gwords', 'gkeys'); $arcade_info = array('name', 'description', 'help'); $x = 0; foreach ($game_info as $info) { if (!empty($config[$info])) { $config[$info] = un_htmlspecialchars($config[$info]); $game[$arcade_info[$x]] = $config[$info]; } $x++; } } // Final install data $gameOptions = array('internal_name' => $game['internal_name'], 'name' => $game['name'], 'description' => !empty($game['description']) ? $game['description'] : '', 'thumbnail' => $game['thumbnail'], 'thumbnail_small' => $game['thumbnail_small'], 'help' => !empty($game['help']) ? $game['help'] : '', 'game_file' => $game['file'], 'game_directory' => $game_directory, 'class' => $game['class'], 'score_type' => $game['score_type'], 'game_settings' => $game['game_settings']); $success = false; if (!isset($game['error']) && ($id_game = createGame($gameOptions))) { $success = true; } else { $game['error'] = array('arcade_install_general_fail', array()); } $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_files SET id_game = {int:game}, status = {int:status}, game_directory = {string:directory} WHERE id_file = {int:file}', array('game' => empty($success) ? 0 : $id_game, 'status' => empty($success) ? 10 : 1, 'file' => $game['id_file'], 'directory' => $game_directory)); $status[] = array('id' => $id_game, 'name' => $game['name'], 'error' => isset($game['error']) ? $game['error'] : false); } $smcFunc['db_free_result']($request); return $status; }
function GamesAdminInstall2() { global $scripturl, $txt, $arcSettings, $context; checkSession('post'); if (!isset($_SESSION['install2']) || !isset($_POST['defaults']) || !isset($_POST['game']) || !is_array($_POST['defaults']) || !is_array($_POST['game'])) { fatal_lang_error('arcade_no_files_selected'); } $messages = array(); foreach ($_SESSION['install2'] as $game2) { $messages = array_merge($messages, createGame(array_merge($_POST['defaults'], array_merge($game2, $_POST['game'][$game2['internal_name']])))); } $context['arcade']['messages'] =& $messages; unset($_SESSION['install']); ArcadeCountGames(); if (file_exists($arcSettings['cacheDirectory'] . 'cats.cache')) { unlink($arcSettings['cacheDirectory'] . 'cats.cache'); } // Template $context['page_title'] = $txt['arcade_title_install_games']; $context['sub_template'] = 'games_install_complete'; }
<?php include 'menu.php'; $deck = 0; //TODO if (isset($_POST["creategame"])) { if ($_POST["gamename"] != "") { createGame(getUserID(), $_POST["gamename"], $_POST["creategame"], $_POST["deck"]); echo "Game created!"; } else { echo "Please specify lobby name!"; } } ?> <h2>Your Games</h2> <?php $uid = getUserID(); $yourgames = getYourGames($uid); for ($i = 0; $i < sizeof($yourgames); $i++) { $opponent = parseGameOpponent($yourgames[$i], $uid); echo 'Game versus ' . $opponent . ': <a href="game.php?id=' . $yourgames[$i] . '">' . getGameName($yourgames[$i]) . '</a><br />'; } ?> <h2>Create Game</h2> <form action="lobby.php" method="post"> <input type="text" size="50" name="gamename" placeholder="Lobby Name"> <select name="creategame">
//insert race relations $races =& Globals::getRaces(); foreach ($races as &$race) { foreach ($races as &$race2) { if ($race['Race ID'] == $race2['Race ID']) { $amount = 500; } elseif ($race['Race ID'] == 1 || $race2['Race ID'] == 1) { $amount = 0; } else { $amount = -500; } $db->query('REPLACE INTO race_has_relation (game_id, race_id_1, race_id_2, relation) VALUES (' . $db->escapeNumber($var['game_id']) . ',' . $db->escapeNumber($race['Race ID']) . ',' . $db->escapeNumber($race2['Race ID']) . ',' . $db->escapeNumber($amount) . ')'); } } createGame($newID); //do the alliances/message stuff $var['message'] = '<span class="green">Success</span> : Succesfully created game.'; } else { if ($submit == 'Create Galaxies') { for ($i = 1; $i <= $var['num_gals']; $i++) { $galaxy =& SmrGalaxy::createGalaxy($var['game_id'], $i); $galaxy->setName($_POST['gal' . $i]); $galaxy->setWidth($_POST['width' . $i]); $galaxy->setHeight($_POST['height' . $i]); $galaxy->setGalaxyType($_POST['type' . $i]); $galaxy->setMaxForceTime($_POST['forces' . $i] * 3600); } SmrGalaxy::saveGalaxies(); $galaxies =& SmrGalaxy::getGameGalaxies($var['game_id'], true); foreach ($galaxies as &$galaxy) {