def __getCompanyAvailabilityData(self): tooltipData = TOOLTIPS.BATTLETYPES_COMPANY battle = g_eventsCache.getCompanyBattles() header = i18n.makeString(tooltipData + "/header") body = i18n.makeString(tooltipData + "/body") serversList = [] if battle.isValid() and battle.isDestroyingTimeCorrect(): for peripheryID in battle.peripheryIDs: host = g_preDefinedHosts.periphery(peripheryID) if host is not None: serversList.append(host.name) beginDate = "" endDate = "" serversString = "" if battle.startTime is not None: beginDate = i18n.makeString( TOOLTIPS.BATTLETYPES_AVAILABLETIME_SINCE, beginDate=BigWorld.wg_getShortDateFormat(battle.startTime) ) if battle.finishTime is not None: endDate = i18n.makeString( TOOLTIPS.BATTLETYPES_AVAILABLETIME_UNTIL, endDate=BigWorld.wg_getShortDateFormat(battle.finishTime) ) if serversList: serversString = i18n.makeString( TOOLTIPS.BATTLETYPES_AVAILABLETIME_SERVERS, servers=", ".join(serversList) ) if beginDate or endDate or serversString: restrictInfo = i18n.makeString( TOOLTIPS.BATTLETYPES_AVAILABLETIME, since=beginDate, until=endDate, servers=serversString ) body = "%s\n\n%s" % (body, restrictInfo) return makeTooltip(header, body)
def canAcceptInvite(self, invite): result = False if invite.alwaysAvailable is True: result = True elif invite.clientID in self.__invites: dispatcher = self.__loader.getDispatcher() if dispatcher: if invite.alreadyJoined: return False if dispatcher.getEntity().hasLockedState(): return False another = invite.anotherPeriphery if another: if g_preDefinedHosts.periphery(invite.peripheryID) is None: LOG_ERROR('Periphery not found') result = False elif self.lobbyContext.getCredentials() is None: LOG_ERROR('Login info not found') result = False elif g_preDefinedHosts.isRoamingPeriphery(invite.peripheryID) and not isRoamingEnabled(self.itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported') result = False else: result = invite.clientID > 0 and invite.isActive() else: result = invite.clientID > 0 and invite.isActive() return result
def __getCompanyAvailabilityData(self): tooltipData = TOOLTIPS.BATTLETYPES_COMPANY battle = g_eventsCache.getCompanyBattles() header = i18n.makeString(tooltipData + '/header') body = i18n.makeString(tooltipData + '/body') serversList = [] if battle.isValid() and battle.isDestroyingTimeCorrect(): for peripheryID in battle.peripheryIDs: host = g_preDefinedHosts.periphery(peripheryID) if host is not None: serversList.append(host.name) beginDate = '' endDate = '' serversString = '' if battle.startTime is not None: beginDate = i18n.makeString(TOOLTIPS.BATTLETYPES_AVAILABLETIME_SINCE, beginDate=BigWorld.wg_getShortDateFormat(battle.startTime)) if battle.finishTime is not None: endDate = i18n.makeString(TOOLTIPS.BATTLETYPES_AVAILABLETIME_UNTIL, endDate=BigWorld.wg_getShortDateFormat(battle.finishTime)) if serversList: serversString = i18n.makeString(TOOLTIPS.BATTLETYPES_AVAILABLETIME_SERVERS, servers=', '.join(serversList)) if beginDate or endDate or serversString: restrictInfo = i18n.makeString(TOOLTIPS.BATTLETYPES_AVAILABLETIME, since=beginDate, until=endDate, servers=serversString) body = '%s\n\n%s' % (body, restrictInfo) return makeTooltip(header, body)
def _getFortSortiesSchemaTexts(activatedDefModeParams, peripheryID, buildingsCount, dirsCount): if activatedDefModeParams: dayOff, defHour, vacation = activatedDefModeParams if dayOff == NOT_ACTIVATED: dayOffString = _ms(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_NODAYOFF) else: dayOffString = fort_fmts.getDayOffString(dayOff) defHourStart, _ = defHour or (None, None) if defHourStart is not None: defHour = fort_fmts.getDefencePeriodString(defHourStart) else: defHour = '' vacStart, vacEnd = vacation if vacStart is not None: vacationString = fort_fmts.getVacationPeriodString(vacStart, vacEnd) else: vacationString = _ms(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_NOVACATION) else: defHour = CLANS.SECTION_FORT_DEFENCE_NOTACTIVATED vacationString = dayOffString = None periphery = g_preDefinedHosts.periphery(peripheryID) if periphery is not None: serverName = periphery.name else: serverName = connectionManager.serverUserName return {'totalBuildingsCount': str(buildingsCount), 'totalDirectionsCount': str(dirsCount), 'defenceHour': defHour, 'server': serverName, 'vacation': vacationString, 'dayOff': dayOffString}
def getPeripheryName(self, peripheryID): name = None if self.isAnotherPeriphery(peripheryID): host = g_preDefinedHosts.periphery(peripheryID) if host is not None: name = host.name return name
def canAcceptInvite(self, invite): result = False if invite.alwaysAvailable is True: result = True elif invite.clientID in self.__invites: dispatcher = self.__loader.getDispatcher() if dispatcher: prbFunctional = dispatcher.getPrbFunctional() unitFunctional = dispatcher.getUnitFunctional() preQueueFunctional = dispatcher.getPreQueueFunctional() if invite.alreadyJoined: return False if prbFunctional and prbFunctional.hasLockedState() or unitFunctional and unitFunctional.hasLockedState() or preQueueFunctional and preQueueFunctional.hasLockedState(): return False another = invite.anotherPeriphery if another: if g_preDefinedHosts.periphery(invite.peripheryID) is None: LOG_ERROR('Periphery not found') result = False elif g_lobbyContext.getCredentials() is None: LOG_ERROR('Login info not found') result = False elif g_preDefinedHosts.isRoamingPeriphery(invite.peripheryID) and not isRoamingEnabled(g_itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported') result = False else: result = invite.clientID > 0 and invite.isActive() else: result = invite.clientID > 0 and invite.isActive() return result
def getPeripheryName(self, peripheryID, checkAnother=True): name = None if not checkAnother or self.isAnotherPeriphery(peripheryID): host = g_preDefinedHosts.periphery(peripheryID) if host is not None: name = host.name return name
def canAcceptInvite(self, invite): result = False if invite.id in self.__receivedInvites: from gui.prb_control.dispatcher import g_prbLoader dispatcher = g_prbLoader.getDispatcher() if dispatcher: prbFunctional = dispatcher.getPrbFunctional() unitFunctional = dispatcher.getUnitFunctional() return (prbFunctional and prbFunctional.hasLockedState() or unitFunctional and unitFunctional.hasLockedState()) and False another = invite.anotherPeriphery if another: if g_preDefinedHosts.periphery(invite.peripheryID) is None: LOG_ERROR('Periphery not found') result = False elif g_lobbyContext.getCredentials() is None: LOG_ERROR('Login info not found') result = False elif g_preDefinedHosts.isRoamingPeriphery( invite.peripheryID) and not isRoamingEnabled( g_itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported') result = False elif invite.id > 0: result = invite.isActive() else: result = invite.id > 0 and invite.isActive() return result
def canAcceptInvite(self, invite): result = False if invite.id in self.__receivedInvites: from gui.prb_control.dispatcher import g_prbLoader dispatcher = g_prbLoader.getDispatcher() if dispatcher: prbFunctional = dispatcher.getPrbFunctional() unitFunctional = dispatcher.getUnitFunctional() return (prbFunctional and prbFunctional.hasLockedState() or unitFunctional and unitFunctional.hasLockedState()) and False another = invite.anotherPeriphery if another: if g_preDefinedHosts.periphery(invite.peripheryID) is None: LOG_ERROR('Periphery not found') result = False elif g_lobbyContext.getCredentials() is None: LOG_ERROR('Login info not found') result = False elif g_preDefinedHosts.isRoamingPeriphery(invite.peripheryID) and not isRoamingEnabled(g_itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported') result = False elif invite.id > 0: result = invite.isActive() else: result = invite.id > 0 and invite.isActive() return result
def __init__(self, peripheryID): super(ConnectToPeriphery, self).__init__() self.__host = g_preDefinedHosts.periphery(peripheryID) self.__endTime = None self.__credentials = self.lobbyContext.getCredentials() self.__wgcLogin = False return
def __processKick(self, peripheryID): if peripheryID > 0: host = g_preDefinedHosts.periphery(peripheryID, False) if host is not None: self.__setHostData(host) self.__reconnect() self.onKickWhileLoginReceived(peripheryID) return
def __getAcceptNotAllowedNote(self, invite): text = '' if invite.anotherPeriphery and invite.isActive(): host = g_preDefinedHosts.periphery(invite.peripheryID) if host is not None: text = ACCEPT_NOT_ALLOWED_I18N_STRING[1] % host.name else: text = ACCEPT_NOT_ALLOWED_I18N_STRING[0] return text
def __getNoteText(self, invite): note = '' hasModalEntity, prbType = self.prbDispatcher.getFunctionalState() if hasModalEntity and prbType: prbName = PREBATTLE_GUI_KEYS.get(prbType, DEF_PREBATTLE_GUI_KEY) if invite.anotherPeriphery: note = i18n.makeString( '#{0:>s}:invites/note/{1:>s}/leave_and_change'.format( INVITES_I18N_FILE, prbName), host=g_preDefinedHosts.periphery(invite.peripheryID).name) else: note = i18n.makeString( '#{0:>s}:invites/note/{1:>s}/leave'.format( INVITES_I18N_FILE, prbName)) elif invite.anotherPeriphery: note = i18n.makeString( '#{0:>s}:invites/note/server_change'.format(INVITES_I18N_FILE), host=g_preDefinedHosts.periphery(invite.peripheryID).name) return note
def isPeripheryAvailable(self, peripheryID): result = True if g_preDefinedHosts.periphery(peripheryID) is None: LOG_ERROR('Periphery not found', peripheryID) result = False elif self.__credentials is None: LOG_ERROR('Login info not found', peripheryID) result = False elif g_preDefinedHosts.isRoamingPeriphery(peripheryID) and not isRoamingEnabled(g_itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported', peripheryID) result = False return result
def __updateForbiddenSortiesData(self): sortiesAvailable, servAvailable = self.__getSortieCurfewStatus() settings = g_lobbyContext.getServerSettings() guiData = {'timeLimits': getForbiddenPeriods(settings.getForbiddenSortieHours(), formatGuiTimeLimitStr)} pIds = settings.getForbiddenSortiePeripheryIDs() if pIds: namesList = [] for pId in pIds: periphery = g_preDefinedHosts.periphery(pId) if periphery: namesList.append(periphery.name) guiData['serverName'] = ', '.join(namesList) self.as_setRegulationInfoS(guiData) self.as_setCurfewEnabledS(not sortiesAvailable or not servAvailable)
def isPeripheryAvailable(self, peripheryID): result = True if _isSkipPeripheryChecking(): LOG_NOTE('Skip periphery checking in standalone mode') return result else: if g_preDefinedHosts.periphery(peripheryID) is None: LOG_ERROR('Periphery not found', peripheryID) result = False elif self.__credentials is None: LOG_ERROR('Login info not found', peripheryID) result = False elif g_preDefinedHosts.isRoamingPeriphery(peripheryID) and not isRoamingEnabled(g_itemsCache.items.stats.attributes): LOG_ERROR('Roaming is not supported', peripheryID) result = False return result
def join(self, ctx, callback = None): player = BigWorld.player() if hasattr(player, 'prebattleAutoInvites'): peripheryID = player.prebattleAutoInvites.get(ctx.getID(), {}).get('peripheryID', 0) if peripheryID and peripheryID != connectionManager.peripheryID: pInfo = g_preDefinedHosts.periphery(peripheryID) if pInfo is None: message = i18n.makeString(SYSTEM_MESSAGES.ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_UNKNOWN) else: message = i18n.makeString(SYSTEM_MESSAGES.ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_KNOWN, pInfo.name) SystemMessages.pushMessage(message, type=SystemMessages.SM_TYPE.Warning) if callback: callback(False) return super(BattleSessionEntry, self).join(ctx, callback) return
def _getHost(self, authMethod, hostName): if hostName != AUTO_LOGIN_QUERY_URL: return hostName else: pickledData = self._preferences['peripheryLifetime'] if pickledData: try: peripheryID, expirationTimestamp = pickle.loads(pickledData) except Exception: LOG_DEBUG("Couldn't to read pickled periphery data. Connecting to {0}.".format(hostName)) return hostName if expirationTimestamp > time.time(): host = g_preDefinedHosts.periphery(peripheryID, False) if host is None: return hostName if authMethod != CONNECTION_METHOD.BASIC and host.urlToken: return host.urlToken return host.url return hostName
def _getHost(self, authMethod, hostName): if hostName != AUTO_LOGIN_QUERY_URL: return hostName else: pickledData = self._preferences['peripheryLifetime'] if pickledData: try: peripheryID, expirationTimestamp = pickle.loads(pickledData) except: LOG_DEBUG("Couldn't to read pickled periphery data. Connecting to {0}.".format(hostName)) return hostName if expirationTimestamp > time.time(): host = g_preDefinedHosts.periphery(peripheryID, False) if host is None: return hostName if authMethod != CONNECTION_METHOD.BASIC and host.urlToken: return host.urlToken return host.url return hostName
def join(self, ctx, callback=None): player = BigWorld.player() if hasattr(player, 'prebattleAutoInvites'): peripheryID = player.prebattleAutoInvites.get(ctx.getID(), {}).get( 'peripheryID', 0) if peripheryID and peripheryID != connectionManager.peripheryID: pInfo = g_preDefinedHosts.periphery(peripheryID) if pInfo is None: message = i18n.makeString( SYSTEM_MESSAGES. ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_UNKNOWN) else: message = i18n.makeString( SYSTEM_MESSAGES. ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_KNOWN, pInfo.name) SystemMessages.pushMessage(message, type=SystemMessages.SM_TYPE.Warning) if callback: callback(False) return super(BattleSessionEntry, self).join(ctx, callback) return
def getPeripheryName(self): periphery = g_preDefinedHosts.periphery(self.periphery) if periphery is not None: return periphery.name else: return ''
def __init__(self, peripheryID): super(ConnectToPeriphery, self).__init__() self.__host = g_preDefinedHosts.periphery(peripheryID) self.__endTime = None self.__credentials = g_lobbyContext.getCredentials() return
def getDisplayableData(self, clanDBID): fortCtrl = g_clanCache.fortProvider.getController() isFortFrozen = False if clanDBID is None: fort = fortCtrl.getFort() fortDossier = fort.getFortDossier() battlesStats = fortDossier.getBattlesStats() isFortFrozen = self._isFortFrozen() clanName, clanMotto, clanTag = g_clanCache.clanName, '', g_clanCache.clanTag clanLvl = fort.level if fort is not None else 0 homePeripheryID = fort.peripheryID playersAtClan, buildingsNum = len(g_clanCache.clanMembers), len(fort.getBuildingsCompleted()) wEfficiencyVal = ProfileUtils.getFormattedWinsEfficiency(battlesStats) combatCount, winsEff, profitEff = battlesStats.getBattlesCount(), ProfileUtils.UNAVAILABLE_SYMBOL if wEfficiencyVal == str(ProfileUtils.UNAVAILABLE_VALUE) else wEfficiencyVal, battlesStats.getProfitFactor() creationTime = fortDossier.getGlobalStats().getCreationTime() defence, vacation, offDay = fort.getDefencePeriod(), fort.getVacationDate(), fort.getLocalOffDay() elif type(clanDBID) in (types.IntType, types.LongType, types.FloatType): clanInfo = fortCtrl.getPublicInfoCache().getItem(clanDBID) if clanInfo is None: LOG_WARNING('Requested clan info is empty', clanDBID) return clanName, clanMotto = clanInfo.getClanName(), '' clanTag, clanLvl = '[%s]' % clanInfo.getClanAbbrev(), clanInfo.getLevel() homePeripheryID = clanInfo.getHomePeripheryID() playersAtClan, buildingsNum = (None, None) combatCount, profitEff = clanInfo.getBattleCount(), clanInfo.getProfitFactor() creationTime = None defence, offDay = clanInfo.getDefencePeriod(), clanInfo.getLocalOffDay() vacation = clanInfo.getVacationPeriod() winsEff = None else: LOG_WARNING('Invalid clanDBID identifier', clanDBID, type(clanDBID)) return topStats = [] host = g_preDefinedHosts.periphery(homePeripheryID) if host is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_HOMEPEREPHIRY), host.name)) if playersAtClan is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_PLAYERSATCLAN), playersAtClan)) if buildingsNum is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_BUILDINGSATFORTIFICATION), buildingsNum)) if combatCount is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_FIGHTSFORFORTIFICATION), combatCount)) if winsEff is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_WINPERCENTAGE), winsEff)) if profitEff is not None: topStats.append((i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_PROFITPERCENTAGE), BigWorld.wg_getNiceNumberFormat(profitEff) if profitEff > 0 else ProfileUtils.UNAVAILABLE_SYMBOL)) if creationTime is not None: fortCreationData = self.app.utilsManager.textManager.getText(TextType.NEUTRAL_TEXT, i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPCLANINFO_FORTCREATIONDATE, creationDate=BigWorld.wg_getLongDateFormat(creationTime))) else: fortCreationData = None def _makeLabels(stats, itemIdx): return '\n'.join((str(a[itemIdx]) for a in stats)) infoTexts, protectionHeader = [], '' if defence[0]: if isFortFrozen: protectionHeader = self.app.utilsManager.textManager.getText(TextType.ERROR_TEXT, i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_DEFENSETIMESTOPPED)) else: protectionHeader = self.app.utilsManager.textManager.getText(TextType.HIGH_TITLE, i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_DEFENSETIME)) statsValueColor = TextType.DISABLE_TEXT if isFortFrozen else TextType.STATS_TEXT defencePeriodString = i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_PERIOD, startTime=BigWorld.wg_getShortTimeFormat(defence[0]), finishTime=BigWorld.wg_getShortTimeFormat(defence[1])) defencePeriodString = self.app.utilsManager.textManager.getText(statsValueColor, defencePeriodString) infoTexts.append(i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_DEFENSEHOUR, period=defencePeriodString)) if offDay > -1: dayOffString = i18n.makeString('#menu:dateTime/weekDays/full/%d' % (offDay + 1)) else: dayOffString = i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_NODAYOFF) dayOffString = self.app.utilsManager.textManager.getText(statsValueColor, dayOffString) infoTexts.append(i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_DAYOFF, dayOff=dayOffString)) if vacation[0] and vacation[1]: vacationString = i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_PERIOD, startTime=BigWorld.wg_getShortDateFormat(vacation[0]), finishTime=BigWorld.wg_getShortDateFormat(vacation[1])) else: vacationString = i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_NOVACATION) vacationString = self.app.utilsManager.textManager.getText(statsValueColor, vacationString) infoTexts.append(i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_VACATION, period=vacationString)) return {'headerText': self.app.utilsManager.textManager.getText(TextType.HIGH_TITLE, i18n.makeString(TOOLTIPS.FORTIFICATION_TOOLTIPENEMYCLANINFO_HEADER, clanTag=clanTag, clanLevel=fort_formatters.getTextLevel(clanLvl))), 'fullClanName': self.app.utilsManager.textManager.getText(TextType.NEUTRAL_TEXT, clanName), 'sloganText': self.app.utilsManager.textManager.getText(TextType.STANDARD_TEXT, clanMotto), 'infoDescriptionTopText': self.app.utilsManager.textManager.getText(TextType.MAIN_TEXT, _makeLabels(topStats, 0)), 'infoTopText': self.app.utilsManager.textManager.getText('statsText', _makeLabels(topStats, 1)), 'infoDescriptionBottomText': '', 'infoBottomText': '', 'protectionHeaderText': protectionHeader, 'infoText': makeHtmlString('html_templates:lobby/fortifications/tooltips/defense_description', 'main', {'text': '\n'.join(infoTexts)}), 'fortCreationDate': fortCreationData}
def setServerPreselection(self, peripheryId): hostItem = g_preDefinedHosts.periphery(peripheryId) if hostItem is not None: self._loginPreferences['server_name'] = hostItem.url self.updateServerList() return
def __getNoteText(self, invite): note = '' hasModalEntity, prbType = self.prbDispatcher.getFunctionalState() if hasModalEntity and prbType: prbName = PREBATTLE_GUI_KEYS.get(prbType, DEF_PREBATTLE_GUI_KEY) if invite.anotherPeriphery: note = i18n.makeString('#{0:>s}:invites/note/{1:>s}/leave_and_change'.format(INVITES_I18N_FILE, prbName), host=g_preDefinedHosts.periphery(invite.peripheryID).name) else: note = i18n.makeString('#{0:>s}:invites/note/{1:>s}/leave'.format(INVITES_I18N_FILE, prbName)) elif invite.anotherPeriphery: note = i18n.makeString('#{0:>s}:invites/note/server_change'.format(INVITES_I18N_FILE), host=g_preDefinedHosts.periphery(invite.peripheryID).name) return note