示例#1
0
    def _on_activate(self, host: Dict[str, Any]) -> None:

        # Sanity check: make sure our gather window gets freed after this.
        tab = self._tab()
        if tab:
            ba.verify_object_death(tab.window)
        _ba.connect_to_party(host['address'])
    def _on_my_saved_party_press(self) -> None:
        if self._my_saved_party_selected is None:
            self._no_saved_party_selected_error()
            return

        config=ba.app.config['Saved Servers'][self._my_saved_party_selected]
        _ba.connect_to_party(config['addr'],config['port'])
示例#3
0
 def _host_lookup_result(self, resolved_address: Optional[str],
                         port: int) -> None:
     if resolved_address is None:
         ba.screenmessage(
             ba.Lstr(resource='internal.unableToResolveHostText'),
             color=(1, 0, 0))
         ba.playsound(ba.getsound('error'))
     else:
         # Store for later.
         config = ba.app.config
         config['Last Manual Party Connect Address'] = resolved_address
         config.commit()
         _ba.connect_to_party(resolved_address, port=port)
示例#4
0
    def _on_public_party_activate(self, party: PartyEntry) -> None:
        if party.queue is not None:
            from bastd.ui.partyqueue import PartyQueueWindow
            ba.playsound(ba.getsound('swish'))
            PartyQueueWindow(party.queue, party.address, party.port)
        else:
            address = party.address
            port = party.port

            # Rate limit this a bit.
            now = time.time()
            last_connect_time = self._last_connect_attempt_time
            if last_connect_time is None or now - last_connect_time > 2.0:
                _ba.connect_to_party(address, port=port)
                self._last_connect_attempt_time = now
示例#5
0
 def _connect_response(self, result: Optional[Dict[str, Any]]) -> None:
     try:
         self._connect_press_time = None
         if result is None:
             raise RuntimeError()
         cresult = dataclass_from_dict(ConnectResult, result)
         if cresult.error is not None:
             self._debug_server_comm('got error connect response')
             ba.screenmessage(
                 ba.Lstr(translate=('serverResponses', cresult.error)),
                 (1, 0, 0))
             ba.playsound(ba.getsound('error'))
             return
         self._debug_server_comm('got valid connect response')
         assert cresult.addr is not None and cresult.port is not None
         _ba.connect_to_party(cresult.addr, port=cresult.port)
     except Exception:
         self._debug_server_comm('got connect response error')
         ba.playsound(ba.getsound('error'))
示例#6
0
    def on_update_response(self, response: Optional[dict[str, Any]]) -> None:
        """We've received a response from an update to the server."""
        # pylint: disable=too-many-branches
        if not self._root_widget:
            return

        # Seeing this in logs; debugging...
        if not self._title_text:
            print('PartyQueueWindows update: Have root but no title_text.')
            return

        if response is not None:
            should_show_field = (response.get('d') is not None)
            self._smoothing = response['s']
            self._initial_offset = response['o']

            # If they gave us a position, show the field.
            if should_show_field:
                ba.textwidget(edit=self._title_text,
                              text=ba.Lstr(resource='waitingInLineText'),
                              position=(self._width * 0.5,
                                        self._height * 0.85))
                self._update_field(response)
                self._field_shown = True
            if not should_show_field and self._field_shown:
                ba.textwidget(
                    edit=self._title_text,
                    text=ba.Lstr(resource='internal.connectingToPartyText'),
                    position=(self._width * 0.5, self._height * 0.55))
                self._hide_field()
                self._field_shown = False

            # if they told us there's a boost button, update..
            if response.get('bt') is not None:
                self._boost_tickets = response['bt']
                self._boost_strength = response['ba']
                if self._boost_button is None:
                    self._boost_button = ba.buttonwidget(
                        parent=self._root_widget,
                        scale=1.0,
                        position=(self._width * 0.5 - 75, 20),
                        size=(150, 100),
                        button_type='square',
                        label='',
                        on_activate_call=self.on_boost_press,
                        enable_sound=False,
                        color=(0, 1, 0),
                        autoselect=True)
                    self._boost_label = ba.textwidget(
                        parent=self._root_widget,
                        draw_controller=self._boost_button,
                        position=(self._width * 0.5, 88),
                        size=(0, 0),
                        color=(0.8, 1.0, 0.8),
                        scale=1.5,
                        h_align='center',
                        v_align='center',
                        text=ba.Lstr(resource='boostText'),
                        maxwidth=150)
                    self._boost_price = ba.textwidget(
                        parent=self._root_widget,
                        draw_controller=self._boost_button,
                        position=(self._width * 0.5, 50),
                        size=(0, 0),
                        color=(0, 1, 0),
                        scale=0.9,
                        h_align='center',
                        v_align='center',
                        text=ba.charstr(ba.SpecialChar.TICKET) +
                        str(self._boost_tickets),
                        maxwidth=150)
            else:
                if self._boost_button is not None:
                    self._boost_button.delete()
                    self._boost_button = None
                if self._boost_price is not None:
                    self._boost_price.delete()
                    self._boost_price = None
                if self._boost_label is not None:
                    self._boost_label.delete()
                    self._boost_label = None

            # if they told us to go ahead and try and connect, do so..
            # (note: servers will disconnect us if we try to connect before
            # getting this go-ahead, so don't get any bright ideas...)
            if response.get('c', False):
                # enforce a delay between connection attempts
                # (in case they're jamming on the boost button)
                now = time.time()
                if (self._last_connect_attempt_time is None
                        or now - self._last_connect_attempt_time > 10.0):
                    _ba.connect_to_party(address=self._address,
                                         port=self._port,
                                         print_progress=False)
                    self._last_connect_attempt_time = now
示例#7
0
 def _on_activate(self, host: Dict[str, Any]) -> None:
     _ba.connect_to_party(host['address'])