Пример #1
0
 def _reloadTasks(self):
     self._taskList = []
     winStreakTaskConf = self.room.roomConf.get('winStreakTask', {})
     for i, reward in enumerate(winStreakTaskConf.get('tasks', [])):
         TYContentItem.decodeFromDict(reward)
         self._taskList.append(WinStreakTask(i, reward))
     self._taskPictures = winStreakTaskConf.get('imgs', [])
Пример #2
0
 def _reloadTasks(self):
     self._taskListMap = {}
     for mixConf in self.room.roomConf.get('mixConf', []):
         mixId = mixConf.get('mixId')
         winStreakTaskList = []
         winStreakTaskConf = mixConf.get('winStreakTask', {})
         for i, reward in enumerate(winStreakTaskConf.get('tasks', [])):
             TYContentItem.decodeFromDict(reward)
             winStreakTaskList.append(WinStreakTask(i, reward))
         self._taskListMap[mixId] = winStreakTaskList
Пример #3
0
    def decodeFromDict(self, d):
        self.id = d.get('id')
        if not isinstance(self.id, int) or self.id < 0:
            raise TYBizConfException(d, 'Bait.id must be int and >0')
        self.name = d.get('name')
        if not isinstance(self.name, (str, unicode)):
            raise TYBizConfException(d, 'Bait.name must be str')
        self.pic = d.get('pic')
        if not isinstance(self.pic, (str, unicode)):
            raise TYBizConfException(d, 'Bait.pic must be str')
        self.chip = d.get('chip')
        if not isinstance(self.chip, int) or self.chip < 0:
            raise TYBizConfException(d, 'Bait.chip must be int and >0')
        self.fish = d.get('fish')
        if not isinstance(self.fish, list):
            raise TYBizConfException(d, 'Bait.id must be int')
        self.superFish = d.get('superFish', 0)
        if not isinstance(self.superFish, int):
            raise TYBizConfException(d, 'Bait.superFish must be int')
        self.couponFishRewards = d.get('couponFishRewards')
        if self.couponFishRewards and not isinstance(self.couponFishRewards,
                                                     list):
            raise TYBizConfException(d, 'Bait.couponFishRewards must be list')
        tempCouponFishRewards = []
        for rewardDict in d.get('couponFishRewards', []):
            itemDict = rewardDict.get('item', {})
            if itemDict:
                tempCouponFishRewards.append({
                    'item':
                    TYContentItem.decodeFromDict(itemDict),
                    'weight':
                    rewardDict.get('weight')
                })
        self.couponFishRewards = tempCouponFishRewards

        self.superFishRewards = d.get('superFishRewards')
        if self.superFishRewards and not isinstance(self.superFishRewards,
                                                    list):
            raise TYBizConfException(d, 'Bait.superFishRewards must be list')
        tempSuperFishRewards = []
        for rewardDict in d.get('superFishRewards', []):
            itemDict = rewardDict.get('item', {})
            if itemDict:
                tempSuperFishRewards.append({
                    'item':
                    TYContentItem.decodeFromDict(itemDict),
                    'weight':
                    rewardDict.get('weight')
                })
        self.superFishRewards = tempSuperFishRewards

        return self
Пример #4
0
def createMatchUser(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.createUserMatchInfo gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if userMatchInfo:
        if userMatchInfo.instId == instId:
            if userMatchInfo.state == UserMatchInfo.ST_SIGNIN:
                return ERR_ALREADY_SIGNIN
            return ERR_ALREADY_IN_MATCH
        else:
            ftlog.warn('match_remote.createUserMatchInfo gameId=', gameId,
                       'userId=', userId,
                       'contentItem=', contentItem,
                       'bigRoomId=', bigRoomId,
                       'instId=', instId,
                       'ctrlRoomId=', ctrlRoomId,
                       'recordInstId=', userMatchInfo.instId)

    userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId)
    userMatchInfo.ctrlRoomId = ctrlRoomId
    userMatchInfo.instId = instId
    if contentItem:
        userMatchInfo.feeItem = TYContentItem.decodeFromDict(contentItem)
    saveUserMatchInfo(userMatchInfo)
    return 0
Пример #5
0
    def sendAssetsListToUser(cls,
                             gameId,
                             userId,
                             assetList,
                             eventId,
                             mail=None,
                             intEventParam=0):
        '''
        :param gameId 统计用途,地主就写6
        :param assetList 要发送的资产, 格式必须是:[{itemId:'item:0011', count:1}, ...]
        :param eventId 事件ID,要在config/poker/map.bieventid.json中注册
        :param mail(optional) 给用户邮箱发送信息,默认不发送
        '''
        timestamp = pktimestamp.getCurrentTimestamp()
        itemList = []
        for i in xrange(0, len(assetList)):
            itemList.insert(i, TYContentItem.decodeFromDict(assetList[i]))
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetList = userAssets.sendContentItemList(gameId, itemList, 1, True,
                                                   timestamp, eventId,
                                                   intEventParam)

        # 通知用户道具和消息存在改变
        if assetList:
            datachangenotify.sendDataChangeNotify(
                gameId, userId, TYAssetUtils.getChangeDataNames(assetList))

        # 发送邮箱信息
        if mail and len(mail) > 0:
            pkmessage.sendPrivate(9999, userId, 0, mail)
Пример #6
0
    def getDay30Reward(self, gameId, userId, clientId):
        from dizhu.activities.login30_360 import Login30
        status = 0
        all_count = 0
        get_count = 0
        tip = ''
        ecode = 0
        try:
            conf = dizhuconf.getActivityConf("huiyuan_360")
            data = gamedata.getGameAttrJson(userId, gameId, Login30.attr_act,
                                            {})
            if data:
                if data["get_count"] != data["current_count"]:
                    reward = conf.get("login30", [])[data["current_count"] - 1]
                    contentItem = TYContentItem.decodeFromDict(reward)
                    tip = self.sendReward(gameId, userId, clientId,
                                          contentItem, 'HUI_YUAN_360', 0)
                    data["get_count"] = data["current_count"]

                all_count = data["all_count"]
                get_count = data["get_count"]

                status = int(data["get_count"] < data["current_count"])

                gamedata.setGameAttr(userId, gameId, Login30.attr_act,
                                     json.dumps(data))
        except:
            ftlog.exception()
            tip = "领取失败"
            ecode = 1

        return tip, ecode, status, all_count, get_count
Пример #7
0
    def _initial(self):
        _exchanges = {}
        for info in self._clientConf['config']['exchange']:
            info2 = copy.copy(info)
            info2['content'] = TYContentRegister.decodeFromDict(info['content'])
            costs = []
            for costdict in info2['costs']:
                costs.append(TYContentItem.decodeFromDict(costdict))
            if not costs:
                raise TYBizConfException(info, 'costs is empty!!!')
            info2['costs'] = costs
            _exchanges[info2['id']] = info2

            # 原始配置填充图片信息
            content_items = info2['content'].getItems()
            assetKind = hallitem.itemSystem.findAssetKind(content_items[0].assetKindId)
            info['pic'] = assetKind.pic
        # 原始配置,还需要一个消耗物品的图片
        for info in _exchanges.itervalues():
            for cost in info['costs']:
                self.costAssetKindId = cost.assetKindId
                assetKind = hallitem.itemSystem.findAssetKind(cost.assetKindId)
                self._clientConf['config']['costAssetPic'] = assetKind.pic
                break
        self._exchanges = _exchanges
Пример #8
0
    def unmarshal(self, d):
        assets = d.get(
            'assets')  # 格式必须是:[{'itemId':'item:0011', 'count':1}, ...]
        if not isinstance(assets, list):
            raise Exception(
                "AttachmentAsset.unmarshal assets wrong:{}".format(assets))
        self._itemlist = []
        for kind_2_cnt in assets:
            d_item = {
                'itemId': kind_2_cnt['itemId'],
                'count': int(kind_2_cnt['count'])
            }
            self._itemlist.append(TYContentItem.decodeFromDict(d_item))

        self._eventid = d.get('eventid')
        if not isstring(self._eventid):
            raise Exception(
                "AttachmentAsset.unmarshal eventid wrong:{}".format(
                    self._eventid))

        self._eventparam = d.get('eventparam')
        if not isinstance(self._eventparam, int):
            raise Exception(
                "AttachmentAsset.unmarshal eventparam wrong:{}".format(
                    self._eventparam))
Пример #9
0
def sendGiftsToUser(userId, gameId, clientId, items):
    '''
        多个奖品时的发奖,或者一个奖品的发奖,items为数组
    '''
    contentItemList = []
    rouletteMap = getRouletteMap()

    for item in items:
        itemMap = rouletteMap.get(item, {})
        if itemMap:
            # 添加判断流程,判断奖励是否需要发送led
            if itemMap.get('isSendLed', False):
                userInfo = halluser.getUserInfo(userId, gameId, clientId)
                msgstr = '恭喜' + userInfo.get(
                    'name', '') + '玩家在幸运大转盘中,抽中了' + itemMap.get(
                        'itemDesc', '') + '大奖!快来参与,大奖得主就是你!'
                hallled.sendLed(HALL_GAMEID, msgstr, 1, 'hall')

            # 添加中奖内容
            contentItemList.append(
                TYContentItem.decodeFromDict({
                    'itemId': itemMap.get('itemId'),
                    'count': itemMap.get('count')
                }))

    userAssets = hallitem.itemSystem.loadUserAssets(userId)
    results = userAssets.sendContentItemList(gameId, contentItemList, 1, True,
                                             int(time.time()), 'ROULETTE_GOLD',
                                             0)
    datachangenotify.sendDataChangeNotify(
        gameId, userId, TYAssetUtils.getChangeDataNames(results))
Пример #10
0
def createMatchUser(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.createUserMatchInfo gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if userMatchInfo:
        if userMatchInfo.instId == instId:
            if userMatchInfo.state == UserMatchInfo.ST_SIGNIN:
                return ERR_ALREADY_SIGNIN
            return ERR_ALREADY_IN_MATCH
        else:
            ftlog.warn('match_remote.createUserMatchInfo gameId=', gameId,
                       'userId=', userId,
                       'contentItem=', contentItem,
                       'bigRoomId=', bigRoomId,
                       'instId=', instId,
                       'ctrlRoomId=', ctrlRoomId,
                       'recordInstId=', userMatchInfo.instId)
            
    userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId)
    userMatchInfo.ctrlRoomId = ctrlRoomId
    userMatchInfo.instId = instId
    if contentItem:
        userMatchInfo.feeItem = TYContentItem.decodeFromDict(contentItem)
    saveUserMatchInfo(userMatchInfo)
    return 0
Пример #11
0
    def sendAssetsToUser(cls,
                         gameId,
                         userId,
                         assets,
                         eventId,
                         mail=None,
                         intEventParam=0):
        '''
        :param gameId 统计用途,地主就写6
        :param assets 要发送的资产, 格式必须是:{itemId:'item:0011', count:1}
        :param eventId 事件ID,要在config/poker/map.bieventid.json中注册
        :param mail(optional) 给用户邮箱发送信息,默认不发送
        '''
        timestamp = pktimestamp.getCurrentTimestamp()
        contentitem = TYContentItem.decodeFromDict(assets)
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetKind, consumecount, finalcount = userAssets.addAsset(
            gameId, contentitem.assetKindId, contentitem.count, timestamp,
            eventId, intEventParam)
        # 通知用户道具和消息存在改变
        if assetKind.keyForChangeNotify:
            datachangenotify.sendDataChangeNotify(
                gameId, userId, [assetKind.keyForChangeNotify, 'message'])

        # 发送邮箱信息
        if mail and len(mail) > 0:
            pkmessage.sendPrivate(9999, userId, 0, mail)

        return (assetKind, consumecount, finalcount)
Пример #12
0
def signoutMatch(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug("match_remote.signoutMatch gameId=", gameId, "userId=",
                    userId, "contentItem=", contentItem, "bigRoomId=",
                    bigRoomId, "instId=", instId, "ctrlRoomId=", ctrlRoomId)
    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if not userMatchInfo:
        return 0, None

    if userMatchInfo.instId != instId:
        ftlog.debug("match_remote.signoutMatch diffInstId gameId=", gameId,
                    "userId=", userId, "contentItem=", contentItem,
                    "bigRoomId=", bigRoomId, "instId=", instId, "ctrlRoomId=",
                    ctrlRoomId, "recordInstId=", userMatchInfo.instId)
        return 0, None

    if userMatchInfo.state != UserMatchInfo.ST_SIGNIN:
        return ERR_ALREADY_IN_MATCH, None

    removeUserMatchInfo(userMatchInfo)
    daobase.executeTableCmd(ctrlRoomId, 0, "srem", "signs:" + str(ctrlRoomId),
                            userId)
    ftlog.debug("match_remote.signoutMatch gameId=", gameId, "userId=", userId,
                "contentItem=", contentItem, "bigRoomId=", bigRoomId,
                "instId=", instId, "ctrlRoomId=", ctrlRoomId)
    if userId > 10000 and contentItem:
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        item = TYContentItem.decodeFromDict(contentItem)
        assetList = userAssets.sendContentItemList(
            gameId, [item], 1, True, pktimestamp.getCurrentTimestamp(),
            "MATCH_RETURN_FEE", bigRoomId)
        datachangenotify.sendDataChangeNotify(
            gameId, userId, TYAssetUtils.getChangeDataNames(assetList))
    return 0, None
Пример #13
0
 def decodeRecord(cls, userId, jstr):
     d = strutil.loads(jstr)
     record = SigninRecord(userId)
     record.signinTime = d['st']
     fee = d.get('fee')
     if fee:
         record.fee = TYContentItem.decodeFromDict(fee)
     return record
Пример #14
0
    def decodeFromDict(self, d):
        self.name = d.get('name', '')
        if not isstring(self.name):
            self.name = ''

        inviteRewardItem = d.get('inviteRewardItem', None)
        if inviteRewardItem:
            self.inviteRewardItem = TYContentItem.decodeFromDict(
                inviteRewardItem)
            self.inviteRewardDesc = inviteRewardItem.get('desc', '')

        rewardsByIndex = d.get('rewardsByIndex', [])
        if rewardsByIndex:
            for rIndexConfig in rewardsByIndex:
                rIndex = TYContentItem.decodeFromDict(rIndexConfig)
                self.inviteRewardsByIndex.append(rIndex)
                self.inviteRewardsDescByIndex.append(
                    rIndexConfig.get('desc', ''))

        return self
Пример #15
0
 def decodeFromDict(self, d):
     self.prizeDetail = d.get('prizeDetail', '')
     if not isstring(self.prizeDetail):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeDetail must be string')
     self.prizeImgUrl = d.get('prizeImgUrl', '')
     if not isstring(self.prizeImgUrl):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeImgUrl must be string')
     self.prizeRewardDesc = d.get('prizeRewardDesc', '')
     if not isstring(self.prizeRewardDesc):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeRewardDesc must be string')
     self.prizeNotGotRewardDesc = d.get('prizeNotGotRewardDesc', '')
     if not isstring(self.prizeNotGotRewardDesc):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeNotGotRewardDesc must be string')
     self.prizeGotTotalRewardDesc = d.get('prizeGotTotalRewardDesc', '')
     if not isstring(self.prizeGotTotalRewardDesc):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeGotTotalRewardDesc must be string')
     self.prizeAvailableRewardDesc = d.get('prizeAvailableRewardDesc', '')
     if not isstring(self.prizeAvailableRewardDesc):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeAvailableRewardDesc must be string')
     self.prizeRewardTips = d.get('prizeRewardTips', '')
     if not isstring(self.prizeRewardTips):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeRewardTips must be string')
     prizeRewardItem = d.get('prizeRewardItem', {})
     if not isinstance(prizeRewardItem, dict):
         raise TYBizConfException(
             d, 'NeituiguangConf.prizeRewardItem must be dict')
     if prizeRewardItem:
         self.prizeRewardItem = TYContentItem.decodeFromDict(
             prizeRewardItem)
     self.shareLoc = d.get('shareLoc', '')
     if not isstring(self.shareLoc):
         raise TYBizConfException(
             d, 'NeituiguangConf.shareLoc must be string')
     self.taskDetail = d.get('taskDetail', '')
     if not isstring(self.taskDetail):
         raise TYBizConfException(
             d, 'NeituiguangConf.taskDetail must be string')
     self.pleaseBindPhone = d.get('pleaseBindPhone', '')
     if not isstring(self.pleaseBindPhone):
         raise TYBizConfException(
             d, 'NeituiguangConf.pleaseBindPhone must be string')
     self.defaultShareId = d.get('defaultShareId')
     if self.defaultShareId is not None and not isinstance(
             self.defaultShareId, int):
         raise TYBizConfException(
             d, 'NeituiguangConf.defaultShareId must be int')
     return self
Пример #16
0
def decodeUserMatchInfo(gameId, userId, bigRoomId, jstr):
    d = strutil.loads(jstr)
    if d:
        ret = UserMatchInfo(gameId, userId, bigRoomId)
        ret.state = d["st"]
        ret.instId = d["instId"]
        ret.ctrlRoomId = d["crid"]
        fee = d.get("fee")
        if fee:
            ret.feeItem = TYContentItem.decodeFromDict(fee)
        return ret
Пример #17
0
 def fromDict(self, d):
     self.ftId = d['ftId']
     fee = d.get('fee')
     if fee:
         self.fee = TYContentItem.decodeFromDict(d['fee'])
     self.userId = d['userId']
     self.nRound = d['nRound']
     self.canDouble = d['canDouble']
     self.playMode = d['playMode']
     self.expires = d['expires']
     self.goodCard = d['goodCard']
     return self
Пример #18
0
def sendGiftsToUser(userId, gameId, clientId, items):
    '''
        多个奖品时的发奖,或者一个奖品的发奖,items为数组
    '''
    contentItemList = []
    rouletteMap = getRouletteMap()

    for item in items:
        itemMap = rouletteMap.get(item, {})
        if itemMap:
            #添加判断流程,判断奖励是否需要发送led
            if itemMap.get('isSendLed', False):
                userInfo = halluser.getUserInfo(userId, gameId, clientId)
                msgstr = '恭喜玩家' + userInfo.get(
                    'name', '') + '在幸运大转盘中,抽中了' + itemMap.get(
                        'itemDesc', '') + '大奖!快来参与,大奖得主就是你!'
                hallled.sendLed(HALL_GAMEID, msgstr, 0, 'hall')

                # 轮播LED仅保留最近10条中奖记录
                doRouletteRecordKey = "roulette:recordLed"
                try:
                    datas = {
                        'name': userInfo.get('name', ''),
                        'itemDesc': itemMap.get('itemDesc', '')
                    }
                    recordledLen = daobase.executeMixCmd(
                        'RPUSH', doRouletteRecordKey, json.dumps(datas))
                    if recordledLen > 10:
                        # 超过10个就截取后10个
                        daobase.executeMixCmd('LTRIM', doRouletteRecordKey,
                                              -10, -1)
                except:
                    ftlog.warn("redis rpush|ltrim roulette:recordLed error",
                               gameId, userId, clientId, msgstr)

                ftlog.debug("sendGiftsToUser|1", userId, gameId, clientId,
                            msgstr)
            ftlog.debug("sendGiftsToUser|2", userId, gameId, clientId,
                        itemMap.get('isSendLed'))

            # 添加中奖内容
            contentItemList.append(
                TYContentItem.decodeFromDict({
                    'itemId': itemMap.get('itemId'),
                    'count': itemMap.get('count')
                }))

    userAssets = hallitem.itemSystem.loadUserAssets(userId)
    results = userAssets.sendContentItemList(gameId, contentItemList, 1, True,
                                             int(time.time()), 'ROULETTE_GOLD',
                                             0)
    datachangenotify.sendDataChangeNotify(
        gameId, userId, TYAssetUtils.getChangeDataNames(results))
Пример #19
0
def decodeUserMatchInfo(gameId, userId, bigRoomId, jstr):
    d = strutil.loads(jstr)
    if d:
        ret = UserMatchInfo(gameId, userId, bigRoomId)
        ret.state = d['st']
        ret.instId = d['instId']
        ret.ctrlRoomId = d['crid']
        fee = d.get('fee')
        if fee:
            ret.feeItem = TYContentItem.decodeFromDict(fee)
        return ret
    return None
Пример #20
0
def decodeUserMatchInfo(gameId, userId, bigRoomId, jstr):
    d = strutil.loads(jstr)
    if d:
        ret = UserMatchInfo(gameId, userId, bigRoomId)
        ret.state = d['st']
        ret.instId = d['instId']
        ret.ctrlRoomId = d['crid']
        fee = d.get('fee')
        if fee:
            ret.feeItem = TYContentItem.decodeFromDict(fee)
        return ret
    return None
Пример #21
0
    def handleEvent(cls, event):
        try:
            gameId = 6
            userId = event.userId
            conf = dizhuconf.getActivityConf("vip_send")

            if not cls.dateCheck(gameId, userId, conf):
                cls.removeVipItems(gameId, userId, conf)
                return

            if not cls.gameCheck(userId, gameId):
                return

            vipLevel = int(
                hallvip.userVipSystem.getUserVip(userId).vipLevel.level)
            vipLevelLimit = conf.get("vip_level", 1)

            ftlog.debug('VipSend.handleEvent vipLevel=', vipLevel,
                        'vipLevelLimit=', vipLevelLimit, 'userId=', userId)

            if vipLevel >= vipLevelLimit:
                attrname = cls.getFlagAttr(conf.get('start_date',
                                                    '2015-01-01'))
                is_send = gamedata.getGameAttr(userId, gameId, attrname)

                if is_send:
                    return

                items = conf.get("item_send", [])
                timestamp = pktimestamp.getCurrentTimestamp()
                for item in items:
                    contentItem = TYContentItem.decodeFromDict(item)
                    userAssets = hallitem.itemSystem.loadUserAssets(userId)
                    assetKind, _, _ = userAssets.addAsset(
                        gameId, contentItem.assetKindId, contentItem.count,
                        timestamp, 'DIZHU_VIP_SEND', 0)
                mail = conf.get("mail", "")
                if mail:
                    pkmessage.sendPrivate(9999, userId, 0, mail)

                if assetKind.keyForChangeNotify:
                    datachangenotify.sendDataChangeNotify(
                        gameId, userId,
                        [assetKind.keyForChangeNotify, 'message'])

                gamedata.setGameAttr(userId, gameId, attrname, 1)

                ftlog.debug('vipsend vipLevel=', vipLevel, 'vipLevelLimit=',
                            vipLevelLimit, 'userId=', userId, "attrname=",
                            attrname)
        except:
            ftlog.exception()
Пример #22
0
 def addRewardToUser(self, userId, rewardDict):
     """
     发送奖励, 发送email
     """
     mail = None
     reward = TYContentItem.decodeFromDict(rewardDict)
     UserBag.sendAssetsToUser(DIZHU_GAMEID,
                              userId, {
                                  'itemId': reward.assetKindId,
                                  'count': reward.count
                              },
                              'DDZ_RED_ENVELOPE_BOMB',
                              mail=mail)
Пример #23
0
    def _decodeFromDictImpl(self, d):
        self._gameId = d.get('gameId')
        if not isinstance(self._gameId, int):
            raise TYBizConfException(d, 'QuweiTaskActivity.gameId must be int')
        refreshFee = d.get('refreshFee')
        if refreshFee is not None:
            refreshFee = TYContentItem.decodeFromDict(refreshFee)
        taskKindMap = {}
        for taskKindConf in d.get('tasks', []):
            taskKind = QuweiTaskKindRegister.decodeFromDict(taskKindConf)
            if taskKind.kindId in taskKindMap:
                raise TYBizConfException(
                    taskKindConf, 'Duplicate taskKind: %s' % (taskKind.kindId))
            taskKindMap[taskKind.kindId] = taskKind

        taskCount = d.get('taskCount')
        if not isinstance(taskCount, int) or taskCount <= 0:
            raise TYBizConfException(
                taskCount, 'QuweiTaskActivity.taskCount must be int > 0')

        autoRefresh = d.get('autoRefresh', 0)
        initPools = []
        for poolConf in d.get('initPools', []):
            cond = poolConf.get('condition')
            if cond is not None:
                cond = UserConditionRegister.decodeFromDict(cond)
            taskKindList = []
            taskKindIds = poolConf.get('kindIds', [])
            for kindId in taskKindIds:
                taskKind = taskKindMap.get(kindId)
                if not taskKind:
                    raise TYBizConfException(poolConf,
                                             'Unknown kindId: %s' % (kindId))
                taskKindList.append(taskKind)
            initPools.append((cond, taskKindList))

        self._taskKindMap = taskKindMap
        self._refreshFee = refreshFee
        self._initPools = initPools
        self._taskCount = taskCount
        self._autoRefresh = autoRefresh
        self._allOpen = d.get('open', 0)

        ftlog.info('QuweiTaskActivity._decodeFromDictImpl', 'gameId=',
                   self.gameId, 'actId=', self.actId, 'taskCount=',
                   self._taskCount, 'autoRefresh=', self._autoRefresh,
                   'tasks=', self._taskKindMap.keys(), 'refreshFee=',
                   self._refreshFee.toDict() if self._refreshFee else None,
                   'allOpen=', self._allOpen, 'initPools=',
                   [(p[0], [tk.kindId for tk in p[1]])
                    for p in self._initPools])
Пример #24
0
def unlockUserForMatch(gameId, userId, bigRoomId, instId, ctrlRoomId, tableId,
                       seatId, contentItem):
    if ftlog.is_debug():
        ftlog.debug("match_remote.unlockUserForMatch gameId=", gameId,
                    "userId=", userId, "bigRoomId=", bigRoomId, "instId=",
                    instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId,
                    "seatId=", seatId, "contentItem=", contentItem)

    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if userMatchInfo:
        # 此处有异常,正常要有userMatchInfo
        removeUserMatchInfo(userMatchInfo)

        if contentItem:
            try:
                contentItemObj = TYContentItem.decodeFromDict(contentItem)
                userAssets = hallitem.itemSystem.loadUserAssets(userId)
                assetList = userAssets.sendContentItemList(
                    gameId, [contentItemObj], 1, True,
                    pktimestamp.getCurrentTimestamp(), "MATCH_RETURN_FEE",
                    bigRoomId)
                datachangenotify.sendDataChangeNotify(
                    gameId, userId, TYAssetUtils.getChangeDataNames(assetList))
                ftlog.info(
                    "match_remote.unlockUserForMatch returnFees ok gameId=",
                    gameId, "userId=", userId, "bigRoomId=", bigRoomId,
                    "instId=", instId, "ctrlRoomId=", ctrlRoomId, "tableId=",
                    tableId, "seatId=", seatId, "contentItem=", contentItem)
            except:
                ftlog.error("match_remote.unlockUserForMatch gameId=", gameId,
                            "userId=", userId, "bigRoomId=", bigRoomId,
                            "instId=", instId, "ctrlRoomId=", ctrlRoomId,
                            "tableId=", tableId, "seatId=", seatId,
                            "contentItem=", contentItem)
        try:
            onlinedata.removeOnlineLoc(userId, ctrlRoomId, tableId)
        except:
            ftlog.error("match_remote.unlockUserForMatch gameId=", gameId,
                        "userId=", userId, "bigRoomId=", bigRoomId, "instId=",
                        instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId,
                        "seatId=", seatId, "contentItem=", contentItem)

        ftlog.info("match_remote.unlockUserForMatch ok gameId=", gameId,
                   "userId=", userId, "bigRoomId=", bigRoomId, "instId=",
                   instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId,
                   "seatId=", seatId, "contentItem=", contentItem)
Пример #25
0
def signinMatch(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.signinMatch gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    try:
        userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
        if userMatchInfo:
            if userMatchInfo.instId == instId:
                if userMatchInfo.state == UserMatchInfo.ST_SIGNIN:
                    return ERR_ALREADY_SIGNIN, None
                return ERR_ALREADY_IN_MATCH, None
            else:
                ftlog.warn('match_remote.signinMatch gameId=', gameId,
                           'userId=', userId,
                           'contentItem=', contentItem,
                           'bigRoomId=', bigRoomId,
                           'instId=', instId,
                           'ctrlRoomId=', ctrlRoomId,
                           'recordInstId=', userMatchInfo.instId)

        userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId)
        userMatchInfo.ctrlRoomId = ctrlRoomId
        userMatchInfo.instId = instId
        if contentItem:
            userMatchInfo.feeItem = TYContentItem.decodeFromDict(contentItem)
        if userId > 10000 and contentItem:
            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            assetTuple = userAssets.consumeAsset(gameId,
                                                 contentItem['itemId'],
                                                 contentItem['count'],
                                                 pktimestamp.getCurrentTimestamp(),
                                                 'MATCH_SIGNIN_FEE', bigRoomId)
            if assetTuple[1] < contentItem['count']:
                raise TYAssetNotEnoughException(assetTuple[0], contentItem['count'], assetTuple[2])
            # 记录用户
            datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames([assetTuple]))
        saveUserMatchInfo(userMatchInfo)
        daobase.executeTableCmd(ctrlRoomId, 0, 'sadd', 'signs:' + str(ctrlRoomId), userId)
        return 0, None
    except TYAssetNotEnoughException, e:
        return ERR_FEE_NOT_ENOUGH, (e.assetKind.kindId, e.required - e.actually)
Пример #26
0
def signinMatch(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.signinMatch gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    try:
        userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
        if userMatchInfo:
            if userMatchInfo.instId == instId:
                if userMatchInfo.state == UserMatchInfo.ST_SIGNIN:
                    return ERR_ALREADY_SIGNIN, None
                return ERR_ALREADY_IN_MATCH, None
            else:
                ftlog.warn('match_remote.signinMatch gameId=', gameId,
                           'userId=', userId,
                           'contentItem=', contentItem,
                           'bigRoomId=', bigRoomId,
                           'instId=', instId,
                           'ctrlRoomId=', ctrlRoomId,
                           'recordInstId=', userMatchInfo.instId)
                
        userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId)
        userMatchInfo.ctrlRoomId = ctrlRoomId
        userMatchInfo.instId = instId
        if contentItem:
            userMatchInfo.feeItem = TYContentItem.decodeFromDict(contentItem)
        if userId > 10000 and contentItem:
            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            assetTuple = userAssets.consumeAsset(gameId,
                                                 contentItem['itemId'],
                                                 contentItem['count'],
                                                 pktimestamp.getCurrentTimestamp(),
                                                 'MATCH_SIGNIN_FEE', bigRoomId)
            if assetTuple[1] < contentItem['count']:
                raise TYAssetNotEnoughException(assetTuple[0], contentItem['count'], assetTuple[2])
            # 记录用户
            datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames([assetTuple]))
        saveUserMatchInfo(userMatchInfo)
        daobase.executeTableCmd(ctrlRoomId, 0, 'sadd', 'signs:' + str(ctrlRoomId), userId)
        return 0, None
    except TYAssetNotEnoughException, e:
        return ERR_FEE_NOT_ENOUGH, (e.assetKind.kindId, e.required - e.actually)
Пример #27
0
def signoutMatch(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.signoutMatch gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if not userMatchInfo:
        return 0, None
    
    if userMatchInfo.instId != instId:
        ftlog.debug('match_remote.signoutMatch diffInstId gameId=', gameId,
                   'userId=', userId,
                   'contentItem=', contentItem,
                   'bigRoomId=', bigRoomId,
                   'instId=', instId,
                   'ctrlRoomId=', ctrlRoomId,
                   'recordInstId=', userMatchInfo.instId)
        return 0, None
    
    if userMatchInfo.state != UserMatchInfo.ST_SIGNIN:
        return ERR_ALREADY_IN_MATCH, None
    
    removeUserMatchInfo(userMatchInfo)
    daobase.executeTableCmd(ctrlRoomId, 0, 'srem', 'signs:' + str(ctrlRoomId), userId)
    ftlog.debug('match_remote.signoutMatch gameId=', gameId,
               'userId=', userId,
               'contentItem=', contentItem,
               'bigRoomId=', bigRoomId,
               'instId=', instId,
               'ctrlRoomId=', ctrlRoomId)
    if userId > 10000 and contentItem and str(contentItem.get('itemId')) not in matchutil.getMatchSigninFeeWithoutCollect():
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        # 折扣价格
        contentItem = match_signin_discount.changeItemToDiscount(userId, bigRoomId, contentItem)
        item = TYContentItem.decodeFromDict(contentItem)
        assetList = userAssets.sendContentItemList(gameId, [item], 1, True,
                                                   pktimestamp.getCurrentTimestamp(),
                                                   'MATCH_RETURN_FEE', bigRoomId)
        datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(assetList))
    return 0, None
Пример #28
0
    def sendRewardToUser(self, gameId, userId, reward, mail):
        ftlog.debug("TYActivityFund.sendRewardToUser: userId=", userId, "reward=", reward, "mail=", mail)

        timestamp = pktimestamp.getCurrentTimestamp()
        contentItem = TYContentItem.decodeFromDict(reward)
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetKind, _, _ = userAssets.addAsset(gameId, contentItem.assetKindId,
                                                      contentItem.count, timestamp,
                                                      'DIZHU_ACT_FUND_SEND', 0)
        # 通知用户道具和消息存在改变
        if assetKind.keyForChangeNotify:
            datachangenotify.sendDataChangeNotify(gameId, userId, [assetKind.keyForChangeNotify, 'message'])

        # 发送邮箱信息
        if mail==None or len(mail) <= 0:
            return
        mail_message = strutil.replaceParams(mail, {"assets":str(reward.get('desc', ''))})
        if mail_message:
            pkmessage.sendPrivate(9999, userId, 0, mail_message)
Пример #29
0
def signoutMatch(gameId, userId, contentItem, bigRoomId, instId, ctrlRoomId):
    if ftlog.is_debug():
        ftlog.debug('match_remote.signoutMatch gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId)
    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if not userMatchInfo:
        return 0, None

    if userMatchInfo.instId != instId:
        ftlog.debug('match_remote.signoutMatch diffInstId gameId=', gameId,
                    'userId=', userId,
                    'contentItem=', contentItem,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId,
                    'recordInstId=', userMatchInfo.instId)
        return 0, None

    if userMatchInfo.state != UserMatchInfo.ST_SIGNIN:
        return ERR_ALREADY_IN_MATCH, None

    removeUserMatchInfo(userMatchInfo)
    daobase.executeTableCmd(ctrlRoomId, 0, 'srem', 'signs:' + str(ctrlRoomId), userId)
    ftlog.debug('match_remote.signoutMatch gameId=', gameId,
                'userId=', userId,
                'contentItem=', contentItem,
                'bigRoomId=', bigRoomId,
                'instId=', instId,
                'ctrlRoomId=', ctrlRoomId)
    if userId > 10000 and contentItem:
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        item = TYContentItem.decodeFromDict(contentItem)
        assetList = userAssets.sendContentItemList(gameId, [item], 1, True,
                                                   pktimestamp.getCurrentTimestamp(),
                                                   'MATCH_RETURN_FEE', bigRoomId)
        datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(assetList))
    return 0, None
Пример #30
0
 def decodeFromDict(self, d):
     self.prizeDetail = d.get('prizeDetail', '')
     if not isstring(self.prizeDetail):
         raise TYBizConfException(d, 'NeituiguangConf.prizeDetail must be string')
     self.prizeImgUrl = d.get('prizeImgUrl', '')
     if not isstring(self.prizeImgUrl):
         raise TYBizConfException(d, 'NeituiguangConf.prizeImgUrl must be string')
     self.prizeRewardDesc = d.get('prizeRewardDesc', '')
     if not isstring(self.prizeRewardDesc):
         raise TYBizConfException(d, 'NeituiguangConf.prizeRewardDesc must be string')
     self.prizeNotGotRewardDesc = d.get('prizeNotGotRewardDesc', '')
     if not isstring(self.prizeNotGotRewardDesc):
         raise TYBizConfException(d, 'NeituiguangConf.prizeNotGotRewardDesc must be string')
     self.prizeGotTotalRewardDesc = d.get('prizeGotTotalRewardDesc', '')
     if not isstring(self.prizeGotTotalRewardDesc):
         raise TYBizConfException(d, 'NeituiguangConf.prizeGotTotalRewardDesc must be string')
     self.prizeAvailableRewardDesc = d.get('prizeAvailableRewardDesc', '')
     if not isstring(self.prizeAvailableRewardDesc):
         raise TYBizConfException(d, 'NeituiguangConf.prizeAvailableRewardDesc must be string')
     self.prizeRewardTips = d.get('prizeRewardTips', '')
     if not isstring(self.prizeRewardTips):
         raise TYBizConfException(d, 'NeituiguangConf.prizeRewardTips must be string')
     prizeRewardItem = d.get('prizeRewardItem', {})
     if not isinstance(prizeRewardItem, dict):
         raise TYBizConfException(d, 'NeituiguangConf.prizeRewardItem must be dict')
     if prizeRewardItem:
         self.prizeRewardItem = TYContentItem.decodeFromDict(prizeRewardItem)
     self.shareLoc = d.get('shareLoc', '')
     if not isstring(self.shareLoc):
         raise TYBizConfException(d, 'NeituiguangConf.shareLoc must be string')
     self.taskDetail = d.get('taskDetail', '')
     if not isstring(self.taskDetail):
         raise TYBizConfException(d, 'NeituiguangConf.taskDetail must be string')
     self.pleaseBindPhone = d.get('pleaseBindPhone', '')
     if not isstring(self.pleaseBindPhone):
         raise TYBizConfException(d, 'NeituiguangConf.pleaseBindPhone must be string')
     self.defaultShareId = d.get('defaultShareId')
     if self.defaultShareId is not None and not isinstance(self.defaultShareId, int):
         raise TYBizConfException(d, 'NeituiguangConf.defaultShareId must be int')
     return self
Пример #31
0
    def decodeFromDict(self, d):
        inviteRewardItem = d.get('inviteRewardItem', {})
        if not isinstance(inviteRewardItem, dict):
            raise TYBizConfException(
                d, 'InviteConf.inviteRewardItem must be dict')
        if inviteRewardItem:
            self.inviteRewardItem = TYContentItem.decodeFromDict(
                inviteRewardItem)

        self.gotoTitle = d.get('gotoTitle', '')
        if not isstring(self.gotoTitle):
            raise TYBizConfException(d, 'InviteConf.gotoTitle must be string')

        self.gotoDesc = ''
        if not isstring(self.gotoDesc):
            raise TYBizConfException(d, 'InviteConf.gotoDesc must be string')

        self.gotoUrl = d.get('gotoUrl', '')
        if not isstring(self.gotoUrl):
            raise TYBizConfException(d, 'InviteConf.gotoUrl must be string')

        self.inviteTitle = d.get('inviteTitle', '')
        if not isstring(self.inviteTitle):
            raise TYBizConfException(d,
                                     'InviteConf.inviteTitle must be string')

        self.inviteDesc = d.get('inviteDesc', '')
        if not isstring(self.inviteDesc):
            raise TYBizConfException(d, 'InviteConf.inviteDesc must be string')

        self.inviteUrl = d.get('inviteUrl', '')
        if not isstring(self.inviteUrl):
            raise TYBizConfException(d, 'InviteConf.inviteUrl must be string')

        self.name = d.get('name', '')
        if not isstring(self.name):
            raise TYBizConfException(d, 'InviteConf.name must be string')

        return self
Пример #32
0
def sendGiftsToUser(userId, gameId, clientId, items):
    '''
        多个奖品时的发奖,或者一个奖品的发奖,items为数组
    '''
    contentItemList = []
    rouletteMap = getRouletteMap()

    for item in items:
        itemMap = rouletteMap.get(item, {})
        if itemMap:
            # 添加判断流程,判断奖励是否需要发送led
            if itemMap.get('isSendLed', False):
                userInfo = halluser.getUserInfo(userId, gameId, clientId)
                msgstr = '恭喜' + userInfo.get('name', '') + '玩家在幸运大转盘中,抽中了' + itemMap.get('itemDesc',
                                                                                         '') + '大奖!快来参与,大奖得主就是你!'
                hallled.sendLed(HALL_GAMEID, msgstr, 1, 'hall')

            # 添加中奖内容    
            contentItemList.append(
                TYContentItem.decodeFromDict({'itemId': itemMap.get('itemId'), 'count': itemMap.get('count')}))

    userAssets = hallitem.itemSystem.loadUserAssets(userId)
    results = userAssets.sendContentItemList(gameId, contentItemList, 1, True, int(time.time()), 'ROULETTE_GOLD', 0)
    datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(results))
Пример #33
0
    def decodeFromDict(self, d):
        inviteRewardItem = d.get('inviteRewardItem', {})
        if not isinstance(inviteRewardItem, dict):
            raise TYBizConfException(d, 'InviteConf.inviteRewardItem must be dict')
        if inviteRewardItem:
            self.inviteRewardItem = TYContentItem.decodeFromDict(inviteRewardItem)

        self.gotoTitle = d.get('gotoTitle', '')
        if not isstring(self.gotoTitle):
            raise TYBizConfException(d, 'InviteConf.gotoTitle must be string')

        self.gotoDesc = ''
        if not isstring(self.gotoDesc):
            raise TYBizConfException(d, 'InviteConf.gotoDesc must be string')

        self.gotoUrl = d.get('gotoUrl', '')
        if not isstring(self.gotoUrl):
            raise TYBizConfException(d, 'InviteConf.gotoUrl must be string')

        self.inviteTitle = d.get('inviteTitle', '')
        if not isstring(self.inviteTitle):
            raise TYBizConfException(d, 'InviteConf.inviteTitle must be string')

        self.inviteDesc = d.get('inviteDesc', '')
        if not isstring(self.inviteDesc):
            raise TYBizConfException(d, 'InviteConf.inviteDesc must be string')

        self.inviteUrl = d.get('inviteUrl', '')
        if not isstring(self.inviteUrl):
            raise TYBizConfException(d, 'InviteConf.inviteUrl must be string')

        self.name = d.get('name', '')
        if not isstring(self.name):
            raise TYBizConfException(d, 'InviteConf.name must be string')

        return self
Пример #34
0
    def decodeFromDict(self, d):
        self.needNum = d.get('needNum', 0)
        if not isinstance(self.needNum, int) or self.needNum < 0:
            raise TYBizConfException(d, 'Fish.needNum must be int and >0')
        self.id = d.get('id')
        if not isinstance(self.id, int) or self.id < 0:
            raise TYBizConfException(d, 'Fish.id must be int and >0')
        self.name = d.get('name')
        if not isinstance(self.name, (str, unicode)):
            raise TYBizConfException(d, 'Fish.name must be str')
        self.type = d.get('type')
        if not isinstance(self.type, (str, unicode)):
            raise TYBizConfException(d, 'Fish.type must be str')

        if not isinstance(d.get('rewards'), list):
            raise TYBizConfException(d, 'Fish.rewards must be list')
        tempRewards = []
        for rewardDict in d.get('rewards'):
            itemDict = rewardDict.get('item', {})
            if itemDict:
                tempRewards.append({
                    'item':
                    TYContentItem.decodeFromDict(itemDict),
                    'weight':
                    rewardDict.get('weight')
                })
        self.rewards = tempRewards
        self.pic = d.get('pic')
        if not isinstance(self.name, (str, unicode)):
            raise TYBizConfException(d, 'Fish.pic must be str')

        self.smallPic = d.get('smallPic', '')
        if not isinstance(self.name, (str, unicode)):
            raise TYBizConfException(d, 'Fish.smallPic must be str')

        return self
Пример #35
0
def unlockUserForMatch(gameId, userId, bigRoomId, instId, ctrlRoomId, tableId, seatId, contentItem):
    if ftlog.is_debug():
        ftlog.debug('match_remote.unlockUserForMatch gameId=', gameId,
                    'userId=', userId,
                    'bigRoomId=', bigRoomId,
                    'instId=', instId,
                    'ctrlRoomId=', ctrlRoomId,
                    'tableId=', tableId,
                    'seatId=', seatId,
                    'contentItem=', contentItem)

    userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId)
    if userMatchInfo:
        # 此处有异常,正常要有userMatchInfo
        removeUserMatchInfo(userMatchInfo)

        if contentItem:
            try:
                contentItemObj = TYContentItem.decodeFromDict(contentItem)
                userAssets = hallitem.itemSystem.loadUserAssets(userId)
                assetList = userAssets.sendContentItemList(gameId, [contentItemObj],
                                                           1, True,
                                                           pktimestamp.getCurrentTimestamp(),
                                                           'MATCH_RETURN_FEE', bigRoomId)
                datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(assetList))
                ftlog.info('match_remote.unlockUserForMatch returnFees ok gameId=', gameId,
                           'userId=', userId,
                           'bigRoomId=', bigRoomId,
                           'instId=', instId,
                           'ctrlRoomId=', ctrlRoomId,
                           'tableId=', tableId,
                           'seatId=', seatId,
                           'contentItem=', contentItem)
            except:
                ftlog.error('match_remote.unlockUserForMatch gameId=', gameId,
                            'userId=', userId,
                            'bigRoomId=', bigRoomId,
                            'instId=', instId,
                            'ctrlRoomId=', ctrlRoomId,
                            'tableId=', tableId,
                            'seatId=', seatId,
                            'contentItem=', contentItem)
        try:
            onlinedata.removeOnlineLoc(userId, ctrlRoomId, tableId)
        except:
            ftlog.error('match_remote.unlockUserForMatch gameId=', gameId,
                        'userId=', userId,
                        'bigRoomId=', bigRoomId,
                        'instId=', instId,
                        'ctrlRoomId=', ctrlRoomId,
                        'tableId=', tableId,
                        'seatId=', seatId,
                        'contentItem=', contentItem)

        ftlog.info('match_remote.unlockUserForMatch ok gameId=', gameId,
                   'userId=', userId,
                   'bigRoomId=', bigRoomId,
                   'instId=', instId,
                   'ctrlRoomId=', ctrlRoomId,
                   'tableId=', tableId,
                   'seatId=', seatId,
                   'contentItem=', contentItem)
Пример #36
0
def createFT(roomId, userId, nRound, playMode, canDouble, fee, goodCard):
    if fee is not None:
        fee = TYContentItem.decodeFromDict(fee)
    ftConf = FTConf(nRound, fee, canDouble, playMode, goodCard)
    ftTable = gdata.rooms()[roomId].createFT(userId, ftConf)
    return ftTable.ftId
Пример #37
0
    def openRedEnvelope(self, userId, itemId=''):
        '''
        打开红包
        '''
        global _redEnvelopeConfig

        # 是否领取过
        receivers = daobase.executeMixCmd('LRANGE', self.dbPrefix + self.id + self.RECEIVER, 0, -1)
        if receivers:
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope receivers:', receivers)

            for receiverJson in receivers:
                receiver = json.loads(receiverJson)
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope receiver:', receiver)
                if userId == receiver['userId']:
                    return False, _redEnvelopeConfig['tips']['opened']

        # 构造添加给获取红包用户的奖励清单        
        contentItemList = []
        prizesJson = self._getPrize(itemId)
        # prizesJson = daobase.executeMixCmd('LPOP', self.dbPrefix + self.id + self.PACKAGES)
        daobase.executeMixCmd('expire', self.dbPrefix + self.id + self.PACKAGES, self.expiredTime)

        if prizesJson:
            prizes = json.loads(prizesJson)
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizes:', prizes)
            for prize in prizes:
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize:', prize)

                result, _itemId = self.getAssetID(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err1: ', prize, ' left: ', self.contents);
                    continue

                result, value = self.getItemValue(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err2: ', prize, ' left: ', self.contents);
                    continue

                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope itemId:', _itemId)
                    ftlog.debug('TYRedEnvelope.openRedEnvelope count:', prizes[prize] * value)

                contentItemList.append(
                    TYContentItem.decodeFromDict({'itemId': _itemId, 'count': prizes[prize] * value}))

            if ftlog.is_debug():
                ftlog.debug('contentItemList:', contentItemList)

            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            # 添加奖励
            results = userAssets.sendContentItemList(HALL_GAMEID, contentItemList, 1, True,
                                                     pktimestamp.getCurrentTimestamp(), self.EVENTID, 0)
            # notify
            datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, TYAssetUtils.getChangeDataNames(results))
            # 构造奖励字符串
            prizeString = TYAssetUtils.buildContentsString(results)

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizeString:', prizeString)

            # add receiver
            re = {}
            re['userId'] = userId
            re['prize'] = prizes
            re['prizeStr'] = prizeString
            re['time'] = pktimestamp.formatTimeMs()

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope add receiver re: ', re)
            daobase.executeMixCmd('LPUSH', self.dbPrefix + self.id + self.RECEIVER, json.dumps(re))
            daobase.executeMixCmd('expire', self.dbPrefix + self.id + self.RECEIVER, self.expiredTime)

            # make response
            response = {}
            response['envelopeId'] = self.id
            response['prizes'] = prizes
            response['prizeStr'] = prizeString

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope response: ', response)

            return True, response
        else:
            if self.state != self.STATE_FINISH:
                self.state = self.STATE_FINISH
                self.save2DB()

            return False, _redEnvelopeConfig['tips']['finished']
Пример #38
0
    def getFishReward(cls, userId, baitId):
        # 钓到没钓到标志
        rewardCount = 0
        record = ''
        fishPic = ''
        couponFishPic = ''
        exchangeDes = ''
        deltaChip = 0
        deltaCouponCount = 0

        # 检查用户Id, baitId 是否匹配, 获取 bait 消费金币
        userName = str(userdata.getAttrs(userId, ['name'])[0])
        bait = cls.getBait(baitId)
        consumeChip = bait.chip if bait else 0

        if not consumeChip or not cls.consumeExpenses(
                userId,
                TYContentItem.decodeFromDict({
                    'itemId': 'user:chip',
                    'count': consumeChip
                })):
            ftlog.warn('FishHelper.getFishReward', 'userId=',
                       userId, 'baitId=', baitId, 'userChip=',
                       userchip.getChip(userId), 'consumeChip=', consumeChip)
            payOrder = {
                "contains": {
                    "count": userchip.getChip(userId),
                    "itemId": "user:chip"
                },
                "shelves": ["lessbuychip"]
            }
            clientId = sessiondata.getClientId(userId)
            product, _shelves = hallstore.findProductByPayOrder(
                DIZHU_GAMEID, userId, clientId, payOrder)
            if not product:
                Alert.sendNormalAlert(DIZHU_GAMEID, userId, '金币不足',
                                      '金币不足了, 请去充值吧', None, None)
                return

            buyType = ''
            orderShow = TodoTaskOrderShow.makeByProduct(
                '金币不足', '', product, buyType)
            orderShow.setParam('sub_action_btn_text', '确定')
            mo = TodoTaskHelper.makeTodoTaskMsg(DIZHU_GAMEID, userId,
                                                orderShow)
            router.sendToUser(mo, userId)
            return

        # 随机获得珍珠, 存入数据库
        couponFish = cls.getCouponFishList()[0]
        # 判断鱼饵有没有奖券鱼的配置
        item = dizhu_util.getItemByWeight(
            bait.couponFishRewards) if bait.couponFishRewards else None
        couponCount = item.count if item else 0
        count = loadUserFishingCount(userId, couponFish.id)
        if couponCount:
            assetKind = hallitem.itemSystem.findAssetKind('user:coupon')
            couponCount = couponCount * 1.0 / assetKind.displayRate
            couponCount = int(couponCount) if couponCount.is_integer(
            ) else round(couponCount, 2)
            rewardCount += 1
            count += 1
            couponFishPic = couponFish.pic
            if count >= couponFish.needNum:
                count = 0
                # 发送奖券
                dictionary = {
                    'zhenzhu_count': couponFish.needNum,
                    'coupon_count': couponCount
                }
                record = json.dumps(
                    cls.getRealUserMail(cls.getMail(couponFish, True, False),
                                        dictionary))
                exchangeDes = json.dumps(
                    cls.getRealUserMail(cls.getMail(couponFish, True, True),
                                        dictionary))
                dictionary2 = {
                    'user_name': userName,
                    'zhenzhu_count': couponFish.needNum,
                    'coupon_count': couponCount
                }
                record2 = json.dumps(
                    cls.getRealUserMail(cls.getMail(couponFish, False, True),
                                        dictionary2))
                saveUserFishingCount(userId, couponFish.id, count)
                UserBag.sendAssetsToUser(DIZHU_GAMEID, userId, {
                    'itemId': item.assetKindId,
                    'count': item.count
                }, 'DDZ_FISHING_SYSTEM')
                deltaCouponCount = item.count
                cls.pushRecord(record2)
                if ftlog.is_debug():
                    ftlog.debug('FishHelper.getFishReward coupon exchangeDes',
                                'userId=', userId, 'fishId=', couponFish.id,
                                'exchangeDes=', exchangeDes)
            else:
                # 获得一个奖券鱼
                dictionary = {
                    'zhenzhu_count': couponFish.needNum,
                    'coupon_count': couponCount
                }
                record = json.dumps(
                    cls.getRealUserMail(cls.getMail(couponFish, True, False),
                                        dictionary))
                dictionary2 = {
                    'user_name': userName,
                    'zhenzhu_count': couponFish.needNum,
                    'coupon_count': couponCount
                }
                record2 = json.dumps(
                    cls.getRealUserMail(cls.getMail(couponFish, False, False),
                                        dictionary2))
                saveUserFishingCount(userId, couponFish.id, count)
                cls.pushRecord(record2)
                if ftlog.is_debug():
                    ftlog.debug('FishHelper.getFishReward coupon', 'userId=',
                                userId, 'fishId=', couponFish.id, 'record=',
                                record)

        # 随机获取金币奖励,对应bait下普通鱼
        userBaits = filter(lambda x: x.id == baitId, _fishingConf.baits)
        fish = userBaits[0].choiceFish()
        if fish.id:  # 钓到鱼了
            reward = fish.choiceReward()
            chip = reward.count
            if chip:
                rewardCount += 1
                bigFish = cls.getSuperFishList()[0]
                bigReward = dizhu_util.getItemByWeight(
                    bait.superFishRewards) if bait.superFishRewards else None
                if bigReward and bigReward.count and fish.id == bait.fishList[
                        -1].id:  # roll 大鱼的机会
                    fish = bigFish
                    chip = bigReward.count
                fishPic = fish.pic
                dictionary = {
                    'random_message': cls.getMessageByFishId(fish.id),
                    'fish_name': fish.name,
                    'chip_count': chip
                }
                if rewardCount == 2:
                    record = json.dumps(
                        cls.getRealUserMail(cls.getCombinationMail(),
                                            dictionary))
                else:
                    record = json.dumps(
                        cls.getRealUserMail(cls.getMail(fish, True),
                                            dictionary))
                dictionary2 = {
                    'user_name': userName,
                    'fish_name': fish.name,
                    'chip_count': chip,
                    'random_message': cls.getMessageByFishId(fish.id)
                }
                record2 = json.dumps(
                    cls.getRealUserMail(cls.getMail(fish, False), dictionary2))
                UserBag.sendAssetsToUser(DIZHU_GAMEID, userId, {
                    'itemId': 'user:chip',
                    'count': chip
                }, 'DDZ_FISHING_SYSTEM')
                cls.pushRecord(record2)
                deltaChip = chip

                if ftlog.is_debug():
                    ftlog.debug('FishHelper.getFishReward', 'userId=', userId,
                                'fishId=', fish.id, 'record=', record)
        return {
            'rewardCount':
            rewardCount,
            'desc':
            json.loads(record)
            if rewardCount and record else cls.getailureMail(),
            'couponFishPic':
            couponFishPic,
            'fishPic':
            fishPic,
            'exchangeDes':
            json.loads(exchangeDes) if exchangeDes else '',
            'finalCouponCount':
            userdata.getAttr(userId, 'coupon'),
            'finalChip':
            userchip.getChip(userId),
            'couponFishCount':
            count,
            'deltaChip':
            deltaChip,
            'deltaCouponCount':
            deltaCouponCount
        }
Пример #39
0
    def openRedEnvelope(self, userId, itemId=''):
        '''
        打开红包
        '''
        global _redEnvelopeConfig

        # 是否领取过
        receivers = daobase.executeMixCmd(
            'LRANGE', self.dbPrefix + self.id + self.RECEIVER, 0, -1)
        if receivers:
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope receivers:',
                            receivers)

            for receiverJson in receivers:
                receiver = json.loads(receiverJson)
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope receiver:',
                                receiver)
                if userId == receiver['userId']:
                    return False, _redEnvelopeConfig['tips']['opened']

        # 构造添加给获取红包用户的奖励清单
        contentItemList = []
        prizesJson = self._getPrize(itemId)
        # prizesJson = daobase.executeMixCmd('LPOP', self.dbPrefix + self.id + self.PACKAGES)
        daobase.executeMixCmd('expire',
                              self.dbPrefix + self.id + self.PACKAGES,
                              self.expiredTime)

        if prizesJson:
            prizes = json.loads(prizesJson)
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizes:', prizes)
            for prize in prizes:
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize:', prize)

                result, _itemId = self.getAssetID(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err1: ',
                                prize, ' left: ', self.contents)
                    continue

                result, value = self.getItemValue(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err2: ',
                                prize, ' left: ', self.contents)
                    continue

                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope itemId:',
                                _itemId)
                    ftlog.debug('TYRedEnvelope.openRedEnvelope count:',
                                prizes[prize] * value)

                contentItemList.append(
                    TYContentItem.decodeFromDict({
                        'itemId': _itemId,
                        'count': prizes[prize] * value
                    }))

            if ftlog.is_debug():
                ftlog.debug('contentItemList:', contentItemList)

            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            # 添加奖励
            results = userAssets.sendContentItemList(
                HALL_GAMEID, contentItemList, 1, True,
                pktimestamp.getCurrentTimestamp(), self.EVENTID, 0)
            # notify
            datachangenotify.sendDataChangeNotify(
                HALL_GAMEID, userId, TYAssetUtils.getChangeDataNames(results))
            # 构造奖励字符串
            prizeString = TYAssetUtils.buildContentsString(results)

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizeString:',
                            prizeString)

            # add receiver
            re = {}
            re['userId'] = userId
            re['prize'] = prizes
            re['prizeStr'] = prizeString
            re['time'] = pktimestamp.formatTimeMs()

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope add receiver re: ',
                            re)
            daobase.executeMixCmd('LPUSH',
                                  self.dbPrefix + self.id + self.RECEIVER,
                                  json.dumps(re))
            daobase.executeMixCmd('expire',
                                  self.dbPrefix + self.id + self.RECEIVER,
                                  self.expiredTime)

            # make response
            response = {}
            response['envelopeId'] = self.id
            response['prizes'] = prizes
            response['prizeStr'] = prizeString

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope response: ',
                            response)

            return True, response
        else:
            if self.state != self.STATE_FINISH:
                self.state = self.STATE_FINISH
                self.save2DB()

            return False, _redEnvelopeConfig['tips']['finished']