class _PlayersInfoFromXmppGetter(_PlayersInfoGetter):

    def __init__(self):
        super(_PlayersInfoFromXmppGetter, self).__init__()
        self._spaResolver = NicknameResolver()
        self._spaResolver.registerHandlers()

    def __del__(self):
        self._spaResolver.unregisterHandlers()
        self._spaResolver.clear()

    @async
    def invalidate(self, results, callback):
        self._infoCache.clear()

        def _cbWrapper(players, error):
            self._infoCache = dict(map(lambda (pID, n): (pID, _PlayerInfo(n)), players.iteritems()))
            callback(True)

        self._spaResolver.resolve(results['players'].keys(), _cbWrapper)
class _PlayersInfoFromXmppGetter(_PlayersInfoGetter):

    def __init__(self):
        super(_PlayersInfoFromXmppGetter, self).__init__()
        self._spaResolver = NicknameResolver()
        self._spaResolver.registerHandlers()

    def __del__(self):
        self._spaResolver.unregisterHandlers()
        self._spaResolver.clear()

    @async
    def invalidate(self, results, callback):
        self._infoCache.clear()

        def _cbWrapper(players, error):
            self._infoCache = dict(map(lambda (pID, n): (pID, _PlayerInfo(n)), players.iteritems()))
            callback(True)

        self._spaResolver.resolve(results['players'].keys(), _cbWrapper)
Exemple #3
0
class XmppPlugin(IProtoPlugin):
    __slots__ = ('__client', '__contacts', '__connection', '__logger', '__messages', '__isClientInited', '__nicknameResolver')

    def __init__(self):
        self.__client = ClientDecorator()
        self.__contacts = ContactsManager()
        self.__connection = ConnectionHandler()
        self.__messages = MessagesManager()
        self.__logger = LogHandler()
        self.__nicknameResolver = NicknameResolver()
        self.__isClientInited = False

    def __repr__(self):
        return 'XmppPlugin(id=0x{0:08X}, ro={1!r:s},'.format(id(self), ['client',
         'contacts',
         'messages',
         'logger'])

    @property
    def client(self):
        return self.__client

    @property
    def logger(self):
        return self.__logger

    @property
    def contacts(self):
        return self.__contacts

    @property
    def messages(self):
        return self.__messages

    @property
    def nicknames(self):
        return self.__nicknameResolver

    def isConnected(self):
        return self.__client.isConnected()

    def clear(self):
        if self.__isClientInited:
            self.__finiClientEnv()
        self.__isClientInited = False
        self.__connection.clear()
        self.__contacts.clear()
        self.__messages.clear()
        self.__logger.clear()
        self.__nicknameResolver.clear()

    def connect(self, scope):
        self.__contacts.switch(scope)

    def view(self, scope):
        if self.__client.isConnected():
            return
        if not self.__isClientInited:
            self.__initClientEnv()
            self.__isClientInited = True
        self.__connection.connect()

    def disconnect(self):
        self.__connection.disconnect()
        if self.__isClientInited:
            self.__isClientInited = False
            self.__finiClientEnv()
            self.__connection.clear()
            self.__logger.clear()
            self.__nicknameResolver.clear()

    def setFilters(self, msgFilterChain):
        if self.__messages:
            self.__messages.setFilters(msgFilterChain)

    def __initClientEnv(self):
        self.__client.init()
        self.__connection.registerHandlers()
        self.__contacts.registerHandlers()
        self.__messages.registerHandlers()
        self.__logger.registerHandlers()
        self.__nicknameResolver.registerHandlers()

    def __finiClientEnv(self):
        self.__connection.unregisterHandlers()
        self.__contacts.unregisterHandlers()
        self.__messages.unregisterHandlers()
        self.__logger.unregisterHandlers()
        self.__nicknameResolver.unregisterHandlers()
        self.__client.fini()
Exemple #4
0
class XmppPlugin(IProtoPlugin):
    __slots__ = ('__client', '__contacts', '__connection', '__logger',
                 '__messages', '__isClientInited', '__nicknameResolver',
                 '__clanListener')

    def __init__(self):
        self.__client = None
        self.__contacts = None
        self.__connection = None
        self.__messages = None
        self.__logger = None
        self.__nicknameResolver = None
        self.__clanListener = None
        self.__isClientInited = False
        return

    def __repr__(self):
        return 'XmppPlugin(id=0x{0:08X}, ro={1!r:s},'.format(
            id(self), ['client', 'contacts', 'messages', 'logger'])

    @property
    def client(self):
        return self.__client

    @property
    def logger(self):
        return self.__logger

    @property
    def contacts(self):
        return self.__contacts

    @property
    def messages(self):
        return self.__messages

    @property
    def nicknames(self):
        return self.__nicknameResolver

    @property
    def clanListener(self):
        return self.__clanListener

    def isConnected(self):
        return self.__client.isConnected()

    def init(self):
        self.__client = ClientDecorator()
        self.__contacts = ContactsManager()
        self.__connection = ConnectionHandler()
        self.__messages = MessagesManager()
        self.__logger = LogHandler()
        self.__nicknameResolver = NicknameResolver()

    def clear(self):
        if self.__isClientInited:
            self.__finiClientEnv()
        self.__isClientInited = False
        self.__connection.clear()
        self.__contacts.clear()
        self.__messages.clear()
        self.__logger.clear()
        self.__nicknameResolver.clear()
        if self.__clanListener is not None:
            self.__clanListener.clear()
        return

    def connect(self, scope):
        self.__contacts.switch(scope)
        self.__clanListener = self.__getClanListener()

    def view(self, scope):
        if self.__client.isConnected():
            return
        if not self.__isClientInited:
            self.__initClientEnv()
            self.__isClientInited = True
        self.__connection.connect()

    def disconnect(self):
        self.__connection.disconnect()
        if self.__isClientInited:
            self.__isClientInited = False
            self.__finiClientEnv()
            self.__connection.clear()
            self.__logger.clear()
            self.__nicknameResolver.clear()
            if self.__clanListener is not None:
                self.__clanListener.clear()
        return

    def setFilters(self, msgFilterChain):
        if self.__messages:
            self.__messages.setFilters(msgFilterChain)

    def __initClientEnv(self):
        self.__client.init()
        self.__connection.registerHandlers()
        self.__contacts.registerHandlers()
        self.__messages.registerHandlers()
        self.__logger.registerHandlers()
        self.__nicknameResolver.registerHandlers()
        if self.__clanListener:
            self.__clanListener.registerHandlers()

    def __finiClientEnv(self):
        self.__connection.unregisterHandlers()
        self.__contacts.unregisterHandlers()
        self.__messages.unregisterHandlers()
        self.__logger.unregisterHandlers()
        self.__nicknameResolver.unregisterHandlers()
        if self.__clanListener is not None:
            self.__clanListener.unregisterHandlers()
        self.__client.fini()
        return

    @classmethod
    def __getClanListener(cls):
        """Gets ClanListener instance
        :return: Instance of XmppClanListener, None if xmpp clan channels aren't enabled
        :rtype XmppClanListener
        """
        if g_settings.server.isXmppClansEnabled():
            return XmppClanListener()
        else:
            return None
Exemple #5
0
class XmppPlugin(IProtoPlugin):
    __slots__ = ('__client', '__contacts', '__connection', '__logger', '__messages', '__isClientInited', '__nicknameResolver', '__clanListener')

    def __init__(self):
        self.__client = ClientDecorator()
        self.__contacts = ContactsManager()
        self.__connection = ConnectionHandler()
        self.__messages = MessagesManager()
        self.__logger = LogHandler()
        self.__nicknameResolver = NicknameResolver()
        self.__clanListener = None
        self.__isClientInited = False
        return

    def __repr__(self):
        return 'XmppPlugin(id=0x{0:08X}, ro={1!r:s},'.format(id(self), ['client',
         'contacts',
         'messages',
         'logger'])

    @property
    def client(self):
        return self.__client

    @property
    def logger(self):
        return self.__logger

    @property
    def contacts(self):
        return self.__contacts

    @property
    def messages(self):
        return self.__messages

    @property
    def nicknames(self):
        return self.__nicknameResolver

    @property
    def clanListener(self):
        return self.__clanListener

    def isConnected(self):
        return self.__client.isConnected()

    def clear(self):
        if self.__isClientInited:
            self.__finiClientEnv()
        self.__isClientInited = False
        self.__connection.clear()
        self.__contacts.clear()
        self.__messages.clear()
        self.__logger.clear()
        self.__nicknameResolver.clear()
        if self.__clanListener is not None:
            self.__clanListener.clear()
        return

    def connect(self, scope):
        self.__contacts.switch(scope)
        self.__clanListener = self.__getClanListener()

    def view(self, scope):
        if self.__client.isConnected():
            return
        if not self.__isClientInited:
            self.__initClientEnv()
            self.__isClientInited = True
        self.__connection.connect()

    def disconnect(self):
        self.__connection.disconnect()
        if self.__isClientInited:
            self.__isClientInited = False
            self.__finiClientEnv()
            self.__connection.clear()
            self.__logger.clear()
            self.__nicknameResolver.clear()
            if self.__clanListener is not None:
                self.__clanListener.clear()
        return

    def setFilters(self, msgFilterChain):
        if self.__messages:
            self.__messages.setFilters(msgFilterChain)

    def __initClientEnv(self):
        self.__client.init()
        self.__connection.registerHandlers()
        self.__contacts.registerHandlers()
        self.__messages.registerHandlers()
        self.__logger.registerHandlers()
        self.__nicknameResolver.registerHandlers()
        if self.__clanListener:
            self.__clanListener.registerHandlers()

    def __finiClientEnv(self):
        self.__connection.unregisterHandlers()
        self.__contacts.unregisterHandlers()
        self.__messages.unregisterHandlers()
        self.__logger.unregisterHandlers()
        self.__nicknameResolver.unregisterHandlers()
        if self.__clanListener is not None:
            self.__clanListener.unregisterHandlers()
        self.__client.fini()
        return

    @classmethod
    def __getClanListener(cls):
        """Gets ClanListener instance
        :return: Instance of XmppClanListener, None if xmpp clan channels aren't enabled
        :rtype XmppClanListener
        """
        if g_settings.server.isXmppClansEnabled():
            return XmppClanListener()
        else:
            return None
            return None
Exemple #6
0
class XmppPlugin(IProtoPlugin):
    __slots__ = ('__client', '__contacts', '__connection', '__logger',
                 '__messages', '__isClientInited', '__nicknameResolver')

    def __init__(self):
        self.__client = ClientDecorator()
        self.__contacts = ContactsManager()
        self.__connection = ConnectionHandler()
        self.__messages = MessagesManager()
        self.__logger = LogHandler()
        self.__nicknameResolver = NicknameResolver()
        self.__isClientInited = False

    def __repr__(self):
        return 'XmppPlugin(id=0x{0:08X}, ro={1!r:s},'.format(
            id(self), ['client', 'contacts', 'messages', 'logger'])

    @property
    def client(self):
        return self.__client

    @property
    def logger(self):
        return self.__logger

    @property
    def contacts(self):
        return self.__contacts

    @property
    def messages(self):
        return self.__messages

    @property
    def nicknames(self):
        return self.__nicknameResolver

    def isConnected(self):
        return self.__client.isConnected()

    def clear(self):
        if self.__isClientInited:
            self.__finiClientEnv()
        self.__isClientInited = False
        self.__connection.clear()
        self.__contacts.clear()
        self.__messages.clear()
        self.__logger.clear()
        self.__nicknameResolver.clear()

    def connect(self, scope):
        self.__contacts.switch(scope)

    def view(self, scope):
        if self.__client.isConnected():
            return
        if not self.__isClientInited:
            self.__initClientEnv()
            self.__isClientInited = True
        self.__connection.connect()

    def disconnect(self):
        self.__connection.disconnect()
        if self.__isClientInited:
            self.__isClientInited = False
            self.__finiClientEnv()
            self.__connection.clear()
            self.__logger.clear()
            self.__nicknameResolver.clear()

    def setFilters(self, msgFilterChain):
        if self.__messages:
            self.__messages.setFilters(msgFilterChain)

    def __initClientEnv(self):
        self.__client.init()
        self.__connection.registerHandlers()
        self.__contacts.registerHandlers()
        self.__messages.registerHandlers()
        self.__logger.registerHandlers()
        self.__nicknameResolver.registerHandlers()

    def __finiClientEnv(self):
        self.__connection.unregisterHandlers()
        self.__contacts.unregisterHandlers()
        self.__messages.unregisterHandlers()
        self.__logger.unregisterHandlers()
        self.__nicknameResolver.unregisterHandlers()
        self.__client.fini()