def execute(self, player, args): type_name = args["type"] object_name = args["name"] try: mod_name, class_name = type_name.rsplit(".", 1) except ValueError: raise utils.UserError("Object type should be of the form " "module.Class") try: module = importlib.import_module(mod_name) object_class = getattr(module, class_name) except ImportError: raise utils.UserError("I don't know of this module: " "{}".format(mod_name)) except AttributeError: raise utils.UserError("{} doesn't have this class: " "{}".format(mod_name, class_name)) if db.Room in object_class.mro(): raise utils.UserError( 'Use "dig", not "create", to make new rooms.') if db.Exit in object_class.mro(): raise utils.UserError('Use "open", not "create", to make new ' 'exits.') new_item = object_class(object_name, owner=player, location=player) db.store(new_item) player.send("Created item #{}, {}.".format(new_item.uid, new_item.name))
def execute(self, player, args): # ... but the tradeoff is we have to do the validity checking down here. obj_grammar = parser.ReachableOrUid(player) attr_grammar = pyp.Word(pyp.alphas + "_", pyp.alphanums + "_") try: obj = obj_grammar.parseString(args["obj"], parseAll=True)[0] except pyp.ParseException: name = args["obj"].strip() raise utils.UserError( "I don't know what object you mean by '{}'".format(name)) try: attr = attr_grammar.parseString(args["attr"], parseAll=True)[0] except pyp.ParseException: name = args["attr"].strip() raise utils.UserError( "'{}' is not a valid attribute name.".format(name)) value_string = args["value"].strip() if value_string.isdigit(): value = int(args["value"]) elif value_string == "True": value = True elif value_string == "False": value = False elif value_string == "None": value = None else: try: pattern = parser.PythonQuoted value = pattern.parseString(args["value"], parseAll=True)[0] value = value.decode("string-escape") except pyp.ParseException: try: pattern = parser.ReachableOrUid(player) value = pattern.parseString(args["value"], parseAll=True)[0] except pyp.ParseException: # okay, I give up raise utils.UserError( "'{}' is not a valid attribute value.".format( args["value"].strip())) name = obj.name # In case it changes, so we can report the old one try: setattr(obj, attr, value) except ValueError as e: raise utils.UserError(str(e)) db.store(obj) player.send("Set {}'s {} attribute to {}".format(name, attr, value))
def execute(self, player, args): if locks.authority() is not locks.SYSTEM: # When user code is implemented, this will create an untrusted REPL # under the player's authority. raise utils.UserError("Not yet implemented: for now, sudo is " "required.") player.send("***********") player.send("* WARNING *") player.send("***********") player.send("") player.send("You are working interactively with the actual Python " "process running the game. Careless actions here can " "really permanently foul up important things.") player.send("") def check_password(line): if player.hash(line) == player.password: with locks.authority_of(locks.SYSTEM): player.enter_mode(PythonMode(player)) else: player.send("Incorrect.") d = handler.prompt(player, "To proceed, enter your password:") d.addCallback(check_password)
def execute(self, player, args): obj_grammar = parser.ReachableOrUid(player) try: obj = obj_grammar.parseString(args["obj"], parseAll=True)[0] except pyp.ParseException: raise utils.UserError( "I don't know what object you mean by '{}'".format( args["obj"].strip())) attr = args["attr"].strip() try: delattr(obj, attr) player.send("Unset {} attribute on {}.".format(attr, obj)) except AttributeError as e: raise utils.UserError("{} doesn't have an attribute '{}'".format( obj, attr))
def execute(self, player, args): item = args["item"] try: item.unequip() except AttributeError: raise utils.UserError("That is not equipment!") player.send("You unequip {}.".format(item.name)) player.emit("{} unequips {}.".format(player.name, item.name), exceptions=[player])
def execute(self, player, args): item = args.get("item") if item: try: item.equip() except AttributeError: raise utils.UserError("That is not equipment!") player.send("You equip {}.".format(item.name)) player.emit("{} equips {}.".format(player.name, item.name), exceptions=[player]) else: equipment = player.equipment_string() if equipment: player.send(equipment) else: player.send("You have nothing equipped.")
def execute(self, player, args): item = args["item"] destination = args["destination"] if destination is player: raise utils.UserError("You already have {}.".format(item)) item.location = destination if destination.type == "player": player.send("You give {} to {}.".format(item, destination)) destination.send("{} gives you {}.".format(player, item)) player.emit("{} gives {} to {}.".format(player, item, destination), exceptions = [player, destination]) else: player.send("You put {} in {}.".format(item, destination)) player.emit("{} puts {} in {}.".format(player, item, destination), exceptions = [player])
def execute(self, player, args): item = args["item"] origin = item.location if origin is player: raise utils.UserError("You already have {}.".format(item)) try: item.location = player except equipment.EquipmentError: raise equipment.EquipmentError("You can't, it's equipped.") if origin is not player.location: player.send("You take {} from {}.".format(item.name, origin)) origin.send("{} takes {} from you.".format(player, item.name)) player.emit("{} takes {} from {}." .format(player, item.name, origin), exceptions=[player, origin]) else: player.send("You take {}.".format(item.name)) player.emit("{} takes {}.".format(player.name, item.name), exceptions=[player])
def execute(self, player, args): if 'channel' in args: channel = args['channel'] if 'text' in args: if args['text'].startswith(Emote.nospace_name): channel.pose(player, args['text'][1:]) elif args['text'].startswith(SpacelessEmote.nospace_name): channel.semipose(player, args['text'][1:]) else: channel.say(player, args['text']) else: player.enter_mode(ChatMode(channel)) player.send( "You are now chatting to {}. To get back to Normal " "Mode, type: .".format(channel)) elif (isinstance(player.mode, SayMode) or isinstance(player.mode, ChatMode)): player.exit_mode() player.send("You are now in Normal Mode.") else: raise utils.UserError("You're already in Normal Mode.")