Beispiel #1
0
    def __init__(self, name, password):
        """
        Create a brand-new player and add it to the database.

        Args:
            name: The player's name.
            password: The player's password, in plaintext, to be discarded
                forever after this method call.
        """
        Object.__init__(self, name, location=get(0), owner=self)
        with locks.authority_of(locks.SYSTEM):
            self.type = 'player'
            self.lock_attr("name", set_lock=locks.Fail())
            self.lock_attr("owner", set_lock=locks.Fail())
            self.password = self.hash(password)
            self.textwrapper = textwrap.TextWrapper()
            # Initialize the mode stack empty, but enter_mode() must be called
            # before any input is handled.
            self.mode_stack = []
            self.lock_attr("mode_stack", set_lock=locks.Owns(self))
            self.last_told = None
        with locks.authority_of(self):
            self.locks.take = locks.Fail()
            self.locks.destroy = locks.Fail()
            # While we're under development, let's assume everybody wants debug
            # information.
            self.debug = True
            # Until there's a command to join a channel, do it automatically.
            channels._channels['Public'].join(self)
Beispiel #2
0
 def __init__(self, name, owner=None):
     super(Room, self).__init__(name, None, owner)
     self.locks.insert = locks.Pass()
     self.locks.remove = locks.Pass()
     self.locks.take = locks.Fail()
     with locks.authority_of(locks.SYSTEM):
         self.type = "room"
Beispiel #3
0
 def test_exit_permissions(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.exit = db.Exit("exit", self.lobby, self.foyer)
         self.exit.locks.go = locks.Fail()
     db.store(self.foyer)
     db.store(self.exit)
     self.assert_response("exit", "You can't go through exit.")
Beispiel #4
0
    def test_move_get_drop_container(self):
        with locks.authority_of(locks.SYSTEM):
            magician = db.Object("magician")
            rabbit = db.Object("stubborn rabbit")
        db.store(magician)
        db.store(rabbit)

        with locks.authority_of(rabbit):
            rabbit.locks.take = locks.Fail()
            rabbit.locks.drop = locks.Fail()
            rabbit.locks.insert = locks.Is(magician)

        with locks.authority_of(magician):
            carrot = db.Object("carrot", magician)
            celery = db.Object("celery", magician)
            hat = db.Container("hat", magician)
            db.store(carrot)
            db.store(celery)
            db.store(hat)

            try:
                rabbit.location = magician
            except locks.LockFailedError as e:
                self.assertEqual(str(e), "You cannot take stubborn rabbit.")
            else:
                self.fail()

            carrot.location = rabbit
            with locks.authority_of(rabbit):
                rabbit.locks.take = locks.Is(magician)
            rabbit.location = magician

            try:
                rabbit.location = hat
            except locks.LockFailedError as e:
                self.assertEqual(str(e), "You cannot drop stubborn rabbit.")
            else:
                self.fail()

            celery.location = rabbit
            with locks.authority_of(rabbit):
                rabbit.locks.drop = locks.Is(magician)
            rabbit.location = hat

            rabbit.location = magician
Beispiel #5
0
 def __getattribute__(self, attr):
     """
     If the lock is defined, return it. If it's not defined, return a
     failing lock. This might be inconvenient behavior in some situations,
     but it beats having to handle an AttributeError every time we check a
     lock.
     """
     try:
         return super(Locks, self).__getattribute__(attr)
     except AttributeError:
         return locks.Fail()
Beispiel #6
0
    def __init__(self, name, location=None, owner=None):
        """
        Create a brand-new object and add it to the database.

        Args: name, location (default None), owner (defaults to current
        authority) as described in the class docstring
        """
        lock = locks.AttributeLock(locks.SYSTEM, locks.Fail(), locks.Fail())
        super(Object, self).__setattr__("attr_locks", {"attr_locks": lock})

        if owner is not None:
            owner_ = owner
        else:
            if locks.authority() is not None:
                owner_ = locks.authority()
            else:
                raise locks.MissingAuthorityError("Object created with no "
                                                  "owner and no authority.")

        with locks.authority_of(locks.SYSTEM):
            self.uid = None  # This will be assigned when we call store()
            self.type = 'thing'
            self.owner = owner_
            self.name = name
            self.lock_attr("name", set_lock=locks.Owns(self))
            self.lock_attr("owner", set_lock=locks.Owns(self))
            self.locks = Locks()
            self.lock_attr("locks", set_lock=locks.Fail())
            self._location = None

        with locks.authority_of(self.owner):
            self.description = "You see nothing special."
            self.locks.take = locks.Pass()
            self.locks.drop = locks.Pass()
            self.locks.insert = locks.Is(self)
            self.locks.remove = locks.Is(self)
            self.locks.destroy = locks.Owns(self)
            if location:
                self.location = location
Beispiel #7
0
    def test_or(self):
        true = locks.Pass()
        false = locks.Fail()

        self.assertTrue(locks.Or(true)(self.player))
        self.assertFalse(locks.Or(false)(self.player))

        self.assertTrue(locks.Or(true, true)(self.player))
        self.assertTrue(locks.Or(true, false)(self.player))
        self.assertTrue(locks.Or(false, true)(self.player))
        self.assertFalse(locks.Or(false, false)(self.player))

        self.assertTrue(locks.Or(false, false, true)(self.player))
        self.assertFalse(locks.Or(false, false, false)(self.player))
Beispiel #8
0
 def test_not(self):
     self.assertFalse(locks.Not(locks.Pass())(self.player))
     self.assertTrue(locks.Not(locks.Fail())(self.player))
Beispiel #9
0
 def test_fail(self):
     lock = locks.Fail()
     self.assertFalse(lock(self.player))
     self.assertFalse(lock(self.player2))
Beispiel #10
0
 def test_put_fail_insert(self):
     self.objects["Bucket"].locks.insert = locks.Fail()
     self.assert_response("put cherry in bucket",
                          "You can't put that in Bucket.")
Beispiel #11
0
 def test_put_fail_drop(self):
     self.objects["cherry"].locks.drop = locks.Fail()
     self.assert_response("put cherry in bucket", "You cannot drop cherry.")