Exemplo n.º 1
0
    def __init__(self, a, b):
        Offer.__init__(self, 'partnership request')

        # FICS informs player A if player B is ratedbanned, but
        # that arguably leaks information unnecessarily

        # block offers from guests if the recipient does not allow tells
        # from guests, to reduce spam
        if a.is_guest and not b.vars_['tell']:
            a.write(_('''Player "%s" isn't listening to unregistered users' tells.\n''' % b.name))
            return
        # check for existing offers
        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        o = next((o for o in b_sent if o.name == self.name and
            o.b == a), None)
        if o:
            # offers intercept
            o.accept()
            return
        o = next((o for o in a_sent if o.name == self.name and
            o.b == b), None)
        if o:
            a.write(_("You are already offering to be %s's partner.\n") %
                b.name)
            return

        self.a = a
        self.b = b
        a.write(_('Making a partnership offer to %s.\n') % b.name)
        b.write_('\n%s offers to be your bughouse partner; type "partner %s" to accept.\n', (a.name, a.name))
        self._register()
        self.pendinfo('partner', '#')
Exemplo n.º 2
0
    def __init__(self, a, b):
        Offer.__init__(self, 'partnership request')

        # check for existing offers
        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        o = next((o for o in b_sent if o.name == self.name and o.b == a), None)
        if o:
            # offers intercept
            o.accept()
            return
        o = next((o for o in a_sent if o.name == self.name and o.b == b), None)
        if o:
            a.write(
                _("You are already offering to be %s's partner.\n") % b.name)
            return

        self.a = a
        self.b = b
        a.write(_('Making a partnership offer to %s.\n') % b.name)
        b.write_('%s offers to be your bughouse partner.\n', (a.name, ))
        self._register()
Exemplo n.º 3
0
    def __init__(self, a, b):
        Offer.__init__(self, 'partnership request')

        # check for existing offers
        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        o = next((o for o in b_sent if o.name == self.name and
            o.b == a), None)
        if o:
            # offers intercept
            o.accept()
            return
        o = next((o for o in a_sent if o.name == self.name and
            o.b == b), None)
        if o:
            a.write(_("You are already offering to be %s's partner.\n") %
                b.name)
            return

        self.a = a
        self.b = b
        a.write(_('Making a partnership offer to %s.\n') % b.name)
        b.write_('%s offers to be your bughouse partner.\n', (a.name,))
        self._register()
Exemplo n.º 4
0
 def __init__(self):
     Offer.__init__(self, 'match offer')
Exemplo n.º 5
0
    def __init__(self, a, b, args=None, tags=None):
        """ Initiate a new offer.  "a" is the player issuing the offer;
        "b" receives the request """
        Offer.__init__(self, 'match offer')

        self.a = a
        self.b = b

        if a.is_guest or b.is_guest:
            self.adjourned = None
        else:
            self.adjourned = db.get_adjourned_between(a.id, b.id)
        if self.adjourned:
            if tags or args:
                a.write_('You have an adjourned game with %s.  You cannot start a new game until you finish it.\n', b.name)
                return
            tags = self.adjourned.copy()
            tags.update({
                'side': None
            })
        else:
            if not check_censor_noplay(a, b):
                return

        if tags:
            # copy match parameters
            self.side = tags['side']
            self.rated = tags['rated']
            self.speed_name = tags['speed_name']
            self.variant_name = tags['variant_name']
            self.clock_name = tags['clock_name']
            self.time = tags['time']
            self.inc = tags['inc']
            self.idn = tags['idn']
            self.speed_variant = speed_variant.from_names(self.speed_name,
                self.variant_name)
            self.a_rating = a.get_rating(self.speed_variant)
            self.b_rating = b.get_rating(self.speed_variant)
            # TODO: overtime move number, bonus
        else:
            # get match parameters from a string or use defaults
            try:
                self._check_open()
                self._parse_args(args, a, b)
            except MatchError as e:
                a.write(e[0])
                return

        # look for a matching offer from player b
        o = next((o for o in a.session.offers_received if
            o.name == self.name and o.equivalent_to(self)), None)
        if o:
            # a already received an identical offer, so just accept it
            a.write_("Your challenge intercepts %s's challenge.\n", (o.a.name,))
            b.write_("%s's challenge intercepts your challenge.\n", (a.name,))
            # XXX don't send "Accepting" and "USER accepts" messages?
            o.accept()
            return

        # build the "Challenge:" string
        if self.side is not None:
            side_str = ' [%s]' % game.side_to_str(self.side)
        else:
            side_str = ''

        rated_str = "rated" if self.rated else "unrated"

        if self.clock_name == 'untimed':
            time_str = ''
        else:
            time_str = ' %d %d' % (self.time, self.inc)

        # example: GuestABCD (++++) [white] hans (----) unrated blitz 5 0.
        challenge_str = '%s (%s)%s %s (%s) %s %s%s' % (self.a.name,
            self.a_rating, side_str, self.b.name, self.b_rating, rated_str,
            self.speed_variant, time_str)
        if self.idn is not None:
            challenge_str = '%s idn=%d' % (challenge_str, self.idn)
        if self.clock_name not in ['fischer', 'untimed']:
            challenge_str = '%s %s' % (challenge_str, self.clock_name)
        if self.clock_name == 'overtime':
            challenge_str = '%s %d/%d,SD/%d+%d' % (challenge_str,
                self.overtime_move_num, self.time, self.overtime_bonus,
                self.inc)
        if self.adjourned:
            challenge_str = '%s (adjourned)' % challenge_str
        #if self.board is not None:
        #    challenge_str = 'Loaded from a board'

        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        a_received = a.session.offers_received
        b_received = b.session.offers_received

        if self in a_sent:
            a.write_('You are already offering an identical match to %s.\n',
                (b.name,))
            return

        if not formula.check_formula(self, b.vars['formula']):
            a.write_('Match request does not meet formula for %s:\n', b.name)
            b.write_('Ignoring (formula): %s\n', challenge_str)
            return

        if self.variant_name == 'bughouse':
            # build the challenge string for the other game
            apart = a.session.partner
            bpart = b.session.partner
            challenge_str2 = '%s (%s) %s (%s) %s %s%s' % (apart.name,
                apart.get_rating(self.speed_variant),
                bpart.name, bpart.get_rating(self.speed_variant), rated_str,
                self.speed_variant, time_str)
            if self.idn is not None:
                challenge_str2 = '%s idn=%d' % (challenge_str2, self.idn)
            if self.clock_name not in ['fischer', 'untimed']:
                challenge_str2 = '%s %s' % (challenge_str2, self.clock_name)
            if self.clock_name == 'overtime':
                challenge_str2 = '%s %d/%d,SD/%d+%d' % (challenge_str2,
                    self.overtime_move_num, self.time, self.overtime_bonus,
                    self.inc)
            if self.adjourned:
                challenge_str2 = '%s (adjourned)' % challenge_str2

            # inform the other two players about the challenge
            apart.write_('Your bughouse partner issues: %s\n', challenge_str)
            apart.write_('Your game will be: %s\n', challenge_str2)
            bpart.write_('Your bughouse partner was challenged: %s\n',
                challenge_str)
            bpart.write_('Your game will be: %s\n', challenge_str2)


        o = next((o for o in b_sent if o.name == self.name and
            o.b == a), None)
        if o:
            a.write_('Declining the offer from %s and proposing a counteroffer.\n', (b.name,))
            b.write_('%s declines your offer and proposes a counteroffer.\n', (a.name,))
            o.decline(notify=False)

        o = next((o for o in a_sent if o.name == self.name and
            o.b == b), None)
        if o:
            a.write_('Updating the offer already made to %s.\n', (b.name,))
            b.write_('%s updates the offer.\n', (a.name,))
            a_sent.remove(o)
            b_received.remove(o)

        self._register()

        a.write_nowrap('Issuing: %s.\n' % challenge_str)
        b.write_nowrap('Challenge: %s.\n' % challenge_str)
        if a.has_title('abuser'):
            b.write_('--** %s is an abuser **--\n', (a.name,))
        if b.has_title('abuser'):
            a.write_('--** %s is an abuser **--\n', (b.name,))
        if a.has_title('computer'):
            b.write_('--** %s is a computer **--\n', (a.name,))
        if b.has_title('computer'):
            a.write_('--** %s is a computer **--\n', (b.name,))
        b.write_('You can "accept", "decline", or propose different parameters.\n')
Exemplo n.º 6
0
    def __init__(self, a, b, args=None, tags=None):
        """ Initiate a new offer.  "a" is the player issuing the offer;
        "b" receives the request """
        Offer.__init__(self, 'match offer')

        self.a = a
        self.b = b

        if a.is_guest or b.is_guest:
            self.adjourned = None
        else:
            self.adjourned = db.get_adjourned_between(a.id, b.id)
        if self.adjourned:
            if tags or args:
                a.write_(
                    'You have an adjourned game with %s.  You cannot start a new game until you finish it.\n',
                    b.name)
                return
            tags = self.adjourned.copy()
            tags.update({'side': None})
        else:
            if not check_censor_noplay(a, b):
                return

        if tags:
            # copy match parameters
            self.side = tags['side']
            self.rated = tags['rated']
            self.speed_name = tags['speed_name']
            self.variant_name = tags['variant_name']
            self.clock_name = tags['clock_name']
            self.time = tags['time']
            self.inc = tags['inc']
            self.idn = tags['idn']
            self.speed_variant = speed_variant.from_names(
                self.speed_name, self.variant_name)
            self.a_rating = a.get_rating(self.speed_variant)
            self.b_rating = b.get_rating(self.speed_variant)
            # TODO: overtime move number, bonus
        else:
            # get match parameters from a string or use defaults
            try:
                self._check_open()
                self._parse_args(args, a, b)
            except MatchError as e:
                a.write(e[0])
                return

        # look for a matching offer from player b
        o = next((o for o in a.session.offers_received
                  if o.name == self.name and o.equivalent_to(self)), None)
        if o:
            # a already received an identical offer, so just accept it
            a.write_("Your challenge intercepts %s's challenge.\n",
                     (o.a.name, ))
            b.write_("%s's challenge intercepts your challenge.\n", (a.name, ))
            # XXX don't send "Accepting" and "USER accepts" messages?
            o.accept()
            return

        # build the "Challenge:" string
        if self.side is not None:
            side_str = ' [%s]' % game.side_to_str(self.side)
        else:
            side_str = ''

        rated_str = "rated" if self.rated else "unrated"

        if self.clock_name == 'untimed':
            time_str = ''
        else:
            time_str = ' %d %d' % (self.time, self.inc)

        # example: GuestABCD (++++) [white] hans (----) unrated blitz 5 0.
        challenge_str = '%s (%s)%s %s (%s) %s %s%s' % (
            self.a.name, self.a_rating, side_str, self.b.name, self.b_rating,
            rated_str, self.speed_variant, time_str)
        if self.idn is not None:
            challenge_str = '%s idn=%d' % (challenge_str, self.idn)
        if self.clock_name not in ['fischer', 'untimed']:
            challenge_str = '%s %s' % (challenge_str, self.clock_name)
        if self.clock_name == 'overtime':
            challenge_str = '%s %d/%d,SD/%d+%d' % (
                challenge_str, self.overtime_move_num, self.time,
                self.overtime_bonus, self.inc)
        if self.adjourned:
            challenge_str = '%s (adjourned)' % challenge_str
        #if self.board is not None:
        #    challenge_str = 'Loaded from a board'

        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        a_received = a.session.offers_received
        b_received = b.session.offers_received

        if self in a_sent:
            a.write_('You are already offering an identical match to %s.\n',
                     (b.name, ))
            return

        if not formula.check_formula(self, b.vars['formula']):
            a.write_('Match request does not meet formula for %s:\n', b.name)
            b.write_('Ignoring (formula): %s\n', challenge_str)
            return

        if self.variant_name == 'bughouse':
            # build the challenge string for the other game
            apart = a.session.partner
            bpart = b.session.partner
            challenge_str2 = '%s (%s) %s (%s) %s %s%s' % (
                apart.name, apart.get_rating(self.speed_variant), bpart.name,
                bpart.get_rating(self.speed_variant), rated_str,
                self.speed_variant, time_str)
            if self.idn is not None:
                challenge_str2 = '%s idn=%d' % (challenge_str2, self.idn)
            if self.clock_name not in ['fischer', 'untimed']:
                challenge_str2 = '%s %s' % (challenge_str2, self.clock_name)
            if self.clock_name == 'overtime':
                challenge_str2 = '%s %d/%d,SD/%d+%d' % (
                    challenge_str2, self.overtime_move_num, self.time,
                    self.overtime_bonus, self.inc)
            if self.adjourned:
                challenge_str2 = '%s (adjourned)' % challenge_str2

            # inform the other two players about the challenge
            apart.write_('Your bughouse partner issues: %s\n', challenge_str)
            apart.write_('Your game will be: %s\n', challenge_str2)
            bpart.write_('Your bughouse partner was challenged: %s\n',
                         challenge_str)
            bpart.write_('Your game will be: %s\n', challenge_str2)

        o = next((o for o in b_sent if o.name == self.name and o.b == a), None)
        if o:
            a.write_(
                'Declining the offer from %s and proposing a counteroffer.\n',
                (b.name, ))
            b.write_('%s declines your offer and proposes a counteroffer.\n',
                     (a.name, ))
            o.decline(notify=False)

        o = next((o for o in a_sent if o.name == self.name and o.b == b), None)
        if o:
            a.write_('Updating the offer already made to %s.\n', (b.name, ))
            b.write_('%s updates the offer.\n', (a.name, ))
            a_sent.remove(o)
            b_received.remove(o)

        self._register()

        a.write_nowrap('Issuing: %s.\n' % challenge_str)
        b.write_nowrap('Challenge: %s.\n' % challenge_str)
        if a.has_title('abuser'):
            b.write_('--** %s is an abuser **--\n', (a.name, ))
        if b.has_title('abuser'):
            a.write_('--** %s is an abuser **--\n', (b.name, ))
        if a.has_title('computer'):
            b.write_('--** %s is a computer **--\n', (a.name, ))
        if b.has_title('computer'):
            a.write_('--** %s is a computer **--\n', (b.name, ))
        b.write_(
            'You can "accept", "decline", or propose different parameters.\n')