def setUp(self): super(AttrLockTestCase, self).setUp() self.obj_owner = db.Player("Objowner", "password") db.store(self.obj_owner) self.attr_owner = db.Player("Attrowner", "password") db.store(self.attr_owner) self.setter = db.Player("Setter", "password") db.store(self.setter) self.getter = db.Player("Getter", "password") db.store(self.getter) self.players = [self.obj_owner, self.attr_owner, self.getter, self.setter] with locks.authority_of(self.obj_owner): self.obj = db.Object("Object") db.store(self.obj) with locks.authority_of(self.attr_owner): self.obj.attr = "value" self.obj.lock_attr("attr", get_lock=locks.Is(self.getter), set_lock=locks.Is(self.setter))
def setUp(self): super(LockTestCase, self).setUp() with locks.authority_of(locks.SYSTEM): self.player = db.Player("Player", "password") db.store(self.player) self.player2 = db.Player("PlayerTwo", "password") db.store(self.player2) self.obj = db.Object("object", owner=self.player) with locks.authority_of(self.player2): self.obj.foreign_attr = 0 db.store(self.obj)
def handle(self, player, line): # Just as in LoginMode, the player arg will be None since no one is # logged in. if line == 'cancel': player.exit_mode() # Drop back to LoginMode player.mode.greet() return if self.stage == 'name': if line.find(" ") > -1: self.protocol.sendLine("Please type only the username; it may " "not contain any spaces. Try again:") return if db.player_name_taken(line): self.protocol.sendLine("That name is already taken. If it's " "yours, type 'cancel' to log in. " "Otherwise, try another name:") return self.name = line self.protocol.sendLine( "Welcome, {}! Please enter a password.".format(self.name)) self.stage = 'password1' return elif self.stage == 'password1': self.password = line self.protocol.sendLine("Please enter it again.") self.stage = 'password2' return elif self.stage == 'password2': if self.password == line: player = db.Player(self.name, self.password) self.protocol.player = player db.store(player) factory.allProtocols[player.name] = self.protocol with locks.authority_of(player): player.enter_mode(handler.NormalMode()) self.protocol.sendLine("Hello, {}!".format(player.name)) self.protocol.sendLine("") from muss.commands.world import Look Look().execute(player, {"obj": player.location}) player.emit("{} has connected for the first time.".format( player.name), exceptions=[player]) return else: self.protocol.sendLine("Passwords don't match; try again. " "Please enter a password.") self.stage = 'password1' return
def test_contents_string(self): with locks.authority_of(locks.SYSTEM): room = db.Room("room") self.patch(db, '_objects', {0: room}) player = db.Player("player", "password") hat = equipment.Equipment("hat") db.store(player) db.store(hat) # not room because we already patched it in for location in [room, player]: with locks.authority_of(locks.SYSTEM): hat.equipped = False hat.location = location self.assertIn("hat", location.contents_string()) self.assertNotIn("hat", location.equipment_string()) with locks.authority_of(locks.SYSTEM): hat.equip() self.assertTrue(hat.equipped) self.assertNotIn("hat", location.contents_string()) self.assertIn("hat", location.equipment_string())
def setUp(self): super(ModeTestCase, self).setUp() self.player = db.Player("name", "password")