Пример #1
0
 def run(self, args, conn):
     if args[0] is not None:
         if isinstance(args[0], basestring):
             u = find_user.online_by_prefix_for_user(args[0], conn)
             if not u:
                 return
             conn.write(_('%s is in the following channels:\n') % u.name)
             s = ''
             for ch in u.channels:
                 s += '%-3d ' % ch
             conn.write(s + '\n')
         else:
             try:
                 ch = global_.channels[args[0]]
             except KeyError:
                 if args[0] < 0 or args[0] > channel.CHANNEL_MAX:
                     conn.write(_('Invalid channel number.\n'))
                 else:
                     conn.write(_('There are %d players in channel %d.\n') %
                         (0, args[0]))
             else:
                 on = ch.get_online()
                 if len(on) > 0:
                     conn.write("%s: %s\n" % (ch.get_display_name(), ' '.join(on)))
                 count = len(on)
                 conn.write(ngettext('There is %d player in channel %d.\n', 'There are %d players in channel %d.\n', count) % (count, args[0]))
     else:
         for ch in global_.channels:
             on = ch.get_online()
             if len(on) > 0:
                 conn.write("%s: %s\n" %
                     (ch.get_display_name(), ' '.join(on)))
Пример #2
0
 def sub(self, item, conn):
     u = find_user.online_by_prefix_for_user(item, conn)
     if u:
         if conn.user not in u.session.idlenotified_by:
             raise ListError(
                 _('%s is not on your idlenotify list.\n') % u.name)
         conn.user.remove_idlenotification(u)
         conn.write(_('%s removed from your idlenotify list.\n') % u.name)
     return defer.succeed(None)
Пример #3
0
    def run(self, args, conn):
        g = conn.user.session.game
        if not g or g.gtype != EXAMINED:
            conn.write(_("You are not examining a game.\n"))
            return

        u = find_user.online_by_prefix_for_user(args[0], conn)
        if not u:
            return

        g.mexamine(u, conn)
Пример #4
0
 def add(self, item, conn):
     u = find_user.online_by_prefix_for_user(item, conn)
     if u:
         if u == conn.user:
             raise ListError(_('You cannot idlenotify yourself.\n'))
         if conn.user in u.session.idlenotified_by:
             raise ListError(
                 _('%s is already on your idlenotify list.\n') % u.name)
         conn.user.add_idlenotification(u)
         conn.write(_('%s added to your idlenotify list.\n') % u.name)
     return defer.succeed(None)
Пример #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 not conn.user.has_title('TD'):
            conn.write(_('Only TD programs are allowed to use this command.\n'))
            return

        u2 = find_user.online_by_prefix_for_user(args[0], conn)
        if not u2:
            return

        g = game.from_name_or_number(args[1], conn)
        if g:
            if u2 in g.observers or u2 in g.players:
                # TODO: how to print error message to TD?
                pass
            else:
                g.observe(u2)
Пример #7
0
    def run(self, args, conn):
        if args[0] is None:
            uf = conn.user.session.following
            if not uf or not conn.user.session.pfollow:
                conn.write(
                    _("You are not following any player's partner's games.\n"))
            else:
                assert (uf.is_online)

                uf.session.followed_by.remove(conn.user)
                conn.user.session.following = None
                # no need to change conn.user.session.pfollow
                conn.write(
                    _("You will not follow any player's partner's games.\n"))
        else:
            u2 = find_user.online_by_prefix_for_user(args[0], conn)
            if u2:
                if conn.user.session.following:
                    if u2 == conn.user.session.following and conn.user.session.pfollow:
                        conn.write(
                            _("You are already following %s's partner's games.\n"
                              ) % u2.name)
                        return
                    if conn.user.session.pfollow:
                        conn.user.write(
                            _("You will no longer be following %s's partner's games.\n"
                              ) % conn.user.session.following.name)
                    else:
                        conn.user.write(
                            _("You will no longer be following %s's games.\n")
                            % conn.user.session.following.name)
                    conn.user.session.following.session.followed_by.remove(
                        conn.user)
                conn.write(
                    _("You will now be following %s's partner's games.\n") %
                    u2.name)
                conn.user.session.following = u2
                conn.user.session.pfollow = True
                u2.session.followed_by.add(conn.user)

                # If there is a game in progress and we are not already
                # observing it, start observing it.
                g = u2.session.game
                if (g and g.variant.name == 'bughouse'
                        and g.bug_link not in conn.user.session.observed
                        and conn.user not in g.players):
                    g.bug_link.observe(conn.user)
Пример #8
0
 def run(self, args, conn):
     u = find_user.online_by_prefix_for_user(args[0], conn)
     if not u:
         return
     if u == conn.user:
         conn.write(_("You can't summon yourself.\n"))
     if not conn.user.is_admin():
         if conn.user.name in u.censor:
             conn.write(_("%s is censoring you.\n") % u.name)
             return
         if conn.user.name not in u.notifiers:
             conn.write(_('You cannot summon a player who doesn\'t have you on his or her notify list.\n'))
             return
     u.write('\a\n')
     u.write_('%s needs to speak to you.  To contact him or her type "tell %s hello".\n', ((conn.user.name, conn.user.name)))
     conn.write(_('Summoning sent to "%s".\n') % u.name)
     conn.user.add_idlenotification(u)
Пример #9
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])
Пример #10
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
        u2 = find_user.online_by_prefix_for_user(args[0], conn)
        if not u2:
            return
        # XXX how to handle guests?

        if args[1] not in [0, 1]:
            raise BadCommandError

        u2.vars_['tourney'] = str(args[1])
        if args[1]:
            u2.write_('\n%s has set your tourney variable to ON.\n',
                (conn.user.name,))
        else:
            u2.write_('\n%s has set your tourney variable to OFF.\n',
                (conn.user.name,))
Пример #11
0
    def run(self, args, conn):
        if args[0] is not None:
            u2 = find_user.online_by_prefix_for_user(args[0], conn)
        else:
            u2 = conn.user

        if u2:
            assert(u2.is_online)
            pt = u2.session.ping_time
            if not u2.has_timeseal():
                conn.write(_('Ping time not available; %s is not using zipseal.\n') %
                    u2.name)
            elif len(pt) < 2:
                conn.write(_('Ping time not available; please wait.\n'))
            else:
                conn.write(_('Ping time for %s, based on %d samples:\n') %
                    (u2.name, len(pt)))
                avg = 1000.0 * sum(pt) / len(pt)
                conn.write(_('Average: %.3fms\n') % (avg))
Пример #12
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)
Пример #13
0
    def run(self, args, conn):
        if args[0] is None:
            u = conn.user
        else:
            u = find_user.online_by_prefix_for_user(args[0], conn)

        if not u:
            return

        conn.write(_("Interface variable settings of %s:\n\n") % u.name)

        conn.write(
            'compressmove=%(compressmove)d     defprompt=%(defprompt)d        lock=%(lock)d             ms=%(ms)d\n'
            % u.session.ivars)
        conn.write(
            'seekremove=%(seekremove)d       startpos=%(startpos)d         block=%(block)d            gameinfo=%(gameinfo)d\n'
            % u.session.ivars)
        conn.write(
            'pendinfo=%(pendinfo)d         graph=%(graph)d            seekinfo=%(seekinfo)d         extascii=%(extascii)d\n'
            % u.session.ivars)
        conn.write(
            'showserver=%(showserver)d       nohighlight=%(nohighlight)d      vthighlight=%(vthighlight)d      pin=%(pin)d\n'
            % u.session.ivars)
        conn.write(
            'pinginfo=%(pinginfo)d         boardinfo=%(boardinfo)d        extuserinfo=%(extuserinfo)d      audiochat=%(audiochat)d\n'
            % u.session.ivars)
        conn.write(
            'seekca=%(seekca)d           showownseek=%(showownseek)d      premove=%(premove)d          smartmove=%(smartmove)d\n'
            % u.session.ivars)
        conn.write(
            'movecase=%(movecase)d         nowrap=%(nowrap)d           allresults=%(allresults)d\n'
            % u.session.ivars)
        conn.write('singleboard=%(singleboard)d\n' % u.session.ivars)
        conn.write(
            'suicide=%(suicide)d          crazyhouse=%(crazyhouse)d       losers=%(losers)d           wildcastle=%(wildcastle)d\n'
            % u.session.ivars)
        conn.write('fr=%(fr)d               atomic=%(atomic)d\n' %
                   u.session.ivars)
        conn.write('xml=?\n\n' % u.session.ivars)
Пример #14
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 conn.user.has_title('computer'):
            conn.write(_('Computers cannot accept seeks.\n'))
            return

        ad = None
        if isinstance(args[0], basestring):
            u = find_user.online_by_prefix_for_user(args[0], conn)
            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 = global_.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 conn.user == ad.a:
                conn.write(_('You cannot accept your own seeks.\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
                c = match.Challenge()
                yield c.finish_init(conn.user, ad.a, tags=tags)

            else:
                ad.a.write_('\n%s accepts your seek.\n', (conn.user.name,))
                yield ad.accept(conn.user)
Пример #15
0
    def _do_tell(self, args, conn):
        if conn.user.is_muted:
            # mute now prevents *all* tells
            conn.write(_('You are muted.\n'))
            return (None, None)
        u = None
        ch = None
        if args[0] == '.':
            u = conn.session.last_tell_user
            if not u:
                conn.write(_("No previous tell.\n"))
            elif not u.is_online:
                # try to find the user if he or she has logged off
                # and since reconnected
                name = u.name
                u = global_.online.find_exact(name)
                if not u:
                    conn.write(_('%s is no longer online.\n') % name)
        elif args[0] == ',':
            ch = conn.session.last_tell_ch
            if not ch:
                conn.write(_('No previous channel.\n'))
        elif args[0] == '!':
            global_.commands['shout'].run(args[1:], conn)
            return (None, None)
        elif args[0] == '^':
            global_.commands['cshout'].run(args[1:], conn)
            return (None, None)
        else:
            if type(args[0]) in [int, long]:
                # we do not try to look up channels in the db, because
                # we are only interested in channels with users online.
                try:
                    ch = global_.channels[args[0]]
                except KeyError:
                    if ch < 0 or ch > channel.CHANNEL_MAX:
                        conn.write(_('Invalid channel number.\n'))
                    else:
                        conn.write(_('Channel is empty.\n'))
                else:
                    if conn.user not in ch.online and (
                            not conn.user.has_title('TD')):
                        conn.user.write(
                            _('''(Not sent because you are not in channel %s.)\n'''
                              ) % ch.id_)
                        ch = None
            else:
                u = find_user.online_by_prefix_for_user(args[0], conn)

        if ch:
            count = ch.tell(args[1], conn.user)
            conn.write(
                ngettext('(told %d player in channel %d)\n',
                         '(told %d players in channel %d)\n', count) %
                (count, ch.id_))
        elif u:
            if conn.user.name in u.censor and not conn.user.is_admin():
                conn.write(_("%s is censoring you.\n") % u.name)
                # TODO: notify admins they are censored
            elif conn.user.is_guest and not u.vars_['tell']:
                conn.write(
                    _('''Player "%s" isn't listening to unregistered users' tells.\n'''
                      % u.name))
            else:
                u.write_('\n%s tells you: %s\n',
                         (conn.user.get_display_name(), args[1]))
                self._told(u, conn)
                if u.session.ftell == conn.user or conn.user.session.ftell == u:
                    for adm in (global_.channels[0].online - set(
                        (conn.user, u))):
                        if adm.hears_channels():
                            adm.write(
                                A_("Fwd tell: %s told %s: %s\n") %
                                (conn.user.name, u.name, args[1]))

        return (u, ch)