예제 #1
0
    def _remove_player_team(self, sessionteam: ba.SessionTeam,
                            activity: Optional[ba.Activity]) -> None:
        """Remove the player-specific team in non-teams mode."""

        # They should have been the only one on their team.
        assert not sessionteam.players

        # Remove their Team from the Activity.
        if activity is not None:
            if sessionteam.activityteam in activity.teams:
                activity.remove_team(sessionteam)
            else:
                print('Team not found in Activity in on_player_leave.')

        # And then from the Session.
        with _ba.Context(self):
            if sessionteam in self.sessionteams:
                try:
                    self.sessionteams.remove(sessionteam)
                    self.on_team_leave(sessionteam)
                except Exception:
                    print_exception(
                        f'Error in on_team_leave for Session {self}.')
            else:
                print('Team no in Session teams in on_player_leave.')
            try:
                sessionteam.leave()
            except Exception:
                print_exception(f'Error clearing sessiondata'
                                f' for team {sessionteam} in session {self}.')
예제 #2
0
    def remove_team(self, sessionteam: ba.SessionTeam) -> None:
        """(internal)"""

        # This should only be called on unexpired activities the team has
        # been added to.
        assert not self.expired
        assert sessionteam.gameteam is not None
        assert sessionteam.gameteam in self.teams

        team = sessionteam.gameteam
        assert isinstance(team, self._teamtype)

        assert team in self.teams
        self.teams.remove(team)
        assert team not in self.teams

        with _ba.Context(self):
            # Make a decent attempt to persevere if user code breaks.
            try:
                self.on_team_leave(team)
            except Exception:
                print_exception(f'Error in on_team_leave for {self}')
            try:
                sessionteam.reset_gamedata()
            except Exception:
                print_exception(f'Error in reset_gamedata for {self}')
            sessionteam.gameteam = None
예제 #3
0
    def remove_team(self, sessionteam: ba.SessionTeam) -> None:
        """Remove a team from a Running Activity

        (internal)
        """
        assert not self.expired
        assert sessionteam.activityteam is not None

        team: Any = sessionteam.activityteam
        assert isinstance(team, self._teamtype)

        assert team in self.teams
        self.teams.remove(team)
        assert team not in self.teams

        with _ba.Context(self):
            # Make a decent attempt to persevere if user code breaks.
            try:
                self.on_team_leave(team)
            except Exception:
                print_exception(f'Error in on_team_leave for {self}.')
            try:
                team.leave()
            except Exception:
                print_exception(f'Error on leave for {team} in {self}.')

            sessionteam.activityteam = None

        # Add the team to a list to keep it around for a while. This is
        # to discourage logic from firing on team object death, which
        # may not happen until activity end if something is holding refs
        # to it.
        self._delay_delete_teams.append(team)
        self._teams_that_left.append(weakref.ref(team))