Beispiel #1
0
function arcadeChallenge($memID)
{
    global $db_prefix, $scripturl, $txt, $modSettings, $context, $settings, $user_info, $smcFunc, $sourcedir;
    require_once $sourcedir . '/Arcade.php';
    require_once $sourcedir . '/ArcadeArena.php';
    require_once $sourcedir . '/Subs-Members.php';
    SMFArcade::loadArcade('profile');
    if (!memberAllowedTo(array('arcade_join_match', 'arcade_join_invite_match'), $memID)) {
        fatal_lang_error('arcade_no_invite', false);
    }
    $context['matches'] = array();
    $request = $smcFunc['db_query']('', '
		SELECT id_match, name
		FROM {db_prefix}arcade_matches
		WHERE id_member = {int:member}
			AND status = 0', array('member' => $user_info['id']));
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['matches'][] = array('id' => $row['id_match'], 'name' => $row['name']);
    }
    $smcFunc['db_free_result']($request);
    // Layout
    $context['sub_template'] = 'arcade_arena_challenge';
    $context['page_title'] = sprintf($txt['arcade_arena_challenge_title'], $context['member']['name']);
}
Beispiel #2
0
function ArcadeNewMatch2()
{
    global $scripturl, $txt, $db_prefix, $context, $smcFunc, $user_info, $sourcedir;
    require_once $sourcedir . '/Subs-Members.php';
    require_once $sourcedir . '/Subs-Auth.php';
    $match = array();
    $showConfirm = false;
    $errors = array();
    if (empty($_REQUEST['match_name']) || trim($_REQUEST['match_name']) == '') {
        $errors[] = 'no_name';
    } elseif ($smcFunc['strlen']($_REQUEST['match_name']) > 20) {
        $errors[] = 'name_too_long';
    }
    if (!empty($_REQUEST['match_name'])) {
        $match['name'] = $_REQUEST['match_name'];
    }
    if (empty($_REQUEST['game_mode']) || !in_array($_REQUEST['game_mode'], array('normal', 'knockout'))) {
        $errors[] = 'invalid_game_mode';
    } else {
        $match['game_mode'] = $_REQUEST['game_mode'];
    }
    $match['private'] = isset($_REQUEST['private']);
    $match['num_players'] = empty($_REQUEST['num_players']) ? 0 : $_REQUEST['num_players'];
    // Check rounds
    $match['rounds'] = array();
    $context['games'] = array();
    if (!empty($_REQUEST['rounds'])) {
        // Check that all are numbers
        foreach ($_REQUEST['rounds'] as $id => $round) {
            if ($round != '::GAME_ID::' && (!isset($_REQUEST['delete_round']) || $_REQUEST['delete_round'] != $id)) {
                $match['rounds'][] = (int) $round;
            }
        }
    }
    // Game from suggester text field?
    if (!empty($_REQUEST['arenagame_input'])) {
        $showConfirm = true;
        $_REQUEST['arenagame_input'] = strtr($_REQUEST['arenagame_input'], array('\\"' => '"'));
        preg_match_all('~"([^"]+)"~', $_REQUEST['arenagame_input'], $matches);
        $games = array_unique(array_merge($matches[1], explode(',', preg_replace('~"([^"]+)"~', '', $_REQUEST['arenagame_input']))));
        $request = $smcFunc['db_query']('', '
			SELECT game.id_game
			FROM {db_prefix}arcade_games AS game
				LEFT JOIN {db_prefix}arcade_categories AS category ON (category.id_cat = game.id_cat)
			WHERE game.game_name IN({array_string:games})
				AND {query_arena_game}', array('games' => $games));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $match['rounds'][] = (int) $row['id_game'];
        }
        unset($games, $matches);
    }
    if (!empty($match['rounds'])) {
        $request = $smcFunc['db_query']('', '
			SELECT game.id_game, game.game_name
			FROM {db_prefix}arcade_games AS game
				LEFT JOIN {db_prefix}arcade_categories AS category ON (category.id_cat = game.id_cat)
			WHERE id_game IN({array_int:games})
				AND {query_arena_game}', array('games' => array_unique($match['rounds'])));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $context['games'][$row['id_game']] = array('id' => $row['id_game'], 'name' => $row['game_name']);
        }
        $smcFunc['db_free_result']($request);
        $valid = true;
        foreach ($match['rounds'] as $i => $r) {
            if (!isset($context['games'][$r])) {
                $valid = false;
                unset($match['rounds'][$i]);
            }
        }
        if (!$valid) {
            $errors[] = 'invalid_rounds';
        }
    }
    // Check players
    $match['players'] = array();
    // Players from add players field?
    if (!empty($_REQUEST['player'])) {
        $showConfirm = true;
        $_REQUEST['player'] = strtr($_REQUEST['player'], array('\\"' => '"'));
        preg_match_all('~"([^"]+)"~', $_REQUEST['player'], $matches);
        $foundMembers = findMembers(array_unique(array_merge($matches[1], explode(',', preg_replace('~"([^"]+)"~', '', $_REQUEST['player'])))));
        foreach ($foundMembers as $member) {
            $match['players'][] = $member['id'];
        }
        unset($foundMembers, $matches);
    }
    // Previous / Players added via suggester
    if (!empty($_REQUEST['players_list'])) {
        foreach ($_REQUEST['players_list'] as $id) {
            if (!isset($_REQUEST['delete_player']) || $_REQUEST['delete_player'] != $id) {
                $match['players'][] = (int) $id;
            }
        }
    }
    // Remove duplicates
    $match['players'] = array_unique($match['players']);
    $totalp = count($match['players']);
    // Check that selected players are allowed to play
    $match['players'] = memberAllowedTo(array('arcade_join_match', 'arcade_join_invite_match'), $match['players']);
    // Check number of players
    if ($match['num_players'] < $totalp || $match['num_players'] < 2) {
        $errors[] = 'not_enough_players';
    }
    if (count($match['players']) != $totalp) {
        $errors[] = 'invalid_members';
    }
    if (count($match['rounds']) === 0) {
        $errors[] = 'no_rounds';
    }
    if (!checkSubmitOnce('check', false)) {
        $errors[] = 'submit_twice';
    }
    $showConfirm = $showConfirm || isset($_REQUEST['delete_round']) || isset($_REQUEST['delete_player']) || isset($_REQUEST['player_submit']) || isset($_REQUEST['arenagame_submit']);
    if ($showConfirm || !empty($errors)) {
        return ArcadeNewMatch($match, $showConfirm ? array() : $errors);
    }
    $matchOptions = array('name' => $smcFunc['htmlspecialchars']($match['name'], ENT_QUOTES), 'starter' => $user_info['id'], 'num_players' => $match['num_players'], 'games' => $match['rounds'], 'num_rounds' => count($match['rounds']), 'players' => $match['players'], 'extra' => array('mode' => $match['game_mode']));
    $id_match = createMatch($matchOptions);
    redirectexit('action=arcade;sa=viewMatch;match=' . $id_match);
}