Пример #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']);
}
Пример #2
0
function matchRemovePlayers($id_match, $players)
{
    global $smcFunc;
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}arcade_matches_players
		WHERE id_match = {int:match}
			AND id_member IN({array_int:players})', array('match' => $id_match, 'players' => $players));
    $request = $smcFunc['db_query']('', '
		SELECT COUNT(*)
		FROM {db_prefix}arcade_matches_players
		WHERE id_match = {int:match}', array('match' => $id_match));
    list($cn) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}arcade_matches
		SET current_players = {int:players}
		WHERE id_match = {int:match}', array('match' => $id_match, 'players' => $cn));
    matchUpdateStatus($id_match);
    return true;
}