diff --git a/src/config_defaults.py b/src/config_defaults.py index cf75c5f600..7293274266 100644 --- a/src/config_defaults.py +++ b/src/config_defaults.py @@ -212,6 +212,7 @@ INSTALLED_APPS = ( 'django.contrib.flatpages', 'src.config', 'src.objects', + 'src.imc2', 'src.helpsys', 'src.genperms', 'game.web.apps.news', diff --git a/src/imc2/admin.py b/src/imc2/admin.py new file mode 100644 index 0000000000..67dd988b5d --- /dev/null +++ b/src/imc2/admin.py @@ -0,0 +1,6 @@ +from src.imc2.models import IMC2ChannelMapping +from django.contrib import admin + +class IMC2ChannelMappingAdmin(admin.ModelAdmin): + list_display = ('channel', 'imc2_channel_name', 'is_enabled') +admin.site.register(IMC2ChannelMapping, IMC2ChannelMappingAdmin) \ No newline at end of file diff --git a/src/imc2/connection.py b/src/imc2/connection.py index 2eeef00fca..eaf72716a3 100644 --- a/src/imc2/connection.py +++ b/src/imc2/connection.py @@ -12,6 +12,8 @@ from src import logger from src.imc2.packets import * from src.imc2.trackers import * from src.imc2 import reply_listener +from src.imc2.models import IMC2ChannelMapping +from src import comsys # The active instance of IMC2Protocol. Set at server startup. IMC2_PROTOCOL_INSTANCE = None @@ -88,6 +90,22 @@ class IMC2Protocol(StatefulTelnetProtocol): logger.log_infomsg(packet) if packet.packet_type == 'is-alive': IMC2_MUDLIST.update_mud_from_packet(packet) + elif packet.packet_type == 'ice-msg-b': + # Received a message. Look for an IMC2 channel mapping and + # route it accordingly. + chan_name = packet.optional_data.get('channel', None) + if chan_name: + chan_name = chan_name.split(':', 1)[1] + try: + mapping = IMC2ChannelMapping.objects.get(imc2_channel_name=chan_name) + ingame_chan_name = mapping.channel.name + message = '[%s] %s@%s: %s' % (ingame_chan_name, + packet.sender, + packet.origin, + packet.optional_data.get('text')) + comsys.send_cmessage(ingame_chan_name, message) + except IMC2ChannelMapping.DoesNotExist: + pass elif packet.packet_type == 'whois-reply': reply_listener.handle_whois_reply(packet) elif packet.packet_type == 'close-notify': diff --git a/src/imc2/models.py b/src/imc2/models.py new file mode 100644 index 0000000000..83d8d0af6d --- /dev/null +++ b/src/imc2/models.py @@ -0,0 +1,18 @@ +from django.db import models +from src.objects.models import CommChannel + +class IMC2ChannelMapping(models.Model): + """ + Each IMC2ChannelMapping object determines which in-game channel incoming + IMC2 messages are routed to. + """ + channel = models.ForeignKey(CommChannel) + imc2_channel_name = models.CharField(max_length=78) + is_enabled = models.BooleanField(default=True) + + class Meta: + verbose_name = "IMC2 Channel mapping" + verbose_name_plural = "IMC2 Channel mappings" + + def __str__(self): + return "%s <-> %s" % (self.channel, self.imc2_channel_name) \ No newline at end of file