Пример #1
0
def run_cpu_benchmark() -> None:
    """Run a cpu benchmark."""
    # pylint: disable=cyclic-import
    from bastd import tutorial
    from ba._session import Session

    class BenchmarkSession(Session):
        """Session type for cpu benchmark."""
        def __init__(self) -> None:

            # print('FIXME: BENCHMARK SESSION WOULD CALC DEPS.')
            depsets: Sequence[ba.DependencySet] = []

            super().__init__(depsets)

            # Store old graphics settings.
            self._old_quality = _ba.app.config.resolve('Graphics Quality')
            cfg = _ba.app.config
            cfg['Graphics Quality'] = 'Low'
            cfg.apply()
            self.benchmark_type = 'cpu'
            self.setactivity(_ba.newactivity(tutorial.TutorialActivity))

        def __del__(self) -> None:

            # When we're torn down, restore old graphics settings.
            cfg = _ba.app.config
            cfg['Graphics Quality'] = self._old_quality
            cfg.apply()

        def on_player_request(self, player: ba.SessionPlayer) -> bool:
            return False

    _ba.new_host_session(BenchmarkSession, benchmark_type='cpu')
Пример #2
0
    def _launch_server_session(self) -> None:
        """Kick off a host-session based on the current server config."""
        app = _ba.app
        appcfg = app.config
        sessiontype = self._get_session_type()

        if _ba.get_account_state() != 'signed_in':
            print('WARNING: launch_server_session() expects to run '
                  'with a signed in server account')

        if self._first_run:
            curtimestr = time.strftime('%c')
            _ba.log(
                f'{Clr.BLD}{Clr.BLU}{_ba.appnameupper()} {app.version}'
                f' ({app.build_number})'
                f' entering server-mode {curtimestr}{Clr.RST}',
                to_server=False)

        if sessiontype is FreeForAllSession:
            appcfg['Free-for-All Playlist Selection'] = self._playlist_name
            appcfg['Free-for-All Playlist Randomize'] = (
                self._config.playlist_shuffle)
        elif sessiontype is DualTeamSession:
            appcfg['Team Tournament Playlist Selection'] = self._playlist_name
            appcfg['Team Tournament Playlist Randomize'] = (
                self._config.playlist_shuffle)
        else:
            raise RuntimeError(f'Unknown session type {sessiontype}')

        app.teams_series_length = self._config.teams_series_length
        app.ffa_series_length = self._config.ffa_series_length

        _ba.set_authenticate_clients(self._config.authenticate_clients)

        _ba.set_enable_default_kick_voting(
            self._config.enable_default_kick_voting)
        _ba.set_admins(self._config.admins)

        # Call set-enabled last (will push state to the cloud).
        _ba.set_public_party_max_size(self._config.max_party_size)
        _ba.set_public_party_name(self._config.party_name)
        _ba.set_public_party_stats_url(self._config.stats_url)
        _ba.set_public_party_enabled(self._config.party_is_public)

        # And here.. we.. go.
        if self._config.stress_test_players is not None:
            # Special case: run a stress test.
            from ba.internal import run_stress_test
            run_stress_test(playlist_type='Random',
                            playlist_name='__default__',
                            player_count=self._config.stress_test_players,
                            round_duration=30)
        else:
            _ba.new_host_session(sessiontype)

        # Run an access check if we're trying to make a public party.
        if not self._ran_access_check and self._config.party_is_public:
            self._run_access_check()
            self._ran_access_check = True
Пример #3
0
 def _fade_end() -> None:
     from ba import _coopsession
     try:
         _ba.new_host_session(_coopsession.CoopSession)
     except Exception:
         from ba import _error
         _error.print_exception()
         from bastd.mainmenu import MainMenuSession
         _ba.new_host_session(MainMenuSession)
Пример #4
0
    def _run_selected_playlist(self) -> None:
        _ba.unlock_all_input()
        try:
            _ba.new_host_session(self._sessiontype)
        except Exception:
            from bastd import mainmenu
            ba.print_exception('exception running session', self._sessiontype)

            # Drop back into a main menu session.
            _ba.new_host_session(mainmenu.MainMenuSession)
Пример #5
0
    def _run_selected_playlist(self) -> None:
        # pylint: disable=cyclic-import
        _ba.unlock_all_input()
        try:
            _ba.new_host_session(self._sessiontype)
        except Exception:
            from bastd import mainmenu
            ba.print_exception(f'Error running session {self._sessiontype}.')

            # Drop back into a main menu session.
            _ba.new_host_session(mainmenu.MainMenuSession)
Пример #6
0
 def do_it() -> None:
     try:
         # reset to normal speed
         _ba.set_replay_speed_exponent(0)
         _ba.fade_screen(True)
         assert self._my_replay_selected is not None
         _ba.new_replay_session(_ba.get_replays_dir() + '/' +
                                self._my_replay_selected)
     except Exception:
         ba.print_exception('exception running replay session')
         # drop back into a fresh main menu session
         # in case we half-launched or something..
         from bastd import mainmenu
         _ba.new_host_session(mainmenu.MainMenuSession)
Пример #7
0
    def _launch_server_session(self) -> None:
        """Kick off a host-session based on the current server config."""
        app = _ba.app
        appcfg = app.config
        sessiontype = self._get_session_type()

        if _ba.get_account_state() != 'signed_in':
            print('WARNING: launch_server_session() expects to run '
                  'with a signed in server account')

        if self._first_run:
            curtimestr = time.strftime('%c')
            print(f'{Clr.BLD}{Clr.BLU}BallisticaCore {app.version}'
                  f' ({app.build_number})'
                  f' entering server-mode {curtimestr}{Clr.RST}')

        if sessiontype is FreeForAllSession:
            appcfg['Free-for-All Playlist Selection'] = self._playlist_name
            appcfg['Free-for-All Playlist Randomize'] = (
                self._config.playlist_shuffle)
        elif sessiontype is DualTeamSession:
            appcfg['Team Tournament Playlist Selection'] = self._playlist_name
            appcfg['Team Tournament Playlist Randomize'] = (
                self._config.playlist_shuffle)
        else:
            raise RuntimeError(f'Unknown session type {sessiontype}')

        app.teams_series_length = self._config.teams_series_length
        app.ffa_series_length = self._config.ffa_series_length

        _ba.set_authenticate_clients(self._config.authenticate_clients)

        _ba.set_enable_default_kick_voting(
            self._config.enable_default_kick_voting)
        _ba.set_admins(self._config.admins)

        # Call set-enabled last (will push state to the cloud).
        _ba.set_public_party_max_size(self._config.max_party_size)
        _ba.set_public_party_name(self._config.party_name)
        _ba.set_public_party_stats_url(self._config.stats_url)
        _ba.set_public_party_enabled(self._config.party_is_public)

        # And here we go.
        _ba.new_host_session(sessiontype)

        if not self._ran_access_check:
            self._run_access_check()
            self._ran_access_check = True
Пример #8
0
def launch_server_session() -> None:
    """Kick off a host-session based on the current server config."""
    from ba._netutils import serverget
    from ba import _freeforallsession
    from ba import _teamssession
    app = _ba.app
    servercfg = copy.deepcopy(app.server_config)
    appcfg = app.config

    # Convert string session type to the class.
    # Hmm should we just keep this as a string?
    session_type_name = servercfg.get('session_type', 'ffa')
    sessiontype: Type[ba.Session]
    if session_type_name == 'ffa':
        sessiontype = _freeforallsession.FreeForAllSession
    elif session_type_name == 'teams':
        sessiontype = _teamssession.TeamsSession
    else:
        raise Exception('invalid session_type value: ' + session_type_name)

    if _ba.get_account_state() != 'signed_in':
        print('WARNING: launch_server_session() expects to run '
              'with a signed in server account')

    if app.run_server_first_run:
        print((('BallisticaCore headless '
                if app.subplatform == 'headless' else 'BallisticaCore ') +
               str(app.version) + ' (' + str(app.build_number) +
               ') entering server-mode ' + time.strftime('%c')))

    playlist_shuffle = servercfg.get('playlist_shuffle', True)
    appcfg['Show Tutorial'] = False
    appcfg['Free-for-All Playlist Selection'] = (servercfg.get(
        'playlist_name', '__default__') if session_type_name == 'ffa' else
                                                 '__default__')
    appcfg['Free-for-All Playlist Randomize'] = playlist_shuffle
    appcfg['Team Tournament Playlist Selection'] = (servercfg.get(
        'playlist_name', '__default__') if session_type_name == 'teams' else
                                                    '__default__')
    appcfg['Team Tournament Playlist Randomize'] = playlist_shuffle
    appcfg['Port'] = servercfg.get('port', 43210)

    # Set series lengths.
    app.teams_series_length = servercfg.get('teams_series_length', 7)
    app.ffa_series_length = servercfg.get('ffa_series_length', 24)

    # And here we go.
    _ba.new_host_session(sessiontype)

    # Also lets fire off an access check if this is our first time
    # through (and they want a public party).
    if app.run_server_first_run:

        def access_check_response(data: Optional[Dict[str, Any]]) -> None:
            gameport = _ba.get_game_port()
            if data is None:
                print('error on UDP port access check (internet down?)')
            else:
                if data['accessible']:
                    print('UDP port', gameport,
                          ('access check successful. Your '
                           'server appears to be joinable '
                           'from the internet.'))
                else:
                    print('UDP port', gameport,
                          ('access check failed. Your server '
                           'does not appear to be joinable '
                           'from the internet.'))

        port = _ba.get_game_port()
        serverget('bsAccessCheck', {
            'port': port,
            'b': app.build_number
        },
                  callback=access_check_response)
    app.run_server_first_run = False
    app.server_config_dirty = False
Пример #9
0
def launch_main_menu_session() -> None:
    from bastd.mainmenu import MainMenuSession
    _ba.new_host_session(MainMenuSession)
Пример #10
0
    def _launch_server_session(self) -> None:
        """Kick off a host-session based on the current server config."""
        # pylint: disable=too-many-branches
        app = _ba.app
        appcfg = app.config
        sessiontype = self._get_session_type()

        if _ba.get_v1_account_state() != 'signed_in':
            print('WARNING: launch_server_session() expects to run '
                  'with a signed in server account')

        # If we didn't fetch a playlist but there's an inline one in the
        # server-config, pull it in to the game config and use it.
        if (self._config.playlist_code is None
                and self._config.playlist_inline is not None):
            self._playlist_name = 'ServerModePlaylist'
            if sessiontype is FreeForAllSession:
                ptypename = 'Free-for-All'
            elif sessiontype is DualTeamSession:
                ptypename = 'Team Tournament'
            elif sessiontype is CoopSession:
                ptypename = 'Coop'
            else:
                raise RuntimeError(f'Unknown session type {sessiontype}')

            # Need to add this in a transaction instead of just setting
            # it directly or it will get overwritten by the master-server.
            _ba.add_transaction({
                'type': 'ADD_PLAYLIST',
                'playlistType': ptypename,
                'playlistName': self._playlist_name,
                'playlist': self._config.playlist_inline
            })
            _ba.run_transactions()

        if self._first_run:
            curtimestr = time.strftime('%c')
            _ba.log(
                f'{Clr.BLD}{Clr.BLU}{_ba.appnameupper()} {app.version}'
                f' ({app.build_number})'
                f' entering server-mode {curtimestr}{Clr.RST}',
                to_server=False)

        if sessiontype is FreeForAllSession:
            appcfg['Free-for-All Playlist Selection'] = self._playlist_name
            appcfg['Free-for-All Playlist Randomize'] = (
                self._config.playlist_shuffle)
        elif sessiontype is DualTeamSession:
            appcfg['Team Tournament Playlist Selection'] = self._playlist_name
            appcfg['Team Tournament Playlist Randomize'] = (
                self._config.playlist_shuffle)
        elif sessiontype is CoopSession:
            app.coop_session_args = {
                'campaign': self._config.coop_campaign,
                'level': self._config.coop_level,
            }
        else:
            raise RuntimeError(f'Unknown session type {sessiontype}')

        app.teams_series_length = self._config.teams_series_length
        app.ffa_series_length = self._config.ffa_series_length

        _ba.set_authenticate_clients(self._config.authenticate_clients)

        _ba.set_enable_default_kick_voting(
            self._config.enable_default_kick_voting)
        _ba.set_admins(self._config.admins)

        # Call set-enabled last (will push state to the cloud).
        _ba.set_public_party_max_size(self._config.max_party_size)
        _ba.set_public_party_name(self._config.party_name)
        _ba.set_public_party_stats_url(self._config.stats_url)
        _ba.set_public_party_enabled(self._config.party_is_public)

        # And here.. we.. go.
        if self._config.stress_test_players is not None:
            # Special case: run a stress test.
            from ba.internal import run_stress_test
            run_stress_test(playlist_type='Random',
                            playlist_name='__default__',
                            player_count=self._config.stress_test_players,
                            round_duration=30)
        else:
            _ba.new_host_session(sessiontype)

        # Run an access check if we're trying to make a public party.
        if not self._ran_access_check and self._config.party_is_public:
            self._run_access_check()
            self._ran_access_check = True
Пример #11
0
def updateSession(session, playlist):
    _ba.new_host_session(session)
    if playlist:
        updatePlaylist(playlist)