Exemple #1
0
    def render_index_players(self, ctx, data):
        data.sort(key=attrgetter('name'))
        lines = []
        for player in data:
            line = []
            name = player.name
            tzid = player.tzid
            tzidcell = T.td(_class="objtzid")[tzid, ':']
            line.append(tzidcell)


            if admin.verify(player):
                line.append(T.td['!'])
            elif wizard.verify(player):
                line.append(T.td['@'])
            else:
                line.append(T.td)

            editlink = T.a(href="/edit/%s" % tzid)[name]
            line.append(T.td(_class="objname")[editlink])

            if player.logged_in:
                room = player.room
                editlink = "/edit/%s" % room.tzid
                link = T.a(href=editlink)[T.span(_class="editlink")[room.name]]
                line.append(T.td[link])
            else:
                line.append(T.td)

            lines.append(T.tr[line])

        return T.table[lines]
Exemple #2
0
def cmd_help(s, r=None):
    '''help [<subject>]

    Get help on some <subject> or general help if no subject given.

    '''

    topic = r.get('topic', None)

    import actions
    if topic is None:
        s.message('Available commands:')
        commands = []
        for func in dir(actions):
            if func.startswith('cmd_'):
                #s.message(func[4:], indent=4)
                commands.append(func[4:])
        commands.sort()
        s.columns_v(commands)

        if wizard.verify(s.player):
            s.message('')
            s.message('Use @help for wizard commands')
        if admin.verify(s.player):
            s.message('')
            s.message('Use !help for admin commands')

    else:
        func_name = 'cmd_%s' % topic
        func = getattr(actions, func_name, None)
        if func is not None:
            doc = func.__doc__
            if doc is not None:
                msg = 'Help on %s:' % topic
                s.message(msg)
                s.message()
                msg = doc.split('\n')
                msg.insert(0, 'Syntax:')
                msg[1] = '        ' + msg[1]
                s.mlmessage(msg)
                return

        msg = 'Sorry. No help available on that subject.'
        s.message(msg)
Exemple #3
0
    def lineReceived(self, line):
        '''Called each time a new line of input is received from the client.

        Except for "login" and "create", if the player is logged in,
            the line is sent to the parser, then dispatched to the
            proper command section if possible.

        Each line received begins a new database transaction, and
            only if the entire command runs without errors will the
            transaction be committed. Any problems will result in a
            rollback so that the database will always be consistent.

        '''

        try:
            line = line.decode('utf-8')
        except UnicodeDecodeError:
            print 'Cannot decode as utf-8'

        line = line.strip()
        #print "received", repr(line)
        if not line:
            return

        try:
            if not self.logged_in and line=='quit':
                self.transport.loseConnection()
            elif not self.logged_in and line.startswith('login '):
                self.login(line[6:])

            elif not self.logged_in and line.startswith('create '):
                self.create(line[7:])

            elif not self.logged_in and line.startswith('purge '):
                self.purge(line[6:])

            elif not self.logged_in:
                self.simessage('Must log in with "login <name> <password>"')

            elif self.room is None:
                # log in not complete yet. Try waiting a bit and sending
                #   this command through again later.
                reactor.callLater(0.6, self.lineReceived, line)
                return

            else:
                t = time.time()
                self.player.active = t
                #print 'player active at ', time.ctime(t)

                # normal command dispatch
                section = actions

                speechmode = self.player.user_settings.get('speech',
                                                    conf.speechmode_default)

                cmd = '##nocmd'
                rest = ''
                firstchar = line[0]
                if firstchar=='!' or (speechmode and line.startswith('.!')):
                    if admin.verify(self.player):
                        section = admin
                        if firstchar=='!':
                            line = line[1:]
                        else:
                            line = line[2:]
                    else:
                        self.message('Admin only.')
                        return

                else:
                    if speechmode and firstchar != '@':
                        if firstchar == '.':
                            line = line[1:]
                        else:
                            line = "say " + line

                    try:
                        result = parse.full_parser.parseString(line)
                    except parse.ParseException:
                        cmd = '##parseproblem'
                    else:
                        cmd = result.asDict().get('verb', '##noverb')
                        section = globals()[result['section']]

                        if section==wizard and not wizard.verify(self.player):
                            self.message('Wizards only.')
                            return

                        rest = result.asDict()
                        #print 'rest', rest

                if cmd == '##nocmd':
                    parts = line.split()
                    cmd = parts[0]
                    rest = ' '.join(parts[1:])

                self.dispatch(section, cmd, rest)

        except Exception, e:
            abort()
            print 'lineReceived ABORTING TRANSACTION'
            if conf.debug:
                self.simessage('Debug')
                self.simlmessage(e)
                import traceback
                print traceback.format_exc()
            try:
                if self.logged_in:
                    if self.room.tzid != self.player._rid:
                        print 'WARNING: Room mismatch. Trying to correct.'
                        room = tzindex.get(self.player._rid)
                        if self.player not in room.players():
                            room.addplayer(self.player)
                        self.player._rid = room.tzid
                        self.room = room
            except:
                print 'Cannot recover from error.'
                raise