def loginGame(userId, gameId, clientId): """ 用户登录一个游戏, 检查用户的游戏数据是否存在(创建用户数据) """ # 确认用户的游戏数据是否存在 iscreate = ensureGameDataExists(userId, gameId, clientId) # 游戏登录次数加1,每次bind_user都会加1,包括断线重连 gamedata.incrGameAttr(userId, gameId, 'loginsum', 1) # 确认是否是今日第一次登录 isdayfirst = False datas = day1st.getDay1stDatas(userId, gameId) if 'daylogin' not in datas: isdayfirst = True datas['daylogin'] = 1 datas['iscreate'] = 1 else: datas['daylogin'] += 1 datas['iscreate'] = 0 day1st.setDay1stDatas(userId, gameId, datas) if isdayfirst: # 消息的数据结构新旧转换 message.convertOldData(gameId, userId) # 插件的登录补充处理 TYGame(gameId).loginGame(userId, gameId, clientId, iscreate, isdayfirst) evt = EventUserLogin(userId, gameId, isdayfirst, iscreate, clientId) TYGame(gameId).getEventBus().publishEvent(evt) userdata.updateUserGameDataAuthorTime(userId, gameId) return isdayfirst, iscreate
def doSpecifyRobotShutDown(self, gameId, roomId0, tableId0, userId): ftlog.debug("doSpecifyRobotShutDown", roomId0, tableId0, userId) """ 关闭指定机器人 """ rmgr = TYGame(gameId).getRobotManager() if rmgr: msg = runcmd.getMsgPack() rmgr.shutDownSpecifyRobot(msg, roomId0, tableId0, userId)
def doRobotCallMatch(self, gameId, roomId0): ''' 比赛开始阶段, 唤醒比赛机器人 ''' ftlog.debug("<<") rmgr = TYGame(gameId).getRobotManager() if rmgr: msg = runcmd.getMsgPack() robotCount = msg.getParam("robotCount") rmgr.callUpRobotsToMatch(msg, roomId0, robotCount)
def doRobotShutDown(self, gameId, roomId0, tableId0, userCount, seatCount, users): ''' 桌子上有人站起, 关闭机器人 ''' rmgr = TYGame(gameId).getRobotManager() if rmgr: msg = runcmd.getMsgPack() rmgr.shutDownRobot(msg, roomId0, tableId0, userCount, seatCount, users)
def doRobotCallUp(self, gameId, roomId0, tableId0, userCount, seatCount, users): ''' 桌子上有人坐下, 唤醒机器人 ''' rmgr = TYGame(gameId).getRobotManager() if rmgr: msg = runcmd.getMsgPack() rmgr.callUpRobot(msg, roomId0, tableId0, userCount, seatCount, users)
def loginGame(userId, gameId, clientId, clipboard=None): """ 用户登录一个游戏, 检查用户的游戏数据是否存在(创建用户数据) """ # 确认用户的游戏数据是否存在 iscreate = ensureGameDataExists(userId, gameId, clientId) if not iscreate: _moveHall51DataBack(userId, gameId, clientId) # 游戏登录次数加1,每次bind_user都会加1,包括断线重连 loginsum = gamedata.incrGameAttr(userId, gameId, 'loginsum', 1) # 确认是否是今日第一次登录 isdayfirst = False datas = day1st.getDay1stDatas(userId, gameId) if 'daylogin' not in datas: isdayfirst = True datas['daylogin'] = 1 datas['iscreate'] = 1 else: datas['daylogin'] += 1 datas['iscreate'] = 0 day1st.setDay1stDatas(userId, gameId, datas) if isdayfirst: # 消息的数据结构新旧转换 message.convertOldData(gameId, userId) # 插件的登录补充处理 TYGame(gameId).loginGame(userId, gameId, clientId, iscreate, isdayfirst) try: from poker.entity.configure import pokerconf numClientId = pokerconf.clientIdToNumber(clientId) updateHistoryClientIdsIfNeed(userId, gameId, numClientId) except: pass evt = EventUserLogin(userId, gameId, isdayfirst, iscreate, clientId) evt.clipboard = clipboard TYGame(gameId).getEventBus().publishEvent(evt) userdata.updateUserGameDataAuthorTime(userId, gameId) # 新大厅v4.56功能入口 # from hall.entity.localservice import localservice # localservice.loginGame_v456(userId, gameId, clientId, loginsum, isdayfirst, datas['daylogin']) return isdayfirst, iscreate
def doRobotDetailInfo(self, gameId): ''' 查询机器人管理器的详细信息 ''' rmgr = TYGame(gameId).getRobotManager() datas = {} if rmgr: msg = runcmd.getMsgPack() datas = rmgr.getRobotDetail(msg) if router.isQuery(): mo = MsgPack() mo.setCmdAction('robotmgr', 'detail') mo.setResult('detail', datas) router.responseQurery(mo)
def createFriendTable(pluginId): ''' 创建好友桌 config - 创建好友桌的参数,非房主依靠config参数加入自建桌 pluginId - 插件游戏ID ''' # 随机选择自建桌ID index = daobase.executeMixCmd('hincrby', FRIEND_TABLE_MAIN_KEY, FRIEND_TABLE_ROOM_INDEX, 1) index = index % FRIEND_TABLE_RANDOM_COUNT ftlog.debug('hall_friend_table.createFriendTable index: ', index) ftNumStr = daobase.executeMixCmd('LINDEX', FRIEND_TABLE_RANDOM_KEY, index) if ftNumStr: ftId = getStringFTId(int(ftNumStr)) ftlog.debug('hall_friend_table.createFriendTable ftId:', ftId) check = TYGame(pluginId).checkFriendTable(ftId) if check: ftlog.info('hall_friend_table.createFriendTable ftId:', ftId, ' already used by plugin:', pluginId) return None else: daobase.executeMixCmd('HSET', FRIEND_TABLE_MAIN_KEY + ftId, FRIEND_TABLE_PLUGIN, pluginId) # 设置过期时间 daobase.executeMixCmd('expire', FRIEND_TABLE_MAIN_KEY + ftId, 604800) ftlog.info('hall_friend_table.createFriendTable distribution ftId:', ftId, ' to plugin:', pluginId) return ftId else: ftlog.info('hall_friend_table.createFriendTable get ftId index:', index, ' error, please check redis!!') return None
def enterFriendTable(userId, gameId, clientId, ftId): """进入自建桌""" if ftlog.is_debug(): ftlog.debug('hall_friend_table.enterFriendTable userId:', userId, ' pluginId:', gameId, ' clientId:', clientId, ' ftId:', ftId) pluginId = queryFriendTable(ftId) if not pluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('该房间不存在')) return if TYPlayer.isRobot(userId): isValidPluginId = True else: isValidPluginId = False from hall.entity import hallgamelist2 template = hallgamelist2.getUITemplate(gameId, userId, clientId) for version in template.versionList: if pluginId == version.game.gameId: isValidPluginId = True break if not isValidPluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('该安装包不支持此房间号所对应的玩法')) return ftlog.info('hall_friend_table.enterFriendTable userId:', userId, ' lead to pluginId:', pluginId) pluginId = int(pluginId) TYGame(pluginId).enterFriendTable(userId, gameId, clientId, ftId)
def checkSetMedal(gameId, userId, baseScore, isGameStart, winchip): winchip = 0 if isGameStart else winchip winrate, oldLevel = gamedata.getGameAttrs(userId, gameId, ['winrate', 'level'], False) winrate = strutil.loads(winrate, ignoreException=True, execptionValue={}) if winrate is None: winrate = {} if winchip >= 0 or isGameStart: _processGamePlayWinTimes(winrate, isGameStart) oldLevel = strutil.parseInts(oldLevel) deltaExp = 0 if winchip > 0 or isGameStart: deltaExp = _calUserDetalExp(winchip, baseScore) exp = userdata.incrExp(userId, deltaExp) explevel, _ = gameexp.getLevelInfo(gameId, exp) gamedata.setGameAttrs(userId, gameId, ['winrate', 'level'], [strutil.dumps(winrate), explevel]) if oldLevel != explevel: TYGame(gameId).getEventBus().publishEvent( UserLevelGrowEvent(gameId, userId, oldLevel, explevel)) if isGameStart: # 广告商通知 pcount = commconf.getAdNotifyPlayCount(gameId) if pcount > 0 and winrate.get('pt', 0) == pcount: sdkclient.adNotifyCallBack(gameId, userId) return exp, deltaExp, winrate
def addUserSkillScore(self, userId, toAdd): score = gamedata.incrGameAttr(userId, self.gameId, 'skillscore', toAdd) # 大师分增量榜 hallranking.rankingSystem.setUserByInputType( self.gameId, TYRankingInputTypes.DASHIFEN_INCR, userId, toAdd, pktimestamp.getCurrentTimestamp()) oldScore = score - toAdd oldLevel = self.getLevel(oldScore) newLevel = self.getLevel(score) ret = buildUserSkillScoreInfo(UserSkillScore(userId, score, newLevel)) ret['userId'] = userId ret['addScore'] = toAdd if oldLevel != newLevel: changeName = False needLevel = commconf.getChangeNickNameLevel(self.gameId) if needLevel == newLevel.level: setNameCount = hallrename.getRenameSum(self.gameId, userId) if setNameCount <= 0: ret['changename'] = 1 changeName = True rewards = self.sendLevelReward(userId, oldLevel, newLevel) if not changeName and rewards: ret['rewards'] = rewards ret['isLevelUp'] = True TYGame(self.gameId).getEventBus().publishEvent( SkillScoreIncrEvent(self.gameId, userId, oldScore, oldLevel.level, score, newLevel.level)) if ftlog.is_debug(): ftlog.debug('SkillScore.incrSkillScore', 'gameId=', self.gameId, 'userId=', userId, 'addScore=', toAdd, 'newScore=', score, 'oldLevel=', oldLevel.level, 'newLevel=', newLevel.level, 'ret=', ret) return ret
def _conform(self, gameId, userAssets, item, timestamp, params): from poker.entity.game.game import TYGame userId = userAssets.userId clientId = sessiondata.getClientId(userId) dashifen = TYGame(self.gameId).getDaShiFen(userId, clientId) level = dashifen.get('level', 0) if dashifen else 0 if ftlog.is_debug(): ftlog.debug('ItemActionConditionGameDashifenLevel._conform gameId=', gameId, 'userId=', userId, 'clientId=', clientId, 'selfGameId=', self.gameId, 'dashifen=', dashifen, 'level=', level, 'minLevel=', self.minLevel, 'maxLevel=', self.maxLevel) return (self.minLevel == -1 or level >= self.minLevel) \ and (self.maxLevel == -1 or level < self.maxLevel)
def _doStart(self, todayStartTime, todayEndTime): self._startTime = todayStartTime self._endTime = todayEndTime self._state = MatchRelaxation.ST_START self.clear() self.tableManager.updateMatchTime(todayStartTime, todayEndTime, self.matchConf) TYGame(self.room.gameId).getEventBus().publishEvent(MatchStartEvent(self.room.gameId, self.room.bigRoomId)) self._logger.info('MatchRelaxation._doStart idleTableCount=', self.tableManager.idleTableCount)
def getGameInfo(userId, gameId, clientId): ''' 取得当前用户的游戏账户信息dict ''' # 获取插件游戏的信息 infos = TYGame(gameId).getGameInfo(userId, clientId) # 数据补丁, 避免客户端崩溃 if 'headUrl' not in infos: infos['headUrl'] = '' return infos
def ensureGameDataExists(userId, gameId, clientId): ''' 判定用户游戏数据是否存在, 若不存在则初始化该游戏的所有的相关游戏数据 包括: 主游戏数据gamedata, 道具, 勋章等 ''' isCreate = False gaccount = TYGame(gameId) # 以游戏主数据的前2个字段为判定条件 ukeys = gaccount.getInitDataKeys()[0:2] d1, d2 = gamedata.getGameAttrs(userId, gameId, ukeys) if d1 is None or d2 is None: gdkeys, gdata = gaccount.createGameData(userId, gameId) gdkeys.append('createTime') gdata.append(timestamp.formatTimeMs()) bireport.creatGameData(gameId, userId, clientId, gdkeys, gdata) bireport.reportGameEvent('CREATE_GAME_DATA', userId, gameId, 0, 0, 0, 0, 0, 0, [], clientId) isCreate = True return isCreate
def _onUserAfterLogin(event): if event.clipboard and event.clipboard.cmd == '开桌' and not hasLoc(event.loc): if ftlog.is_debug(): ftlog.debug('hall_joinfriendgame._onUserAfterLogin', 'userId=', event.userId, 'clipboard=', event.clipboard.content) ftId = event.clipboard.urlParams.get('ftId') if ftId: pluginId = hall_friend_table.queryFriendTable(ftId) TYGame(pluginId).enterFriendTable(event.userId, event.gameId, event.clientId, ftId)
def sendTodoTaskResponse(self, userId, gameId, clientId, isdayfirst): ''' 发送当前用户的TODOtask列表消息 ''' ftlog.debug('UtilHelper.sendTodoTaskResponse userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst) todotasks = TYGame(gameId).getTodoTasksAfterLogin( userId, gameId, clientId, isdayfirst) if todotasks: TodoTaskHelper.sendTodoTask(gameId, userId, todotasks)
def doGameQuickStart(self, userId, gameId, clientId, roomId0, tableId0, playMode): msg = runcmd.getMsgPack() if ftlog.is_debug(): ftlog.debug("<< |userId, gameId, clientId, msg:", userId, gameId, clientId, msg, caller=self) TYGame(gameId).QuickStartDispatcherClass.dispatchQuickStart( msg, userId, gameId, roomId0, tableId0, playMode, clientId)
def enterFriendTable(userId, gameId, clientId, ftId): """进入自建桌""" if ftlog.is_debug(): ftlog.debug('hall_friend_table.enterFriendTable userId:', userId, ' pluginId:', gameId, ' clientId:', clientId, ' ftId:', ftId) pluginId = queryFriendTable(ftId) if not pluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip(ROOM_NOT_EXIST['info'])) responseEnterFriendTable(userId, ROOM_NOT_EXIST) return ftlog.info('hall_friend_table.enterFriendTable userId:', userId, ' lead to pluginId:', pluginId) pluginId = int(pluginId) TYGame(pluginId).enterFriendTable(userId, gameId, clientId, ftId) responseEnterFriendTable(userId, ENTER_FRIEND_OK)
def getGameInfo(userId, clientId): ''' 取得当前用户的游戏账户信息dict ''' ftlog.debug('hall.getGameInfo', userId, clientId) # 大厅游戏, 获取所有游戏的大师分 gameids = hallconf.getDaShiFenFilter(clientId) allGameIds = gdata.gameIds() dashifen = {} i = 0 for gid in gameids : if gid in allGameIds : infos = TYGame(gid).getDaShiFen(userId, clientId) if infos : infos['index'] = i dashifen[gid] = infos i = i + 1 return {'dashifen' : dashifen}
def _doFinish(self): assert (self.state == MatchRelaxation.ST_START) self._state = MatchRelaxation.ST_IDLE TYGame(self.room.gameId).getEventBus().publishEvent(MatchOverEvent(self.room.gameId, self.room.bigRoomId)) needNotifyTableList = [] needNotifyTableList.extend(self.tableManager.waitTableList) needNotifyTableList.extend(self.tableManager.busyTableList) lenTables = len(needNotifyTableList) for x in xrange(lenTables): self.tableController.notifyMatchOver(needNotifyTableList[x]) self.returnTable(needNotifyTableList[x]) # 排序最终排名 self._sortMatchRanks() # 发送奖励 for _, player in self._playerMap.items(): self._doPlayerMatchOver(player) self._logger.info('MatchRelaxation._doFinish ...')
def doTableThrowEmojiFrom(gameId, userId, roomId, bigRoomId, tableId, emojiId, minchip, price, charmDelta, clientId): eventId = 'EMOTICON_%s_CONSUME' % (emojiId.upper()) trueDelta, final = userchip.incrChipLimit( userId, gameId, -price, price + minchip, -1, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, eventId, roomId, clientId) # 发送通知 if trueDelta != 0: datachangenotify.sendDataChangeNotify(gameId, userId, 'chip') if trueDelta != -price: return 0, trueDelta, final bireport.gcoin('out.chip.emoticon', gameId, price) # 魅力值 userdata.incrCharm(userId, charmDelta) bireport.gcoin('out.smilies.' + emojiId + '.' + str(bigRoomId), gameId, price) TYGame(gameId).getEventBus().publishEvent( UseTableEmoticonEvent(gameId, userId, roomId, tableId, emojiId, price)) return 1, trueDelta, final
def getBestTableIdWithScore(self, userId, shadowRoomId, exceptTableId=None): '''原子化从redis里获取和删除评分最高的桌子Id Return: 0, 0: tableScores 队列为空, 所有桌子都在分配座位中 ''' def getBestTableIdFromRedis(shadowRoomId): '''从redis里取出并删除一个评分最高的牌桌 ''' tableId, tableScore = 0, 0 datas = daobase.executeTableLua( shadowRoomId, 0, room_scripts.ALIAS_GET_BEST_TABLE_ID_LUA, 1, self.getTableScoresKey(shadowRoomId), 0) if datas and len(datas) == 2: tableId, tableScore = datas[0], datas[1] ftlog.info("getBestTableIdFromRedis <<|tableId, tableScore:", tableId, tableScore) return tableId, tableScore if ftlog.is_debug(): ftlog.debug("<<", "|shadowRoomId, exceptTableId:", shadowRoomId, exceptTableId, caller=self) pigTables = [] tableId = 0 tableScore = 0 for _ in xrange(5): # 所有桌子有可能正在分配座位,如果取桌子失败,需要休眠后重试 if gdata.roomIdDefineMap()[shadowRoomId].tableCount == 1: tableId = shadowRoomId * 10000 + 1 tableScore = 100 else: tableId, tableScore = getBestTableIdFromRedis( shadowRoomId) # 从redis取一个牌桌 # 该牌桌被客户端指定排除了,另外再取一个牌桌 if exceptTableId and tableId and exceptTableId == tableId: tableId1, tableScore1 = getBestTableIdFromRedis( shadowRoomId) # 把之前从redis取出的牌桌加回redis self._updateTableScore(shadowRoomId, tableScore, tableId, force=True) tableId, tableScore = tableId1, tableScore1 if ftlog.is_debug(): ftlog.debug( 'getBestTableId shadowRoomId, tableId, tableScore=', shadowRoomId, tableId, tableScore) if tableId: if TYGame(self.gameId).isWaitPigTable(userId, self, tableId): pigTables.append([shadowRoomId, tableScore, tableId]) tableId = 0 continue else: break else: FTTasklet.getCurrentFTTasklet().sleepNb(0.2) if ftlog.is_debug(): ftlog.debug('getBestTableId pigTables=', pigTables) if pigTables: for pig in pigTables: self._updateTableScore(pig[0], pig[1], pig[2], False) return tableId, tableScore
def _getFriendGameInfo(userId, gameIds, for_level_info, for_winchip, for_online_info=1): uid = int(userId) datas = {} gid, rid, tid, sid = 0, 0, 0, 0 state = daoconst.OFFLINE if for_online_info: loclist = onlinedata.getOnlineLocList(uid) state = onlinedata.getOnlineState(uid) if len(loclist) > 0: _rid, _tid, _sid = loclist[0] # gid表示用户在哪个游戏中 gid = strutil.getGameIdFromInstanceRoomId(_rid) # 检查是否可加入游戏 if TYGame(gid).canJoinGame(userId, _rid, _tid, _sid): # rid/tid/sid表示用户所在的游戏是否可加入游戏 # 分享出来的都是可以加入游戏的牌桌信息 rid = _rid tid = _tid sid = _sid if ftlog.is_debug(): ftlog.debug('getFriendGameInfo userId:', userId, ' gameId:', gid, ' roomId:', _rid, ' tableId:', _tid, ' seatId:', _sid, ' can not join game....') if state == daoconst.OFFLINE: offline_time = gamedata.getGameAttr(uid, HALL_GAMEID, 'offlineTime') if not offline_time: # 取不到离线时间,取上线时间 offline_time = userdata.getAttr(uid, 'authorTime') if offline_time: offline_time = pktimestamp.parseTimeMs(offline_time) delta = datetime.now() - offline_time delta = delta.days * 24 * 60 + delta.seconds / 60 # 分钟数 else: # 异常情况 delta = 24 * 60 datas['offline_time'] = delta if delta > 0 else 1 if rid > 0: try: room = gdata.roomIdDefineMap().get(rid, None) if room: datas['room_name'] = room.configure['name'] except: ftlog.error() # 构造回传给SDK的游戏数据 datas.update({ 'uid': uid, 'gid': gid, 'rid': rid, 'tid': tid, 'sid': sid, 'state': state }) if for_level_info: datas['level_game_id'] = 0 datas['level'] = 0 datas['level_pic'] = '' try: for gameId in gameIds: if gameId not in gdata.games(): continue dashifen_info = gdata.games()[gameId].getDaShiFen(uid, '') if dashifen_info: level = dashifen_info['level'] if level > 0 and level > datas['level']: datas['level_game_id'] = gameId datas['level'] = level level_pic = dashifen_info.get('picbig') datas[ 'level_pic'] = level_pic if level_pic else dashifen_info.get( 'pic') except: ftlog.error() if for_winchip: datas['winchip'] = 0 datas['winchips'] = 0 try: for gameId in gameIds: winchips, todaychips = gamedata.getGameAttrs( userId, gameId, ['winchips', 'todaychips'], False) winchips = strutil.parseInts(winchips) yest_winchip = 0 todaychips = strutil.loads(todaychips, ignoreException=True) if todaychips and 'today' in todaychips and 'chips' in todaychips and 'last' in todaychips: if pktimestamp.formatTimeDayInt() == todaychips['today']: yest_winchip = todaychips['last'] elif pktimestamp.formatTimeYesterDayInt( ) == todaychips['today']: yest_winchip = todaychips['chips'] datas['winchip'] += yest_winchip datas['winchips'] += winchips except: ftlog.error() return datas
def doTreasureBox(gameId, userId, bigRoomId): data = _getTbData(gameId, userId) bigRoomId = data['tbroomid'] if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'bigRoomId=', bigRoomId) # 判定房间配置 tbconfiger = getTreasureBoxConf(gameId, bigRoomId) if not tbconfiger or not tbconfiger.get('reward', None): if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'err=', 'NotTBoxRoom') return {'ok': 0, 'info': '本房间不支持宝箱,请进入高倍房再使用'} # 判定是否可以领取 tbplaytimes, tblasttime, datas = getUserTbInfo(gameId, userId, bigRoomId) tbplaycount = tbconfiger['playCount'] if tblasttime <= 0 or tbplaytimes < tbplaycount: if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'err=', 'CanNotTBox') return { 'ok': 0, 'tbt': min(tbplaytimes, tbplaycount), 'tbc': tbplaycount, 'info': tbconfiger['desc'] } # 更新宝箱状态 datas['tblasttime'] = int(time.time()) datas['tbplaytimes'] = 0 _setTbData(gameId, userId, datas) rewards = tbconfiger['reward'] content = TYContentRegister.decodeFromDict(rewards) sitems = content.getItems() # 活动加成 ditems = _getDoubleInfos(gameId, bigRoomId) if ditems: for si in sitems: kindId = si.assetKindId mutil = ditems.get(kindId, 0) if mutil and mutil > 0: si.count = int(si.count * mutil) # 发送道具 ua = hallitem.itemSystem.loadUserAssets(userId) aslist = ua.sendContentItemList(gameId, sitems, 1, True, timestamp.getCurrentTimestamp(), 'TASK_OPEN_TBOX_REWARD', bigRoomId) addmsg = TYAssetUtils.buildContentsString(aslist) items = [] for x in aslist: kindId = hallconf.translateAssetKindIdToOld(x[0].kindId) items.append({'item': kindId, 'count': x[1], 'total': x[2]}) TYGame(gameId).getEventBus().publishEvent( UserTBoxLotteryEvent(gameId, userId)) data = { 'ok': 1, 'tbt': 0, 'tbc': tbplaycount, 'info': '开启宝箱,获得' + addmsg, 'items': items } if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'data=', data) return data
def getShareReward(gameId, userId, share, shareLoc, timestamp): ''' 给用户发放分享奖励 ''' # 分享BI日志汇报 clientId = sessiondata.getClientId(userId) bireport.reportGameEvent('SHARE_CALLBACK', userId, gameId, share.shareId, 0, 0, 0, 0, 0, [], clientId) # 记录分享次数 gamedata.incrGameAttr(userId, HALL_GAMEID, 'shareCount', 1) TGHall.getEventBus().publishEvent( HallShareEvent(gameId, userId, share.shareId, shareLoc)) # 首先处理 分享相关的通知 notifyInfoStr = pkgamedata.getGameAttr(userId, HALL_GAMEID, 'shareInfo') newInfo = {} pkgamedata.setGameAttr(userId, HALL_GAMEID, 'shareInfo', json.dumps(newInfo)) if notifyInfoStr: notifyInfo = json.loads(notifyInfoStr) shareId = notifyInfo.get('shareId', 0) if shareId == share.shareId: # 通知 info = notifyInfo.get('info', '') module = notifyInfo.get('module', '') if module == hall_red_envelope.TYRedEnvelope.EVENTID: hall_red_envelope.TYRedEnvelopeMgr.changeRedEnvelopeState( info, hall_red_envelope.TYRedEnvelope.STATE_SHARED) from poker.entity.game.game import TYGame clientId = sessiondata.getClientId(userId) gameids = hallconf.getDaShiFenFilter(clientId) for gid in gameids: TYGame(gid).sendTuyooRedEnvelopeCallBack( userId, clientId, info) # 分享奖励 ok, rewardCount = incrRewardCount(userId, share, timestamp) if not ok: if ftlog.is_debug(): ftlog.debug( 'hallshare.getShareReward already no share, check update share promote ...' ) ftlog.debug('hallshare.getShareReward fail gameId=', gameId, 'userId=', userId, 'shareId=', share.shareId, 'shareLoc=', shareLoc, 'rewardCount=', rewardCount, 'maxRewardCount=', share.maxRewardCount) return False assetList = sendReward(gameId, userId, share, shareLoc) if assetList and share.mail: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskGoldRain(share.mail)) ftlog.debug('hallshare.getShareReward ok gameId=', gameId, 'userId=', userId, 'shareId=', share.shareId, 'shareLoc=', shareLoc, 'rewardCount=', rewardCount, 'maxRewardCount=', share.maxRewardCount, 'reward=', [(at[0].kindId, at[1]) for at in assetList] if assetList else []) if share.mail: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, share.mail) # udpate free & promotion_loc datachangenotify.sendDataChangeNotify(gameId, userId, ['free', 'promotion_loc']) # 深圳研发中心修改,增加领奖后的返回指令 from freetime.entity.msg import MsgPack from poker.protocol import router mp = MsgPack() mp.setCmd('share_hall') mp.setAction('reward') mp.setResult('gameId', gameId) mp.setResult('userId', userId) mp.setResult('shareId', share.shareId) mp.setResult('rewards', [(at[0].kindId, at[1]) for at in assetList] if assetList else []) router.sendToUser(mp, userId) return True