diff --git a/src/server/portal/imc2.py b/src/server/portal/imc2.py index 5238012f49..8629cdd207 100644 --- a/src/server/portal/imc2.py +++ b/src/server/portal/imc2.py @@ -10,6 +10,7 @@ from twisted.conch import telnet from src.server.session import Session from src.utils import logger, utils +from src.server.portal.imc2lib import imc2_ansi from src.server.portal.imc2lib import imc2_packets as pck from django.utils.translation import ugettext as _ @@ -111,11 +112,10 @@ class IMC2ChanList(dict): pass - - # # IMC2 protocol # + class IMC2Bot(telnet.StatefulTelnetProtocol, Session): """ Provides the abstraction for the IMC2 protocol. Handles connection, @@ -165,7 +165,8 @@ class IMC2Bot(telnet.StatefulTelnetProtocol, Session): # not using that here response_text = imc2_ansi.parse_ansi(packet.optional_data.get('text', 'Unknown')) string = _('Whois reply from %(origin)s: %(msg)s') % {"origin":packet.origin, "msg":response_text} - # somehow pass reply on to a given player + # somehow pass reply on to a given player, for now we just send to channel + self.data_in(string) def _format_tell(self, packet): """ @@ -264,6 +265,7 @@ class IMC2Bot(telnet.StatefulTelnetProtocol, Session): self.data_out(text=line, packettype="broadcast") elif packet.packet_type == 'whois-reply': # handle eventual whois reply + self._whois_reply(packet) elif packet.packet_type == 'close-notify': self.imc2_mudlist.remove_mud_from_packet(packet) elif packet.packet_type == 'ice-update': @@ -278,6 +280,7 @@ class IMC2Bot(telnet.StatefulTelnetProtocol, Session): """ Data IMC2 -> Evennia """ + text = "bot_data_in " + text self.sessionhandler.data_in(self, text=text, **kwargs) def data_out(self, text=None, **kwargs): diff --git a/src/server/portal/imc2lib/imc2_listeners.py b/src/server/portal/imc2lib/imc2_listeners.py deleted file mode 100644 index ab31076f49..0000000000 --- a/src/server/portal/imc2lib/imc2_listeners.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This module handles some of the -reply packets like whois-reply. - -""" -from src.objects.models import ObjectDB -from src.comms.imc2lib import imc2_ansi - -from django.utils.translation import ugettext as _ - -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')) - string = _('Whois reply from %(origin)s: %(msg)s') % {"origin":packet.origin, "msg":response_text} - pobject.msg(string.strip()) - except ObjectDB.DoesNotExist: - # No match found for whois sender. Ignore it. - pass diff --git a/src/server/portal/imc2lib/imc2_trackers.py b/src/server/portal/imc2lib/imc2_trackers.py deleted file mode 100644 index a276c54afa..0000000000 --- a/src/server/portal/imc2lib/imc2_trackers.py +++ /dev/null @@ -1,101 +0,0 @@ -""" -Certain periodic packets are sent by connected MUDs (is-alive, user-cache, -etc). The IMC2 protocol assumes that each connected MUD will capture these and -populate/maintain their own lists of other servers connected. This module -contains stuff like this. -""" -from time import time - - -class IMC2Mud(object): - """ - Stores information about other games connected to our current IMC2 network. - """ - def __init__(self, packet): - self.name = packet.origin - self.versionid = packet.optional_data.get('versionid', None) - self.networkname = packet.optional_data.get('networkname', None) - self.url = packet.optional_data.get('url', None) - self.host = packet.optional_data.get('host', None) - self.port = packet.optional_data.get('port', None) - self.sha256 = packet.optional_data.get('sha256', None) - # This is used to determine when a Mud has fallen into inactive status. - self.last_updated = time() - - -class IMC2MudList(dict): - """ - Keeps track of other MUDs connected to the IMC network. - """ - def get_mud_list(self): - """ - Returns a sorted list of connected Muds. - """ - muds = self.items() - muds.sort() - return [value for key, value in muds] - - def update_mud_from_packet(self, packet): - """ - This grabs relevant info from the packet and stuffs it in the - Mud list for later retrieval. - """ - mud = IMC2Mud(packet) - self[mud.name] = mud - - def remove_mud_from_packet(self, packet): - """ - Removes a mud from the Mud list when given a packet. - """ - mud = IMC2Mud(packet) - try: - del self[mud.name] - except KeyError: - # No matching entry, no big deal. - pass - - -class IMC2Channel(object): - """ - Stores information about channels available on the network. - """ - def __init__(self, packet): - self.localname = packet.optional_data.get('localname', None) - self.name = packet.optional_data.get('channel', None) - self.level = packet.optional_data.get('level', None) - self.owner = packet.optional_data.get('owner', None) - self.policy = packet.optional_data.get('policy', None) - self.last_updated = time() - - -class IMC2ChanList(dict): - """ - Keeps track of Channels on the IMC network. - """ - - def get_channel_list(self): - """ - Returns a sorted list of cached channels. - """ - channels = self.items() - channels.sort() - return [value for key, value in channels] - - def update_channel_from_packet(self, packet): - """ - This grabs relevant info from the packet and stuffs it in the - channel list for later retrieval. - """ - channel = IMC2Channel(packet) - self[channel.name] = channel - - def remove_channel_from_packet(self, packet): - """ - Removes a channel from the Channel list when given a packet. - """ - channel = IMC2Channel(packet) - try: - del self[channel.name] - except KeyError: - # No matching entry, no big deal. - pass