Пример #1
0
def readUTC(section, field, default=None):
    timeData = section.readString(field, '')
    try:
        return timeDataToUTC(timeData, default)
    except Exception as e:
        raise SoftException('Invalid field %s: %s' % (field, e))
 def getActiveEffects(self, effects, args):
     raise SoftException('This function should not be called by hand.')
 def __readId(config):
     if not config.has_key('id'):
         raise SoftException(_ERR_TEMPLATE.format('Missing id',
                                                  config.name))
     return config['id'].asInt
 def initiateSocialLogin(self, socialNetworkName, serverName, rememberUser,
                         isRegistration):
     raise SoftException(
         'This method should not be reached in this context')
 def _doRun(self, client):
     raise SoftException(
         'This method should not be reached in this context')
Пример #6
0
 def __readCondition_IGRType(self, _, section, node):
     igrType = section.asInt
     if igrType not in IGR_TYPE.RANGE:
         raise SoftException('Invalid IGR type %s' % (igrType, ))
     node.addChild(igrType)
 def request(self, callback):
     raise SoftException(
         'This method should not be reached in this context')
Пример #8
0
 def pack(self, model=None):
     raise SoftException('This function should be overriden.')
Пример #9
0
 def registerGuiKeyHandler(self, handler):
     if not isinstance(handler, BattleGUIKeyHandler):
         raise SoftException('Handler should extends BattleGUIKeyHandler')
     if handler not in self.__keyHandlers:
         self.__keyHandlers.append(handler)
Пример #10
0
 def getDetailedTitle(self):
     raise SoftException('This method should not be reached in this context')
Пример #11
0
 def doRawRequest(self, methodName, *args, **kwargs):
     raise SoftException(
         'NOT IMPLEMENTED FOR StrongholdUnitRequestProcessor')
Пример #12
0
 def _findEvents(self, srvEvents):
     raise SoftException('This method should not be reached in this context')
Пример #13
0
def __readBonus_factor(bonus, name, section):
    value = section.asFloat
    if value < 0:
        raise SoftException('Negative value (%s)' % name)
    bonus[name] = value
Пример #14
0
def __readBonus_int(bonus, name, section):
    value = section.asInt
    if value < 0:
        raise SoftException('Negative value (%s)' % name)
    bonus[name] = section.asInt
Пример #15
0
 def __readCondition_cumulative(self, _, section, node):
     for name, sub in section.items():
         if name not in battle_results_shared.VEH_FULL_RESULTS.names(
         ) and name not in battle_results_shared.VEH_BASE_RESULTS.names():
             raise SoftException("Unsupported misc variable '%s'" % name)
         node.addChild((name, int(sub.asFloat)))
Пример #16
0
 def addSortIDs(self, arenaDP, *flags):
     raise SoftException(
         'This method should not be reached in this context')
Пример #17
0
 def __readCondition_attackReason(self, _, section, node):
     attackReason = section.asInt
     if not 0 <= attackReason < len(ATTACK_REASONS):
         raise SoftException('Invalid attack reason index')
     node.addChild(section.asInt)
Пример #18
0
 def addTotalStats(self, stats):
     raise SoftException(
         'This method should not be reached in this context')
Пример #19
0
 def getFileName(self):
     if self.__account is None:
         raise SoftException('Account is not defined')
     return cacheFileName(self.__account, self.__cacheType,
                          self.__cacheName)
Пример #20
0
    def __readXML(self,
                  section,
                  curTime,
                  gStartTime=DEFAULT_QUEST_START_TIME,
                  gFinishTime=DEFAULT_QUEST_FINISH_TIME):
        nodes = {}
        for typeName, questSection in section.items():
            enabled = questSection.readBool('enabled', False)
            if not enabled:
                continue
            eventType = EVENT_TYPE.NAME_TO_TYPE[typeName]
            mainNode = XMLNode('main')
            mainNode.info = info = self.__readHeader(eventType, questSection,
                                                     curTime, gStartTime,
                                                     gFinishTime)
            if not info['announceTime'] <= curTime <= info['finishTime']:
                LOG_WARNING('Skipping outdated quest', info['id'], curTime,
                            info['announceTime'], info['finishTime'])
                continue
            if eventType == EVENT_TYPE.GROUP:
                mainNode.groupContent = tuple(
                    self.__readGroupContent(questSection))
            conditionReaders = self.__getConditionReaders(eventType)
            availableBonuses = self.__getAvailableBonuses(eventType)
            commonNode = XMLNode('common')
            bonusNode = XMLNode('bonus')
            bonusDelayedNode = XMLNode('bonusDelayed')
            prebattleNode = XMLNode('preBattle')
            accountNode = XMLNode('account')
            prebattleNode.addChild(accountNode)
            vehicleNode = XMLNode('vehicle')
            prebattleNode.addChild(vehicleNode)
            battleNode = XMLNode('battle')
            prebattleNode.addChild(battleNode)
            postbattleNode = XMLNode('postBattle')
            mainNode.addChild(prebattleNode)
            mainNode.addChild(postbattleNode)
            mainNode.addChild(commonNode)
            mainNode.addChild(bonusNode)
            mainNode.addChild(bonusDelayedNode)
            info['isIGR'] = accountNode.isExistChildNode('igrType')
            conditions = questSection['conditions']
            if conditions and conditions.has_key('preBattle'):
                condition = conditions['preBattle']
                if condition.has_key('account'):
                    self.__readBattleResultsConditionList(
                        conditionReaders, condition['account'], accountNode)
                if eventType in EVENT_TYPE.LIKE_BATTLE_QUESTS:
                    if condition.has_key('vehicle'):
                        self.__readBattleResultsConditionList(
                            conditionReaders, condition['vehicle'],
                            vehicleNode)
                    if condition.has_key('battle'):
                        self.__readBattleResultsConditionList(
                            conditionReaders, condition['battle'], battleNode)
            if eventType in EVENT_TYPE.LIKE_BATTLE_QUESTS and conditions and conditions.has_key(
                    'postBattle'):
                condition = conditions['postBattle']
                self.__readBattleResultsConditionList(conditionReaders,
                                                      condition,
                                                      postbattleNode)
            if conditions and conditions.has_key('common'):
                condition = conditions['common']
                self.__readBattleResultsConditionList(conditionReaders,
                                                      condition, commonNode)
            daily = commonNode.getChildNode('daily')
            info['isDaily'] = daily is not None
            groupBy = commonNode.getChildNode('groupBy')
            info['groupBy'] = groupBy.getChildNode(
                'groupName').getFirstChildValue() if groupBy else None
            inrow = commonNode.getChildNode('inrow')
            unit = commonNode.getChildNode('unit')
            bonusLimit = commonNode.getChildNode('bonusLimit')
            cumulative = commonNode.getChildNode('cumulative')
            vehicleKills = commonNode.getChildNode('vehicleKills')
            battles = commonNode.getChildNode('battles')
            battleCount = battles.getChildNode(
                'count').getFirstChildValue() if battles else None
            if bonusLimit is None:
                bonusLimitNode = XMLNode('bonusLimit')
                bonusLimitNode.addChild(1 if eventType in EVENT_TYPE.
                                        ONE_BONUS_QUEST else MAX_BONUS_LIMIT)
                commonNode.addChild(bonusLimitNode)
            if eventType in EVENT_TYPE.LIKE_BATTLE_QUESTS:
                if (cumulative or unit or vehicleKills) and inrow:
                    raise SoftException(
                        'battleQuest: Unexpected tags (vehicleKills, cumulative, unit/cumulative) with inrow'
                    )
                if not (cumulative or unit or vehicleKills or bonusLimit
                        or battles) and (daily or groupBy):
                    raise SoftException(
                        'battleQuest: daily and groupBy should be used with cumulative, unit, vehicleKills, bonusLimit or battles tags'
                    )
                if battles and not battleCount:
                    raise SoftException('Invalid battles section')
            elif eventType in EVENT_TYPE.LIKE_TOKEN_QUESTS:
                if cumulative or unit or vehicleKills or groupBy or battles:
                    raise SoftException(
                        'tokenQuest: Unexpected tags (cumulative, unit, vehicleKills, groupBy, battles)'
                    )
                if not bonusLimit and daily:
                    raise SoftException(
                        'tokenQuest: daily should be used with bonusLimit tag')
            mainNode.bonus = walkBonuses(
                readBonusSection(availableBonuses, questSection['bonus'],
                                 eventType), FilterVisitor(eventType))
            mainNode.bonusDelayed = walkBonuses(
                readBonusSection(availableBonuses,
                                 questSection['bonusDelayed'], eventType),
                FilterVisitor(eventType))
            questClientData = dict(info)
            questClientData['bonus'] = deepcopy(mainNode.bonus)
            if mainNode.bonusDelayed is not None:
                questClientData['bonus'].update(mainNode.bonusDelayed)
            questClientData['bonusDelayed'] = deepcopy(mainNode.bonusDelayed)
            questClientData['conditions'] = mainNode.questClientConditions
            if mainNode.groupContent:
                questClientData['groupContent'] = mainNode.groupContent
            self.__stripServerQuestData(questClientData)
            mainNode.info['questClientData'] = questClientData
            nodes.setdefault(eventType, []).append(mainNode)

        return nodes
 def getAvailableSocialNetworks():
     raise SoftException(
         'This method should not be reached in this context')
Пример #22
0
    def __readHeader(self, eventType, questSection, curTime, gStartTime,
                     gFinishTime):
        id = questSection.readString('id', '')
        if not id:
            raise SoftException('Quest id must be specified.')
        if questSection.has_key('name'):
            questName = self.__readMetaSection(questSection['name'])
        else:
            questName = ''
        if questSection.has_key('description'):
            description = self.__readMetaSection(questSection['description'])
        else:
            description = ''
        startTime = readUTC(questSection, 'startTime', gStartTime)
        finishTime = readUTC(questSection, 'finishTime', gFinishTime)
        progressExpiryTime = readUTC(questSection, 'progressExpiryTime',
                                     finishTime)
        defaultAnnounceTime = gStartTime if gStartTime != DEFAULT_QUEST_START_TIME else startTime
        announceTime = readUTC(questSection, 'announceTime',
                               defaultAnnounceTime)
        weekDayNames = questSection.readString('weekDays', '').split()
        weekDays = set([_WEEKDAYS[val] for val in weekDayNames])
        intervalsInString = questSection.readString('activeTimeIntervals',
                                                    '').split()
        makeHM = lambda hm: tuple((int(v) for v in hm.split(':')))
        makeIntervals = lambda intervals: tuple(
            (makeHM(v) for v in intervals.split('_')))
        activeTimeIntervals = [makeIntervals(i) for i in intervalsInString]
        if announceTime < gStartTime:
            raise SoftException(
                'Invalid announce time. announceTime:%s < gStartTime:%s' %
                (announceTime, gStartTime))
        if startTime < announceTime:
            raise SoftException(
                'Invalid announce time. startTime:%s < announceTime:%s' %
                (startTime, announceTime))
        if startTime < gStartTime:
            raise SoftException(
                'Invalid start time. startTime:%s < gStartTime:%s' %
                (startTime, gStartTime))
        if finishTime > gFinishTime:
            raise SoftException(
                'Invalid finish time. finishTime:%s > gFinishTime:%s' %
                (finishTime, gFinishTime))
        if progressExpiryTime < finishTime:
            raise SoftException(
                'Invalid progress expiry time. progressExpiryTime:%s < finishTime:%s'
                % (progressExpiryTime, finishTime))
        requiredToken = questSection.readString('requiredToken', '')
        if eventType == EVENT_TYPE.PERSONAL_QUEST:
            if not requiredToken:
                raise SoftException(
                    'Personal quest must contain tag <requiredToken> with not empty token'
                )
        runFlags = []
        if questSection.has_key('run'):
            for flagName, flagValue in questSection['run'].items():
                if flagName == 'on':
                    runFlags.append(
                        QUEST_RUN_FLAGS.NAME_TO_TYPE[flagValue.asString])

        tOption = curTime > time.time()
        showCongrats = questSection.readBool(
            'showCongrats', eventType in (EVENT_TYPE.PERSONAL_MISSION, ))
        onlyForPeripheriesList = questSection.readString('peripheryIDs', '')
        info = {
            'id': id,
            'hidden': questSection.readBool('hidden', False),
            'serverOnly': questSection.readBool('serverOnly', False),
            'name': questName,
            'type': eventType,
            'description': description,
            'progressExpiryTime': progressExpiryTime,
            'weekDays': weekDays,
            'activeTimeIntervals': activeTimeIntervals,
            'startTime': startTime if not tOption else time.time() - 300,
            'finishTime': finishTime,
            'announceTime': announceTime,
            'disableGui': questSection.readBool('disableGui', False),
            'showCongrats': showCongrats,
            'requiredToken': requiredToken,
            'Toption': None if not tOption else startTime,
            'priority': questSection.readInt('priority', 0),
            'uiDecoration': questSection.readInt('uiDecoration', 0),
            'peripheryIDs': {int(p)
                             for p in onlyForPeripheriesList.split()}
            if onlyForPeripheriesList else set(),
            'runFlags': runFlags
        }
        if eventType == EVENT_TYPE.MOTIVE_QUEST:
            extraSubsectionsNames = ('advice', 'requirements',
                                     'congratulation')
            for subsectionName in extraSubsectionsNames:
                if questSection.has_key(subsectionName):
                    info[subsectionName] = self.__readMetaSection(
                        questSection[subsectionName])

        if eventType == EVENT_TYPE.RANKED_QUEST:
            if finishTime > curTime + _YEAR:
                raise SoftException(
                    "'finishTime' section is missing or too far into the future",
                    info['id'])
            seasonSectionName = 'conditions/common/season'
            if questSection.has_key(seasonSectionName):
                season = questSection[seasonSectionName].asInt
            else:
                raise SoftException("'season' condition is compulsory",
                                    info['id'])
            cycleSectionName = 'conditions/common/cycle'
            if questSection.has_key(cycleSectionName):
                cycle = questSection[cycleSectionName].asInt
            else:
                cycle = None
            info['subtype'] = questSection['subtype'].asString
            info['ranked'] = (season, cycle)
        if eventType in EVENT_TYPE.QUESTS_WITH_SHOP_BUTTON:
            info['shopButton'] = questSection.readString('shopButton', 'hide')
        return info
Пример #23
0
 def _makeQueueCtxByAction(self, action=None):
     invID = g_currentVehicle.invID
     if not invID:
         raise SoftException('Inventory ID of vehicle can not be zero')
     return SandboxQueueCtx(invID, waitingID='prebattle/join')
Пример #24
0
 def __readGroupContent(self, questSection):
     if not questSection.has_key('groupContent'):
         raise SoftException("'groupContent' section is compulsory")
     return questSection.readString('groupContent').split()
Пример #25
0
def _raiseWrongXml(fileName, msg):
    raise SoftException("error in '" + fileName + "': " + msg)
Пример #26
0
 def __readCondition_groupBy(self, _, section, node):
     s = section.asString
     if s not in ('vehicle', 'nation', 'class', 'level'):
         raise SoftException('Unknown groupBy name %s' % s)
     node.addChild(s)
Пример #27
0
def _validateValue1inf(keyName, value):
    if value < 1:
        raise SoftException(
            'invalid value for "%s": %s (it should be in range [1, +inf])' %
            (keyName, value))
Пример #28
0
 def __readCritName(self, _, section, node):
     critName = section.asString
     if critName not in vehicles.VEHICLE_DEVICE_TYPE_NAMES + vehicles.VEHICLE_TANKMAN_TYPE_NAMES:
         raise SoftException('Invalid crit name (%s)' % critName)
     node.addChild(critName)
 def _validateType(self, other):
     if type(self) is not type(other):
         raise SoftException('Comparable MultiSlots has different types',
                             self, other)
 def setUniqueName(self, name):
     raise SoftException('This method is not implemented')