ch.send(ch.see_as(obj) + " is not a container.") elif obj.container_is_closed: ch.send(ch.see_as(obj) + " is already closed.") elif not obj.container_is_closable: ch.send(ch.see_as(obj) + " cannot be closed.") else: mud.message(ch, None, obj, None, True, "to_char", "You close $o.") mud.message(ch, None, obj, None, True, "to_room", "$n closes $o.") obj.container_is_closed = True hooks.run("close_obj", hooks.build_info("ch obj", (ch, obj))) ################################################################################ # load all of our commands ################################################################################ mudsys.add_cmd("give", None, cmd_give, "player", True) mudsys.add_cmd("get", None, cmd_get, "player", True) mudsys.add_cmd("drop", None, cmd_drop, "player", True) mudsys.add_cmd("remove", None, cmd_remove, "player", True) mudsys.add_cmd("wear", None, cmd_wear, "player", True) mudsys.add_cmd("put", None, cmd_put, "player", True) mudsys.add_cmd("open", None, cmd_open, "player", True) mudsys.add_cmd("close", None, cmd_close, "player", True) mudsys.add_cmd("lock", None, cmd_lock, "player", True) mudsys.add_cmd("unlock", None, cmd_unlock, "player", True) def chk_can_manip(ch, cmd): if not ch.pos in ["sitting", "standing", "flying"]: ch.send("You cannot do that while " + ch.pos + ".") return False
def new_prompt(sock): '''this prompt will be used to override the default NM prompt''' sock.send_raw("\r\nnew prompt> ") def example_prompt(sock): '''used as an example of how to interact with the input handler stack''' sock.send_raw("\r\nexample prompt> ") def example_handler(sock, arg): '''used as an example of how to interact with the input handler stack''' if arg.upper() == 'Q': sock.pop_ih() else: sock.send("You typed " + arg + ". Q to quit.") def cmd_pyih(ch, cmd, arg): '''used as an example of how to interact with the input handler stack''' ch.socket.push_ih(example_handler, example_prompt) ch.send("New input handler set.") # add the command that allows us to interact with the input handler stack mudsys.add_cmd("pyih", None, cmd_pyih, "admin", False) # override our default prompt with a new one mudsys.show_prompt = new_prompt
import mud, mudsock, mudsys def finish_desc_editor(sock, editor_output): '''this function is passed to edit_text, and called after a socket exits the text editor.''' # make sure our character has not somehow vanished. # If it is still around, change its description to the output of the editor if sock.ch != None: sock.ch.desc = editor_output def cmd_describe(ch, cmd, arg): '''Allows a character to set his or her own description.''' # first, make sure we have a socket. The text editor pushes an input # handler onto the socket's stack. Thus, the socket needs to exist. if ch.sock != None: ch.sock.edit_text(ch.desc, finish_desc_editor) # add the 'describe' command to the game mudsys.add_cmd("describe", None, cmd_describe, "player", True)
# return the exit we found (if we found any) return ex, success def cmd_move(ch, cmd, arg): '''A basic movement command, relocating you to another room in the specified direction.''' # cmd_move is the basic entry to all of the movement utilities. # See try_move() in movement.py try_move_mssg(ch, cmd) ################################################################################ # mud commands ################################################################################ mudsys.add_cmd("north", "n", cmd_move, "player", True) mudsys.add_cmd("west", "w", cmd_move, "player", True) mudsys.add_cmd("east", "e", cmd_move, "player", True) mudsys.add_cmd("south", "s", cmd_move, "player", True) mudsys.add_cmd("up", "u", cmd_move, "player", True) mudsys.add_cmd("down", "d", cmd_move, "player", True) mudsys.add_cmd("northwest", None, cmd_move, "player", True) mudsys.add_cmd("northeast", None, cmd_move, "player", True) mudsys.add_cmd("southwest", None, cmd_move, "player", True) mudsys.add_cmd("southeast", None, cmd_move, "player", True) mudsys.add_cmd("nw", None, cmd_move, "player", True) mudsys.add_cmd("ne", None, cmd_move, "player", True) mudsys.add_cmd("sw", None, cmd_move, "player", True) mudsys.add_cmd("se", None, cmd_move, "player", True) mudsys.add_cmd("wake", None, cmd_wake, "player", True)
try: uid, = mud.parse_args(ch, True, cmd, arg, "int(uid)") except: return for sock in mudsock.socket_list(): if sock.uid == uid: ch.send("You disconnect socket %d." % uid) sock.close() break ################################################################################ # add our commands ################################################################################ mudsys.add_cmd("shutdow", None, cmd_shutdown_net, "admin", False) mudsys.add_cmd("shutdown", None, cmd_shutdown, "admin", False) mudsys.add_cmd("copyove", None, cmd_copyover_net, "admin", False) mudsys.add_cmd("copyover", None, cmd_copyover, "admin", False) mudsys.add_cmd("at", None, cmd_at, "wizard", False) mudsys.add_cmd("lockdown", None, cmd_lockdown, "admin", False) mudsys.add_cmd("pulserate", None, cmd_pulserate, "admin", False) mudsys.add_cmd("repeat", None, cmd_repeat, "wizard", False) mudsys.add_cmd("force", None, cmd_force, "wizard", False) mudsys.add_cmd("goto", None, cmd_goto, "wizard", False) mudsys.add_cmd("transfer", None, cmd_transfer, "wizard", False) mudsys.add_cmd("eval", None, cmd_eval, "admin", False) mudsys.add_cmd("exec", None, cmd_exec, "admin", False) mudsys.add_cmd("connections", None, cmd_connections, "admin", False) mudsys.add_cmd("disconnect", None, cmd_disconnect, "admin", False) mudsys.add_cmd("instance", None, cmd_instance, "admin", False)
################################################################################ # commands ################################################################################ def cmd_history(ch, cmd, arg): '''Communication logs are stored as you receive communication. To review communication you have used, you can use the history command.''' arg = arg.lower() if arg == "": opts = comm_table.keys() opts.sort() ch.send("History logs available to you are:") ch.send(" " + ", ".join(opts)) elif not arg in comm_table: ch.send("There is no history log for that type of communication.") else: group_func, table = comm_table[arg] key = group_func(ch) if not key in table: ch.send("Your history is empty.") else: ch.page("\r\n".join(table[key]) + "\r\n") ################################################################################ # initialization ################################################################################ mudsys.add_cmd("history", None, cmd_history, "player", False)
tgt, routine, repeat = mud.parse_args(ch, True, cmd, arg, "ch.room.noself word(py_list) | bool(repeat)") except: return set_routine(tgt, eval(routine), repeat) ch.send("Routine set.") ################################################################################ # initialization ################################################################################ # auxiliary data auxiliary.install("routine_data", RoutineAuxData, "character") # base check. Don't do a routine if we're currently doing an action register_routine_check(lambda ch: ch.isActing()) # commands mudsys.add_cmd("routine", None, cmd_routine, "admin", False) # misc initialization # mud.set_routine = set_routine # # now use: ch.set_routine(routine) # instead of: mud.set_routine(ch, routine) # mudsys.add_char_method("set_routine", set_routine)
sound on their computer to get their attention. Page can be used on anyone in the mud, regardless if you are in the same room as them or not. ''' try: tgt, mssg = mud.parse_args(ch, True, cmd, arg, "ch.world.noself string(message)") except: return ch.send("\007\007You page " + ch.see_as(tgt)) tgt.send("\007\007*" + tgt.see_as(ch) + "* " + mssg) ################################################################################ # add our commands ################################################################################ mudsys.add_cmd("ask", None, cmd_ask, "player", False) mudsys.add_cmd("say", None, cmd_say, "player", False) mudsys.add_cmd("'", None, cmd_say, "player", False) mudsys.add_cmd("tell", None, cmd_tell, "player", False) mudsys.add_cmd("chat", None, cmd_chat, "player", False) mudsys.add_cmd("wizchat", "wiz",cmd_wiz, "wizard", False) mudsys.add_cmd("gossip", None, cmd_chat, "player", False) mudsys.add_cmd("\"", None, cmd_chat, "player", False) mudsys.add_cmd("page", None, cmd_page, "player", False) mudsys.add_cmd("greet", None, cmd_greet, "player", False) mudsys.add_cmd("approach",None, cmd_greet, "player", False) mudsys.add_cmd("emote", None, cmd_emote, "player", False) mudsys.add_cmd("gemote", None, cmd_gemote,"player", False) mudsys.add_cmd(":", None, cmd_emote, "player", False) def chk_room_communication(ch, cmd):
well as how the default prompt can be overwritten in Python. ''' import mud, mudsys, socket def new_prompt(sock): '''this prompt will be used to override the default NM prompt''' sock.send_raw("\r\nnew prompt> ") def example_prompt(sock): '''used as an example of how to interact with the input handler stack''' sock.send_raw("\r\nexample prompt> ") def example_handler(sock, arg): '''used as an example of how to interact with the input handler stack''' if arg.upper() == 'Q': sock.pop_ih() else: sock.send("You typed " + arg + ". Q to quit.") def cmd_pyih(ch, cmd, arg): '''used as an example of how to interact with the input handler stack''' ch.socket.push_ih(example_handler, example_prompt) ch.send("New input handler set.") # add the command that allows us to interact with the input handler stack mudsys.add_cmd("pyih", None, cmd_pyih, "admin", False) # override our default prompt with a new one mudsys.show_prompt = new_prompt
try: tgt, routine, repeat = mud.parse_args( ch, True, cmd, arg, "ch.room.noself word(py_list) | bool(repeat)") except: return set_routine(tgt, eval(routine), repeat) ch.send("Routine set.") ################################################################################ # initialization ################################################################################ # auxiliary data auxiliary.install("routine_data", RoutineAuxData, "character") # base check. Don't do a routine if we're currently doing an action register_routine_check(lambda ch: ch.isActing()) # commands mudsys.add_cmd("routine", None, cmd_routine, "admin", False) # misc initialization # mud.set_routine = set_routine # # now use: ch.set_routine(routine) # instead of: mud.set_routine(ch, routine) # mudsys.add_char_method("set_routine", set_routine)
success = True # return the exit we found (if we found any) return ex, success def cmd_move(ch, cmd, arg): '''A basic movement command, relocating you to another room in the specified direction.''' # cmd_move is the basic entry to all of the movement utilities. # See try_move() in movement.py try_move_mssg(ch, cmd) ################################################################################ # mud commands ################################################################################ mudsys.add_cmd("north", "n", cmd_move, "player", True) mudsys.add_cmd("west", "w", cmd_move, "player", True) mudsys.add_cmd("east", "e", cmd_move, "player", True) mudsys.add_cmd("south", "s", cmd_move, "player", True) mudsys.add_cmd("up", "u", cmd_move, "player", True) mudsys.add_cmd("down", "d", cmd_move, "player", True) mudsys.add_cmd("northwest", None, cmd_move, "player", True) mudsys.add_cmd("northeast", None, cmd_move, "player", True) mudsys.add_cmd("southwest", None, cmd_move, "player", True) mudsys.add_cmd("southeast", None, cmd_move, "player", True) mudsys.add_cmd("nw", None, cmd_move, "player", True) mudsys.add_cmd("ne", None, cmd_move, "player", True) mudsys.add_cmd("sw", None, cmd_move, "player", True) mudsys.add_cmd("se", None, cmd_move, "player", True) mudsys.add_cmd("wake", None, cmd_wake, "player", True)
elif obj.container_is_closed: ch.send(ch.see_as(obj) + " is already closed.") elif not obj.container_is_closable: ch.send(ch.see_as(obj) + " cannot be closed.") else: mud.message(ch, None, obj, None, True, "to_char", "You close $o.") mud.message(ch, None, obj, None, True, "to_room", "$n closes $o.") obj.container_is_closed = True hooks.run("close_obj", hooks.build_info("ch obj", (ch, obj))) ################################################################################ # load all of our commands ################################################################################ mudsys.add_cmd("give", None, cmd_give, "player", True) mudsys.add_cmd("get", None, cmd_get, "player", True) mudsys.add_cmd("drop", None, cmd_drop, "player", True) mudsys.add_cmd("remove", None, cmd_remove, "player", True) mudsys.add_cmd("wear", None, cmd_wear, "player", True) mudsys.add_cmd("put", None, cmd_put, "player", True) mudsys.add_cmd("open", None, cmd_open, "player", True) mudsys.add_cmd("close", None, cmd_close, "player", True) mudsys.add_cmd("lock", None, cmd_lock, "player", True) mudsys.add_cmd("unlock", None, cmd_unlock, "player", True) def chk_can_manip(ch, cmd): if not ch.pos in ["sitting", "standing", "flying"]: ch.send("You cannot do that while " + ch.pos + ".") return False
################################################################################ # commands ################################################################################ def cmd_path(ch, cmd, arg): '''Usage: path <room> Prints out a Python list of the directions needed to move from your current location to a specified destination.''' try: dest, = mud.parse_args(ch, True, cmd, arg, "room") except: return path = build_patrol([ch.room, dest]) if len(path) == 0: ch.send("Path doesn't exist") else: ch.send(str(path)) ################################################################################ # initialization ################################################################################ # add our commands mudsys.add_cmd("path", None, cmd_path, "admin", False) # mud initialization mud.build_patrol = build_patrol
# returns a storage set representation of the auxiliary data def store(self): set = storage.StorageSet() set.storeString("val", self.val) return set # allows people to peek at the value stored in their ExampleAux data def cmd_getaux(ch, cmd, arg): aux = ch.account.getAuxiliary("example_aux") ch.send("The val is " + aux.val) # allows people to set the value stored in their ExampleAux data def cmd_setaux(ch, cmd, arg): aux = ch.account.getAuxiliary("example_aux") aux.val = arg ch.send("val set to " + arg) # install our auxiliary data on characters when this module is loaded. # auxiliary data can also be installed onto rooms and objects. You can install # auxiliary data onto more than one type of thing by comma-separating them in # the third argument of this method. auxiliary.install("example_aux", ExampleAux, "account") # add in our two commands add_cmd("getaux", None, cmd_getaux, "admin", False) add_cmd("setaux", None, cmd_setaux, "admin", False)
def cmd_save(ch, cmd, arg): """Attempt to save your character and all recent changes made to it, to disk. This automatically happens when logging out.""" if mudsys.do_save(ch): ch.send("Saved.") else: ch.send("Your character was not saved.") def cmd_quit(ch, cmd, arg): """Attempts to save and log out of the game.""" mud.log_string(ch.name + " has left the game.") mudsys.do_save(ch) mudsys.do_quit(ch) ################################################################################ # add our commands ################################################################################ mudsys.add_cmd("stop", None, cmd_stop, "player", False) mudsys.add_cmd("clear", None, cmd_clear, "player", False) mudsys.add_cmd("delay", None, cmd_delay, "player", False) mudsys.add_cmd("motd", None, cmd_motd, "player", False) mudsys.add_cmd("save", None, cmd_save, "player", False) mudsys.add_cmd("quit", None, cmd_quit, "player", True) chk_can_save = lambda ch, cmd: not ch.is_npc mudsys.add_cmd_check("save", chk_can_save) mudsys.add_cmd_check("quit", chk_can_save)
specified, instead delete a key.''' try: key, val = mud.parse_args(ch, True, cmd, arg, "word(key) | string(val)") except: return # are we trying to delete a key? if val == None: if key in ch.aux("example_aux").pairs: del ch.aux("example_aux").pairs[key] ch.send("Key deleted.") else: ch.aux("example_aux").pairs[key] = val ch.send("Key '%s' set to '%s'." % (key, val)) ################################################################################ # initialization ################################################################################ # install our auxiliary data on characters when this module is loaded. # auxiliary data can also be installed onto rooms and objects. You can install # auxiliary data onto more than one type of thing by comma-separating them in # the third argument of this method. auxiliary.install("example_aux", ExampleAux, "character") # add in our two commands mudsys.add_cmd("getaux", None, cmd_getaux, "admin", False) mudsys.add_cmd("setaux", None, cmd_setaux, "admin", False)
> doc char.Char Will return all available documentation for the Char class. """ if arg == "": ch.page("\r\n".join(display.pagedlist({ "Topics" : suggested_reading }, header = "Suggested doc readings include:"))) else: # just because sometimes I forget periods arg = arg.replace(" ", ".") # are we looking for a shortcut value? if arg in shortcuts: arg = shortcuts[arg] # try to find what we're documenting todoc = pydoc.locate(arg) if todoc == None: ch.send("Could not find Python documentation on: '%s'" % arg) else: doc = pydoc.TextDoc() ch.page(doc.document(todoc).replace("{", "{{")) ################################################################################ # initialization ################################################################################ mudsys.add_cmd("doc", None, cmd_doc, "wizard", False) mudsys.add_cmd("htmldoc", None, cmd_htmldoc, "admin", False)
def cmd_save(ch, cmd, arg): '''Attempt to save your character and all recent changes made to it, to disk. This automatically happens when logging out.''' if mudsys.do_save(ch): ch.send("Saved.") else: ch.send("Your character was not saved.") def cmd_quit(ch, cmd, arg): '''Attempts to save and log out of the game.''' mud.log_string(ch.name + " has left the game.") mudsys.do_save(ch) mudsys.do_quit(ch) ################################################################################ # add our commands ################################################################################ mudsys.add_cmd("stop", None, cmd_stop, "player", False) mudsys.add_cmd("clear", None, cmd_clear, "player", False) mudsys.add_cmd("delay", None, cmd_delay, "player", False) mudsys.add_cmd("motd", None, cmd_motd, "player", False) mudsys.add_cmd("save", None, cmd_save, "player", False) mudsys.add_cmd("quit", None, cmd_quit, "player", True) chk_can_save = lambda ch, cmd: not ch.is_npc mudsys.add_cmd_check("save", chk_can_save) mudsys.add_cmd_check("quit", chk_can_save)
found, type = mud.generic_find(ch, arg, "all", "immediate", False) # what did we find? if found == None: ch.send("What did you want to look at?") elif type == "obj" or type == "in": inform.look_at_obj(ch, found) elif type == "char": inform.look_at_char(ch, found) elif type == "exit": inform.look_at_exit(ch, found) # extra descriptions as well ############ # FINISH ME ############ ################################################################################ # add our commands ################################################################################ mudsys.add_cmd("inventory", "i", cmd_inventory, "player", False) mudsys.add_cmd("equipment", "eq", cmd_equipment, "player", False) mudsys.add_cmd("worn", None, cmd_equipment, "player", False) mudsys.add_cmd("who", None, cmd_who, "player", False) ''' mudsys.add_cmd("look", "l", cmd_look, "player", False) '''