예제 #1
0
    def parse(cls, conf):
        """解析"""
        ret = cls()
        ret.conf = conf
        ret.startRank = conf["ranking"]["start"]
        ret.endRank = conf["ranking"]["end"]

        rewards = conf.get("rewards", [])
        ret.rewards = []
        for reward in rewards:
            if not isinstance(reward, dict):
                raise MatchConfException("reward item must dict")
            itemId = reward.get("itemId", None)
            if not isstring(itemId) or not itemId:
                raise MatchConfException(
                    "reward item.name must be not empty string")
            count = reward.get("count", None)
            if not isinstance(count, (int, float)) or count < 0:
                raise MatchConfException(
                    "reward item.count must be int or float >= 0")
            if count > 0:
                ret.rewards.append(reward)

        ret.desc = conf["desc"]
        ret.message = conf.get("message", None)
        ret.todotask = conf.get("todotask", None)
        return ret.checkValid()
예제 #2
0
 def checkValid(self):
     """检查是否合法"""
     if not isinstance(self.matchId, int):
         raise MatchConfException("matchId must be int")
     if not isinstance(self.tableSeatCount,
                       int) or self.tableSeatCount <= 0:
         raise MatchConfException("table.seat.count must be int > 0")
     return self
예제 #3
0
 def checkValid(self):
     """检查是否合法"""
     if not isinstance(self.startRank, int) or self.startRank < -1:
         raise MatchConfException("rank.start must be int >= -1")
     if not isinstance(self.endRank, int) or self.endRank < -1:
         raise MatchConfException("rank.end must be int >= -1")
     if self.endRank != -1 and self.endRank < self.startRank:
         raise MatchConfException(
             "rank.end must greater than rewards.rank.start")
     return self
예제 #4
0
    def parse(cls, gameId, roomId, matchId, name, conf):
        """
        解析房间配置
        :param gameId:
        :param roomId:
        :param matchId: bigRoomId 44401
        :param name: 房间名
        :param conf: 比赛配置
        """
        ret = MatchConfig()
        ret.conf = conf  # 比赛配置
        ret.gameId = gameId
        ret.roomId = roomId
        ret.matchId = matchId
        ret.recordId = matchId
        ret.name = name
        ret.desc = conf.get("desc", "")
        ret.tableSeatCount = conf.get("table.seat.count", None)
        ret.fishPool = conf.get("fishPool", 44101)
        ret.bullet = conf.get("bullet", 0)
        ret.playingTime = conf.get("playingTime", 240)
        ret.discountTime = conf.get("discountTime", [])
        start = conf.get("start", None)
        if not isinstance(start, dict):
            raise MatchConfException("start must be dict")
        ret.start = StartConfig.parse(start)

        fees = conf.get("fees", [])
        ret.fees = []
        for fee in fees:
            matchFee = MatchFee.decodeFromDict(fee)
            if matchFee.count > 0:
                ret.fees.append(matchFee)
        # 开赛的tips
        ret.tips = cls.getTipsConfigClass().parse(conf.get("tips", {}))
        ret.stages = []
        stages = conf.get("stages", None)
        if not isinstance(stages, list):
            raise MatchConfException("stages must be list")
        for i, stage in enumerate(stages):
            stage = StageConfig.parse(stage)
            stage.index = i
            ret.stages.append(stage)

        ret.rankRewardsList = []
        rankRewardsList = conf.get("rank.rewards")
        if rankRewardsList is not None:
            if not isinstance(rankRewardsList, list):
                raise MatchConfException("rank.rewards must be list")
            for rankRewards in rankRewardsList:
                ret.rankRewardsList.append(
                    cls.getRankRewardsClass().parse(rankRewards))
        ret.rankRewardsDesc = cls.getRankRewardsClass().buildRewardDescList(
            ret.rankRewardsList)
        return ret.checkValid()
예제 #5
0
    def checkValid(self):
        """检查是否合法"""
        if not isinstance(self.infos, list):
            raise MatchConfException("tips.infos must be array")
        for info in self.infos:
            if not isstring(info):
                raise MatchConfException("tips.infos.item must be string")

        if not isinstance(self.interval, int) or self.interval <= 0:
            raise MatchConfException("tips.interval must be int > 0")
        return self
예제 #6
0
 def checkValid(self):
     """检查是否合法"""
     if not GroupingType.isValid(self.type):
         raise MatchConfException("matchs.grouping.type must in:" +
                                  str(GroupingType.VALID_TYPES))
     if GroupingType.TYPE_GROUP_COUNT:
         if not isinstance(self.groupCount, int) or self.groupCount <= 0:
             raise MatchConfException(
                 "matchs.grouping.group.count must in:" +
                 str(GroupingType.VALID_TYPES))
     else:
         if not isinstance(self.userCount, int) or self.userCount <= 0:
             raise MatchConfException(
                 "matchs.grouping.user.count must be int > 0")
     return self
예제 #7
0
    def checkValid(self):
        """检查是否合法"""
        if not isstring(self.name):
            raise MatchConfException("Stage.name must be string")

        if not SeatQueuingType.isValid(self.seatQueuing):
            raise MatchConfException("Stage.seat.principles must in:" +
                                     str(SeatQueuingType.VALID_TYPES))

        if (not isinstance(self.riseUserCount, int)
                or self.riseUserCount <= 0):
            raise MatchConfException(
                "Stage.raise.user.count must be integer >= 0")

        if not GroupingType.isValid(self.groupingType):
            raise MatchConfException("Stage.grouping.type must in:" +
                                     str(GroupingType.VALID_TYPES))

        if self.groupingType == GroupingType.TYPE_GROUP_COUNT:
            if not isinstance(self.groupingGroupCount,
                              int) or self.groupingGroupCount <= 0:
                raise MatchConfException(
                    "Stage.grouping.group.count must be integer > 0")
        elif self.groupingType == GroupingType.TYPE_USER_COUNT:
            if not isinstance(self.groupingUserCount,
                              int) or self.groupingUserCount <= 0:
                raise MatchConfException(
                    "Stage.grouping.user.count must be integer > 0")
        return self
예제 #8
0
    def parse(cls, conf):
        """阶段解析"""
        ret = StageConfig()
        ret.conf = conf

        # 通用配置
        ret.name = conf.get("name", None)
        ret.seatQueuing = conf.get("seat.principles", None)
        ret.riseUserCount = conf.get("rise.user.count", None)
        ret.groupingType = conf.get("grouping.type",
                                    GroupingType.TYPE_NO_GROUP)
        ret.groupingUserCount = conf.get("grouping.user.count", None)
        ret.groupingGroupCount = conf.get("grouping.group.count", None)

        ret.rankRewardsList = []
        rankRewardsList = conf.get("rank.rewards")
        if rankRewardsList is not None:
            if not isinstance(rankRewardsList, list):
                raise MatchConfException("rank.rewards must be list")
            for rankRewards in rankRewardsList:
                ret.rankRewardsList.append(RankRewards.parse(rankRewards))
        ret.rankRewardsDesc = RankRewards.buildRewardDescList(
            ret.rankRewardsList)
        return ret.checkValid()
예제 #9
0
 def checkValid(self):
     if not MatchType.isValid(self.type):
         raise MatchConfException("start.type must in:" +
                                  str(MatchType.VALID_TYPES))
     if not FeeType.isValid(self.feeType):
         raise MatchConfException("start.fee.type must in:" +
                                  str(FeeType.VALID_TYPES))
     if not isinstance(self.maxPlayTime, int) or self.maxPlayTime <= 0:
         raise MatchConfException("start.maxplaytime must be int > 0")
     if not isinstance(self.tableTimes, int) or self.tableTimes <= 0:
         raise MatchConfException("start.tableTimes must be int > 0")
     if not isinstance(self.startMatchSpeed,
                       int) or self.startMatchSpeed <= 0:
         raise MatchConfException("start.speed must be int > 0")
     if self.isUserCountType():
         if not isinstance(self.userCount, int) or self.userCount <= 0:
             raise MatchConfException("start.user.size must be int > 0")
     else:
         if not isinstance(self.userMaxCount,
                           int) or self.userMaxCount <= 0:
             raise MatchConfException("start.user.maxsize must be int > 0")
         if not isinstance(self.userMinCount,
                           int) or self.userMinCount <= 0:
             raise MatchConfException("start.user.minsize must be int > 0")
         if not isinstance(self.signinMaxCount,
                           int) or self.signinMaxCount <= 0:
             raise MatchConfException(
                 "start.signin.minsize must be int > 0")
         if self.signinMaxCount < self.userMinCount:
             raise MatchConfException(
                 "start.signin.minsize must > start.user.maxsize")
         if self.userMaxCount < self.userMinCount:
             raise MatchConfException(
                 "start.user.maxsize must greater than start.user.minsize")
         if not isinstance(self.signinTimes, int) or self.signinTimes < 0:
             raise MatchConfException("start.signin.times must be int >= 0")
         if not isstring(self.signinTimesStr):
             raise MatchConfException(
                 "start.signin.times.str must be string")
         if not isinstance(self.prepareTimes, int) or self.signinTimes < 0:
             raise MatchConfException(
                 "start.prepare.times must be int >= 0")
         if self.isTimePointType():
             if not isinstance(self.closeTime, int) or self.closeTime < 0:
                 raise MatchConfException(
                     "start.close.times must be int >= 0")
             if not isinstance(self.rewardTimes,
                               int) or self.rewardTimes < 0:
                 raise MatchConfException(
                     "start.reward.times must be int >= 0")
         if not isinstance(self.times, dict):
             raise MatchConfException("start.times must be dict")
         if not self._cron:
             raise MatchConfException("start.times is invalid")
         if not isinstance(self.userNextGroup, (int, float)):
             raise MatchConfException("start.user.next.group must be float")
         if self.selectFirstStage not in (0, 1):
             raise MatchConfException(
                 "start.selectFirstStage must in (0, 1)")
     return self