コード例 #1
0
 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()
コード例 #2
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
 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))
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 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)
コード例 #6
0
 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)
         ])
コード例 #7
0
 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))
コード例 #8
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
 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()
コード例 #9
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
 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)
コード例 #10
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
 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)
コード例 #11
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
 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)
コード例 #12
0
ファイル: bwchannelsmanager.py プロジェクト: Difrex/wotsdk
    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
コード例 #13
0
 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()
コード例 #14
0
 def __onLeaveChat(self, chatAction):
     wrapper = ChatActionWrapper(**dict(chatAction))
     channel = self.channelsStorage.getChannel(
         entities.BWChannelLightEntity(wrapper.channel))
     if channel:
         channel.removeMembers([wrapper.originator])
コード例 #15
0
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