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 __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 __pe_onClanMembersListChanged(self): """Listener for event _PlayerEvents.onClanMembersListChanged. """ clanMembers = getattr(BigWorld.player(), 'clanMembers', {}) LOG_DEBUG('setClanMembersList', clanMembers) clanAbbrev = self.playerCtx.getClanAbbrev() clanDBID = self.playerCtx.getClanDbID() members = [] if self.__clanChannel is not None: getter = self.__clanChannel.getMember else: def getter(dbID): return None playerID = getPlayerDatabaseID() for dbID, (name, roleFlags) in clanMembers.iteritems(): if getter(dbID) is None: gos = GAME_ONLINE_STATUS.UNDEFINED else: gos = GAME_ONLINE_STATUS.ONLINE if playerID == dbID: user = XMPPUserEntity(dbID, name=name, clanInfo=ClanInfo(clanDBID, clanAbbrev, roleFlags)) else: user = XMPPUserEntity(dbID, name=name, clanInfo=ClanInfo(clanDBID, clanAbbrev, roleFlags), gos=gos, tags={USER_TAG.CLAN_MEMBER}) members.append(user) self.usersStorage.setClanMembersList(members) return
def __pe_onClanMembersListChanged(self): clanMembers = getattr(BigWorld.player(), 'clanMembers', {}) LOG_DEBUG('setClanMembersList', clanMembers) if not self.__initSteps & _INIT_STEPS.MEMBERS_LIST_RECEIVED: self.__initSteps |= _INIT_STEPS.MEMBERS_LIST_RECEIVED clanAbbrev = self.playerCtx.getClanAbbrev() members = [] if self.__clanChannel is not None: getter = self.__clanChannel.getMember else: getter = lambda dbID: None playerID = getPlayerDatabaseID() for dbID, (name, roleFlags) in clanMembers.iteritems(): if getter(dbID) is None: gos = GAME_ONLINE_STATUS.UNDEFINED else: gos = GAME_ONLINE_STATUS.ONLINE if playerID == dbID: user = CurrentUserEntity(dbID, name=name, clanInfo=ClanInfo(0, clanAbbrev, roleFlags)) else: user = SharedUserEntity(dbID, name=name, clanInfo=ClanInfo(0, clanAbbrev, roleFlags), gos=gos, tags={USER_TAG.CLAN_MEMBER}) members.append(user) self.usersStorage.setClanMembersList(members) if self.__initSteps & _INIT_STEPS.LIST_INITED != 0: g_messengerEvents.users.onClanMembersListChanged() return
def getMember(self, memberDbID=None): memberDbID = memberDbID or getPlayerDatabaseID() if self.hasMember(memberDbID): return self.__makeMemberItem(memberDbID, self._clubDescr.members[memberDbID]) else: return None
def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return LOG_DEBUG('Clan gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request() if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the clan lib...') result = yield self.sendRequest( contexts.LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for clan gate', response) self.__loginState = nextLoginState if self.isLoggedOn(): self._clanCtrl.onStateUpdated() self.__processWaitingRequests() callback(self.isLoggedOn())
def getPermissions(self, memberDbID = None): if memberDbID is None: memberDbID = getPlayerDatabaseID() if self.hasMember(memberDbID): return MemberPermissions(self._clubDescr.members[memberDbID]) else: return DefaultMemberPermissions()
def __pe_onClanMembersListChanged(self): clanMembers = getattr(BigWorld.player(), 'clanMembers', {}) LOG_DEBUG('setClanMembersList', clanMembers) if not self.__initSteps & _INIT_STEPS.MEMBERS_LIST_RECEIVED: self.__initSteps |= _INIT_STEPS.MEMBERS_LIST_RECEIVED clanAbbrev = self.playerCtx.getClanAbbrev() members = [] if self.__clanChannel is not None: getter = self.__clanChannel.getMember else: getter = lambda dbID: None playerID = getPlayerDatabaseID() for dbID, (name, roleFlags) in clanMembers.iteritems(): if getter(dbID) is None: gos = GAME_ONLINE_STATUS.UNDEFINED else: gos = GAME_ONLINE_STATUS.ONLINE if playerID == dbID: user = CurrentUserEntity(dbID, name=name, clanInfo=ClanInfo( 0, clanAbbrev, roleFlags)) else: user = SharedUserEntity(dbID, name=name, clanInfo=ClanInfo( 0, clanAbbrev, roleFlags), gos=gos, tags={USER_TAG.CLAN_MEMBER}) members.append(user) self.usersStorage.setClanMembersList(members) if self.__initSteps & _INIT_STEPS.LIST_INITED != 0: g_messengerEvents.users.onClanMembersListChanged() return
def restoreFromCache(self): if self.__storageCache: return from gui.shared.utils import getPlayerDatabaseID, getPlayerName self.__storageCache = StorageLocalCache((getPlayerDatabaseID(), getPlayerName(), 'storage')) self.__storageCache.onRead += self.__onRead self.__storageCache.read()
def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return LOG_DEBUG('Clan gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request() if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the clan lib...') result = yield self.sendRequest(contexts.LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for clan gate', response) self.__loginState = nextLoginState if self.isLoggedOn(): self._clanCtrl.onStateUpdated() self.__processWaitingRequests() callback(self.isLoggedOn())
def __onPlayerSpeaking(self, accountDBID, isSpeak): """ Raise flash event after receiving notification about player speaking. :param accountDBID: player db id :param isSpeak: is player speaking """ self.as_onPlayerSpeakS(accountDBID, isSpeak, accountDBID == getPlayerDatabaseID())
def getPermissions(self, memberDbID=None): if memberDbID is None: memberDbID = getPlayerDatabaseID() if self.hasMember(memberDbID): return MemberPermissions(self._clubDescr.members[memberDbID]) else: return DefaultMemberPermissions()
def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return LOG_DEBUG('Wgcg gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request(allowDelay=True) if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the wgcg lib...') responseTime = time_utils.getServerUTCTime() result = yield self.sendRequest( LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON data = result.getData() self.__accessTokenData = AccessTokenData( data['access_token'], responseTime + float(data['expires_in'])) else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for wgcg gate', response) self.__loginState = nextLoginState self.__clanSync = False self.__processWaitingRequests() callback(self.isLoggedOn())
def getFullJID(self, databaseID = None): if databaseID is None: databaseID = getPlayerDatabaseID() raise databaseID or AssertionError("Player's databaseID can not be empty") jid = ContactJID() jid.setNode(databaseID) jid.setDomain(self.domain) jid.setResource(self.resource) return jid
def getFullJID(self, databaseID=None): if databaseID is None: databaseID = getPlayerDatabaseID() assert databaseID, "Player's databaseID can not be empty" jid = ContactJID() jid.setNode(databaseID) jid.setDomain(self.domain) jid.setResource(self.resource) return jid
def _updateInvites(self, invites): self._contactsState |= _CONTACTS_LIST.INVITES prevInvites = self._invites self._invites = {} for sendingTime, inviterDbID, clubDbID, status, updatingTime in invites: invite = ClubInvite(clubDbID, getPlayerDatabaseID(), inviterDbID, sendingTime, status, updatingTime) self._invites[invite.getID()] = invite self.__processInvitations(prevInvites)
def __removeMember(self, jid, dbID, nickname): _, found = self._searchChannel(jid.getBareJID()) if dbID: leave = utils.getPlayerDatabaseID() == dbID else: leave = utils.getPlayerName() == nickname if leave: self._removeChannel(found) else: found.removeMember(jid)
def _updateApps(self, apps): self._apps = {} for clubDbID, sendingTime, comment, status, updatingTime in apps: app = ClubApplication(clubDbID, getPlayerDatabaseID(), comment, sendingTime, status, updatingTime) self._apps[app.getID()] = app if not self._isSynced: self.__notify('onAccountClubAppsInited', self._apps.values()) else: self.__notify('onAccountClubAppsChanged', self._apps.values())
def getFullJID(self, databaseID=None): if databaseID is None: databaseID = getPlayerDatabaseID() if not databaseID: raise SoftException("Player's databaseID can not be empty") jid = ContactJID() jid.setNode(databaseID) jid.setDomain(self.domain) jid.setResource(self.resource) return jid
def __init__(self): super(ClanPersonalInvitesView, self).__init__() self._paginator = ClanPersonalInvitesPaginator(self.webCtrl, getPlayerDatabaseID(), [CLAN_INVITE_STATES.ACTIVE]) self._cooldown = CooldownHelper([WebRequestDataType.ACCEPT_APPLICATION, WebRequestDataType.ACCEPT_INVITE, WebRequestDataType.DECLINE_APPLICATION, WebRequestDataType.DECLINE_INVITE, WebRequestDataType.DECLINE_INVITES, WebRequestDataType.CLANS_INFO, WebRequestDataType.CLAN_RATINGS, WebRequestDataType.ACCOUNT_INVITES], self._onCooldownHandle, CoolDownEvent.WGCG)
def __removeMember(self, jid, dbID, nickname): _, found = self._searchChannel(jid.getBareJID()) if found: if dbID: leave = utils.getPlayerDatabaseID() == dbID else: leave = utils.getPlayerName() == nickname if leave: self._removeChannel(found) else: found.removeMember(jid)
def __init__(self): super(ClanPersonalInvitesView, self).__init__() self._paginator = ClanPersonalInvitesPaginator(g_clanCtrl, getPlayerDatabaseID(), [CLAN_INVITE_STATES.ACTIVE]) self._cooldown = CooldownHelper([CLAN_REQUESTED_DATA_TYPE.ACCEPT_APPLICATION, CLAN_REQUESTED_DATA_TYPE.ACCEPT_INVITE, CLAN_REQUESTED_DATA_TYPE.DECLINE_APPLICATION, CLAN_REQUESTED_DATA_TYPE.DECLINE_INVITE, CLAN_REQUESTED_DATA_TYPE.DECLINE_INVITES, CLAN_REQUESTED_DATA_TYPE.CLANS_INFO, CLAN_REQUESTED_DATA_TYPE.CLAN_RATINGS, CLAN_REQUESTED_DATA_TYPE.ACCOUNT_INVITES], self._onCooldownHandle, CoolDownEvent.CLAN)
def __updateVehicles(self): maxVehs = self._proxy.getConfig().maxVehiclesPerPlayer valid = [INV_ID_CLEAR_VEHICLE] * maxVehs slots = self.__getExtra().accountVehicles.get(getPlayerDatabaseID(), ()) vehicles = map(lambda (vehInvID, vehIntCD): vehInvID, slots) vehGetter = g_itemsCache.items.getVehicle for idx, invID in enumerate(vehicles[:maxVehs]): invVehicle = vehGetter(invID) if invVehicle is not None: valid[idx] = invID self.__vehicles = valid
def sendMessage(self, jid, body, filters): channel = self.channelsStorage.getChannel(entities.XMPPChatChannelEntity(jid)) if channel: if self.playerCtx.isBanned(components=XMPP_BAN_COMPONENT.PRIVATE): error = createChatBanError(self.playerCtx.getBanInfo()) if error: g_messengerEvents.onErrorReceived(error) return dbID = getPlayerDatabaseID() name = getPlayerName() g_messengerEvents.channels.onMessageReceived(ChatMessage(dbID, name, filters.chainIn(dbID, body), time.time()), channel) self.client().sendMessage(ChatMessageHolder(jid, msgBody=body))
def _addChannel(self, channel, dbID, name): contact = self.usersStorage.getUser(dbID) if contact: if contact.isIgnored(): return None isOnline = contact.isOnline() else: isOnline = False channel.addMembers([entities.XMPPMemberEntity(getPlayerDatabaseID(), getPlayerName(), True), entities.XMPPMemberEntity(dbID, name, isOnline)]) if self.channelsStorage.addChannel(channel): channel.setStored(True) g_messengerEvents.channels.onChannelInited(channel) return channel
def onUnitRosterChanged(self): super(FortBattleRoomWindow, self).onUnitRosterChanged() chat = self.chat if chat: _, unit = self.unitFunctional.getUnit() commanderID = unit.getCommanderDBID() if commanderID != getPlayerDatabaseID(): getter = storage_getter('users') commander = getter().getUser(commanderID) division = getDivisionNameByUnit(unit) divisionName = i18n.makeString(I18N_SYSTEM_MESSAGES.unit_notification_divisiontype(division)) key = I18N_SYSTEM_MESSAGES.UNIT_NOTIFICATION_CHANGEDIVISION txt = i18n.makeString(key, name=commander.getName(), division=divisionName) chat.addNotification(txt)
def __init__(self): super(ClanPersonalInvitesView, self).__init__() self._paginator = ClanPersonalInvitesPaginator( self.clansCtrl, getPlayerDatabaseID(), [CLAN_INVITE_STATES.ACTIVE]) self._cooldown = CooldownHelper([ CLAN_REQUESTED_DATA_TYPE.ACCEPT_APPLICATION, CLAN_REQUESTED_DATA_TYPE.ACCEPT_INVITE, CLAN_REQUESTED_DATA_TYPE.DECLINE_APPLICATION, CLAN_REQUESTED_DATA_TYPE.DECLINE_INVITE, CLAN_REQUESTED_DATA_TYPE.DECLINE_INVITES, CLAN_REQUESTED_DATA_TYPE.CLANS_INFO, CLAN_REQUESTED_DATA_TYPE.CLAN_RATINGS, CLAN_REQUESTED_DATA_TYPE.ACCOUNT_INVITES ], self._onCooldownHandle, CoolDownEvent.CLAN)
def getLeaderEventEnqueueData(self): selfDBID = getPlayerDatabaseID() if self.isCommander(dbID=selfDBID): return None else: unitId, unit = self.getUnit() for slot in self.getSlotsIterator(unitId, unit): if not slot.player: continue dbID = slot.player.dbID pInfo = self.getPlayerInfo(dbID=dbID) if pInfo.isReady and self.isCommander(dbID=dbID): return pInfo.extraData.get('eventEnqueueData', {}) return None
def sendMessage(self, jid, body, filters): channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) if channel: if self.playerCtx.isBanned(components=XMPP_BAN_COMPONENT.PRIVATE): error = createChatBanError(self.playerCtx.getBanInfo()) if error: g_messengerEvents.onErrorReceived(error) return dbID = getPlayerDatabaseID() name = getPlayerName() g_messengerEvents.channels.onMessageReceived( ChatMessage(dbID, name, filters.chainIn(dbID, body), time.time()), channel) self.client().sendMessage(ChatMessageHolder(jid, msgBody=body))
def _getOldInviteMaker(self, rosterGetter): receiver = getPlayerName() receiverDBID = getPlayerDatabaseID() receiverClanAbbrev = self.lobbyContext.getClanAbbrev(self.__clanInfo) def _inviteMaker(item): (prebattleID, peripheryID), data = item inviteID = self._makeInviteID(prebattleID, peripheryID, data['creatorDBID'], receiverDBID) if data is not None: invite = PrbInviteWrapper(clientID=inviteID, receiver=receiver, receiverDBID=receiverDBID, receiverClanAbbrev=receiverClanAbbrev, peripheryID=peripheryID, prebattleID=prebattleID, **data) else: invite = None return (inviteID, invite) return _inviteMaker
def _getOldInviteMaker(self, rosterGetter): receiver = getPlayerName() receiverDBID = getPlayerDatabaseID() receiverClanAbbrev = g_lobbyContext.getClanAbbrev(self.__clanInfo) def _inviteMaker(item): (prebattleID, peripheryID), data = item inviteID = self._makeInviteID(prebattleID, peripheryID, data['creatorDBID'], receiverDBID) if data is not None: invite = PrbInviteWrapper(clientID=inviteID, receiver=receiver, receiverDBID=receiverDBID, receiverClanAbbrev=receiverClanAbbrev, peripheryID=peripheryID, prebattleID=prebattleID, **data) else: invite = None return (inviteID, invite) return _inviteMaker
def _addChannel(self, channel, dbID, name): contact = self.usersStorage.getUser(dbID) if contact: if contact.isIgnored(): return None isOnline = contact.isOnline() else: isOnline = False channel.addMembers([ entities.XMPPMemberEntity(getPlayerDatabaseID(), getPlayerName(), True), entities.XMPPMemberEntity(dbID, name, isOnline) ]) if self.channelsStorage.addChannel(channel): channel.setStored(True) g_messengerEvents.channels.onChannelInited(channel) return channel
def onUnitRosterChanged(self): super(FortBattleRoomWindow, self).onUnitRosterChanged() chat = self.chat if chat: _, unit = self.unitFunctional.getUnit() commanderID = unit.getCommanderDBID() if commanderID != getPlayerDatabaseID(): getter = storage_getter('users') commander = getter().getUser(commanderID) division = getDivisionNameByUnit(unit) divisionName = i18n.makeString( I18N_SYSTEM_MESSAGES.unit_notification_divisiontype( division)) key = I18N_SYSTEM_MESSAGES.UNIT_NOTIFICATION_CHANGEDIVISION txt = i18n.makeString(key, name=commander.getName(), division=divisionName) chat.addNotification(txt)
def __sendRequest(self, invite, context, sucessStatus): self.__sentRequestCount += 1 userDbID = getPlayerDatabaseID() temp = self.__accountNameMapping.get(userDbID, set()) temp.add(invite.getDbID()) self.__accountNameMapping[userDbID] = temp result = yield self._requester.sendRequest(context, allowDelay=True) if result.isSuccess(): status = sucessStatus else: status = CLAN_INVITE_STATES.ERROR result, users = yield self._requester.requestUsers([userDbID]) sender = users.get(userDbID, items.AccountClanRatingsData(userDbID)) senderName = self.getUserName(userDbID) item = self.__updateInvite(invite, status, sender, senderName) self.syncUsersInfo() self.__sentRequestCount -= 1 self.onListItemsUpdated(self, [item])
def setPresence(self, jid, dbID, nickname, presence, mucInfo): result = False if self._step == ENTRY_STEP.UNDEFINED: return result else: if jid.getBareJID() == self._room.getID(): result = True if presence in PRESENCE.OFFLINE: self._room.removeMember(jid) if jid == self._getUserJID(): self._leave(mucInfo) else: if not dbID and mucInfo is not None and MUC_STATUS.SELF_PRESENCE in mucInfo.statuses: dbID = utils.getPlayerDatabaseID() self._room.addMember(entities.XMPPMUCOccupant(jid, nickname, dbID, presence, mucInfo)) if jid == self._getUserJID(): self._join(mucInfo) return result
def __setClanInfo(self, info): if info: length = len(info) else: length = 0 if length > 1: abbrev = info[1] else: abbrev = "" if length > 3: role = info[3] else: role = 0 clanInfo = ClanInfo(abbrev=abbrev, role=role) self.playerCtx._setClanInfo(clanInfo) user = self.usersStorage.getUser(getPlayerDatabaseID()) if user: user.update(clanInfo=clanInfo) user.addTags({USER_TAG.CLAN_MEMBER})
def __setClanInfo(self, info): if info: length = len(info) else: length = 0 if length > 1: abbrev = info[1] else: abbrev = '' if length > 3: role = info[3] else: role = 0 clanInfo = ClanInfo(abbrev=abbrev, role=role) self.playerCtx._setClanInfo(clanInfo) user = self.usersStorage.getUser(getPlayerDatabaseID()) if user: user.update(clanInfo=clanInfo) user.addTags({USER_TAG.CLAN_MEMBER})
def handlePresence(self, jid, resource): result = False presence = resource.presence if not self.__isAccountInited and utils.getPlayerDatabaseID() == resource.getWgDatabaseID() and presence == PRESENCE.AVAILABLE: self.release(excludeLazy=True) self.__isAccountInited = True if g_settings.server.XMPP.isMucServiceAllowed(hostname=jid.getDomain()): mucInfo = resource.getMucInfo() dbID = resource.getWgDatabaseID() nickname = resource.getWgNickname() or jid.getResource() for action in self.__actions.itervalues(): result |= action.setPresence(jid, dbID, nickname, presence, mucInfo) if not result: if presence in PRESENCE.OFFLINE: self.__removeMember(jid, dbID, nickname) else: self.__addMember(jid, dbID, nickname, presence, mucInfo) self.__filterActions() return result
def __setClanInfo(self, info): if info: length = len(info) else: length = 0 if length > _CLAN_INFO_ABBREV_INDEX: abbrev = info[_CLAN_INFO_ABBREV_INDEX] else: abbrev = '' if length > _CLAN_INFO_ROLE_INDEX: role = info[_CLAN_INFO_ROLE_INDEX] else: role = 0 clanDBID = g_itemsCache.items.stats.clanDBID clanInfo = ClanInfo(dbID=clanDBID, abbrev=abbrev, role=role) self.playerCtx.setClanInfo(clanInfo) user = self.usersStorage.getUser(getPlayerDatabaseID()) if user: user.update(clanInfo=clanInfo) user.addTags({USER_TAG.CLAN_MEMBER})
def __setClanInfo(self, info): if info: length = len(info) else: length = 0 if length > _CLAN_INFO_ABBREV_INDEX: abbrev = info[_CLAN_INFO_ABBREV_INDEX] else: abbrev = '' if length > _CLAN_INFO_ROLE_INDEX: role = info[_CLAN_INFO_ROLE_INDEX] else: role = 0 clanDBID = self.itemsCache.items.stats.clanDBID clanInfo = ClanInfo(dbID=clanDBID, abbrev=abbrev, role=role) self.playerCtx.setClanInfo(clanInfo) user = self.usersStorage.getUser(getPlayerDatabaseID()) if user: user.update(clanInfo=clanInfo) user.addTags({USER_TAG.CLAN_MEMBER})
def __sendRequest(self, invite, context, successStatus): self.__sentRequestCount += 1 userDbID = getPlayerDatabaseID() temp = self.__accountNameMapping.get(userDbID, set()) temp.add(invite.getDbID()) self.__accountNameMapping[userDbID] = temp result = yield self._requester.sendRequest(context, allowDelay=True) if result.isSuccess(): status = (successStatus, None) else: status = (CLAN_INVITE_STATES.ERROR, result.getCode()) result, users = yield self._requester.requestUsers([userDbID]) sender = users.get(userDbID, items.AccountClanRatingsData(userDbID)) senderName = self.getUserName(userDbID) changerName = getPlayerName() item = self.__updateInvite(invite, status, sender, senderName, changerName) self.syncUsersInfo() self.__sentRequestCount -= 1 self.onListItemsUpdated(self, [item]) return
def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return else: self.__accessTokenData = None LOG_DEBUG('Clan gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request(allowDelay=True) if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the clan lib...') responseTime = time_utils.getCurrentTimestamp() result = yield self.sendRequest(contexts.LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON data = result.getData() accessToken = data.get(_FIELD_ACCESS_TOKEN, None) if accessToken is not None: expiresIn = data.get(_FIELD_EXPIRES_IN, 0) if expiresIn is None: LOG_WARNING('Login success but ExpiresIn not defined! Use default value == 0!') else: responseTime += float(expiresIn) self.__accessTokenData = AccessTokenData(accessToken, responseTime) else: LOG_WARNING('Login success but AccessToken not defined!') else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for clan gate', response) self.__loginState = nextLoginState self.__clanSync = False self.__processWaitingRequests() callback(self.isLoggedOn()) return
def _getInfo4AccountPlayer(): return (getPlayerDatabaseID(), getPlayerName(), None)
def isCurrentPlayer(dbID): return getPlayerDatabaseID() == dbID
def __ce_onConnectStateChanged(self, channel): if self.__isPrivateOpen and channel.isJoined() and channel.isPrivate() and channel.getProtoType() == PROTO_TYPE.BW and channel.getProtoData().owner == getPlayerDatabaseID(): g_messengerEvents.channels.onPlayerEnterChannelByAction(channel)
def canRevokeInvite(self, invite): result = False if invite.clientID in self.__invites: result = invite.clientID > 0 and invite.isActive() and invite.creatorDBID == getPlayerDatabaseID() return result
def isIncoming(self): return self.ownerDBID != getPlayerDatabaseID()
def getName(self): channelName = self._data.channelName if getPlayerDatabaseID() != self._data.owner: channelName = passCensor(channelName) return cgi.escape(channelName)
def getMember(self, memberDbID = None): memberDbID = memberDbID or getPlayerDatabaseID() if self.hasMember(memberDbID): return self.__makeMemberItem(memberDbID, self._clubDescr.members[memberDbID]) else: return None
def getPlayerFullJID(self): return g_settings.server.XMPP.getFullJID(getPlayerDatabaseID())
def __init__(self): super(ClanPersonalInvitesView, self).__init__() self._paginator = ClanPersonalInvitesPaginator(g_clanCtrl, getPlayerDatabaseID(), [CLAN_INVITE_STATES.ACTIVE]) self._cooldown = CooldownHelper(self.__coolDownRequests, self._onCooldownHandle, CoolDownEvent.CLAN)