diff --git a/game/gamesrc/parents/examples/red_button.py b/game/gamesrc/parents/examples/red_button.py index c4977ff805..30080294da 100644 --- a/game/gamesrc/parents/examples/red_button.py +++ b/game/gamesrc/parents/examples/red_button.py @@ -1,25 +1,27 @@ """ An example script parent for a """ -from src.cmdtable import CommandTable from game.gamesrc.parents.base.basicobject import BasicObject -COMMAND_TABLE = CommandTable() def cmd_push_button(command): """ An example command to show how the pluggable command system works. """ # By building one big string and passing it at once, we cut down on a lot # of emit_to() calls, which is generally a good idea. - retval = "Test" + retval = "You have pushed the button on: %s" % (command.scripted_obj.get_name()) command.source_object.emit_to(retval) -# Add the command to the object's command table. -COMMAND_TABLE.add_command("push button", cmd_push_button) class RedButton(BasicObject): - def __init__(self, source_obj, *args, **kwargs): - super(RedButton, self).__init__(source_obj, args, kwargs) - self.command_table = COMMAND_TABLE + def __init__(self, scripted_obj, *args, **kwargs): + """ + + """ + # Calling the super classes __init__ is critical! Never forget to do + # this or everything else from here on out will fail. + super(RedButton, self).__init__(scripted_obj, args, kwargs) + # Add the command to the object's command table. + self.command_table.add_command("pushbutton", cmd_push_button) def class_factory(source_obj): """ diff --git a/src/cmdhandler.py b/src/cmdhandler.py index 5d864129fa..f7f0cee619 100755 --- a/src/cmdhandler.py +++ b/src/cmdhandler.py @@ -262,7 +262,7 @@ def match_channel(command): command.command_string = "@cemit" command.command_switches = ["sendername", "quiet"] command.command_argument = second_arg - + def command_table_lookup(command, command_table, eval_perms=True): """ Performs a command table lookup on the specified command table. Also @@ -279,6 +279,25 @@ def command_table_lookup(command, command_table, eval_perms=True): # If flow reaches this point, user has perms and command is ready. command.command_function = cmdtuple[0] command.extra_vars = cmdtuple[2] + return True + +def match_neighbor_ctables(command): + """ + Looks through the command tables of neighboring objects for command + matches. + """ + source_object = command.source_object + if source_object.location != None: + neighbors = source_object.location.get_contents() + for neighbor in neighbors: + if command_table_lookup(command, + neighbor.scriptlink.command_table): + # If there was a command match, set the scripted_obj attribute + # for the script parent to pick up. + command.scripted_obj = neighbor + return True + # No matches + return False def handle(command): """ @@ -308,8 +327,10 @@ def handle(command): match_channel(command) # See if the user is trying to traverse an exit. match_exits(command) - # Retrieve the appropriate (if any) command function. - command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE) + neighbor_match_found = match_neighbor_ctables(command) + if not neighbor_match_found: + # Retrieve the appropriate (if any) command function. + command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE) """ By this point, we assume that the user has entered a command and not diff --git a/src/config_defaults.py b/src/config_defaults.py index 463ac7fc45..752e0326b1 100644 --- a/src/config_defaults.py +++ b/src/config_defaults.py @@ -82,6 +82,8 @@ You'll want to change the values below to reflect what you entered. """ # Make sure this is True in your settings.py. IMC2_ENABLED = False +# While True, emit additional debugging info. +IMC2_DEBUG = False # The hostname/ip address of your IMC2 server of choice. IMC2_SERVER_ADDRESS = None # The port to connect to on your IMC2 server. diff --git a/src/imc2/connection.py b/src/imc2/connection.py index 868b612ca6..9eba9c6a3c 100644 --- a/src/imc2/connection.py +++ b/src/imc2/connection.py @@ -121,10 +121,10 @@ class IMC2Protocol(StatefulTelnetProtocol): if not self.is_authenticated: self._parse_auth_response(line) else: - if 'is-alive' not in line: + if settings.IMC2_DEBUG and 'is-alive' not in line: logger.log_infomsg("PACKET: %s" % line) packet = IMC2Packet(packet_str = line) - if packet.packet_type not in ['is-alive', 'keepalive-request']: + if settings.IMC2_DEBUG and packet.packet_type not in ['is-alive', 'keepalive-request']: logger.log_infomsg(packet) if packet.packet_type == 'is-alive': IMC2_MUDLIST.update_mud_from_packet(packet) diff --git a/src/script_parents/basicobject.py b/src/script_parents/basicobject.py index 5a3c53cc82..558ceae683 100644 --- a/src/script_parents/basicobject.py +++ b/src/script_parents/basicobject.py @@ -7,6 +7,7 @@ NOTE: This file should NOT be directly modified. Sub-class the BasicObject class in game/gamesrc/parents/base/basicobject.py and change the SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class. """ +from src.cmdtable import CommandTable from src.ansi import ANSITable class EvenniaBasicObject(object): @@ -25,6 +26,7 @@ class EvenniaBasicObject(object): scripted_obj: (Object) A reference to the object being scripted (the child). """ self.scripted_obj = scripted_obj + self.command_table = CommandTable() def at_object_creation(self): """