} $smallimagefileslider = $_FILES['slider_image']; if ($smallimagefileslider['name'] == "") { $slider_image = $_REQUEST['prev_image2']; } else { $slider_image = $smallimagefileslider['name']; } if (!$smallimage['error']) { if (!@move_uploaded_file($smallimagefileslider['tmp_name'], "../games/game_slider/" . $smallimagefileslider['name'])) { header("location:addgame.php?err=Unknown Error Occured please try again"); exit; } else { $work = new ImgResizer("../games/game_slider/" . $smallimagefileslider['name']); } } updateGame($game_id, $game_name, $game_image, $game_file, $slider_image, $game_title, $meta_tag_keyword, $meta_tag_description); header("location:games.php"); } else { header("games.php"); } class ImgResizer { var $originalFile = ''; function ImgResizer($originalFile = '') { $this->originalFile = $originalFile; } function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false;
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; case -1: $echoAnswer = "Игра успешно обновлена!"; break; case 1: $echoAnswer = "Произошла ошибка во время передачи визуализатора!"; break; case 2: $echoAnswer = "Произошла ошибка во время работы с БД!"; break; case 3: $echoAnswer = "Не удалось подключиться к БД!";
// echo "<!-- $game: " . $game . " -->"; if ($game == NULL) { // echo "<!-- The game doesn't exist. -->"; insertGame($review["game"]); // echo "<!-- Game inserted with success. -->\n"; $game["game_id"] = $app->lastInsertId(); // echo "<!-- game_id: " . $game["game_id"] . " -->"; } $review["game_id"] = $game["game_id"]; // echo "<!-- Update like status for the game. -->\n"; if ($review["like"] == "yes") { $game["like_it"] += 1; } else { $game["not_like_it"] += 1; } updateGame($game); require 'model/reviews.php'; // echo "<!-- Insert the new review in the database. -->\n"; // echo "<!-- game_id: " . $review["game_id"] . " -->\n"; // echo "<!-- audience_id: " . $review["audience_id"] . " -->\n"; insertReview($review); // echo "<!-- Get the ID of the newly inserted review. -->\n"; $review["review_id"] = $app->lastInsertId(); require 'model/comments.php'; // echo "<!-- Insert the different comments into the database. -->\n"; if ($review["why_like"] != NULL) { $comments["why"]["genre_id"] = NULL; $comments["why"]["review_id"] = NULL; $comments["why"]["feature_id"] = NULL; $comments["why"]["game_id"] = $review["game_id"]; $comments["why"]["content"] = $review["why_like"];
} $small_instruction_image = $_FILES['game_instrustion_image']; if ($small_instruction_image['name'] == "") { $game_instrustion_image = $_REQUEST['prev_image4']; } else { $game_instrustion_image = $small_instruction_image['name']; } if (!$small_instruction_image['error']) { if (!@move_uploaded_file($small_instruction_image['tmp_name'], "../silverhat_games/game_instrustion_image/" . $small_instruction_image['name'])) { header("location:add-new-game.php?err=Unknown Error Occured please try again"); exit; } else { $work = new ImgResizer("../silverhat_games/game_instrustion_image/" . $small_instruction_image['name']); } } updateGame($game_id, $game_name, $game_price, $game_points, $game_filename, $game_seo_title, $game_description, $meta_tag_description, $meta_tag_keywords, $game_image, $game_slider_image, $game_home_image, $game_background_image, $game_instrustion_image, rtrim($game_seo, "-")); header("location:maverick-games.php?update"); class ImgResizer { var $originalFile = ''; function ImgResizer($originalFile = '') { $this->originalFile = $originalFile; } function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this->originalFile); list($width, $height) = getimagesize($this->originalFile);
function fixScores($id_game, $score_type) { global $db_prefix, $modSettings, $smcFunc; // This will use a lot of queries so don't use unless necassary ;) if ($score_type == 0) { $order = 'DESC'; } elseif ($score_type == 1) { $order = 'ASC'; } else { return false; } $users = array(); $position = 1; $request = $smcFunc['db_query']('', ' SELECT COUNT(*) AS scores, id_member FROM {db_prefix}arcade_scores WHERE id_game = {int:game} GROUP BY id_member', array('game' => $id_game)); $removeScores = array(); $scoreCount = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!empty($modSettings['arcadeMaxScores']) && $row['scores'] > $modSettings['arcadeMaxScores']) { $removeScores[$row['id_member']] = $row['scores'] - $modSettings['arcadeMaxScores']; $scoreCount[$row['id_member']] = $row['scores'] - $modSettings['arcadeMaxScores']; } else { $scoreCount[$row['id_member']] = $row['scores']; } } $smcFunc['db_free_result']($request); // Remove some scores if (!empty($removeScores)) { $request = $smcFunc['db_query']('', ' SELECT id_member, id_score FROM {db_prefix}arcade_scores WHERE id_game = {int:game} AND id_member IN({array_int:members}) ORDER BY score ' . ($score_type == 0 ? 'ASC' : 'DESC'), array('game' => $id_game, 'members' => array_keys($removeScores))); $removeIds = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($removeScores[$row['id_member']] > 0) { $removeIds[] = $row['id_score']; $removeScores[$row['id_member']]--; } } if (!empty($removeIds)) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}arcade_scores WHERE id_score IN({array_int:scores})', array('scores' => $removeIds)); } } $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET personal_best = 0 WHERE id_game = {int:game}', array('game' => $id_game)); $request = $smcFunc['db_query']('', ' SELECT id_score, score, id_member, position FROM {db_prefix}arcade_scores WHERE id_game = {int:game} ORDER BY score ' . $order, array('game' => $id_game)); if ($smcFunc['db_num_rows']($request) == 0) { updateGame($id_game, array('champion' => 0, 'champion_score' => 0)); } // Postions and personalbest while ($row = $smcFunc['db_fetch_assoc']($request)) { $set = array(); if (!in_array($row['id_member'], $users)) { $users[] = $row['id_member']; $set[] = 'personal_best = 1'; } if ($position != $row['position']) { $set[] = 'position = {int:position}'; } if (count($set) > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET ' . implode(',', $set) . ' WHERE id_score = {int:score}', array('score' => $row['id_score'], 'position' => $position)); } if ($position == 1) { updateGame($id_game, array('champion' => $row['id_member'], 'champion_score' => $row['id_score'])); } $position++; } $smcFunc['db_free_result']($request); // And champion times is still left $request = $smcFunc['db_query']('', ' SELECT id_score, score, end_time FROM {db_prefix}arcade_scores WHERE id_game = {int:game} ORDER BY score ' . $order, array('game' => $id_game)); $best = 0; $best_id = 0; while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($score_type == 0 && $best <= $row['score'] || $score_type == 1 && $best >= $row['score']) { $end = $row['end_time'] - 1; if ($best_id > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET champion_from = end_time, champion_to = {int:champion_to} WHERE id_score = {int:best}', array('champion_to' => $end, 'best' => $best_id)); } $best = $row['score']; $best_id = $row['id_score']; } } $smcFunc['db_free_result']($request); return true; }
function moveGames() { global $db_prefix, $modSettings, $smcFunc; $request = $smcFunc['db_query']('', ' SELECT id_game, internal_name, game_directory, game_file, thumbnail, thumbnail_small FROM {db_prefix}arcade_games'); if (!is_writable($modSettings['gamesDirectory'])) { fatal_lang_error('arcade_not_writable', false, array($modSettings['gamesDirectory'])); } while ($row = $smcFunc['db_fetch_assoc']($request)) { $from = $modSettings['gamesDirectory'] . '/' . (!empty($row['game_directory']) ? $row['game_directory'] . '/' : ''); $to = $modSettings['gamesDirectory'] . '/' . $row['internal_name'] . '/'; if ($from == $to) { continue; } if (file_exists($to) && !is_dir($to) || !mkdir($to)) { fatal_lang_error('arcade_not_writable', false, array($to)); } chdir($from); // These should be at least there $files = array(); $files[] = $row['game_file']; $files[] = $row['thumbnail']; $files[] = $row['thumbnail_small']; foreach ($files as $file) { if (@file_exists($from . $file)) { if (!@rename($from . $row['gameFile'], $to . $file)) { fatal_lang_error('arcade_unable_to_move', false, array($file, $from, $to)); } } } updateGame($row['id_game'], array('game_directory' => $row['internal_name'])); } $smcFunc['db_free_result']($request); }
function ArcadeFavorite() { global $scripturl, $txt, $db_prefix, $modSettings, $context, $user_info, $smcFunc; $xml = isset($_REQUEST['xml']); is_not_guest(); if (empty($modSettings['arcadeEnableFavorites']) || !($game = getGameInfo((int) $_REQUEST['game']))) { fatal_lang_error('arcade_game_not_found', false); } // It's favorite so we can remove it if ($game['is_favorite']) { $remove = true; $smcFunc['db_query']('', ' DELETE FROM {db_prefix}arcade_favorite WHERE id_member = {int:member} AND id_game = {int:game}', array('game' => $game['id'], 'member' => $user_info['id'])); // Update favorites count $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}arcade_favorite WHERE id_game = {int:game} GROUP BY id_game', array('game' => $game['id'])); list($num_favorites) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); updateGame($game['id'], array('num_favorites' => $num_favorites)); if ($xml) { ArcadeXMLOutput(array('message' => &$txt['arcade_favorite_removed'], 'state' => 0)); } } else { $remove = false; $smcFunc['db_insert']('insert', '{db_prefix}arcade_favorite', array('id_member' => 'int', 'id_game' => 'int'), array($user_info['id'], $game['id']), array()); // Update favorites count updateGame($game['id'], array('num_favorites' => '+')); if ($xml) { ArcadeXMLOutput(array('message' => $txt['arcade_favorite_added'], 'state' => 1)); } } redirectexit('?action=arcade;sa=highscore;game=' . $game['id']); }
function update_champ_cups($id_game) { global $arcSettings, $smcFunc; $cups_update = array('id_score_first' => 0, 'id_member_first' => 0, 'id_member_second' => 0, 'id_score_second' => 0, 'id_member_third' => 0, 'id_score_third' => 0); $loop = 0; $result = $smcFunc['db_query']('', ' SELECT id_score, id_member FROM {db_prefix}arcade_scores WHERE id_game = {int:id_game} ORDER BY position LIMIT 0,3', array('id_game' => $id_game)); while ($cups = $smcFunc['db_fetch_assoc']($result)) { if ($loop == 0) { $cups_update['id_member_first'] = $cups['id_member']; $cups_update['id_score_first'] = $cups['id_score']; } if ($loop == 1) { $cups_update['id_member_second'] = $cups['id_member']; $cups_update['id_score_second'] = $cups['id_score']; } if ($loop == 2) { $cups_update['id_member_third'] = $cups['id_member']; $cups_update['id_score_third'] = $cups['id_score']; } $loop++; } $smcFunc['db_free_result']($result); updateGame($id_game, $cups_update); }
if (isset($_POST['delete_all_games'])) { $q = "SELECT " . TBL_GAMES . ".*" . " FROM " . TBL_GAMES; $result = $sql->db_Query($q); $num_rows = mysql_numrows($result); for ($i = 0; $i < $num_rows; $i++) { $game_id = mysql_result($result, $i, TBL_GAMES . ".GameID"); deleteGame($game_id); } header("Location: admin_config.php?eb_games"); exit; } if (isset($_POST['update_selected_games'])) { if (count($_POST['game_sel']) > 0) { $del_ids = $_POST['game_sel']; foreach ($del_ids as $game_id) { updateGame($game_id); } } header("Location: admin_config.php?eb_games"); exit; } if (isset($_POST['update_all_games'])) { updateAllGames(); //header("Location: {$_SERVER['HTTP_REFERER']}"); echo '<META HTTP-EQUIV="Refresh" Content="0; URL=admin_config.php?eb_games">'; } if (isset($_POST['add_games'])) { insertGames(); header("Location: admin_config.php?eb_games"); exit; }
function deleteScores(&$game, $id_score) { global $scripturl, $txt, $db_prefix, $modSettings, $context, $smcFunc, $user_info; if (!is_array($id_score) && is_numeric($id_score)) { $id_score = array((int) $id_score); } if (empty($id_score)) { return true; } $request = $smcFunc['db_query']('', ' SELECT id_score, id_member, position, score, personal_best FROM {db_prefix}arcade_scores WHERE id_score IN({array_int:score}) AND id_game = {int:game} ORDER BY position', array('game' => $game['id'], 'score' => $id_score)); $removeIds = array(); $personalBest = array(); $positions = array(); $championUpdate = false; while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($row['personal_best']) { $personalBest[] = $row['id_member']; } $removeIds[] = $row['id_score']; $positions[] = $row['position']; if ($row['position'] == 1) { $championUpdate = true; } } $smcFunc['db_free_result']($request); $personalBest = array_unique($personalBest); $count = -1; if (empty($positions)) { return true; } $startPos = $positions[0]; $smcFunc['db_query']('', ' DELETE FROM {db_prefix}arcade_scores WHERE id_score IN({array_int:scores})', array('scores' => $removeIds)); // Log removed scores logAction('arcade_remove_scores', array('game' => $game['id'], 'scores' => count($removeIds))); for ($i = 0; $i < count($positions); $i++) { if (isset($positions[$i + 1]) && $positions[$i] + 1 == $positions[$i + 1]) { $count--; } else { updatePositions($game, $startPos, $count); $startPos = $positions[$i]; $count = -1; } } if ($championUpdate) { $request = $smcFunc['db_query']('', ' SELECT id_score, id_member FROM {db_prefix}arcade_scores WHERE position = 1 AND id_game = {int:game} LIMIT 1', array('game' => $game['id'])); $row = $smcFunc['db_fetch_assoc']($request); if ($row !== false) { updateGame($game['id'], array('champion' => $row['id_member'], 'champion_score' => $row['id_score'])); } else { updateGame($game['id'], array('champion' => 0, 'champion_score' => 0)); } $smcFunc['db_free_result']($request); if (!empty($row['id_score'])) { $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET champion_from = {int:time} WHERE id_score = {int:score}', array('time' => time(), 'score' => $row['id_score'])); } } if (empty($personalBest)) { return true; } $request = $smcFunc['db_query']('', ' SELECT id_score, id_member FROM {db_prefix}arcade_scores WHERE id_game = {int:game} AND id_member IN({array_int:members}) ORDER BY position', array('game' => $game['id'], 'members' => $personalBest)); $newPersonalBest = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($newPersonalBest[$row['id_member']])) { $newPersonalBest[$row['id_member']] = $row['id_score']; } } $smcFunc['db_free_result']($request); if (empty($newPersonalBest)) { return true; } $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET personal_best = 1 WHERE id_score IN({array_int:scores})', array('scores' => $newPersonalBest)); return true; }
function generateBoard($diff) { if (isset($this->modes[$diff])) { $this->board_size = $this->modes[$diff]['board']; $this->scoring = $this->modes[$diff]['scoring']; } else { return; } $this->difficulty = $diff; // Generate board array without any mines if ($this->board_size['x'] * $this->board_size['y'] < $this->board_size['mines']) { $this->board_size['mines'] = $this->board_size['x'] * $this->board_size['y']; } $i = 1; for ($y = 0; $y <= $this->board_size['y']; $y++) { $this->board[$y] = array(); for ($x = 0; $x <= $this->board_size['x']; $x++) { $this->board[$y][$x] = array('id' => $i++, 'is_mine' => false, 'mines' => 0, 'open' => false, 'flag' => false); } } updateGame($this->game['id'], array('num_plays' => '+')); }
function EditGame2() { global $scripturl, $txt, $db_prefix, $modSettings, $context, $sourcedir, $smcFunc, $boarddir; $context['game_permissions'] = $modSettings['arcadePermissionMode'] > 2; $context['edit_page'] = !isset($_REQUEST['advanced']) ? 'basic' : 'advanced'; if (!isset($context['game'])) { $id = loadGame((int) $_REQUEST['game'], true); if ($id === false) { fatal_lang_error('arcade_game_not_found', false); } $game =& $context['arcade']['game_data'][$id]; $context['game'] = array('id' => $game['id_game'], 'internal_name' => $game['internal_name'], 'category' => $game['id_cat'], 'name' => htmlspecialchars($game['game_name']), 'thumbnail' => htmlspecialchars($game['thumbnail']), 'thumbnail_small' => htmlspecialchars($game['thumbnail_small']), 'description' => htmlspecialchars($game['description']), 'help' => htmlspecialchars($game['help']), 'game_file' => $game['game_file'], 'game_directory' => $game['game_directory'], 'submit_system' => $game['submit_system'], 'score_type' => $game['score_type'], 'member_groups' => explode(',', $game['member_groups']), 'extra_data' => unserialize($game['extra_data']), 'enabled' => !empty($game['enabled'])); if (!is_array($context['game']['extra_data']) || isset($_REQUEST['detect'])) { require_once $sourcedir . '/SWFReader.php'; $swf = new SWFReader(); if (substr($game['game_file'], -3) == 'swf') { $swf->open($modSettings['gamesDirectory'] . '/' . $game['game_directory'] . '/' . $game['game_file']); $context['game']['extra_data'] = array('width' => $swf->header['width'], 'height' => $swf->header['height'], 'flash_version' => $swf->header['version'], 'background_color' => $swf->header['background']); $swf->close(); } else { $context['game']['extra_data'] = array('width' => '', 'height' => '', 'flash_version' => '', 'background_color' => array('', '', '')); } } } $context['game_permissions'] = $modSettings['arcadePermissionMode'] > 2; // Load categories if (!isset($context['arcade_category'])) { $request = $smcFunc['db_query']('', ' SELECT id_cat, cat_name FROM {db_prefix}arcade_categories'); $context['arcade_category'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['arcade_category'][] = array('id' => $row['id_cat'], 'name' => $row['cat_name']); } $smcFunc['db_free_result']($request); } // Load Sumbit Systems if (!isset($context['submit_systems'])) { $context['submit_systems'] = SubmitSystemInfo('*'); } $gameOptions = array(); $errors = array(); if (checkSession('post', '', false) !== '') { $errors['session'] = 'session_timeout'; } // Basic if (empty($_REQUEST['edit_page']) || $_REQUEST['edit_page'] == 'basic') { if (isset($_POST['game_name']) && trim($_POST['game_name']) == '') { $errors['game_name'] = 'invalid'; } $gameOptions['name'] = $_POST['game_name']; $gameOptions['description'] = $_POST['description']; $gameOptions['thumbnail'] = $_POST['thumbnail']; $gameOptions['thumbanil_small'] = $_POST['thumbnail_small']; $gameOptions['help'] = $_POST['help']; $gameOptions['enabled'] = !empty($_POST['game_enabled']); if ($context['game_permissions']) { $gameOptions['member_groups'] = array(); if (!empty($_POST['groups'])) { foreach ($_POST['groups'] as $id) { $gameOptions['member_groups'][] = (int) $id; } } } $gameOptions['category'] = (int) $_POST['category']; } else { if (trim($_POST['internal_name']) == '') { $errors['internal_name'] = 'invalid'; } if (trim($_POST['game_file']) == '') { $errors['game_file'] = 'invalid'; } if (!isset($context['submit_systems'][$_POST['submit_system']])) { $errors['submit_system'] = 'invalid'; } $extra_data = $context['game']['extra_data']; if (isset($_POST['extra_data'])) { foreach ($_POST['extra_data'] as $item => $value) { $extra_data[$item] = $value; } } $gameOptions['internal_name'] = $_POST['internal_name']; $gameOptions['submit_system'] = $_POST['submit_system']; $gameOptions['game_directory'] = $_POST['game_directory']; $gameOptions['game_file'] = $_POST['game_file']; $gameOptions['score_type'] = (int) $_POST['score_type']; $gameOptions['extra_data'] = $extra_data; } if (!empty($errors)) { $context['errors'] = $errors; return EditGame(); } updateGame($context['game']['id'], $gameOptions, true); redirectexit('action=admin;area=managegames'); }