Example #1
0
def cmd_destroy(s, r):
    '''destroy <object>

    Destroy the specified object.

    '''

    objname = r.get('objname', '')
    objtzid = r.get('objtzid', 0)
    if not objname and not objtzid:
        s.message('Try: @destroy <object>')
        raise SyntaxError

    player = s.player
    room = s.room
    obj = find(r, room, player)
    if obj is None:
        obj = rooms.getname(objname) or \
                rooms.get(objtzid) or \
                tzindex.get(objtzid)

    if obj is not None:
        s.message('You speak a word of power and ...')
        s.room.action(dict(act="destroy", actor=player))
        obj.destroy()

    else:
        s.message('Object not found.')
Example #2
0
    def move(self, destination):
        'Remove the mob from its current room, and put it in the destination.'

        origin = rooms.get(self._rid)
        if origin is not None:
            origin.rmmob(self)

        destination.addmob(self)
        self._rid = destination.tzid
Example #3
0
    def move(self, room):
        '''Remove player from its current room and
            put it in the destination room.

        Any time the player changes rooms, this method should
            be used. Never change the player's room manually.

        '''

        leaving = rooms.get(self._rid)
        if leaving is not None:
            try:
                leaving.rmplayer(self)
            except ValueError:
                print 'Tried to move from', leaving, 'but failed.'

        room.addplayer(self)
        self._rid = room.tzid
        tzprotocol.TZ.playerclient(self).room = room
Example #4
0
def upgrade(from_version, to_version):
    from share import upgrade
    if from_version==0 and to_version==1:
        from db import TZDict
        dbroot['exits'] = TZDict()
        commit()

        all_exits = []
        import rooms
        for room in rooms.ls():
            all_exits.extend(room.exits())

        for x in all_exits:
            print 'upgrading', x
            updated = upgrade(x, Exit)
            updated.destination = rooms.get(updated._destid)
            add(updated)

        commit()
Example #5
0
def _clone_room(s, objname, objtzid, newname=''):
    # next, try to clone a room
    # first look at existing rooms
    orig = rooms.getname(objname) or \
            rooms.get(objtzid)

    # if it is not there, it might be a Room class
    if orig is None:
        if objname in rooms.classes():
            cls = getattr(rooms, objname)
            obj = cls()
        else:
            obj = None
    else:
        obj = copy.copy(orig)

    if obj:
        if newname:
            obj.name = newname
        s.message(obj, 'created.')
        return obj
Example #6
0
 def _get_destination(self):
     'Getter for the destination property.'
     return rooms.get(self._destid)
Example #7
0
 def _get_room(self):
     'Getter for the room property.'
     return rooms.get(self._rid)
Example #8
0
def cmd_dig(s, r):
    '''dig <exit> to <destination> [return by <exit>]

    Connect exit to room and optionally from the new room back to here.

    Destination or exits can be existing objects, or if they do not
        yet exist, they will be created.

    If the exit out name is one of the compass directions (ie north,
        south, east, northeast, etc) and no return by exit name is
        given, the return by exit will be created automatically with
        the opposite direction name. (eg. if an exit out is dug to
        the west, an exit in will also be added to the east from
        the destination.)

    '''

    room = s.room

    destname = r.get('destname', '')
    desttzid = r.get('desttzid', 0)
    if not destname and not desttzid:
        s.message('Try: @dig <exit> to <destination>')
        raise SyntaxError
    destination = rooms.getname(destname) or rooms.get(desttzid)

    if destination is None and destname:
        destination = rooms.Room(destname)
        s.message(destination, 'created.')
    elif destination is None:
        s.message('#', desttzid, 'is not a room.')
        return

    exitoutname = r.get('exitoutname', '')
    exitouttzid = r.get('exitouttzid', 0)
    xo = room.exitname(exitoutname) or room.exit(exitouttzid)

    exitinname = r.get('exitinname', '')
    exitintzid = r.get('exitintzid', 0)
    if not exitinname and not exitintzid and xo is not None:
        exitinname = xo.autoreturn()

    xi = destination.exitname(exitinname) or destination.exit(exitintzid)
    if xi is not None:
        exitinname = xi.name

    if xo is not None:
        xo.destination = destination
        if xi is not None:
            xi.destination = room
        else:
            exitinname = exitinname or 'door'
            xi = exits.Exit(exitinname, room=destination, destination=room)
            xo.link(xi)
            destination.action(dict(act='dig', actor=None, exit=xi))
        s.message('You connect', xo, 'to', destination, '.')

    elif exitoutname:
        if exitinname or xi is None:
            xo = exits.Exit(exitoutname, room=room, destination=destination, return_name=exitinname)
            room.action(dict(act='dig', actor=s.player, exit=xo))
            xi = xo.get_linked_exit()
            if xi is None:
                exitinname = 'door'
                xi = exits.Exit(exitinname, room=destination, destination=room)
            destination.action(dict(act='dig', actor=None, exit=xi))
            s.message('You dig', xo, 'to', destination, '.')
        else:
            s.message('#', exitintzid, 'is not an exit in', destination, '.')
            raise TypeError

    else:
        s.message('#', exitouttzid, 'is not an exit in this room.')
Example #9
0
def cmd_teleport(s, r=None):
    '''teleport [to [<room>|<character>]] OR teleport <object> to <room>

    Teleport self to the named room or character, or if no name is given
        teleport self to home, OR

    Teleport the object to the room.

    '''

    room = s.room
    player = s.player
    if room is not None:
        room.action(dict(act='teleport', actor=player))

    objname = r.get('objname', '')
    objtzid = r.get('objtzid', 0)

    destname = r.get('obj2name', '')
    desttzid = r.get('obj2tzid', 0)

    if (objname or objtzid) and (destname or desttzid):
        destination = rooms.getname(destname) or rooms.get(desttzid)
        if destination is None:
            s.message('No such place.')
            return

        obj = find(r, room, player, room) or \
                players.getname(objname) or players.get(objtzid) or \
                mobs.getname(objname) or mobs.get(objtzid) or \
                tzindex.get(objtzid)
        if obj is None:
            s.message('No such object.')
        elif obj._bse == 'Room':
            s.message('You cannot teleport a room.')
        else:
            obj.teleport(destination)
            s.message('You teleport', obj, '.')

    elif not (destname or desttzid):
        # send the player home
        player.teleport()

    else:
        destination = rooms.getname(destname) or \
                        rooms.get(desttzid)

        if destination is None:
            toplayer = players.getname(destname) or \
                        players.get(desttzid)

            if toplayer is not None:
                destination = toplayer.room
                if destination is None:
                    s.message('Player is not logged in.')
                    return
            else:
                tomob = mobs.getname(destname) or \
                        mobs.get(desttzid)

                if tomob is not None:
                    destination = tomob.room
                else:
                    s.message('No such room or character.')
                    return

        player.teleport(destination)
Example #10
0
s.listen(5)

checkOnline = Thread(target=online, args=[])
checkOnline.start()

while True:
    conn, addr = s.accept()
    data = decrypt(conn.recv(1024))
    data = json.loads(data)
    print('new connection ', data, ' ', addr)

    if data['action'] == 'newroom':
        if rooms.exists(data['room']):
            conn.send(encrypt('False'))
        else:
            rooms.add(data['room'], addr[0])
            conn.send(encrypt('True'))

    elif data['action'] == 'joinroom':
        if rooms.exists(data['room']):
            conn.send(encrypt(rooms.get(data['room'])))
        else:
            conn.send(encrypt('0.0.0.0'))

    elif data['action'] == 'close':
        rooms.remove(data['room'], addr[0])

    conn.close()

# this module is functional
# implement online function