Example #1
0
function ArcadeFavorite()
{
    global $smcFunc, $txt, $db, $arcSettings, $context, $user_info;
    $xml = isset($_REQUEST['xml']) ? true : false;
    if ($user_info['is_guest']) {
        fatal_lang_error('arcade_not_for_guest');
    }
    $game = ArcadeGameInfo((int) $_REQUEST['game']);
    if ($game === false) {
        fatal_lang_error('arcade_game_not_found');
    }
    // Game was not found
    // It's favorite so we can remove it
    if ($game['isFavorite']) {
        $remove = true;
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}arcade_favorite
			WHERE id_member = {int:mem}
			AND id_game = {int:game}', array('mem' => $user_info['id'], 'game' => $game['id']));
    } else {
        $remove = false;
        $smcFunc['db_insert']('', '{db_prefix}arcade_favorite', array('id_member' => 'int', 'id_game' => 'int'), array($user_info['id'], $game['id']), array('id_favorite'));
    }
    if (!$xml) {
        if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
            redirectexit('?action=arcade');
        } else {
            redirectexit($_SERVER['HTTP_REFERER']);
        }
    } else {
        $state = $remove ? 0 : 1;
        $context['sub_template'] = 'xml';
        $context['arcade']['message'] = $remove ? 'arcade_favorite_removed' : 'arcade_favorite_added';
        $context['arcade']['extra'] = '<state>' . $state . '</state>';
    }
}
Example #2
0
function ArcadeSubmit()
{
    global $smcFunc, $scripturl, $txt, $arcSettings, $context;
    // if you cant save...we do nothing theres no point!!!
    if (allowedTo('arcade_submit')) {
        //what type of game is it?
        //normal ipb game
        if (isset($_REQUEST['gametype']) && $_REQUEST['gametype'] == 2) {
            $theGame = $_POST['gname'];
            $theScore = isset($_POST['gscore']) && is_numeric($_POST['gscore']) ? (double) $_POST['gscore'] : '';
        } elseif (isset($_REQUEST['gametype']) && $_REQUEST['gametype'] == 3) {
            $theGame = isset($_POST['gname']) ? $_POST['gname'] : $_SESSION['arcade']['ibp']['gamename'];
            $theScore = isset($_POST['gscore']) && is_numeric($_POST['gscore']) ? (double) $_POST['gscore'] : '';
            $time_taken = microtime_float() - $_SESSION['arcade']['ibp']['verify'][2];
            if ($time_taken < 0 || $time_taken > 7) {
                unset($_SESSION['arcade']['play']);
                fatal_lang_error('arcade_submit_ibp_error_time');
            }
            if ($_POST['enscore'] != ($theScore * $_SESSION['arcade']['ibp']['verify'][0] ^ $_SESSION['arcade']['ibp']['verify'][1])) {
                unset($_SESSION['arcade']['play']);
                fatal_lang_error('arcade_submit_ibp_error_check');
            }
        } elseif (isset($_REQUEST['gametype']) && $_REQUEST['gametype'] == 4) {
            $result = $smcFunc['db_query']('', '
				SELECT game , score
				FROM {db_prefix}arcade_v3temp
				WHERE id = {int:game}', array('game' => $_POST['id']));
            $tempGame = $smcFunc['db_fetch_assoc']($result);
            $smcFunc['db_free_result']($result);
            if (!isset($tempGame)) {
                fatal_lang_error('arcade_submit_v3_error');
            }
            $theGame = $tempGame['game'];
            $theScore = $tempGame['score'];
        } else {
            $theGame = isset($_POST['game']) ? $_POST['game'] : '';
            $theScore = isset($_POST['score']) && is_numeric($_POST['score']) ? (double) $_POST['score'] : '';
        }
        //we should have a game and a score so lets do some checks...
        //if no game or no score or no session were gone...
        if (!isset($theGame) || !isset($theScore) || !isset($_SESSION['arcade']['play'][$theGame])) {
            unset($_SESSION['arcade']['play']);
            fatal_lang_error('arcade_submit_error_empty');
        } else {
            //do the cheat check now..
            // Preset these
            $checkPassed = false;
            $allowFail = false;
            if (!CheatingCheck($allowFail, $checkPassed)) {
                ClearSession($game);
                fatal_lang_error('arcade_submit_error_check_failed');
            }
            //does the posted game match the session game name?
            if ($theGame != $_SESSION['arcade']['play'][$theGame]['game']) {
                // No..were gone..
                unset($_SESSION['arcade']['play']);
                fatal_lang_error('arcade_game_no_match');
            }
            //we have the game name so lets check it exists and get its info..
            $game = ArcadeGameInfo(0, $theGame);
            if ($game === false) {
                // No..were gone..
                unset($_SESSION['arcade']['play']);
                fatal_lang_error('arcade_game_not_found');
            }
            //so far so good..a game that matches, a score, a valid session and a header
            $session_info =& $_SESSION['arcade']['play'][$theGame];
            //..so lets check if the session game matches the temp game in the db...
            $result = $smcFunc['db_query']('', '
				SELECT game , score , starttime
				FROM {db_prefix}arcade_v3temp
				WHERE id = {int:game}', array('game' => $session_info['db_id']));
            $tempGame = $smcFunc['db_fetch_assoc']($result);
            $smcFunc['db_free_result']($result);
            if (!isset($tempGame)) {
                fatal_lang_error('arcade_submit_v3_error');
            }
            //..yip so lets check the session info matches the temp game info in the db...
            if ((string) $session_info['starttime'] != $tempGame['starttime'] || $session_info['game'] != $tempGame['game']) {
                fatal_lang_error('arcade_submit_error1');
            }
            //if we got this far we have a valid game, a score, and a session so we can go ahead and save...
            $start_time = round($tempGame['starttime']);
            $end_time = time();
            if (isset($_SESSION['arcade']['play']['tour'])) {
                $save = ArcadeSaveScore($game, $theScore, $start_time, $end_time, $checkPassed, $_SESSION['arcade']['play']['tour'], $_SESSION['arcade']['play']['round']);
                $tour = $_SESSION['arcade']['play']['tour'];
                ClearSession();
                redirectexit('action=arcade;sa=tour;ta=join;id=' . $tour);
            } else {
                $save = ArcadeSaveScore($game, $theScore, $start_time, $end_time, $checkPassed);
                ClearSession();
                // Saving failed
                if ($save === false || $save['id_score'] === false) {
                    $_SESSION['arcade']['highscore'] = array('id' => false, 'game' => $game['internal_name'], 'score' => $theScore, 'gameid' => $game['id'], 'position' => 0, 'start' => 0, 'saved' => false, 'error' => isset($save['error']) ? $save['error'] : 'arcade_no_permission');
                } else {
                    $_SESSION['arcade']['highscore'] = array('id' => $save['id_score'], 'game' => $game['internal_name'], 'score' => $theScore, 'gameid' => $game['id'], 'position' => $save['position'], 'start' => $save['start'], 'champion' => $save['new_champion'], 'best' => $save['ownbest'], 'saved' => true);
                }
                // Go to scores list
                redirectexit('action=arcade;sa=highscore;game=' . $game['id']);
            }
        }
    } else {
        //cant save
        fatal_lang_error('arcade_no_permission');
    }
}
Example #3
0
function GamesAdminEditor2()
{
    global $scripturl, $txt, $context;
    if (!isset($_POST['data']['enabled'])) {
        $_POST['data']['enabled'] = 0;
    }
    if (!isset($_REQUEST['game'])) {
        fatal_error('arcade_no_game');
    }
    $game = ArcadeGameInfo((int) $_REQUEST['game'], null, true);
    if ($game === false) {
        fatal_error('arcade_no_game');
    }
    $errors = UpdateGame((int) $_REQUEST['game'], $_POST['data']);
    // There were no errors no need to display this again
    if (count($errors) === 0) {
        if (!isset($_SESSION['arcade_page'])) {
            redirectexit('action=admin;area=managearcade;sa=listgames');
        } else {
            redirectexit('action=admin;area=managearcade;sa=listgames;start=' . $_SESSION['arcade_page']);
        }
    }
    $context['arcade']['config_errors'] =& $errors;
    prepareEditor($game);
    // Title for page
    $context['page_title'] = $txt['arcade_title_manage_games'] . ' - ' . $game['name'];
    // Template layers for editor
    //$context['template_layers'][] = 'editor';
    $context['sub_template'] = 'arcadeadmin_editor';
    // Game data
    $context['arcade']['game'] =& $game;
}