def __handlePresence(self, jid, resource): jid = ContactJID(jid) dbID = jid.getDatabaseID() if not dbID: return else: user = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP) if resource.presence == PRESENCE.UNAVAILABLE: if user and not user.isCurrentPlayer(): user.update(jid=jid, resource=None, clanInfo=resource.getClanInfo()) g_logOutput.debug(_LOG.RESOURCE, 'Resource is removed', user.getName(), jid.getResource(), resource) elif resource.presence != PRESENCE.UNKNOWN: if not user: user = entities.XMPPUserEntity(dbID) self.usersStorage.setUser(user) if user.isCurrentPlayer(): self.playerCtx.setBanInfo(resource.getBanInfo()) else: user.update(jid=jid, resource=resource, clanInfo=resource.getClanInfo()) g_logOutput.debug(_LOG.RESOURCE, 'Resource is set', user.getName(), jid.getResource(), resource) if user: g_messengerEvents.users.onUserStatusUpdated(user) return
def __addContactToXmppRoster(self, jid, userName = '******', groups = None): if not GROUPS_SYNC_ENABLED: groups = None client = self.client() g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'Adds contact from BW roster and sends request to add subscription', jid, userName, groups) client.setContactToRoster(jid, userName, groups) client.setSubscribeTo(jid)
def connect(self): if self.__reconnectCallbackID is None: self.__connectionsInfo.init() self.__doConnect() else: g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Connection already is processing') return
def _doSync(self, name, groups=None, sub=None, clanInfo=None): user = super(AddRosterItemTask, self)._doSync(name, groups, sub, clanInfo) if user: g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Item is added to roster', user) self._doNotify(USER_ACTION_ID.FRIEND_ADDED, user)
def sync(self): if self.__isBWRosterReceived and self.client().isConnected(): g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'Syncing XMPP rosters from BW') domain = g_settings.server.XMPP.domain contacts = set() for user in self.usersStorage.getList(_BWRosterFindCriteria()): jid = ContactBareJID() jid.setNode(user.getID()) jid.setDomain(domain) contacts.add(jid) if user.isCurrentPlayer(): self.xmppRoster[jid].name = user.getName() continue groups = self.__getBWRosterGroups(user) if self.xmppRoster.hasItem(jid): if GROUPS_SYNC_ENABLED and groups ^ self.xmppRoster[jid].groups: self.__setContactToXmppRoster(jid, user.getName(), groups) if self.xmppRoster[jid].subscriptionTo == SUBSCRIPTION.OFF: self.__setSubscribeTo(jid) else: self.__addContactToXmppRoster(jid, user.getName(), groups) toRemove = set(self.xmppRoster.keys()).difference(contacts) for jid in toRemove: contact = self.xmppRoster[jid] if contact.subscriptionFrom != SUBSCRIPTION.OFF: if contact.subscriptionTo == SUBSCRIPTION.ON: self.__removeSubscribeTo(jid) else: self.__removeContactFromXmppRoster(jid)
def __addToLocalXmppRoster(self, jid, name, groups, to, from_): if self.xmppRoster.hasItem(jid): g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'Updating item in local XMPP roster', jid, name, groups, to, from_) self.xmppRoster[jid].update(name, groups, to, from_) else: g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'Adding item to local XMPP roster', jid, name, groups, to, from_) self.xmppRoster[jid] = RosterItem(jid, name, groups, to, from_)
def addMessage(self, jid, message): if message.isHistory(): self.__historyRQ.addHistory(message) return dbID = message.accountDBID name = message.accountName if jid not in self.__sessions and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(dbID) if not contact or not USER_TAG.filterClosedContactsTags(contact.getTags()): g_logOutput.debug( CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's message is ignored", jid, name, ) return search = entities.XMPPChatChannelEntity(jid, name) channel = self.channelsStorage.getChannel(search) if not channel: channel = self._addChannel(search, dbID, name) if not channel: return self.__sessions.add(jid) if message.body: g_messengerEvents.channels.onMessageReceived(message, channel)
def addMessage(self, jid, message): if message.isHistory(): self.__historyRQ.addHistory(message) return else: contactDBID = message.accountDBID or jid.getDatabaseID() nickname = message.accountName or jid.getNode() created, exists = self._searchChannel(jid, nickname) if exists is None and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(contactDBID) if not contact or not USER_TAG.filterClosedContactsTags( contact.getTags()): g_logOutput.debug( CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's message is ignored", jid, nickname) return if exists is None: if self.__addSession(created, contactDBID): exists = created else: return if message.body: g_messengerEvents.channels.onMessageReceived(message, exists) return
def __handleRosterResourceRemoved(self, jid): user = self.usersStorage.getUser(jid.getDatabaseID(), PROTO_TYPE.XMPP) if user and not user.isCurrentPlayer(): user.update(jid=jid, resource=None) g_logOutput.debug(CLIENT_LOG_AREA.RESOURCE, 'Resource is removed', jid.getResource(), user.getName()) g_messengerEvents.users.onUserStatusUpdated(user) return
def disconnect(self): client = self.client() if client: g_logOutput.debug( CLIENT_LOG_AREA.CONNECTION, 'Sends request to disconnect and removes all listeners') client.disconnect() self.clear()
def __handleRosterItemSet(self, jid, name, groups, sub, clanInfo): g_logOutput.debug(_LOG.ROSTER, 'Roster push is received', jid, name, groups, sub, clanInfo) self.__tasks.sync(jid, name, groups, sub, clanInfo, defaultTask=roster_tasks.SyncSubscriptionTask)
def __onSeqsInited(self): g_logOutput.debug(_LOG.GENERIC, 'Starts to process contacts tasks') self.__presence.sendPresence(True) self.__tasks.release() self.__tasks.onSeqTaskRequested += self.__onSeqTaskRequested self.__subsRestrictions.setToUseCachedCounts(True) self.__subsBatch.process(self.__tasks) self.__subsRestrictions.setToUseCachedCounts(False) g_messengerEvents.users.onUsersListReceived({USER_TAG.FRIEND, USER_TAG.IGNORED})
def __onSeqsInited(self): g_logOutput.debug(_LOG.GENERIC, 'Starts to process contacts tasks') self.__presence.sendPresence(True) self.__tasks.release() self.__tasks.onSeqTaskRequested += self.__onSeqTaskRequested self.__subsRestrictions.setToUseCachedCounts(True) self.__subsBatch.process(self.__tasks) self.__subsRestrictions.setToUseCachedCounts(False) g_messengerEvents.users.onUsersListReceived({USER_TAG.FRIEND, USER_TAG.IGNORED, USER_TAG.MUTED})
def _doRun(self, client): user = self._getUser() if user and user.getItemType() in XMPP_ITEM_TYPE.TMP_BLOCKING_LIST: user.update(item=None) user.removeTags({USER_TAG.MUTED}) g_logOutput.debug(CLIENT_LOG_AREA.BLOCK_LIST, 'Temporary block item is removed', self._jid, {'name': self._name}) self._doNotify(USER_ACTION_ID.TMP_IGNORED_REMOVED, user) self._doNotify(USER_ACTION_ID.MUTE_UNSET, user, False) self._result = TASK_RESULT.REMOVE return
def __handleRosterResourceAdded(self, jid, resource): dbID = jid.getDatabaseID() user = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP) if not user: user = entities.XMPPUserEntity(dbID) self.usersStorage.setUser(user) if not user.isCurrentPlayer(): user.update(jid=jid, resource=resource) g_logOutput.debug(CLIENT_LOG_AREA.RESOURCE, 'Resource is set', user.getName(), jid.getResource(), resource) g_messengerEvents.users.onUserStatusUpdated(user)
def _doSync(self, name, groups = None, sub = None, clanInfo = None): user = self._getUser() if not user or user.isCurrentPlayer(): return user if user.getItemType() == XMPP_ITEM_TYPE.ROSTER_ITEM: user.update(item=None) _syncEmptyGroups(self.usersStorage, self._groups) g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Roster item is removed', user) self._doNotify(USER_ACTION_ID.FRIEND_REMOVED, user) return user
def set(self, pyGlooxTag): result = blocking_cmd.BlockItemHandler().handleTag(pyGlooxTag) jid, info = findFirst(None, result, ('', {})) if jid != self._jid: return user = _syncBlockItem(self.usersStorage, self._jid, **info) if user: g_logOutput.debug(CLIENT_LOG_AREA.BLOCK_LIST, 'Block item is added', jid, info) self._doNotify(USER_ACTION_ID.IGNORED_ADDED, user) self._doNotify(USER_ACTION_ID.MUTE_SET, user, False) self._result = TASK_RESULT.REMOVE
def _doRun(self, client): user = self._getUser() if not user: contact = entities.XMPPUserEntity(self._jid.getDatabaseID(), name=self._name) self.usersStorage.setUser(contact) user = _syncTmpBlockItem(self.usersStorage, self._jid, name=self._name) if user: g_logOutput.debug(CLIENT_LOG_AREA.BLOCK_LIST, 'Temporary block item is added', self._jid, {'name': self._name}) self._doNotify(USER_ACTION_ID.TMP_IGNORED_ADDED, user) self._doNotify(USER_ACTION_ID.MUTE_SET, user, False) self._result = TASK_RESULT.REMOVE
def __handleTokenError(self): client = self.client() if not client: return if self.__reqTokenBackOff.getTries() < _MAX_REQ_TOKEN_TRIES: delay = self.__reqTokenBackOff.next() self.__reqTokenCallbackID = BigWorld.callback(delay, self.__doNextLogin) g_logOutput.debug(CLIENT_LOG_AREA.TOKEN, 'Will try to request token after {0} seconds'.format(delay)) else: self.client().disconnect() self.__handleDisconnect(DISCONNECT_REASON.OTHER_ERROR, 'Received chat token is not valid')
def __handlePresenceWithIGR(self, jid, resource): dbID = jid.getDatabaseID() user = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP) if user and user.isCurrentPlayer(): return if not user: user = entities.XMPPUserEntity(dbID) self.usersStorage.setUser(user) user.update(jid=jid, resource=resource) g_logOutput.debug(CLIENT_LOG_AREA.RESOURCE, 'Resource with IGR is set', user.getName(), jid.getResource(), resource) g_messengerEvents.users.onUserActionReceived(USER_ACTION_ID.IGR_CHANGED, user)
def _populate(self, taskQueue): jids = [] while self._cancelTasks: jid, tasks = self._cancelTasks.popitem() jids.append(jid) if taskQueue.addTasks(jid, *tasks): taskQueue.runFirstTask(jid) if jids: g_logOutput.debug(_LOG.SUBSCRIPTION, 'Inbound subscriptions are canceled automatically', jids[:10]) jids = [] while self._approveTasks: jid, tasks = self._approveTasks.popitem() jids.append(jid) if taskQueue.addTasks(jid, *tasks): taskQueue.runFirstTask(jid) if jids: g_logOutput.debug(_LOG.SUBSCRIPTION, 'Inbound subscriptions are approved automatically', jids[:10]) if self._newRqs: g_logOutput.debug(_LOG.SUBSCRIPTION, 'New inbound subscriptions are received', self._newRqs[:10]) g_messengerEvents.users.onFriendshipRequestsAdded(self._newRqs) if self._oldRqs: g_logOutput.debug(_LOG.SUBSCRIPTION, 'Inbound subscriptions are ignored to display', self._oldRqs[:10]) g_messengerEvents.users.onFriendshipRequestsUpdated(self._oldRqs)
def _populate(self, taskQueue): jids = [] while self._cancelTasks: jid, tasks = self._cancelTasks.popitem() jids.append(jid) if taskQueue.addTasks(jid, *tasks): taskQueue.runFirstTask(jid) if jids: g_logOutput.debug( _LOG.SUBSCRIPTION, 'Inbound subscriptions are canceled automatically', jids[:10]) jids = [] while self._approveTasks: jid, tasks = self._approveTasks.popitem() jids.append(jid) if taskQueue.addTasks(jid, *tasks): taskQueue.runFirstTask(jid) if jids: g_logOutput.debug( _LOG.SUBSCRIPTION, 'Inbound subscriptions are approved automatically', jids[:10]) if self._newRqs: g_logOutput.debug(_LOG.SUBSCRIPTION, 'New inbound subscriptions are received', self._newRqs[:10]) g_messengerEvents.users.onFriendshipRequestsAdded(self._newRqs) if self._oldRqs: g_logOutput.debug(_LOG.SUBSCRIPTION, 'Inbound subscriptions are ignored to display', self._oldRqs[:10]) g_messengerEvents.users.onFriendshipRequestsUpdated(self._oldRqs)
def _doSync(self, name, groups = None, sub = None, clanInfo = None): user = self._getUser() if not user or user.isCurrentPlayer(): return user if user.getItemType() in XMPP_ITEM_TYPE.ROSTER_ITEMS: user.update(item=ContactItem(user.getJID())) _syncEmptyGroups(self.usersStorage, self._groups) g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Roster item is removed', user) self._doNotify(USER_ACTION_ID.FRIEND_REMOVED, user) elif user.getItemType() in XMPP_ITEM_TYPE.SUB_PENDING_ITEMS: user.update(item=ContactItem(user.getJID())) _syncEmptyGroups(self.usersStorage, self._groups) g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Friendship request is revoked by sender', user) g_messengerEvents.users.onFriendshipRequestsUpdated([user]) return user
def set(self, pyGlooxTag): result = blocking_cmd.UnblockItemHandler().handleTag(pyGlooxTag) jid, info = findFirst(None, result, ('', {})) if jid != self._jid: return user = self._getUser() if user and user.getItemType() in XMPP_ITEM_TYPE.BLOCKING_LIST: user.update(item=None) user.removeTags({USER_TAG.MUTED}) g_logOutput.debug(CLIENT_LOG_AREA.BLOCK_LIST, 'Block item is removed', jid, info) self._doNotify(USER_ACTION_ID.IGNORED_REMOVED, user) self._doNotify(USER_ACTION_ID.MUTE_UNSET, user, False) if user.isFriend(): self._doNotify(USER_ACTION_ID.FRIEND_ADDED, user, False) self._result = TASK_RESULT.REMOVE
def sendEventToServer(eventType, host, port, errorCode=0, errorDescr="", tries=1): sender = getattr(BigWorld.player(), "logXMPPEvents", None) if not sender or not callable(sender): return address = "{0}:{1}".format(host, port) currentTime = time.time() g_logOutput.debug( CLIENT_LOG_AREA.GENERIC, "Sends log to server", [eventType, currentTime, errorCode, tries], [address, errorDescr], ) try: sender([eventType, currentTime, errorCode, tries], [address, errorDescr]) except: LOG_CURRENT_EXCEPTION()
def __handleDisconnect(self, reason, description): client = self.client() if not client: return g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Client is disconnected') self.__cancelReconnectCallback() self.__cancelReqTokenCallback() if reason == DISCONNECT_REASON.AUTHENTICATION: self.__tokenRequester.clear() if self.isInGameServer() and reason != DISCONNECT_REASON.BY_REQUEST: delay = self.__connectionsInfo.getNextDelay() self.__reconnectCallbackID = BigWorld.callback(delay, self.__doNextConnect) g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Will try to reconnect after {0} seconds'.format(delay), description) (host, port,) = self.__connectionsInfo.getLastAddress() tries = self.__connectionsInfo.getTries() sendEventToServer(XMPP_EVENT_LOG.DISCONNECT, host, port, reason, description, tries)
def onMessageReceived(self, jid, body, _, info, sentAt): dbID = info['dbID'] name = info['name'] if jid not in self.__sessions and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(dbID) if not contact or not USER_TAG.filterClosedContactsTags(contact.getTags()): g_logOutput.debug(CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's massage is ignored", jid, name) return search = entities.XMPPChatChannelEntity(jid, name) channel = self.channelsStorage.getChannel(search) if not channel: channel = self._addChannel(search, dbID, name, True) if not channel: return self.__sessions.add(jid) if body: g_messengerEvents.channels.onMessageReceived(XMPPMessageData(dbID, name, body, sentAt), channel)
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')
def __handleDisconnect(self, reason, description): g_messengerEvents.onPluginDisconnected(PROTO_TYPE.XMPP) client = self.client() if not client: return g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Client is disconnected') self.__cancelReconnectCallback() self.__cancelReqTokenCallback() if reason == DISCONNECT_REASON.AUTHENTICATION: self.__tokenRequester.clear() if self.isInGameServer() and reason != DISCONNECT_REASON.BY_REQUEST: delay = self.__connectionsInfo.getNextDelay() self.__reconnectCallbackID = BigWorld.callback(delay, self.__doNextConnect) g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Will try to reconnect after {0} seconds'.format(delay), description) host, port = self.__connectionsInfo.getLastAddress() tries = self.__connectionsInfo.getTries() g_messengerEvents.onPluginConnectFailed(PROTO_TYPE.XMPP, (host, port), tries) sendEventToServer(XMPP_EVENT_LOG.DISCONNECT, host, port, reason, description, tries)
def sendEventToServer(eventType, host, port, errorCode=0, errorDescr='', tries=1): sender = getattr(BigWorld.player(), 'logXMPPEvents', None) if not sender or not callable(sender): return address = '{0}:{1}'.format(host, port) currentTime = time.time() g_logOutput.debug(CLIENT_LOG_AREA.GENERIC, 'Sends log to server', [eventType, currentTime, errorCode, tries], [address, errorDescr]) try: sender([eventType, currentTime, errorCode, tries], [address, errorDescr]) except: LOG_CURRENT_EXCEPTION()
def __handlePresence(self, jid, resource): dbID = jid.getDatabaseID() user = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP) if resource.presence == PRESENCE.UNAVAILABLE: if user and not user.isCurrentPlayer(): user.update(jid=jid, resource=None, clanInfo=resource.getClanInfo()) g_logOutput.debug(_LOG.RESOURCE, 'Resource is removed', user.getName(), jid.getResource(), resource) elif resource.presence != PRESENCE.UNKNOWN: if not user: user = entities.XMPPUserEntity(dbID) self.usersStorage.setUser(user) if user.isCurrentPlayer(): self.playerCtx.setBanInfo(resource.getBanInfo()) else: user.update(jid=jid, resource=resource, clanInfo=resource.getClanInfo()) g_logOutput.debug(_LOG.RESOURCE, 'Resource is set', user.getName(), jid.getResource(), resource) if user: g_messengerEvents.users.onUserStatusUpdated(user) return
def __me_onRosterUpdate(self, actionIdx, user): groups = self.__getBWRosterGroups(user) databaseID = user.getID() g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'BW roster update', groups, user) jid = ContactBareJID() jid.setNode(databaseID) jid.setDomain(g_settings.server.XMPP.domain) hasItem = self.xmppRoster.hasItem(jid) if len(groups): if hasItem: if GROUPS_SYNC_ENABLED and groups ^ self.xmppRoster[jid].groups: self.__setContactToXmppRoster(jid, user.getName(), groups) self.__setSubscribeTo(jid) else: self.__addContactToXmppRoster(jid, user.getName(), groups) elif hasItem: self.__removeSubscribeTo(jid) if actionIdx == USER_ROSTER_ACTION.RemoveFromFriend and g_settings.server.useToShowOnline(PROTO_TYPE.XMPP) and not self.usersStorage.isClanMember(databaseID): user.update(isOnline=False)
def addMessage(self, jid, message): if message.isHistory(): self.__historyRQ.addHistory(message) return else: contactDBID = message.accountDBID or jid.getDatabaseID() nickname = message.accountName or jid.getNode() created, exists = self._searchChannel(jid, nickname) if exists is None and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(contactDBID) if not contact or not USER_TAG.filterClosedContactsTags(contact.getTags()): g_logOutput.debug(CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's message is ignored", jid, nickname) return if exists is None: if self.__addSession(created, contactDBID): exists = created else: return if message.body: g_messengerEvents.channels.onMessageReceived(message, exists) return
def sendEventToServer(eventType, host, port, errorCode = 0, errorDescr = '', tries = 1): player = BigWorld.player() sender = getattr(player, 'logXMPPEvents', None) if sender is None or not callable(sender) or not player.isPlayer or player.isDestroyed: return else: address = '{0}:{1}'.format(host, port) currentTime = time.time() g_logOutput.debug(CLIENT_LOG_AREA.GENERIC, 'Sends log to server', [eventType, currentTime, errorCode, tries], [address, errorDescr]) try: sender([eventType, currentTime, errorCode, tries], [address, errorDescr]) except: LOG_CURRENT_EXCEPTION() return
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()
def log(self): if g_settings.server.XMPP.isEnabled(): client = self.client() if client and client.isConnected(): g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Client is connected to XMPP', client.getConnectionAddress()) else: g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Client is not connected to XMPP') else: g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'XMPP protocol is disabled')
def sendEventToServer(eventType, host, port, errorCode=0, errorDescr='', tries=1): player = BigWorld.player() sender = getattr(player, 'logXMPPEvents', None) if sender is None or not callable( sender) or not player.isPlayer or player.isDestroyed: return else: address = '{0}:{1}'.format(host, port) currentTime = time.time() g_logOutput.debug(CLIENT_LOG_AREA.GENERIC, 'Sends log to server', [eventType, currentTime, errorCode, tries], [address, errorDescr]) try: sender([eventType, currentTime, errorCode, tries], [address, errorDescr]) except Exception: LOG_CURRENT_EXCEPTION() return
def addMessage(self, jid, message): if message.isHistory(): self.__historyRQ.addHistory(message) return dbID = message.accountDBID name = message.accountName if jid not in self.__sessions and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(dbID) if not contact or not USER_TAG.filterClosedContactsTags( contact.getTags()): g_logOutput.debug( CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's message is ignored", jid, name) return search = entities.XMPPChatChannelEntity(jid, name) channel = self.channelsStorage.getChannel(search) if not channel: channel = self._addChannel(search, dbID, name) if not channel: return self.__sessions.add(jid) if message.body: g_messengerEvents.channels.onMessageReceived(message, channel)
def log(self, request = None): if g_settings.server.XMPP.isEnabled(): client = self.client() if client and client.isConnected(): roster = self.xmppRoster result = ['Client is connected to XMPP. XMPP roster is:'] for (jid, item,) in roster.iteritems(): if request is None or request == 'to' and item.subscriptionTo != SUBSCRIPTION.OFF or request == 'from' and item.subscriptionFrom != SUBSCRIPTION.OFF: result.append(repr(item)) g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, '\n'.join(result)) else: g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Client is not connected to XMPP yet. Try to run it command later.') else: g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'XMPP protocol is disabled')
def log(self): if g_settings.server.XMPP.isEnabled(): client = self.client() if client and client.isConnected(): roster = self.xmppRoster result = ['Client is connected to XMPP. XMPP groups are:'] groups = defaultdict(set) for item in roster.itervalues(): if len(item.groups): contactGroups = item.groups for group in contactGroups: groups[group].add('name = {0}, jid = {1}'.format(item.name, item.jid)) for (group, names,) in sorted(groups.iteritems()): result.append(group + ':') result.append('\t\t' + '\n\t\t'.join(names)) result.append('\n') g_logOutput.debug(CLIENT_LOG_AREA.GROUP, '\n'.join(result)) else: g_logOutput.debug(CLIENT_LOG_AREA.GROUP, 'Client is not connected to XMPP yet. Try to run it command later') else: g_logOutput.debug(CLIENT_LOG_AREA.GROUP, 'XMPP protocol is disabled')
def __handleRosterResult(self, generator): g_logOutput.debug(_LOG.ROSTER, 'Roster result is received') self.__seq.sync(0, generator())
def _doSync(self, name, groups = None, sub = None, clanInfo = None): user = super(AddRosterItemTask, self)._doSync(name, groups, sub, clanInfo) if user: g_logOutput.debug(CLIENT_LOG_AREA.ROSTER, 'Item is added to roster', user) self._doNotify(USER_ACTION_ID.FRIEND_ADDED, user)
def __handleLogin(self): g_logOutput.debug(CLIENT_LOG_AREA.LOGIN, 'Client is login') self.__connectionsInfo.clear() self.__reqTokenBackOff.reset() g_messengerEvents.onPluginConnected(PROTO_TYPE.XMPP)
def __handleConnect(self): g_logOutput.debug(CLIENT_LOG_AREA.CONNECTION, 'Client is connected') self.__cancelReconnectCallback() self.__reqTokenBackOff.reset() self.__doLogin()