예제 #1
0
파일: tasks.py 프로젝트: webiumsk/WoT
 def error(self, pyGlooxTag):
     error = self._getError(pyGlooxTag)
     if error:
         g_messengerEvents.onErrorReceived(error)
     else:
         g_logOutput.error(_LOG_AREA.PY_WRAPPER, 'Error is not resolved on the client', self.__class__.__name__, pyGlooxTag.getXml())
     self._result = TASK_RESULT.CLEAR
예제 #2
0
파일: xmpplogger.py 프로젝트: Difrex/wotsdk
 def logger(self, key):
     if key in self.__loggers:
         return self.__loggers[key]
     else:
         g_logOutput.error(CLIENT_LOG_AREA.GENERIC, 'Events logger is not found. Available loggers are', self.__loggers.keys())
         return None
         return None
예제 #3
0
 def __doCallback(self, result = None, error = None):
     if error:
         g_logOutput.error(CLIENT_LOG_AREA.GENERIC, 'Error has been received on requesting nicknames', error)
     if self.__callback:
         self.__callback(result or {}, error)
         self.__callback = None
     return
예제 #4
0
 def unregisterHandler(self, event, handler):
     if event in GLOOX_EVENT.ALL:
         handlers = self.__handlers[event]
         if handler in handlers:
             handlers.remove(handler)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Event is not found', event)
    def __onRequestChannels(self, chatAction, join=False):
        chatActionDict = dict(chatAction)
        data = chatActionDict.get('data', [])
        requestID = chatActionDict.get('requestID', -1)
        channels = set()
        isStore = requestID == -1
        isMucEnabled = g_settings.server.isUserRoomsEnabled(PROTO_TYPE.XMPP)
        for channelData in data:
            received = entities.BWChannelEntity(dict(channelData))
            if isMucEnabled and not received.isSystem(
            ) and not received.isLazy() and not received.isPrivate(
            ) and not received.isClan():
                g_logOutput.error(
                    CLIENT_LOG_AREA.OBSOLETE,
                    'Game server sends BW channel on which player is joined, but MUC are enabled. BW channel is ignored',
                    received)
                continue
            channel = self.channelsStorage.getChannel(received)
            if channel:
                channel.update(other=received)
                if not isStore:
                    self.__channels[received.getID()] = received
            else:
                if isStore:
                    if self.channelsStorage.addChannel(received):
                        g_messengerEvents.channels.onChannelInited(received)
                else:
                    self.__channels[received.getID()] = received
                channel = received
            channels.add(channel)
            if join:
                self.joinToChannel(channel.getID())

        self.onRequestChannelsComplete(requestID, channels)
예제 #6
0
 def error(self, pyGlooxTag):
     error = self._getError(pyGlooxTag)
     if error:
         g_messengerEvents.onErrorReceived(error)
     else:
         g_logOutput.error(_LOG_AREA.PY_WRAPPER, 'Error is not resolved on the client', self.__class__.__name__, pyGlooxTag.getXml())
     self._result = TASK_RESULT.CLEAR
예제 #7
0
 def logger(self, key):
     if key in self.__loggers:
         return self.__loggers[key]
     else:
         g_logOutput.error(CLIENT_LOG_AREA.GENERIC, 'Events logger is not found. Available loggers are', self.__loggers.keys())
         return None
         return None
예제 #8
0
 def __doCallback(self, result = None, error = None):
     if error:
         g_logOutput.error(CLIENT_LOG_AREA.GENERIC, 'Error has been received on requesting nicknames', error)
     if self.__callback:
         self.__callback(result or {}, error)
         self.__callback = None
     return
예제 #9
0
 def __doLogin(self):
     client = self.client()
     if not client.isConnecting():
         g_logOutput.warning(CLIENT_LOG_AREA.LOGIN,
                             'Client is not connecting',
                             client.getConnectionAddress(),
                             client.getConnectionState())
         yield lambda callback: callback(None)
         return
     g_logOutput.debug(CLIENT_LOG_AREA.TOKEN, 'Sends request to SPA')
     response = yield self.__tokenRequester.request()
     g_logOutput.debug(CLIENT_LOG_AREA.TOKEN,
                       'Response is received from SPA', response)
     if not response:
         g_logOutput.error(CLIENT_LOG_AREA.TOKEN,
                           'Received chat token is empty')
         return
     if response.isValid():
         if response.getDatabaseID() == getPlayerDatabaseID():
             g_logOutput.debug(CLIENT_LOG_AREA.LOGIN, 'Login to XMPP sever')
             client.login(response.getCredential())
         else:
             g_logOutput.error(CLIENT_LOG_AREA.LOGIN,
                               "Player's database ID mismatch",
                               getPlayerDatabaseID())
     else:
         g_logOutput.warning(CLIENT_LOG_AREA.TOKEN,
                             'Received chat token is not valid', response)
         self.__handleTokenError()
예제 #10
0
    def __filterActions(self):
        for jid, action in self.__actions.items()[:]:
            if action.isRunning():
                continue
            self.__actions.pop(jid)
            room = action.getRoom()
            result = action.getResult()
            if room is None and result != ACTION_RESULT.DO_NOTHING:
                g_logOutput.error(_LOG.MESSAGE, 'Action is failed', jid)
                continue
            if result & ACTION_RESULT.LAZY_JOIN > 0:
                LOG_DEBUG('LAZY_JOIN')
                room.setJoined(True)
            elif result & ACTION_RESULT.LAZY_LEAVE > 0:
                LOG_DEBUG('LAZY_LEAVE')
                room.clearHistory()
                room.setJoined(False)
            elif result & ACTION_RESULT.ADD_TO_STORAGE > 0:
                self._addChannel(room,
                                 byAction=result & ACTION_RESULT.SHOW_ROOM > 0)
            elif result & ACTION_RESULT.REMOVE_FROM_STORAGE > 0:
                self._removeChannel(room)
            action.clear(full=False)

        return
예제 #11
0
 def unregisterHandler(self, event, handler):
     if event in GLOOX_EVENT.ALL:
         handlers = self.__handlers[event]
         if handler in handlers:
             handlers.remove(handler)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Event is not found', event)
예제 #12
0
 def __handleEvent(self, eventName, *args, **kwargs):
     handlers = self.__handlers[eventName]
     for handler in handlers:
         try:
             handler(*args, **kwargs)
         except TypeError:
             g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, ' Handler is invoked with error', handler)
             LOG_CURRENT_EXCEPTION()
예제 #13
0
 def __handleEvent(self, eventName, *args, **kwargs):
     handlers = self.__handlers[eventName]
     for handler in handlers:
         try:
             handler(*args, **kwargs)
         except TypeError:
             g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, ' Handler is invoked with error', handler)
             LOG_CURRENT_EXCEPTION()
예제 #14
0
파일: tasks.py 프로젝트: webiumsk/WoT
 def sync(self, jid, name = '', groups = None, to = _SUB.OFF, from_ = _SUB.OFF, defaultTask = None):
     if not jid.getDatabaseID():
         g_logOutput.error(_LOG_AREA.SYNC, 'JID "{0}" is invalid'.format(jid))
         return
     generator = self._getSyncGenerator(jid, name, groups, to, from_)
     if not self._handleTasksResult(jid, generator) and defaultTask:
         task = defaultTask(jid)
         task.sync(name, groups, to, from_)
         task.clear()
예제 #15
0
 def sync(self, jid, name='', groups=None, sub=None, clanInfo=None, defaultTask=None):
     if not jid.getDatabaseID():
         g_logOutput.error(_LOG_AREA.SYNC, 'JID "{0}" is invalid'.format(jid))
         return
     generator = self._getSyncGenerator(jid, name, groups, sub, clanInfo)
     if not self._handleTasksResult(jid, generator) and defaultTask:
         task = defaultTask(jid)
         task.sync(name, groups, sub, clanInfo)
         task.clear()
예제 #16
0
    def fini(self):
        client = self.__client
        for handlerName, _ in _GLOOX_EVENTS_LISTENERS:
            if not hasattr(client, handlerName):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler no is found', handlerName)
                continue
            setattr(client, handlerName, None)

        self.__handlers.clear()
        g_logOutput.clear()
        ClientHolder._clearClient()
        return
예제 #17
0
 def error(self, pyGlooxTag=None):
     self._error = self._getError(
         pyGlooxTag) if pyGlooxTag is not None else None
     if self._shadowPath is None:
         if self._error:
             g_messengerEvents.onErrorReceived(self._error)
         else:
             g_logOutput.error(_LOG_AREA.PY_WRAPPER,
                               'Error is not resolved on the client',
                               self.__class__.__name__, pyGlooxTag.getXml())
     self._result = TaskResult.CLEAR
     return
예제 #18
0
    def fini(self):
        self.__cancelInboundSubsCallback()
        client = self.__client
        for handlerName, _ in _GLOOX_EVENTS_LISTENERS:
            if not hasattr(client, handlerName):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER,
                                  'Handler no is found', handlerName)
                continue
            setattr(client, handlerName, None)

        self.__handlers.clear()
        g_logOutput.clear()
        ClientHolder._clearClient()
예제 #19
0
파일: messages.py 프로젝트: kblw/wot_client
 def __handleMessage(self, _, msgType, body, jid, pyGlooxTag):
     if msgType not in MESSAGE_TYPE_TO_ATTR:
         return
     message = MessageHandler(MESSAGE_TYPE_TO_ATTR[msgType]).handleTag(pyGlooxTag)
     if not message.accountDBID:
         g_logOutput.error(CLIENT_LOG_AREA.MESSAGE, 'Can not find sender info', pyGlooxTag.getXml())
         return
     if body:
         message.body = self.__msgFilters.chainIn(message.accountDBID, body)
     if not _REQUIRED_USER_TAGS.issubset(self.__receivedTags):
         self.__pending.insert(0, (msgType, (jid, message)))
         return
     if msgType == MESSAGE_TYPE.CHAT or msgType == MESSAGE_TYPE.NORMAL and message.isHistory():
         self.__chatSessions.addMessage(jid, message)
    def __addTasks(self, actionID, jid, shadowMode, *tasks):
        if shadowMode:
            if all([ task.canShadowMode() for task in tasks ]):
                for task in tasks[:-1]:
                    task.setShadowMode(actionID, False)

                tasks[-1].setShadowMode(actionID, True)
            else:
                g_logOutput.error(_LOG.PY_WRAPPER, "Trying to shadow tasks seq, but some tasks can't be shadowed")
                g_messengerEvents.shadow.onActionFailed(jid.getDatabaseID(), actionID, None)
        if self.__tasks.addTasks(jid, *tasks):
            self.__tasks.runFirstTask(jid)
        else:
            return (False, ClientActionError(actionID, CLIENT_ERROR_ID.LOCKED))
        return (True, None)
예제 #21
0
 def __handleMessage(self, _, msgType, body, jid, pyGlooxTag):
     if msgType == MESSAGE_TYPE.CHAT:
         state, info, sentAt = ChatMessageHandler().handleTag(pyGlooxTag)
         if not info:
             g_logOutput.error(CLIENT_LOG_AREA.MESSAGE, 'Can not find sender info', pyGlooxTag.getXml())
             return
         if body:
             body = self.__msgFilters.chainIn(info['dbID'], body)
         if _REQUIRED_USER_TAGS.issubset(self.__receivedTags):
             self.__chatSessions.onMessageReceived(jid, body, state, info, sentAt)
         else:
             self.__pending.insert(0, (msgType, (jid,
               body,
               state,
               info,
               sentAt)))
예제 #22
0
 def __doConnect(self):
     client = self.client()
     if not client.isDisconnected():
         g_logOutput.warning(CLIENT_LOG_AREA.CONNECTION, 'Client already is connected(ing)', client.getConnectionAddress(), client.getConnectionState())
         return
     jid = self.__connectionsInfo.getPlayerFullJID()
     if jid:
         cType, host, port = self.__connectionsInfo.getNextConnection()
         g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Connect to XMPP sever', jid, host, port)
         if cType == CONNECTION_IMPL_TYPE.TCP:
             client.connect(str(jid), host, port)
         elif cType == CONNECTION_IMPL_TYPE.BOSH:
             client.connectBosh(str(jid), host, port, '/bosh/')
         else:
             g_logOutput.error(CLIENT_LOG_AREA.CONNECTION, 'This type of connection is not supported', cType)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.CONNECTION, 'JID is empty')
예제 #23
0
 def __doConnect(self):
     client = self.client()
     if not client.isDisconnected():
         g_logOutput.warning(CLIENT_LOG_AREA.CONNECTION, 'Client already is connected(ing)', client.getConnectionAddress(), client.getConnectionState())
         return
     jid = self.__connectionsInfo.getPlayerFullJID()
     if jid:
         cType, host, port = self.__connectionsInfo.getNextConnection()
         g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Connect to XMPP sever', jid, host, port)
         if cType == CONNECTION_IMPL_TYPE.TCP:
             client.connect(str(jid), host, port)
         elif cType == CONNECTION_IMPL_TYPE.BOSH:
             client.connectBosh(str(jid), host, port, '/bosh/')
         else:
             g_logOutput.error(CLIENT_LOG_AREA.CONNECTION, 'This type of connection is not supported', cType)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.CONNECTION, 'JID is empty')
예제 #24
0
    def __filterActions(self):
        for jid, action in self.__actions.items()[:]:
            if action.isRunning():
                continue
            self.__actions.pop(jid)
            room = action.getRoom()
            result = action.getResult()
            if room is None and result != ACTION_RESULT.DO_NOTHING:
                g_logOutput.error(_LOG.MESSAGE, 'Action is failed', jid)
                continue
            if result & ACTION_RESULT.ADD_TO_STORAGE > 0:
                self._addChannel(room, byAction=result & ACTION_RESULT.SHOW_ROOM > 0)
            elif result & ACTION_RESULT.REMOVE_FROM_STORAGE > 0:
                self._removeChannel(room)
            action.clear(full=False)

        return
예제 #25
0
 def __handleMessage(self, _, msgType, body, jid, pyGlooxTag):
     if msgType not in MESSAGE_TYPE_TO_ATTR:
         return
     message = MessageHandler(
         MESSAGE_TYPE_TO_ATTR[msgType]).handleTag(pyGlooxTag)
     if not message.accountDBID:
         g_logOutput.error(CLIENT_LOG_AREA.MESSAGE,
                           'Can not find sender info', pyGlooxTag.getXml())
         return
     if body:
         message.body = self.__msgFilters.chainIn(message.accountDBID, body)
     if not _REQUIRED_USER_TAGS.issubset(self.__receivedTags):
         self.__pending.insert(0, (msgType, (jid, message)))
         return
     if msgType == MESSAGE_TYPE.CHAT or msgType == MESSAGE_TYPE.NORMAL and message.isHistory(
     ):
         self.__chatSessions.addMessage(jid, message)
예제 #26
0
    def init(self):
        client = self.__client
        ClientHolder._clearClient()
        for (handlerName, listenerName,) in _GLOOX_EVENTS_LISTENERS:
            if not hasattr(client, handlerName):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler no is found', handlerName)
                continue
            handler = getattr(client, handlerName)
            if handler:
                g_logOutput.warning(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler already is set', handlerName)
                continue
            listener = getattr(self, listenerName, None)
            if listener is None or not callable(listener):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Listener no is found', listenerName)
                continue
            setattr(client, handlerName, listener)

        ClientEventsHandler._setClient(self)
예제 #27
0
    def init(self):
        client = self.__client
        ClientHolder._clearClient()
        for handlerName, listenerName in _GLOOX_EVENTS_LISTENERS:
            if not hasattr(client, handlerName):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler no is found', handlerName)
                continue
            handler = getattr(client, handlerName)
            if handler:
                g_logOutput.warning(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler already is set', handlerName)
                continue
            listener = getattr(self, listenerName, None)
            if listener is None or not callable(listener):
                g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Listener no is found', listenerName)
                continue
            setattr(client, handlerName, listener)

        ClientEventsHandler._setClient(self)
        return
예제 #28
0
 def __doLogin(self):
     client = self.client()
     if not client.isConnecting():
         g_logOutput.warning(CLIENT_LOG_AREA.LOGIN, 'Client is not connecting', client.getConnectionAddress(), client.getConnectionState())
         yield lambda callback: callback(None)
         return
     g_logOutput.debug(CLIENT_LOG_AREA.TOKEN, 'Sends request to SPA')
     response = yield self.__tokenRequester.request()
     g_logOutput.debug(CLIENT_LOG_AREA.TOKEN, 'Response is received from SPA', response)
     if not response:
         g_logOutput.error(CLIENT_LOG_AREA.TOKEN, 'Received chat token is empty')
         return
     if response.isValid():
         if response.getDatabaseID() == getPlayerDatabaseID():
             g_logOutput.debug(CLIENT_LOG_AREA.LOGIN, 'Login to XMPP sever')
             client.login(response.getCredential())
         else:
             g_logOutput.error(CLIENT_LOG_AREA.LOGIN, "Player's database ID mismatch", getPlayerDatabaseID())
     else:
         g_logOutput.warning(CLIENT_LOG_AREA.TOKEN, 'Received chat token is not valid', response)
         self.__handleTokenError()
예제 #29
0
 def registerHandler(self, event, handler):
     if event in GLOOX_EVENT.ALL:
         handlers = self.__handlers[event]
         if handler in handlers:
             g_logOutput.warning(CLIENT_LOG_AREA.PY_WRAPPER, 'handler already exists', event, handler)
         elif not hasattr(handler, '__self__') or not isinstance(handler.__self__, ClientEventsHandler):
             g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Class of handler is not subclass of ClientEventsHandler', handler)
             return 
         if callable(handler):
             handlers.add(handler)
         else:
             g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler is invalid', handler)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Event is not found', event)
예제 #30
0
 def registerHandler(self, event, handler):
     if event in GLOOX_EVENT.ALL:
         handlers = self.__handlers[event]
         if handler in handlers:
             g_logOutput.warning(CLIENT_LOG_AREA.PY_WRAPPER, 'handler already exists', event, handler)
         else:
             if not hasattr(handler, '__self__') or not isinstance(handler.__self__, ClientEventsHandler):
                 g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Class of handler is not subclass of ClientEventsHandler', handler)
                 return
             if callable(handler):
                 handlers.add(handler)
             else:
                 g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Handler is invalid', handler)
     else:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Event is not found', event)
 def setClientPresence(self, presence):
     if presence not in PRESENCE.RANGE:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER,
                           'Value of presence is invalid', presence)
         return
     self.__client.presence = presence
예제 #32
0
 def setClientPresenceWithIGR(self, presence, igrID = 0, igrRoomID = 0):
     if presence not in PRESENCE.RANGE:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Value of presence is invalid', presence)
         return
     self.__client.setPresenceWithIGR(presence, str(igrID), str(igrRoomID))
예제 #33
0
 def setClientPresence(self, presence):
     if presence not in PRESENCE.RANGE:
         g_logOutput.error(CLIENT_LOG_AREA.PY_WRAPPER, 'Value of presence is invalid', presence)
         return
     self.__client.presence = presence