示例#1
0
    def run(self, args, conn):
        if conn.user.session.game:
            if conn.user.session.game.gtype == EXAMINED:
                conn.write(_('You are examining a game.\n'))
            else:
                conn.write(_('You are playing a game.\n'))
            return

        if len(conn.user.session.seeks) >= seek.LIMIT:
            conn.write(_('You can only have %d active seeks.\n') % seek.LIMIT)
            return

        try:
            s = seek.Seek(conn.user, args[0])
        except match.MatchError as e:
            conn.write(e.args[0])
            return

        # Check if the user has already posted the same seek.  It might be
        # more efficient to do this check as part of seek.find_matching()
        if s in global_.seeks.values():
            conn.write(_('You already have an active seek with the same parameters.\n'))
            return

        (auto_matches, manual_matches) = seek.find_matching(s)
        if auto_matches:
            ad = auto_matches[0]
            assert(not ad.manual)
            assert(not ad.expired)
            conn.write(_('Your seek matches one posted by %s.\n') %
                ad.a.name)
            ad.a.write_('\nYour seek matches one posted by %s.\n',
                (conn.user.name,))
            ad.b = conn.user
            g = game.PlayedGame(ad)
            yield g.finish_init(ad)
            return

        if manual_matches:
            conn.write(_('Issuing match request since the seek was set to manual.\n'))
            for ad in manual_matches:
                tags = ad.tags.copy()
                # the challenge should use the same parameters as the
                # seek, except that the color requested (if any) is reversed
                if ad.side is not None:
                    tags['side'] = opp(ad.side)
                else:
                    tags['side'] = None
                c = match.Challenge()
                yield c.finish_init(conn.user, ad.a, tags=tags)
            # go on to post the seek, too

        count = s.post()
        conn.write(_('Your seek has been posted with index %d.\n') % s.num)
        conn.write(ngettext('(%d player saw the seek.)\n',
            '(%d players saw the seek.)\n', count) % count)
示例#2
0
    def run(self, args, conn):
        if conn.user.session.game:
            if conn.user.session.game.gtype == game.EXAMINED:
                conn.write(_("You can't challenge while you are examining a game.\n"))
            else:
                conn.write(_("You can't challenge while you are playing a game.\n"))
            return
        u = user.find_by_prefix_for_user(args[0], conn, online_only=True)
        if not u:
            return
        if u == conn.user:
            conn.write(_("You can't match yourself.\n"))
            return

        match.Challenge(conn.user, u, args[1])
示例#3
0
 def run(self, args, conn):
     # note that rematch uses history to determine the previous opp,
     # so unlike "say", it works after logging out and back in, and
     # ignores aborted games
     hist = conn.user.get_history()
     if not hist:
         conn.write(_('You have no previous opponent.\n'))
         return
     h = hist[-1]
     opp = online.find_exact(h['opp_name'])
     if not opp:
         conn.write(_('Your last opponent, %s, is not logged in.\n') % h['opp_name'])
         return
     variant_name = speed_variant.variant_abbrevs[h['flags'][1]]
     assert(h['flags'][2] in ['r', 'u'])
     match_str = '%d %d %s %s' % (h['time'], h['inc'], h['flags'][2],
         variant_name)
     match.Challenge(conn.user, opp, match_str)
示例#4
0
    def run(self, args, conn):
        if conn.user.session.game:
            if conn.user.session.game.gtype == EXAMINED:
                conn.write(
                    _("You can't challenge while you are examining a game.\n"))
            else:
                conn.write(
                    _("You can't challenge while you are playing a game.\n"))
            return
        u = find_user.online_by_prefix_for_user(args[0], conn)
        if not u:
            return
        if u == conn.user:
            conn.write(_("You can't match yourself.\n"))
            return

        c = match.Challenge()
        yield c.finish_init(conn.user, u, args[1])
示例#5
0
 def run(self, args, conn):
     if not conn.user.has_title('TD'):
         conn.write(_('Only TD programs are allowed to use this command.\n'))
         return
     u1 = find_user.online_by_prefix_for_user(args[0], conn)
     if not u1:
         return
     u2 = find_user.online_by_prefix_for_user(args[1], conn)
     if not u2:
         return
     # ignore censor lists, noplay lists, and open var
     if u1 == u2:
         conn.write(_("A player cannot match himself or herself.\n"))
         return
     if u1.session.game:
         conn.write(_("%s is playing a game.\n") % u1.name)
         return
     if u2.session.game:
         conn.write(_("%s is playing a game.\n") % u2.name)
         return
     m = match.Challenge()
     yield m.finish_init(u1, u2, args[2])
示例#6
0
    def run(self, args, conn):
        if conn.user.session.game:
            if conn.user.session.game.gtype == game.EXAMINED:
                conn.write(_('You are examining a game.\n'))
            else:
                conn.write(_('You are playing a game.\n'))
            return

        ad = None
        if type(args[0]) == str:
            u = user.find_by_prefix_for_user(args[0], conn, online_only=True)
            if u:
                if not u.session.seeks:
                    conn.write(_("%s isn't seeking any games.\n") % u.name)
                elif len(u.session.seeks) > 1:
                    conn.write(_("%s is seeking several games.\n") % u.name)
                else:
                    ad = u.session.seeks[0]
                    assert(not ad.expired)
        else:
            try:
                ad = seek.seeks[args[0]]
            except KeyError:
                # no such seek
                ad = None
            else:
                if ad.expired:
                    ad = None
            if not ad:
                conn.write(_('That seek is not available.\n'))

        if ad:
            if conn.user.is_playbanned:
                conn.write(_('You may not play games.\n'))
                ad = None
            elif ad.rated and conn.user.is_guest:
                conn.write(_('Only registered players can play rated games.\n'))
                ad = None
            elif ad.rated and conn.user.is_ratedbanned:
                conn.write(_('You may not play rated games.\n'))
                ad = None
            elif not match.check_censor_noplay(conn.user, ad.a):
                ad = None
            # check formula
            elif not ad.check_formula(conn.user):
                conn.write(_('Match request does not fit formula for %s:') %
                    ad.a.name)
                ad = None
            # we don't check this user's formula, since using the "play"
            # command implicitly accepted the match terms

        if ad:
            if ad.manual:
                conn.write(_('Issuing match request since the seek was set to manual.\n'))
                tags = ad.tags.copy()
                if ad.side is not None:
                    tags['side'] = opp(ad.side)
                else:
                    tags['side'] = None
                match.Challenge(conn.user, ad.a, tags=tags)
            else:
                ad.a.write_('\n%s accepts your seek.\n', (conn.user.name,))
                ad.accept(conn.user)