Example #1
0
function ArcadeViewMatch()
{
    global $scripturl, $txt, $db_prefix, $context, $smcFunc, $user_info;
    if (empty($_REQUEST['match'])) {
        fatal_lang_error('match_not_found', false);
    }
    loadMatch((int) $_REQUEST['match']);
    // Delete Match
    if (isset($_REQUEST['delete']) && $context['can_edit_match']) {
        checkSession('get');
        deleteMatch($context['match']['id']);
        redirectexit('action=arcade;sa=arena');
    } elseif (isset($_GET['start']) && $context['can_start_match']) {
        checkSession('get');
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}arcade_matches
			SET num_players = current_players
			WHERE id_match = {int:match}', array('match' => $context['match']['id']));
        matchUpdateStatus($context['match']['id']);
        redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']);
    } elseif (isset($_REQUEST['leave']) && ($context['can_leave'] || $context['can_decline'])) {
        checkSession('get');
        // It's starter leaving, delete whole match
        if ($user_info['id'] == $context['match']['starter']) {
            deleteMatch($context['match']['id']);
            redirectexit('action=arcade;sa=arena');
        } else {
            matchRemovePlayers($context['match']['id'], array($user_info['id']));
        }
        redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']);
    } elseif (isset($_REQUEST['kick']) && !empty($context['match']['players'][$_REQUEST['player']]['can_kick'])) {
        checkSession('get');
        matchRemovePlayers($context['match']['id'], array($_REQUEST['player']));
        redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']);
    } elseif (isset($_REQUEST['join']) && $context['can_join_match']) {
        checkSession('get');
        matchAddPlayers($context['match']['id'], array($user_info['id'] => 1));
        redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']);
    } elseif (isset($_REQUEST['join']) && $context['can_accept']) {
        checkSession('get');
        matchUpdatePlayers($context['match']['id'], array($user_info['id']), 1);
        redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']);
    }
    // Layout
    loadTemplate('ArcadeArena');
    $context['template_layers'][] = 'arcade_arena_view_match';
    $context['sub_template'] = 'arcade_arena_view_match';
    $context['page_title'] = sprintf($txt['arcade_arena_view_match_title'], $context['match']['name']);
    // Add Arena to link tree
    $context['linktree'][] = array('url' => $scripturl . '?action=arcade;sa=arena', 'name' => $txt['arcade_arena']);
    $context['linktree'][] = array('url' => $scripturl . '?action=arcade;sa=viewMatch;match=' . $context['match']['id'], 'name' => $context['match']['name']);
}
Example #2
0
function ArcadeSubmit()
{
    global $scripturl, $sourcedir, $modSettings, $txt, $db_prefix, $context, $smcFunc, $user_info;
    if (!($system = SubmitSystemInfo())) {
        fatal_lang_error('arcade_submit_error', false);
    }
    require_once $sourcedir . '/' . $system['file'];
    if ($system['get_game'] !== false) {
        $context['game'] = $system['get_game']();
    }
    // Check that everyhing is ok
    if (!$context['game'] || !isset($_SESSION['arcade_play_' . $context['game']['id']]) || !isset($_SESSION['arcade_play_extra_' . $context['game']['id']])) {
        fatal_lang_error('arcade_submit_error_session', false);
    }
    if ($context['game']['score_type'] == 2 || $context['game']['submit_system'] != $system['system']) {
        log_error(sprintf($txt['arcade_submit_error_configure_log'], $context['game']['name'], $system['system']));
        fatal_lang_error('arcade_submit_error', false);
    }
    $session_info = $_SESSION['arcade_play_' . $context['game']['id']];
    $extra = $_SESSION['arcade_play_extra_' . $context['game']['id']];
    unset($_SESSION['arcade_play_' . $context['game']['id']], $_SESSION['arcade_play_extra_' . $context['game']['id']]);
    $submit_info = $system['info']($context['game'], $session_info);
    if (!$submit_info || isset($submit_info['error'])) {
        fatal_lang_error('arcade_submit_error', false);
    }
    if (isset($extra['match'])) {
        $id_match = (int) $extra['match'];
        $request = $smcFunc['db_query']('', '
			SELECT m.id_match, m.name, m.current_players, m.num_players, m.current_round, m.num_rounds, m.status
			FROM {db_prefix}arcade_matches AS m
			WHERE m.id_match = {int:match}
				AND status = 1', array('match' => $id_match));
        $matchInfo = $smcFunc['db_fetch_assoc']($request);
        $smcFunc['db_free_result']($request);
        if (!$matchInfo) {
            fatal_lang_error('arcade_game_not_found', false);
        }
        $request = $smcFunc['db_query']('', '
			SELECT id_game
			FROM {db_prefix}arcade_matches_rounds
			WHERE id_match = {int:match}
				AND round = {int:round}', array('match' => $id_match, 'round' => $matchInfo['current_round']));
        $round = $smcFunc['db_fetch_assoc']($request);
        $smcFunc['db_free_result']($request);
        if (!$round) {
            fatal_lang_error('arcade_game_not_found', false);
        }
        $request = $smcFunc['db_query']('', '
			SELECT status
			FROM {db_prefix}arcade_matches_players
			WHERE id_match = {int:match}
				AND id_member = {int:member}', array('match' => $id_match, 'round' => $matchInfo['current_round'], 'member' => $user_info['id']));
        $result = $smcFunc['db_fetch_assoc']($request);
        $smcFunc['db_free_result']($request);
        if (!$result) {
            fatal_lang_error('arcade_game_not_found', false);
        }
        if ($result['status'] == 2) {
            $smcFunc['db_insert']('insert', '{db_prefix}arcade_matches_results', array('id_match' => 'int', 'id_member' => 'int', 'round' => 'int', 'score' => 'float', 'duration' => 'float', 'end_time' => 'int', 'score_status' => 'string-30', 'validate_hash' => 'string-255'), array($id_match, $user_info['id'], $matchInfo['current_round'], $submit_info['score'], $submit_info['duration'], $submit_info['end_time'], $submit_info['cheating'], !empty($submit_info['hash']) ? $submit_info['hash'] : 'v1' . sha1($submit_info['score'])), array('id_match', 'id_member', 'round'));
            matchUpdatePlayers($id_match, array($user_info['id']), 3);
            redirectexit('action=arcade;sa=viewMatch;match=' . $id_match);
        }
    }
    if ($user_info['is_guest'] && !$context['arcade']['can_submit']) {
        $_SESSION['arcade']['highscore'] = array('id' => false, 'game' => $context['game']['id'], 'score' => $submit_info['score'], 'position' => 0, 'start' => 0, 'saved' => false, 'error' => 'arcade_no_permission');
        redirectexit('action=arcade;sa=highscore;game=' . $context['game']['id']);
    } elseif ($user_info['is_guest']) {
        $member = array('id' => $user_info['id'], 'name' => isset($_SESSION['playerName']) ? $_SESSION['playerName'] : '', 'ip' => $user_info['ip']);
    } else {
        $member = array('id' => $user_info['id'], 'name' => $user_info['name'], 'ip' => $user_info['ip']);
    }
    $score = array('score' => $submit_info['score'], 'duration' => $submit_info['duration'], 'endTime' => $submit_info['end_time'], 'status' => $submit_info['cheating'], 'hash' => !empty($submit_info['hash']) ? $submit_info['hash'] : '');
    if ($context['arcade']['can_submit'] && empty($member['name'])) {
        $_SESSION['save_score'] = array($context['game'], $member, $score);
        redirectexit('action=arcade;sa=save;game=' . $context['game']['id']);
    } elseif ($context['arcade']['can_submit']) {
        $save = SaveScore($context['game'], $member, $score);
        if ($save === false || $save['id'] === false) {
            $_SESSION['arcade']['highscore'] = array('id' => false, 'game' => $context['game']['id'], 'score' => $score['score'], 'start' => 0, 'saved' => false, 'error' => isset($save['error']) ? $save['error'] : 'arcade_saving_error');
        } else {
            $_SESSION['arcade']['highscore'] = array('id' => $save['id'], 'position' => $save['position'], 'game' => $context['game']['id'], 'newChampion' => $save['newChampion'], 'personalBest' => $save['isPersonalBest'], 'score' => $score['score'], 'start' => floor(($save['position'] - 1) / $context['scores_per_page']) * $context['scores_per_page'], 'saved' => true);
        }
    } else {
        $_SESSION['arcade']['highscore'] = array('id' => false, 'game' => $context['game']['id'], 'score' => $submit_info['score'], 'position' => 0, 'start' => 0, 'saved' => false, 'error' => 'arcade_no_permission');
    }
    if (!isset($_REQUEST['xml'])) {
        redirectexit('action=arcade;sa=highscore;game=' . $context['game']['id'] . ';start=' . $_SESSION['arcade']['highscore']['start']);
    }
}