コード例 #1
0
ファイル: Profile-Arcade.php プロジェクト: nikop/SMF-Arcade
function arcadeSettings($memID)
{
    global $scripturl, $txt, $db_prefix, $context, $smcFunc, $user_info, $sourcedir, $modSettings;
    require_once $sourcedir . '/Arcade.php';
    SMFArcade::loadArcade('profile');
    $events = arcadeEvent('get');
    $arcadeSettings = loadArcadeSettings($memID);
    $context['profile_fields'] = array('notifications' => array('type' => 'callback', 'callback_func' => 'arcade_notification'), 'gamesPerPage' => array('label' => $txt['arcade_user_gamesPerPage'], 'type' => 'select', 'options' => array(0 => sprintf($txt['arcade_user_gamesPerPage_default'], $modSettings['gamesPerPage']), 5 => 5, 10 => 10, 20 => 20, 25 => 25, 50 => 50), 'cast' => 'int', 'validate' => 'int', 'value' => isset($arcadeSettings['gamesPerPage']) ? $arcadeSettings['gamesPerPage'] : 0), 'scoresPerPage' => array('label' => $txt['arcade_user_scoresPerPage'], 'type' => 'select', 'options' => array(0 => sprintf($txt['arcade_user_scoresPerPage_default'], $modSettings['scoresPerPage']), 5 => 5, 10 => 10, 20 => 20, 25 => 25, 50 => 50), 'cast' => 'int', 'validate' => 'int', 'value' => isset($arcadeSettings['scoresPerPage']) ? $arcadeSettings['scoresPerPage'] : 0));
    if (!empty($modSettings['disableCustomPerPage'])) {
        unset($context['profile_fields']['gamesPerPage']);
        unset($context['profile_fields']['scoresPerPage']);
    }
    if (isset($_REQUEST['save'])) {
        checkSession('post');
        $updates = array();
        $errors = false;
        foreach ($events as $event) {
            foreach ($event['notification'] as $notify => $default) {
                if (empty($_POST[$notify])) {
                    $updates[] = array($memID, $notify, 0);
                } else {
                    $updates[] = array($memID, $notify, 1);
                }
            }
        }
        foreach ($context['profile_fields'] as $id => $field) {
            if ($id == 'notifications' || !isset($_POST[$id])) {
                continue;
            }
            if ($field['cast'] == 'int') {
                $_POST[$id] = (int) $_POST[$id];
            }
            if ($field['type'] == 'select') {
                if (isset($field['options'][$_POST[$id]])) {
                    $updates[] = array($memID, $id, $_POST[$id]);
                }
            }
        }
        if (!$errors) {
            $smcFunc['db_insert']('replace', '{db_prefix}arcade_settings', array('id_member' => 'int', 'variable' => 'string-255', 'value' => 'string'), $updates, array('id_member', 'variable'));
            redirectexit('action=profile;u=' . $memID . ';sa=arcadeSettings');
        }
    }
    $context['notifications'] = array();
    foreach ($events as $event) {
        foreach ($event['notification'] as $notify => $default) {
            $context['notifications'][$notify] = array('id' => $notify, 'text' => $txt['arcade_notification_' . $notify], 'value' => isset($arcadeSettings[$notify]) ? (bool) $arcadeSettings[$notify] : $default, 'default' => !isset($arcadeSettings[$notify]));
        }
    }
    // Template
    $context['profile_custom_submit_url'] = $scripturl . '?action=profile;area=arcadeSettings;u=' . $memID . ';save';
    $context['page_desc'] = $txt['arcade_usersettings_desc'];
    $context['sub_template'] = 'edit_options';
}
コード例 #2
0
ファイル: Subs-Arcade.php プロジェクト: nikop/SMF-Arcade
function matchUpdateStatus($id_match)
{
    global $smcFunc, $scripturl;
    $request = $smcFunc['db_query']('', '
		SELECT m.id_match, m.name, m.current_players, m.num_players, m.current_round, m.num_rounds, m.status, m.match_data
		FROM {db_prefix}arcade_matches AS m
		WHERE m.id_match = {int:match}', array('match' => $id_match));
    $matchInfo = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
    if (!empty($matchInfo['match_data'])) {
        $matchInfo['match_data'] = unserialize($matchInfo['match_data']);
    } else {
        $matchInfo['match_data'] = array();
    }
    if ($matchInfo['status'] == 0) {
        $request = $smcFunc['db_query']('', '
			SELECT COUNT(*)
			FROM {db_prefix}arcade_matches_players
			WHERE id_match = {int:match}
				AND status = 0', array('match' => $id_match));
        list($cn) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        if ($cn > 0) {
            return;
        }
        if ($matchInfo['current_players'] == $matchInfo['num_players']) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_matches
				SET status = 1, current_round = 1
				WHERE id_match = {int:match}', array('match' => $id_match));
            // No one has played yet
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_matches_players
				SET status = 1
				WHERE id_match = {int:match}', array('match' => $id_match));
        }
    } elseif ($matchInfo['status'] == 1) {
        if ($matchInfo['current_round'] == 0) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_matches
				SET current_round = 1
				WHERE id_match = {int:match}', array('match' => $id_match));
            // No one has played yet
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_matches_players
				SET status = 1
				WHERE id_match = {int:match}', array('match' => $id_match));
        } else {
            $request = $smcFunc['db_query']('', '
				SELECT COUNT(*)
				FROM {db_prefix}arcade_matches_players
				WHERE id_match = {int:match}
					AND (status = 1 OR status = 2)', array('match' => $id_match));
            list($cn) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            // Has all played?
            if ($cn > 0) {
                return;
            }
            $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);
            $request = $smcFunc['db_query']('', '
				SELECT id_game, score_type, extra_data
				FROM {db_prefix}arcade_games
				WHERE id_game = {int:game}', array('game' => $round['id_game']));
            $game = $smcFunc['db_fetch_assoc']($request);
            $smcFunc['db_free_result']($request);
            if ($game['score_type'] == 0) {
                $order = 'DESC';
            } elseif ($game['score_type'] == 1) {
                $order = 'ASC';
            }
            // Scores to give
            $scores = array(10, 8, 6, 5, 4, 3, 2, 1);
            $request = $smcFunc['db_query']('', '
				SELECT id_member
				FROM {db_prefix}arcade_matches_results
				WHERE id_match = {int:match}
					AND round = {int:round}
				ORDER BY score ' . $order . '', array('match' => $id_match, 'round' => $matchInfo['current_round']));
            $current = 0;
            $players = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                if (isset($scores[$current])) {
                    $smcFunc['db_query']('', '
						UPDATE {db_prefix}arcade_matches_players
						SET score = score + {int:score}
						WHERE id_match = {int:match}
							AND id_member = {int:player}', array('match' => $id_match, 'player' => $row['id_member'], 'score' => $scores[$current]));
                }
                $players[] = $row['id_member'];
                $current++;
            }
            $smcFunc['db_free_result']($request);
            if ($matchInfo['match_data']['mode'] == 'knockout') {
                $request = $smcFunc['db_query']('', '
					SELECT id_member
					FROM {db_prefix}arcade_matches_players
					WHERE id_match = {int:match}
					ORDER BY score
					LIMIT 1', array('match' => $id_match));
                list($knockout) = $smcFunc['db_fetch_row']($request);
                $smcFunc['db_free_result']($request);
                $request = $smcFunc['db_query']('', '
					UPDATE {db_prefix}arcade_matches_players
					SET status = 4
					WHERE id_match = {int:match}
						AND id_member = {int:member}', array('match' => $id_match, 'member' => $knockout));
            }
            // Last round?
            if ($matchInfo['current_round'] == $matchInfo['num_rounds']) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}arcade_matches
					SET status = 2
					WHERE id_match = {int:match}', array('match' => $id_match));
                arcadeEvent('arena_match_end', array('match_name' => $matchInfo['name'], 'match_id' => $id_match, 'match_url' => $scripturl . '?action=arcade;match=' . $id_match, 'players' => $players));
                return;
            } else {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}arcade_matches
					SET current_round = current_round + 1
					WHERE id_match = {int:match}', array('match' => $id_match));
                // No one has played yet
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}arcade_matches_players
					SET status = 1
					WHERE id_match = {int:match}
						AND status = 3', array('match' => $id_match));
                arcadeEvent('arena_new_round', array('match_name' => $matchInfo['name'], 'match_id' => $id_match, 'match_url' => $scripturl . '?action=arcade;match=' . $id_match, 'players' => $players));
            }
        }
    }
    return;
}