Exemplo n.º 1
0
def _set_bugopen_var(u, val):
    if not val:
        # end any partnerships and partnership requests
        for offer in u.session.offers_sent[:]:
            if offer.name == 'partnership request':
                offer.b.write_(
                    '\n%s, who was offering a partnership with you, has become unavailable for bughouse.\n',
                    u.name)
                offer.withdraw(notify=False)
                u.write(
                    _("Partnership offer to %s withdrawn.\n") % offer.b.name)
                offer.b.write_("\nPartnership offer from %s removed.\n",
                               u.name)
        for offer in u.session.offers_received[:]:
            if offer.name == 'partnership request':
                offer.a.write_(
                    '\n%s, whom you were offering a partnership with, has become unavailable for bughouse.\n',
                    u.name)
                offer.withdraw(notify=False)
                u.write(
                    _("Partnership offer from %s removed.\n") % offer.a.name)
                offer.a.write_("\nPartnership offer to %s withdrawn.\n",
                               u.name)
        if u.session.partner:
            u.session.partner.write_(
                '\nYour partner has become unavailable for bughouse.\n')
            partner.end_partnership(u, u.session.partner)
Exemplo n.º 2
0
    def close(self):
        assert (not self.closed)
        self.closed = True
        # XXX this will not remove draw offers; game-related offers
        # should probably be saved when a game is adjourned
        for v in self.offers_sent[:]:
            assert (v.a == self.user)
            v.withdraw_logout()
        for v in self.offers_received[:]:
            assert (v.b == self.user)
            v.decline_logout()
        if self.partner:
            #self.conn.write(_('Removing partnership with %s.\n') %
            #    partner.name)
            self.partner.write_('\nYour partner, %s, has departed.\n',
                                self.user.name)
            partner.end_partnership(self.partner, self.user)

        if self.game:
            self.game.leave(self.user)
            assert (self.game == None)
        del self.offers_received[:]
        del self.offers_sent[:]

        for u in self.idlenotified_by:
            u.write_(
                "\nNotification: %s, whom you were idlenotifying, has departed.\n",
                (self.user.name, ))
            u.session.idlenotifying.remove(self.user)
        self.idlenotified_by.clear()

        if self.followed_by:
            for p in self.followed_by.copy():
                p.write_(
                    '\n%s, whose games you were following, has logged out.\n',
                    self.user.name)
            self.followed_by = set()

        # unobserve games
        assert (self.user.session == self)
        for g in self.observed.copy():
            g.unobserve(self.user)
        assert (not self.observed)

        # remove seeks
        if self.seeks:
            for s in self.seeks[:]:
                s.remove()
            self.conn.write(_('Your seeks have been removed.\n'))
        assert (not self.seeks)
Exemplo n.º 3
0
    def close(self):
        assert(not self.closed)
        self.closed = True
        # XXX this will not remove draw offers; game-related offers
        # should probably be saved when a game is adjourned
        for v in self.offers_sent[:]:
            assert(v.a == self.user)
            v.withdraw_logout()
        for v in self.offers_received[:]:
            assert(v.b == self.user)
            v.decline_logout()
        if self.partner:
            #self.conn.write(_('Removing partnership with %s.\n') %
            #    partner.name)
            self.partner.write_('\nYour partner, %s, has departed.\n',
                self.user.name)
            partner.end_partnership(self.partner, self.user)

        if self.game:
            self.game.leave(self.user)
            assert(self.game == None)
        del self.offers_received[:]
        del self.offers_sent[:]

        for u in self.idlenotified_by:
            u.write_("\nNotification: %s, whom you were idlenotifying, has departed.\n", (self.user.name,))
            u.session.idlenotifying.remove(self.user)
        self.idlenotified_by.clear()

        if self.followed_by:
            for p in self.followed_by.copy():
                p.write_('\n%s, whose games you were following, has logged out.\n', self.user.name)
            self.followed_by = set()

        # unobserve games
        assert(self.user.session == self)
        for g in self.observed.copy():
            g.unobserve(self.user)
        assert(not self.observed)

        # remove seeks
        if self.seeks:
            for s in self.seeks[:]:
                s.remove()
            self.conn.write(_('Your seeks have been removed.\n'))
        assert(not self.seeks)
Exemplo n.º 4
0
    def run(self, args, conn):
        if not args[0]:
            if conn.user.session.partner:
                p = conn.user.session.partner
                assert(p.is_online)
                assert(p.session.partner == conn.user)
                partner.end_partnership(conn.user, p)
            else:
                conn.write(_('You do not have a bughouse partner.\n'))
        else:
            u = find_user.online_by_prefix_for_user(args[0], conn)
            if not u:
                return

            if conn.user.name in u.censor:
                conn.write(_('%s is censoring you.\n') % u.name)
                return

            if u == conn.user:
                conn.write(_("You can't be your own bughouse partner.\n"))
                return
            if u == conn.user.session.partner:
                conn.write(_("You are already %s's bughouse partner.\n") %
                    conn.user.session.partner.name)
                return
            if u.session.partner:
                conn.write(_('%s already has a partner.\n') % u.name)
                return

            if not u.vars_['bugopen']:
                conn.write(_('%s is not open for bughouse.\n') % u.name)
                return
            if not conn.user.vars_['bugopen']:
                conn.write(_('Setting you open for bughouse.\n'))
                # A deferred is returned for API reasons, but it is
                # not really needed here.
                d = global_.vars_['bugopen'].set(conn.user, '1')
                assert(d.called)

            partner.Partner(conn.user, u)
Exemplo n.º 5
0
    def run(self, args, conn):
        if not args[0]:
            if conn.user.session.partner:
                p = conn.user.session.partner
                assert (p.is_online)
                assert (p.session.partner == conn.user)
                p.write_('\n%s has left the partnership.\n', conn.user.name)
                partner.end_partnership(conn.user, p)
            else:
                conn.write(_('You do not have a bughouse partner.\n'))
        else:
            u = user.find_by_prefix_for_user(args[0], conn, online_only=True)
            if not u:
                return

            if conn.user.name in u.censor:
                conn.write(_('%s is censoring you.\n') % u.name)
                return

            if u == conn.user:
                conn.write(_("You can't be your own bughouse partner.\n"))
                return
            if conn.user.session.partner:
                conn.write(
                    _("You are already %s's bughouse partner.\n") %
                    conn.user.session.partner.name)
                return
            if u.session.partner:
                conn.write(_('%s already has a partner.\n') % u.name)
                return

            if not u.vars['bugopen']:
                conn.write(_('%s is not open for bughouse.\n') % u.name)
                return
            if not conn.user.vars['bugopen']:
                conn.write(_('Setting you open for bughouse.\n'))
                var.vars['bugopen'].set(conn.user, '1')

            partner.Partner(conn.user, u)
Exemplo n.º 6
0
    def run(self, args, conn):
        if not args[0]:
            if conn.user.session.partner:
                p = conn.user.session.partner
                assert(p.is_online)
                assert(p.session.partner == conn.user)
                p.write_('\n%s has left the partnership.\n', conn.user.name)
                partner.end_partnership(conn.user, p)
            else:
                conn.write(_('You do not have a bughouse partner.\n'))
        else:
            u = user.find_by_prefix_for_user(args[0], conn, online_only=True)
            if not u:
                return

            if conn.user.name in u.censor:
                conn.write(_('%s is censoring you.\n') % u.name)
                return

            if u == conn.user:
                conn.write(_("You can't be your own bughouse partner.\n"))
                return
            if conn.user.session.partner:
                conn.write(_("You are already %s's bughouse partner.\n") %
                    conn.user.session.partner.name)
                return
            if u.session.partner:
                conn.write(_('%s already has a partner.\n') % u.name)
                return

            if not u.vars['bugopen']:
                conn.write(_('%s is not open for bughouse.\n') % u.name)
                return
            if not conn.user.vars['bugopen']:
                conn.write(_('Setting you open for bughouse.\n'))
                var.vars['bugopen'].set(conn.user, '1')

            partner.Partner(conn.user, u)
Exemplo n.º 7
0
    def close(self):
        assert(not self.closed)
        self.closed = True
        # XXX this will not remove draw offers; game-related offers
        # should probably be saved when a game is adjourned
        for v in self.offers_sent[:]:
            assert(v.a == self.user)
            v.withdraw_logout()
        for v in self.offers_received[:]:
            assert(v.b == self.user)
            v.decline_logout()
        if self.partner:
            #self.conn.write(_('Removing partnership with %s.\n') %
            #    partner.name)
            self.partner.write_('\nYour partner, %s, has departed.\n',
                self.user.name)
            partner.end_partnership(self.user, self.partner)

        if self.game:
            try:
                yield self.game.leave(self.user)
            except:
                raise
                print('exception ending game due to logout')
                traceback.print_exc()
        del self.offers_received[:]
        del self.offers_sent[:]

        for u in self.idlenotified_by:
            u.write_("\nNotification: %s, whom you were idlenotifying, has departed.\n", (self.user.name,))
            u.session.idlenotifying.remove(self.user)
        self.idlenotified_by.clear()
        for u in self.idlenotifying:
            u.session.idlenotified_by.remove(self.user)

        if self.followed_by:
            for p in self.followed_by.copy():
                assert(p.session.following == self.user)
                if p.session.pfollow:
                    p.write_("\n%s, whose partner's games you were following, has logged out.\n", self.user.name)
                else:
                    p.write_("\n%s, whose games you were following, has logged out.\n", self.user.name)
                p.session.following = None
            self.followed_by = set()
        if self.following:
            # stop following
            self.following.session.followed_by.remove(self.user)

        # unobserve games
        assert(self.user.session == self)
        for g in self.observed.copy():
            g.unobserve(self.user)
        assert(not self.observed)

        # remove seeks
        if self.seeks:
            for s in self.seeks[:]:
                s.remove()
            self.conn.write(_('Your seeks have been removed.\n'))
        assert(not self.seeks)

        # remove ftells
        if self.ftell:
            ch0 = global_.channels[0]
            self.ftell.session.ftell_admins.remove(self.user)
            ch0.tell("I am logging out now - conversation forwarding stopped.", self.user)

        if self.ftell_admins:
            ch0 = global_.channels[0]
            for adm in self.ftell_admins:
                ch0.tell(A_("*%s* has logged out - conversation forwarding stopped.") % self.user.name, adm)
                adm.write(A_("%s, whose tells you were forwarding, has logged out.\n") % self.user.name)
                adm.session.ftell = None
            self.ftell_admins = []

        for u in self.notified_online:
            u.session.notifiers_online.remove(self.user)
        for u in self.notifiers_online:
            u.session.notified_online.remove(self.user)
        self.notifiers_online = None
        self.notified_online = None