def __onSelfEnterChat(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channelID = wrapper.channel channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(channelID)) isJoinAction = False if not channel and channelID in self.__channels: channel = self.__channels[channelID] if self.channelsStorage.addChannel(channel): g_messengerEvents.channels.onChannelInited(channel) g_messengerEvents.channels.onPlayerEnterChannelByAction( channel) isJoinAction = True if not channel: raise ChannelNotFound(channelID) name = channel.getName() if not isJoinAction and name in self.__creationInfo and channel.getProtoData( ).owner == getPlayerDatabaseID(): self.__creationInfo.pop(name) g_messengerEvents.channels.onPlayerEnterChannelByAction(channel) if not channel.isJoined(): channel.setJoined(True) g_messengerEvents.channels.onConnectStateChanged(channel) self.requestChannelMembers(channelID) else: channel.clearHistory()
def __onMemberStatusUpdate(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(wrapper.channel)) if channel: member = channel.getMember(wrapper.originator) if member: member.setStatus(int(wrapper.data))
def __onChannelDestroyed(self, chatAction): LOG_DEBUG('onChannelDestroyed : %s' % (dict(chatAction), )) wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) if channel and self.channelsStorage.removeChannel(channel): g_messengerEvents.channels.onChannelDestroyed(channel)
def __onSelfLeaveChat(self, chatAction): LOG_DEBUG('onSelfLeaveChat:%s' % (dict(chatAction), )) wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) if channel: channel.setJoined(False) g_messengerEvents.channels.onConnectStateChanged(channel)
def __onBroadcast(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) self._filtersChain.chainIn(wrapper) if len(wrapper.data) == 0: return channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) g_messengerEvents.channels.onMessageReceived(wrapper, channel)
def __onEnterChat(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) if channel: channel.addMembers([ entities.BWMemberEntity(wrapper.originator, nickName=wrapper.originatorNickName) ])
def __onRequestChannelMembers(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) if channel is not None: channel.addMembers( map( lambda memberData: self.__makeMemberFromDict( dict(memberData)), wrapper.data))
def __onChannelDestroyed(self, chatAction): LOG_DEBUG('onChannelDestroyed : %s' % (dict(chatAction),)) wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(wrapper.channel)) if channel and self.channelsStorage.removeChannel(channel, clear=False): g_messengerEvents.channels.onChannelDestroyed(channel) if channel.getID() in self.__channels: self.__channels.pop(channel.getID()) self.onChannelExcludeFromSearch(channel) channel.clear()
def __onSelfLeaveChat(self, chatAction): """ Event handler. When current player exit from channel, remove page for this channel """ LOG_DEBUG('onSelfLeaveChat:%s' % (dict(chatAction),)) wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(wrapper.channel)) if channel: channel.setJoined(False) g_messengerEvents.channels.onConnectStateChanged(channel)
def joinToChannel(self, channelID, password = None): channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(channelID)) if not channel and channelID in self.__channels: channel = self.__channels[channelID] if not channel: raise ChannelNotFound(channelID) if channel.isJoined(): g_messengerEvents.channels.onPlayerEnterChannelByAction(channel) return if channel and channel.getProtoData().isSecured and not password: g_messengerEvents.channels.onConnectingToSecureChannel(channel) return BigWorld.player().enterChat(channelID, password)
def __onBroadcast(self, chatAction): if not self.__isMessageEnabled: self.__messagesQueue.append(dict(chatAction)) return wrapper = ChatActionWrapper(**dict(chatAction)) senderDBID = wrapper.originator user = self.usersStorage.getUser(senderDBID) if user and user.isIgnored(): return text = self.__filtersChain.chainIn(senderDBID, wrapper.data) if not text: return wrapper.data = text channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(wrapper.channel)) g_messengerEvents.channels.onMessageReceived(wrapper, channel)
def __onReceiveMembersDelta(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel(entities.BWChannelLightEntity(wrapper.channel)) if channel is None: return else: added = [] removed = [] for dbID, data in wrapper.data: if data[0] == 1: added.append(entities.BWMemberEntity(dbID, nickName=data[1], status=data[2])) elif data[0] == 0: removed.append(dbID) if len(added): channel.addMembers(added) if len(removed): channel.removeMembers(removed) return
def __onSelfEnterChat(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channelID = wrapper.channel channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(channelID)) if not channel and channelID in self.__channels: channel = self.__channels[channelID] if self.channelsStorage.addChannel(channel): g_messengerEvents.channels.onChannelInited(channel) g_messengerEvents.channels.onPlayerEnterChannelByAction( channel) if not channel: raise ChannelNotFound(channelID) if not channel.isJoined(): channel.setJoined(True) g_messengerEvents.channels.onConnectStateChanged(channel) self.requestChannelMembers(channelID) else: channel.clearHistory()
def __onLeaveChat(self, chatAction): wrapper = ChatActionWrapper(**dict(chatAction)) channel = self.channelsStorage.getChannel( entities.BWChannelLightEntity(wrapper.channel)) if channel: channel.removeMembers([wrapper.originator])
class _ChannelController(IChannelController): _teamChannel = entities.BWChannelLightEntity(-1) def __init__(self, channel): super(_ChannelController, self).__init__() self._channel = channel channel.onConnectStateChanged += self._onConnectStateChanged self._view = None return def __del__(self): LOG_DEBUG('Channel controller deleted:', self) @proto_getter(PROTO_TYPE.BW) def proto(self): return None def getChannel(self): return self._channel def setView(self, view): if self._view: LOG_ERROR('View is defined', self._view) elif isinstance(view, BattleChannelView): self._view = view self._view.setController(self) else: LOG_ERROR('View must be extends BattleEntry', self._view) def removeView(self): if self._view is not None: self._view.removeController() self._view = None return def clear(self): self._channel.onConnectStateChanged -= self._onConnectStateChanged self._channel = None self.removeView() return def activate(self): self._onConnectStateChanged(self._channel) def getFullPlayerName(self, chatAction): return g_battleContext.getFullPlayerName(accID=chatAction.originator) def getMessageColors(self, message): return ( g_settings.getColorScheme('battle/player').getHexStr('unknown'), g_settings.getColorScheme('battle/message').getHexStr('unknown')) def canSendMessage(self): result, errorMsg = True, '' if cooldown.isBroadcatInCooldown(): result, errorMsg = False, cooldown.BROADCAST_COOL_DOWN_MESSAGE return (result, errorMsg) def sendMessage(self, message): result, errorMsg = self.canSendMessage() if result: self.proto.channels.sendMessage(self._channel.getID(), message) else: self._view.addMessage( g_settings.htmlTemplates.format('battleErrorMessage', ctx={'error': errorMsg})) return result def addMessage(self, message, doFormatting=True): isCurrent = isCurrentPlayer(message.originator) if doFormatting: text = self._format(message, message.data) else: text = message.data self._channel.addMessage(text) if BattleReplay.g_replayCtrl.isRecording: BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent) if self._view: self._view.addMessage(text, isCurrentPlayer=isCurrent) return True def addCommand(self, command): cmdData = command.getProtoData() isCurrent = isCurrentPlayer(cmdData.originator) text = self._format(cmdData, command.getCommandText()) if BattleReplay.g_replayCtrl.isRecording: BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent) if self._view: self._view.addMessage(text, isCurrentPlayer=isCurrent) def _format(self, chatAction, msgText): playerColor, msgColor = self.getMessageColors(chatAction) return g_settings.battle.messageFormat % { 'playerColor': playerColor, 'playerName': unicode( self.getFullPlayerName(chatAction), 'utf-8', errors='ignore'), 'messageColor': msgColor, 'messageText': msgText } def _onConnectStateChanged(self, channel): pass