Go to the documentation of this file.00001 '''
00002 Anoria (c) Gsk 2010
00003 '''
00004
00005 import BigWorld
00006
00007 ''' This module is not yet fully functional and tested ! '''
00008
00009 class ChatSubscription:
00010 def __init__(self, entity, chat_channel_id):
00011 self.entity = entity
00012 self.channel_id = chat_channel_id
00013
00014
00015 class ChatManager(BigWorld.Base):
00016 def __init__(self):
00017 BigWorld.Base.__init__(self)
00018
00019 self.dSubs = {}
00020
00021 def subscribe(self, entity, chat_channel_id):
00022 print 'ChatManager.subscribe(): processing subscription request entity=%d, channel=%d' % (entity.id, chat_channel_id)
00023 sub = ChatSubscription(entity, chat_channel_id)
00024 try:
00025 channel_sub_list = self.dSubs[chat_channel_id]
00026 except KeyError:
00027 channel_sub_list = []
00028 self.dSubs[chat_channel_id] = channel_sub_list
00029
00030 channel_sub_list.append(sub)
00031 return sub
00032
00033 def unsubscribe(self, subscription):
00034 try:
00035 channel_sub_list = self.dSubs[subscription.channel_id]
00036 except KeyError:
00037 return
00038
00039 channel_sub_list.remove(subscription)
00040
00041 def chatToChannel(self, text, chat_channel_id):
00042 try:
00043 channel_sub_list = self.dSubs[chat_channel_id]
00044 except KeyError:
00045 print 'ChatManager::sendToChannel(): invalid channel_id %s' % (chat_channel_id)
00046 return
00047
00048
00049 for subscription in channel_sub_list:
00050 subscription.entity.chatText(chat_channel_id, text)
00051
00052
00053
00054