From c70d59045a842a48924b60d16e9c552e75deaa47 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 19 Apr 2011 21:40:53 +0000 Subject: [PATCH] Some bug fixes in the IMC system. --- src/commands/default/comms.py | 5 +---- src/comms/imc2.py | 29 +++++++++++++++-------------- src/comms/imc2lib/imc2_listeners.py | 6 ++++++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/commands/default/comms.py b/src/commands/default/comms.py index e42cabcd4a..a278fc7f25 100644 --- a/src/commands/default/comms.py +++ b/src/commands/default/comms.py @@ -990,11 +990,8 @@ class CmdIMC2Chan(MuxCommand): mudname = settings.SERVERNAME if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches: - chanmatch = find_channel(self.caller, channel, silent=True) - if chanmatch: - channel = chanmatch.key - ok = imc2.delete_connection(channel, imc2_network, imc2_port, mudname) + ok = imc2.delete_connection(imc2_network, imc2_port, mudname) if not ok: self.caller.msg("IMC2 connection could not be removed, does it exist?") else: diff --git a/src/comms/imc2.py b/src/comms/imc2.py index 12140867cc..9c763b4e13 100644 --- a/src/comms/imc2.py +++ b/src/comms/imc2.py @@ -228,17 +228,19 @@ class IMC2Protocol(telnet.StatefulTelnetProtocol): # If the packet lacks the 'echo' key, don't bother with it. if not conn_name or not packet.optional_data.get('echo', None): return - chan_name = conn_name.split(':', 1)[1] - if not chan_name in self.factory.channel: - # we are not listening to this channel. - return key = "imc2_%s" % conn_name # Look for matching IMC2 channel maps. conns = ExternalChannelConnection.objects.filter(db_external_key=self.factory.key) if not conns: return + + # get channel subscriptions + chansubs = conns[0].db_external_config.split("|")[2].split(",") + if not chan_name in chansubs: + # we are not listening to this channel. + return # Format the message to send to local channel. message = '[%s] %s@%s: %s' % (self.factory.evennia_channel, packet.sender, packet.origin, packet.optional_data.get('text')) @@ -344,7 +346,7 @@ class IMC2Factory(protocol.ClientFactory): def __init__(self, key, channel, network, port, mudname, client_pwd, server_pwd, evennia_channel): self.key = key self.mudname = mudname - self.channel = channel + self.channel = channel # this is a list! self.pretty_key = "%s:%s/%s (%s)" % (network, port, channel, mudname) self.network = network sname, host = network.split(".", 1) @@ -366,11 +368,9 @@ class IMC2Factory(protocol.ClientFactory): logger.log_errmsg('IMC2: %s' % message) -def build_connection_key(channel, imc2_network, imc2_port, imc2_mudname): +def build_connection_key(imc2_network, imc2_port, imc2_mudname): "Build an id hash for the connection" - if hasattr(channel, 'key'): - channel = channel.key - return "imc2_%s:%s(%s)<>%s" % (imc2_network, imc2_port, imc2_mudname, channel) + return "imc2_%s:%s(%s)<>Evennia" % (imc2_network, imc2_port, imc2_mudname) def build_service_key(key): return "IMC2:%s" % key @@ -397,13 +397,16 @@ def create_connection(channel, imc2_network, imc2_port, imc2_channel, imc2_mudna """ This will create a new IMC2<->channel connection. """ + + key = build_connection_key(imc2_network, imc2_port, imc2_mudname) + if not type(channel) == Channel: new_channel = Channel.objects.filter(db_key=channel) if not new_channel: logger.log_errmsg("Cannot attach IMC2<->Evennia: Evennia Channel '%s' not found" % channel) return False channel = new_channel[0] - key = build_connection_key(channel, imc2_network, imc2_port, imc2_mudname) + old_conns = ExternalChannelConnection.objects.filter(db_external_key=key) if old_conns: @@ -437,12 +440,10 @@ def create_connection(channel, imc2_network, imc2_port, imc2_channel, imc2_mudna start_scripts() return True -def delete_connection(channel, imc2_network, imc2_port, mudname): +def delete_connection(imc2_network, imc2_port, mudname): "Destroy a connection" - if hasattr(channel, 'key'): - channel = channel.key - key = build_connection_key(channel, imc2_network, imc2_port, mudname) + key = build_connection_key(imc2_network, imc2_port, mudname) service_key = build_service_key(key) try: conn = ExternalChannelConnection.objects.get(db_external_key=key) diff --git a/src/comms/imc2lib/imc2_listeners.py b/src/comms/imc2lib/imc2_listeners.py index b8c173bfa2..88dec66500 100644 --- a/src/comms/imc2lib/imc2_listeners.py +++ b/src/comms/imc2lib/imc2_listeners.py @@ -6,6 +6,12 @@ from src.objects.models import ObjectDB from src.comms.imc2lib import imc2_ansi def handle_whois_reply(packet): + """ + When the player sends an imcwhois request, the outgoing + packet contains the id of the one asking. This handler catches the + (possible) reply from the server, parses the id back to the + original asker and tells them the result. + """ try: pobject = ObjectDB.objects.get(id=packet.target) response_text = imc2_ansi.parse_ansi(packet.optional_data.get('text', 'Unknown'))