def _on_start_advertizing_press(self) -> None: from bastd.ui.account import show_sign_in_prompt if _ba.get_account_state() != 'signed_in': show_sign_in_prompt() return name = cast(str, ba.textwidget(query=self._host_name_text)) if name == '': ba.screenmessage(ba.Lstr(resource='internal.invalidNameErrorText'), color=(1, 0, 0)) ba.playsound(ba.getsound('error')) return _ba.set_public_party_name(name) cfg = ba.app.config cfg['Public Party Name'] = name cfg.commit() ba.playsound(ba.getsound('shieldUp')) _ba.set_public_party_enabled(True) # In GUI builds we want to authenticate clients only when hosting # public parties. _ba.set_authenticate_clients(True) self._do_status_check() ba.buttonwidget( edit=self._host_toggle_button, label=ba.Lstr( resource='gatherWindow.makePartyPrivateText', fallback_resource='gatherWindow.stopAdvertisingText'), on_activate_call=self._on_stop_advertising_press)
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
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
def _on_stop_advertising_press(self) -> None: _ba.set_public_party_enabled(False) # In GUI builds we want to authenticate clients only when hosting # public parties. _ba.set_authenticate_clients(False) ba.playsound(ba.getsound('shieldDown')) text = self._host_status_text if text: ba.textwidget( edit=text, text=ba.Lstr(resource='gatherWindow.' 'partyStatusNotPublicText'), color=(0.6, 0.6, 0.6), ) ba.buttonwidget( edit=self._host_toggle_button, label=ba.Lstr( resource='gatherWindow.makePartyPublicText', fallback_resource='gatherWindow.startAdvertisingText'), on_activate_call=self._on_start_advertizing_press)
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