def _do_http_gm_room_list(self, gameId, httpRequest, httpArgs, httpResult): '''获取房间列表''' roomOnlineInfos = daobase._executeBiCmd('HGETALL', daoconst.BI_KEY_ROOM_ONLINES % (gameId)) roomOnlineInfos = dict(utils.pairwise(roomOnlineInfos)) bigRoomOnlineInfos = {} for roomId, onlineInfo in roomOnlineInfos.items(): bigRoomId = gdata.getBigRoomId(roomId) tcs = map(int, onlineInfo.split('|')) ucount, tcount = tcs[0], tcs[-1] if bigRoomId not in bigRoomOnlineInfos: bigRoomOnlineInfos[bigRoomId] = [0, 0] bigRoomOnlineInfos[bigRoomId][0] += ucount bigRoomOnlineInfos[bigRoomId][1] += tcount roomList = [] for bigRoomId in gdata.gameIdBigRoomidsMap()[gameId]: ctrlRoomId = gdata.bigRoomidsMap()[bigRoomId][0] roomDefine = gdata.roomIdDefineMap()[ctrlRoomId] ucount, tcount = bigRoomOnlineInfos.get(roomDefine.bigRoomId, [0, 0]) roomInfo = { 'bigRoomId': bigRoomId, 'tableCount': roomDefine.configure['gameServerCount'] * roomDefine.configure['gameTableCount'], 'name': roomDefine.configure['tableConf'].get('tname', ''), 'playingPlayers': ucount, 'playingTables': tcount, } roomList.append(roomInfo) httpResult['roomList'] = roomList
def onMatchWinlose(cls, event): ''' 监听比赛结局胜负 ''' ok = cls.checkActivityDate() if not ok: if ftlog.is_debug(): ftlog.debug('ActivityDdzFund.onMatchWinlose OutDate userId=', event.userId, 'matchId=', event.matchId) return userId = event.userId status = cls.loadFundStatus(userId, event.timestamp) if not status.isActivated: ftlog.debug('ActivityDdzFund.onMatchWinlose userId=', userId, 'status=', status.__dict__) return roomId = event.matchId try: roomId = int(roomId) except: ftlog.warn('ActivityDdzFund.onMatchWinlose BadMatchId userId=', userId, 'status=', status.__dict__) return bigRoomId = gdata.getBigRoomId(roomId) data_wrapper = UserPlayDataDatabase(userId) data_wrapper.increase(event.isWin, True, 0, bigRoomId) ftlog.info('ActivityDdzFund.onMatchWinlose userId=', userId, 'matchId=', event.matchId, 'isWin=', event.isWin, 'isMatch=', True, 'roomLevel=', 0, 'bigRoomId=', bigRoomId, 'roomId=', roomId)
def handle_event(self, event): if not self.act.checkOperative(): return if not isinstance(event, GameOverEvent): return if self.play_result is not None and self.play_result != event.gameResult: return # 历史原因,很多插件都写成9999了,尽量纠正一把 gameid = event.gameId if event.gameId != HALL_GAMEID else strutil.getGameIdFromHallClientId( event.clientId) if gameid != self.gameid: return bigRoomId = gdata.getBigRoomId(event.roomId) bigroom = bigRoomId if bigRoomId else event.roomId credit = self.room2credit.get(str(bigroom), 0) if ftlog.is_debug(): ftlog.debug('CreditSourceGamePlay.handle_event userId=', event.userId, 'gameId=', gameid, 'self.gameId=', self.gameid, 'bigroom=', bigroom, 'credit=', credit, 'event.roomId=', event.roomId, 'room2credit', self.room2credit) if credit <= 0: return self._add_credit(event.userId, credit, event.roundNum)
def onTableWinlose(cls, event): ''' 监听非比赛场的结局胜负 ''' ok = cls.checkActivityDate() if not ok: if ftlog.is_debug(): ftlog.debug('ActivityDdzFund.onTableWinlose OutDate userId=', event.userId, 'roomId=', event.roomId) return userId = event.userId status = cls.loadFundStatus(userId, event.timestamp) if not status.isActivated: ftlog.debug('ActivityDdzFund.onTableWinlose userId=', userId, 'roomId=', event.roomId, 'status=', status.__dict__) return roomLevel = gdata.roomIdDefineMap()[event.roomId].configure.get('roomLevel', 1) data_wrapper = UserPlayDataDatabase(userId) bigRoomId = event.mixConfRoomId or gdata.getBigRoomId(event.roomId) data_wrapper.increase(event.winlose.isWin, False, roomLevel, bigRoomId) ftlog.info('ActivityDdzFund.onTableWinlose userId=', userId, 'isWin=', event.winlose.isWin, 'isMatch=', True, 'roomLevel=', 0, 'roomId=', event.roomId, 'bigRoomId=', bigRoomId)
def returnSignInfFees(userId, roomId, fees): #获取用户报名券信息 roomId = gdata.getBigRoomId(roomId) jstr = daobase.executeRePlayCmd('hget', 'match:discount:6', userId) match_discounts = strutil.loads(jstr) if jstr else [] if match_discounts: for discount in match_discounts: itemId = discount.get('itemId', '') matchId = discount.get('matchId', '') if matchId == roomId: for fee in fees: if fee['itemId'] == ASSET_DIAMOND_KIND_ID: discounted = 10 lottery_conf = dizhuconf.getMatchLotteryConf() discountItems = lottery_conf.get('discountItem') for discountItem in discountItems: if itemId == discountItem.get('itemId', ''): discounted = discountItem.get('discount', 10) fee['count'] = fee['count'] * discounted / 10 fees.append({'itemId':itemId, 'count':1}) delMatchLotteryInfo(userId, roomId) break ftlog.debug('returnSignInfFees userId=', userId, 'roomId=', roomId, 'fees=', fees, 'match_discounts=', match_discounts) return fees
def checkMatchSigninCond(userId, roomId): if userId <= 10000: # 机器人不检查 return True, None matchCondConf = configure.getGameJson(DIZHU_GAMEID, 'bigmatch.filter', {}) if not matchCondConf: if ftlog.is_debug(): ftlog.debug( 'dizhumatchcond.checkMatchSigninCond EmptyMatchCondConf roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) return True, None bigRoomId = gdata.getBigRoomId(roomId) condConf = matchCondConf.get(str(bigRoomId)) if ftlog.is_debug(): ftlog.debug('dizhumatchcond.checkMatchSigninCond roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'bigRoomId=', bigRoomId, 'condConf=', condConf, 'matchCondConf=', matchCondConf) if condConf: clientId = sessiondata.getClientId(userId) timestamp = pktimestamp.getCurrentTimestamp() cond = MatchCondition().decodeFromDict(condConf) if not cond.check(DIZHU_GAMEID, userId, clientId, timestamp): return False, cond return True, None
def start(self, roomId, tableId, isMatch=False): gameId = 0 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == roomId: gameId = strutil.getGameIdFromBigRoomId(bigRoomId) else: gameId, _, _, _ = strutil.parseInstanceRoomId(roomId) self.gameId = gameId self.roomId = roomId self.tableId = tableId ftlog.info('robot start', self.snsId, self.roomId, self.tableId, caller=self) self._isMatch = isMatch self._start() try: self._doLogin() if self.isbusy == 0: # 已经关闭 return self._doConnTcp() if self.isbusy == 0: # 已经关闭 return except: ftlog.error('robot start error %s %s %s' % (self.snsId, roomId, tableId)) self.stop()
def convertToBigRoomId(cls, roomId): ''' 可以将房间ID转为配置中的房间ID :param roomId 配置中的ID,如:60151000 :return 例如将60151000=>6015 ''' return gdata.getBigRoomId(roomId)
def getMatchRoomStartTime(roomId, roomInfoMap): bigRoomId = gdata.getBigRoomId(roomId) roomInfo = roomInfoMap.get(bigRoomId) if bigRoomId else roomInfoMap.get( roomId) if roomInfo.startTime: return roomInfo.startTime else: return roomInfo.signinTime if roomInfo.signinTime else 0
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): ''' 拦截父类处理的选择房间逻辑,先于父类处理,若选择成功,则不进行父类的选择房间处理逻辑,否则正常走父类的处理逻辑 ''' if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) ftlog.debug( 'DizhuQuickStartV4_0.onCmdQuickStart:old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts( lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId ftlog.debug( 'DizhuQuickStartV4_0.onCmdQuickStartold client, reset roomId, tableId->', roomId, tableId, caller=cls) _, version, _ = strutil.parseClientId(clientId) ftlog.debug("DizhuQuickStartV4_0.onCmdQuickStart: clientId=", clientId, "userId=", userId, "roomId=", roomId, "tableId=", tableId, "version=", version, "type:", type(version), "playMode=", playMode) # 地主会优先去匹配比赛的房间,客户端是3.76及更高版本才支持 if (playMode == None or playMode == "match" or playMode == "straightMatch") and roomId == 0 and gameId == 6 and ( version >= 3.76 or (version >= 3.73 and not (clientId in _DIZHU_QMATCH_V3_73_IGNORE))): chose_roomid, ok = cls._chooseDizhuMatchRoom( userId, gameId, playMode) ftlog.debug( "DizhuQuickStartV4_0._chooseDizhuMatchRoom:chosen|room_id=", chose_roomid, "userId=", userId, "ok=", ok) if ok: bigroomid = gdata.getBigRoomId(chose_roomid) ftlog.debug( "DizhuQuickStartV4_0._chooseDizhuMatchRoom: userId=", userId, "roomId=", chose_roomid) cls.notifyQuickGotoDizhuMatch(gameId, userId, bigroomid) return if playMode == "match": playMode = dizhuconf.PLAYMODE_123 super(DizhuQuickStartV4_0, cls).onCmdQuickStart(msg, userId, gameId, roomId, tableId, playMode, clientId) return
def onCmdQuickStart1(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): ''' 拦截父类处理的选择房间逻辑,先于父类处理,若选择成功,则不进行父类的选择房间处理逻辑,否则正常走父类的处理逻辑 ''' if not pokerconf.isOpenMoreTable(clientId): ok, loc = cls.checkUserLoc(userId, gameId, roomId, tableId, clientId) if not ok: # 弹框 tipsPlaying = dizhuconf.getPublicConf('tips.playing', '您正在其它房间对局,是否回去?') showInfo = TodoTaskShowInfo(tipsPlaying) showInfo.setSubCmd( TodoTaskQuickStart(loc[0], loc[1], loc[2], loc[3])) TodoTaskHelper.sendTodoTask(gameId, userId, showInfo) ftlog.debug('DizhuQuickStartV4_0.onCmdQuickStart Fail userId=', userId, 'roomId=', roomId, 'tableId=', tableId, 'clientId=', clientId, 'loc=', loc) return if loc: tableId = loc[2] _, version, _ = strutil.parseClientId(clientId) ftlog.debug("DizhuQuickStartV4_0.onCmdQuickStart: clientId=", clientId, "userId=", userId, "roomId=", roomId, "tableId=", tableId, "version=", version, "type:", type(version), "playMode=", playMode) # 地主会优先去匹配比赛的房间,客户端是3.76及更高版本才支持 if (playMode == None or playMode == "match" or playMode == "straightMatch") and roomId == 0 and gameId == 6 and ( version >= 3.76 or (version >= 3.73 and not (clientId in _DIZHU_QMATCH_V3_73_IGNORE))): chose_roomid, ok = cls._chooseDizhuMatchRoom( userId, gameId, playMode) ftlog.debug( "DizhuQuickStartV4_0._chooseDizhuMatchRoom:chosen|room_id=", chose_roomid, "userId=", userId, "ok=", ok) if ok: bigroomid = gdata.getBigRoomId(chose_roomid) ftlog.debug( "DizhuQuickStartV4_0._chooseDizhuMatchRoom: userId=", userId, "roomId=", chose_roomid) cls.notifyQuickGotoDizhuMatch(gameId, userId, bigroomid) return if playMode == "match": playMode = dizhuconf.PLAYMODE_123 super(DizhuQuickStartV4_0, cls).onCmdQuickStart(msg, userId, gameId, roomId, tableId, playMode, clientId) return
def getMatchConditionDesc(cls, roomId, userId): matchCondConf = configure.getGameJson(DIZHU_GAMEID, 'bigmatch.filter', {}) if not matchCondConf: if ftlog.is_debug(): ftlog.debug('bigmatch EmptyMatchCondConf roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) return None else: ftlog.debug('bigmatch EmptyMatchCondConf roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) bigRoomId = gdata.getBigRoomId(roomId) condConf = matchCondConf.get(str(bigRoomId)) if not condConf: if ftlog.is_debug(): ftlog.debug('bigmatch roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'bigRoomId=', bigRoomId, 'condConf=', condConf, 'matchCondConf=', matchCondConf) return None else: ftlog.debug('bigmatch EmptyMatchCondConf roomId=', roomId, 'bigRoomId=', bigRoomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) condition = condConf.get('condition') if not condition: if ftlog.is_debug(): ftlog.debug('bigmatch EmptyMatchCondConf.condition roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) return None desc = condition.get('desc') if not desc: if ftlog.is_debug(): ftlog.debug('bigmatch EmptyMatchCondConf.condition.desc roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) return None from sre_compile import isstring if not isstring(desc): if ftlog.is_debug(): ftlog.debug('bigmatch EmptyMatchCondConf.condition.desc roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'matchCondConf=', matchCondConf) return None return desc
def getOnlineLoc(userId, gameId, roomId=0, tableId=0, locList=None): if not locList: locList = onlinedata.getOnlineLocList(userId) for onlineLoc in locList: if gameId != strutil.getGameIdFromInstanceRoomId(onlineLoc[0]): continue if roomId == 0: return onlineLoc if gdata.getBigRoomId(onlineLoc[0]) == gdata.getBigRoomId(roomId): if tableId == 0: return onlineLoc if onlineLoc[1] == tableId: return onlineLoc return [0, 0, 0]
def getOnlineLoc(userId, gameId, roomId=0, tableId=0, locList=None): if not locList: locList = onlinedata.getOnlineLocList(userId) for onlineLoc in locList: if gameId != strutil.getGameIdFromInstanceRoomId(onlineLoc[0]): continue if roomId == 0: return onlineLoc if gdata.getBigRoomId(onlineLoc[0]) == gdata.getBigRoomId(roomId): if tableId == 0: return onlineLoc if onlineLoc[1] == tableId: return onlineLoc return [0, 0, 0]
def _sendChargeLeadTodoTask(cls, userId, roomId, clientId, mixId): bigRoomId = gdata.getBigRoomId(roomId) ctrRoomId = bigRoomId * 10000 + 1000 roomConfig = gdata.roomIdDefineMap()[ctrRoomId].configure mixConfRoomId = cls.getMixConf(roomConfig, mixId).get('roomId', 0) if roomConfig.get('isMix', 0) and mixConfRoomId: roomId = mixConfRoomId product, _ = hallproductselector.selectLessbuyProduct(DIZHU_GAMEID, userId, clientId, roomId) t = TodoTaskPayOrder(product) msg = TodoTaskHelper.makeTodoTaskMsg(DIZHU_GAMEID, userId, t) router.sendToUser(msg, userId)
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) if ftlog.is_debug(): ftlog.debug('DizhuQuickStart old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: if ftlog.is_debug(): ftlog.debug('DizhuQuickStart _quickStart re-connected |userId, loc:', userId, loc, '|roomId, tableId:', roomId, tableId, caller=cls) roomId = lroomId tableId = ltableId msg.setParam('isReConnected', True) if ftlog.is_debug(): ftlog.debug('DizhuQuickStart old client, reset roomId, tableId->', roomId, tableId, caller=cls) if not tableId and game.isShutDown(): cls._sendTodoTaskToUser(userId, ENTER_ROOM_REASON_GAME_SHUTDOWN_GO) return # 带有roomId if roomId: cls._quickStart(msg, userId, gameId, roomId, tableId, playMode, clientId) return # 不带 roomId 服务器来选择房间 ctrlRoomIds, mixRoomReversed = cls._getQuickStartRoomList(userId, playMode, rankId=msg.getParam('rankId', '-1')) # 快开列表 chose_roomid, ok, mixId = cls._chooseRoom(userId, ctrlRoomIds, rankId=msg.getParam('rankId', '-1'), mixRoomReversed=mixRoomReversed) # 选择一个 if ok == ENTER_ROOM_REASON_OK: bigroomid = gdata.getBigRoomId(chose_roomid) ismatch = gdata.roomIdDefineMap()[chose_roomid].configure.get('ismatch', 0) if ftlog.is_debug(): ftlog.debug("DizhuQuickStart._chooseRoom: userId=", userId, "roomId=", chose_roomid, 'mixId=', mixId) if ismatch: cls.notifyQuickGotoDizhuMatch(gameId, userId, bigroomid, mixId=mixId) else: msg.setParam('mixId', mixId) ctrRoomIds = gdata.bigRoomidsMap()[bigroomid] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求发给 GR elif ok == ENTER_ROOM_REASON_QUIT_ROOM_ERROR: cls._sendTodoTaskToUser(userId, ok) elif (ok == ENTER_ROOM_REASON_LESS_MIN or ok == ENTER_ROOM_REASON_LESS_MIN_QUICKSTART) and msg.getParam('rankId', '-1') in ['0', '1']: cls._sendTodoTaskBuyChip(userId, chose_roomid, clientId, mixId) elif ok == ENTER_ROOM_REASON_LESS_MIN_QUICKSTART: cls._sendTodoTaskBuyChip(userId, chose_roomid, clientId, mixId) else: cls._sendTodoTaskJumpHighRoom(userId, playMode, clientId, rankId='-1') return
def onWinlose(cls, event): needSendLed = cls.needSendLed(event) if ftlog.is_debug(): ftlog.debug('XingyaoLed.onWinlose gameId=', event.gameId, 'userId=', event.userId, 'roomId=', event.roomId, 'bigRoomId=', gdata.getBigRoomId(event.roomId), 'isWin=', event.winlose.isWin, 'deltaChip=', event.winlose.deltaChip, 'WINCHIP_LIMIT=', cls.WINCHIP_LIMIT, 'ROOM_IDS=', cls.ROOM_IDS, 'needSendLed=', needSendLed) if needSendLed: userName = userdata.getAttr(event.userId, 'name') dizhuled.sendLed('恭喜%s在经典星耀大师场赢取金币%s!' % (userName, event.winlose.deltaChip))
def loadAllRoomInfo(gameId): ret = {} roomInfoMap = roominfo.loadAllRoomInfo(gameId) for roomId, roomInfo in roomInfoMap.iteritems(): bigRoomId = gdata.getBigRoomId(roomId) if not bigRoomId: continue bigRoomInfo = ret.get(bigRoomId) if bigRoomInfo: bigRoomInfo.signinCount += max(0, roomInfo.signinCount) bigRoomInfo.playerCount += max(0, roomInfo.playerCount) else: roomInfo.roomId = bigRoomId ret[bigRoomId] = roomInfo return ret
def checkMatchRank(cls, userId, matchId, rank): matchId = gdata.getBigRoomId(matchId) lottery_conf = dizhuconf.getMatchLotteryConf() lottery_switch = lottery_conf.get('open') if not lottery_switch: return False # 钻石数量为0触发 user_diamond = userdata.getAttrInt(userId, 'diamond') if user_diamond != 0: return False # 身上没有任何报名券 触发 discount_conf = lottery_conf.get('discountItem', []) if not discount_conf: return False for discountItem in discount_conf: itemId = discountItem.get('itemId') userHaveAssetsCount = UserBag.getAssetsCount(userId, itemId) if userHaveAssetsCount != 0: return False match_conf = lottery_conf.get('matchList', {}).get(str(matchId), []) if not match_conf: return False for conf in match_conf: beginRank = conf['beginRank'] endRank = conf['endRank'] if beginRank <= rank <= endRank: if ftlog.is_debug(): ftlog.debug('checkMatchRank userId=', userId, 'matchId=', matchId, 'return True') return True # 若是客户端请求则需要验证排名信息 # histories = MatchHistoryHandler.getMatchHistory(userId, recordId, 1, mixId) # for history in histories: # recordRank = history.get('rank') # if rank != recordRank: # return False # timestamp = history.get('timestamp') # currtimestamp = pktimestamp.getCurrentTimestamp() # if (currtimestamp - timestamp) > 300: # return False if ftlog.is_debug(): ftlog.debug('checkMatchRank userId=', userId, 'matchId=', matchId, 'return False') return False
def handle_event(self, event): if not self.act.checkOperative(): return if not isinstance(event, GameOverEvent): return if self.play_result is not None and self.play_result != event.gameResult: return # 历史原因,很多插件都写成9999了,尽量纠正一把 gameid = event.gameId if event.gameId != HALL_GAMEID else strutil.getGameIdFromHallClientId(event.clientId) if gameid != self.gameid: return bigroom = gdata.getBigRoomId(event.roomId) credit = self.room2credit.get(str(bigroom), 0) if credit <= 0: return self._add_credit(event.userId, credit, event.roundNum)
def _sendTodoTaskBuyChip(cls, userId, roomId, clientId, mixId): if ftlog.is_debug(): ftlog.debug('DizhuQuickStart._sendTodoTaskBuyChip', 'userId=', userId, 'roomId=', roomId, 'clientId=', clientId, 'mixId=', mixId) bigRoomId = gdata.getBigRoomId(roomId) ctrRoomId = bigRoomId * 10000 + 1000 roomConfig = gdata.roomIdDefineMap()[ctrRoomId].configure mixConfRoomId = cls.getMixConf(roomConfig, mixId).get('roomId', 0) if roomConfig.get('isMix', 0) and mixConfRoomId: roomId = mixConfRoomId todotask = hallpopwnd.makeTodoTaskLessbuyChip(DIZHU_GAMEID, userId, clientId, roomId, minCoin=cls.getMixConf(roomConfig, mixId).get('minCoin', None)) if todotask: TodoTaskHelper.sendTodoTask(DIZHU_GAMEID, userId, todotask)
def getMatchRewardSplitWord(self, roomId): ret = "以下是分组阶段未晋级名次奖励" splitConf = configure.getGameJson(DIZHU_GAMEID, 'room.split', {}) if not splitConf: return ret bigRoomId = gdata.getBigRoomId(roomId) roomConf = splitConf.get(str(bigRoomId)) if not roomConf: roomConf = splitConf.get('default') if not roomConf: return ret word = roomConf.get('splitWord') if not word or not isstring(word): return ret ret = word return ret
def getUserChampionLimitFlag(userId, roomId, recordId, mixId=None): ''' 获取用户获取冠军的限制标记 ''' matchChampionConf = configure.getGameJson(DIZHU_GAMEID, 'match.champion.limit', {}) if not matchChampionConf: return False bigRoomId = gdata.getBigRoomId(roomId) limitConf = matchChampionConf.get(str(mixId or bigRoomId), {}) if limitConf.get('open', 0) == 0: return False playCountLimit = limitConf.get('playCountLimit', 20) playHoursLimit = limitConf.get('playHoursLimit', 48) # 获取最近40局的信息 currentTimeStamp = pktimestamp.getCurrentTimestamp() playCount = 0 histories = MatchHistoryHandler.getMatchHistory(userId, recordId, 40, mixId) if ftlog.is_debug(): ftlog.debug('Matchutil.getUserChampionLimitSign userId=', userId, 'roomId=', roomId, 'mixId=', mixId, 'playCountLimit=', playCountLimit, 'playHoursLimit=', playHoursLimit, 'histories=', histories) for history in histories: playCount += 1 rank = history.get('rank') if rank not in [1, 2, 3]: continue timestamp = history.get('timestamp') hourDelta = int((currentTimeStamp - timestamp) / 3600) # 与配置相比较,局数以且时间 if ftlog.is_debug(): ftlog.debug('Matchutil.getUserChampionLimitSign userId=', userId, 'roomId=', roomId, 'mixId=', mixId, 'playCount=', playCount, 'hourDelta=', hourDelta, 'playCountLimit=', playCountLimit, 'playHoursLimit=', playHoursLimit) if playCount <= playCountLimit and hourDelta <= playHoursLimit: return True return False return False
def handle_event(self, event): if not self.act.checkOperative(): return if not isinstance(event, GameOverEvent): return if self.play_result is not None and self.play_result != event.gameResult: return # 历史原因,很多插件都写成9999了,尽量纠正一把 gameid = event.gameId if event.gameId != HALL_GAMEID else strutil.getGameIdFromHallClientId( event.clientId) if gameid != self.gameid: return bigroom = gdata.getBigRoomId(event.roomId) credit = self.room2credit.get(str(bigroom), 0) if credit <= 0: return self._add_credit(event.userId, credit, event.roundNum)
def _fillUpdateUserScore(event): from poker.entity.dao import gamedata winStreak = gamedata.getGameAttrInt(event.userId, DIZHU_GAMEID, 'winstreak') bigRoomId = gdata.getBigRoomId(event.roomId) if not _scoreRankConf: return False if ftlog.is_debug(): ftlog.debug('_fillUpdateUserScore userId=', event.userId, 'bigRoomId=', bigRoomId, '_scoreRankConf=', _scoreRankConf, 'closed=', _scoreRankConf.closed) if _scoreRankConf.closed: return False clientVer = SessionDizhuVersion.getVersionNumber(event.userId) if clientVer < _scoreRankConf.minVer: if ftlog.is_debug(): ftlog.debug('_fillUpdateUserScore version too low. userId=', event.userId, 'clientVer=', clientVer, 'minVer=', _scoreRankConf.minVer) return False if ftlog.is_debug(): ftlog.debug('_fillUpdateUserScore userId=', event.userId, 'clientVer=', clientVer) rankingDefine = _scoreRankConf.rankDefineForRoomId(bigRoomId) if not rankingDefine: if ftlog.is_debug(): ftlog.debug('_fillUpdateUserScore NoRankingForRoom userId=', event.userId, 'roomId=', event.roomId, 'chipDelta=', event.winlose.deltaChip, 'winStreak=', winStreak) return False timestamp = pktimestamp.getCurrentTimestamp() if rankingDefine.isOutOfTime(timestamp): if ftlog.is_debug(): ftlog.debug('_fillUpdateUserScore outOfTime userId=', event.userId, 'roomId=', event.roomId, 'curTimeStamp=', timestamp) return False updateUserScore(event.userId, bigRoomId, event.winlose.deltaChip, winStreak)
def getMatchConditionDesc(self, roomId, userId): matchCondConf = configure.getGameJson(DIZHU_GAMEID, 'bigmatch.filter', {}) if not matchCondConf: if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch.getMatchConditionDesc EmptyMatchCondConf', 'roomId=', roomId, 'userId=', userId, 'matchCondConf=', matchCondConf) return None bigRoomId = gdata.getBigRoomId(roomId) condConf = matchCondConf.get(str(bigRoomId)) if not condConf: if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch.getMatchConditionDesc EmptyCondConf', 'roomId=', roomId, 'gameId=', DIZHU_GAMEID, 'userId=', userId, 'bigRoomId=', bigRoomId, 'condConf=', condConf, 'matchCondConf=', matchCondConf) return None else: if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch.getMatchConditionDesc', 'roomId=', roomId, 'userId=', userId, 'matchCondConf=', matchCondConf) condition = condConf.get('condition') if not condition: if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch.getMatchConditionDesc EmptyCond', 'roomId=', roomId, 'userId=', userId, 'matchCondConf=', matchCondConf) return None desc = condition.get('desc') if not desc or not isstring(desc): if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch.getMatchConditionDesc EmptyMatchCondConf.condition.desc', 'roomId=', roomId, 'userId=', userId, 'matchCondConf=', matchCondConf) return None return desc
def getMatchLotteryConf(self, roomId, rank): lottery_conf = dizhuconf.getMatchLotteryConf() self.decodeFromDict(lottery_conf) bigRoomId = gdata.getBigRoomId(roomId) discount_conf = lottery_conf.get('matchList') room_discount_conf = discount_conf.get(str(bigRoomId)) if discount_conf else None if room_discount_conf: for conf in room_discount_conf: beginRank = conf.get('beginRank') endRank = conf.get('endRank') items = conf.get('items') if beginRank <= rank <= endRank: if ftlog.is_debug(): ftlog.debug('getMatchLotteryConf. roomId=', roomId, 'rank=', rank, 'items=', items, 'room_discount_conf=', room_discount_conf) return items return None
def getRoomInfo(cls, roomId): ''' 获得大房间信息 :param roomId:要获得的房间号,大房间号 :return: {'signinCount': 0, "playerCount": 0} ''' allroominfo = loadAllRoomInfo(6) allrooms = {} for id in allroominfo: subroom = allroominfo.get(id) bigroomId = gdata.getBigRoomId(id) room = allrooms.get(bigroomId, { 'signinCount': 0, "playerCount": 0 }) room['signinCount'] += subroom.signinCount or 0 room['playerCount'] += subroom.playerCount or 0 allrooms[bigroomId] = room return allrooms.get(roomId)
def _canQuickStartDizhuMatch(cls, userId, gameId, roomId, playMode): ''' 检测比赛房间是否符合快开条件 @return ok{Bool} 是否满足条件进入地主比赛 ''' roomconf = gdata.roomIdDefineMap()[roomId].configure bigRoomId = gdata.getBigRoomId(roomId) ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] reason = cls._canQuickEnterMatchRoom(userId, gameId, ctrlRoomId, 1) ftlog.debug( "DizhuQuickStartV4_0._canQuickStartDizhuMatch: roomCond|userId=", userId, "roomId=", roomId, "bigRoomId=", bigRoomId, "ctrlRoomId=", ctrlRoomId, "reason=", reason) if reason != TYRoom.ENTER_ROOM_REASON_OK: return False # 若不存在开关,或者开关为0,代表房间关闭比赛快开 quickMatchToggle = roomconf.get("quickMatchToggle", 0) ftlog.debug("DizhuQuickStartV4_0._canQuickStartDizhuMatch: userId=", userId, "roomId=", roomId, "quickMatchToggle=", quickMatchToggle) if quickMatchToggle == 0: return False # 获取选择比赛快开的条件列表 coin_toplimit = roomconf.get("quickMatchCoinTopLimit", 0) # 获得用户的coin chip = userchip.getChip(userId) ftlog.debug("DizhuQuickStartV4_0._canQuickStartDizhuMatch: userId=", userId, "roomId=", roomId, "chip=", chip, "coin_toplimit", coin_toplimit) # 直接去比赛,不判断金币 if playMode == dizhuconf.PLAYMODE_STRAIGHT_MATCH: return True if chip < coin_toplimit: return True return False
def buildTableInfoResp(self, seat, isRobot): mp = DizhuTableProtoCommonBase.buildTableInfoResp(self, seat, isRobot) winstreak = {} playerTask = self.room.winStreakTask.getPlayerTask(seat.player) cur = playerTask.progress if playerTask else 0 if cur >= len(self.room.winStreakTask.taskList): cur = 0 winstreak['cur'] = cur winstreak['maxWinStreak'] = playerTask.maxWinStreak if playerTask else 0 rewards = [] for task in self.room.winStreakTask.taskList: rewards.append(task.reward) winstreak['rewards'] = rewards winstreak['imgs'] = self.room.winStreakTask.taskPictures mp.setResult('winstreak', winstreak) # 房间属于哪个积分榜 scoreRankingConf = dizhu_score_ranking.getConf() bigRoomId = gdata.getBigRoomId(self.roomId) rankDef = scoreRankingConf.rankDefineForRoomId(bigRoomId) if not scoreRankingConf.closed and rankDef and rankDef.switch == 1: mp.setResult('scoreboardFlag', rankDef.rankId) taskInfo = task_remote.getNewbieTaskInfo(DIZHU_GAMEID, seat.userId, seat.player.playShare.totalCount) if taskInfo is not None: mp.setResult('newertask', taskInfo) winSteakBuff, loseStreakBuff = dizhu_giftbag.checkUserGiftBuff(seat.player.userId) if winSteakBuff: mp.setResult('buff', 'winSteakBuff') elif loseStreakBuff: mp.setResult('buff', 'loseStreakBuff') dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(seat.userId, DIZHU_GAMEID) mp.setResult('dailyPlay', dailyPlayCount) if ftlog.is_debug(): ftlog.debug('normalbase.tableproto.buildTableInfoResp.checkUserGiftBuff', 'bigRoomId=', bigRoomId, 'winSteakBuff=', winSteakBuff, 'loseStreakBuff=', loseStreakBuff, 'mp=', mp) return mp
def _processUserPlayCount(event): """ 增加玩次数 """ if ftlog.is_debug(): ftlog.debug('dizhu_red_envelope_bomb._processUserPlayCount', 'mixConfRoomId=', event.mixConfRoomId, 'userId=', event.userId, 'roomId=', event.roomId, 'tableId=', event.tableId) bigRoomId = int( event.mixConfRoomId) if event.mixConfRoomId else gdata.getBigRoomId( event.roomId) if not _redEnvelopeBomb.isActive(bigRoomId, pktimestamp.getCurrentTimestamp()): return version = SessionDizhuVersion.getVersionNumber(event.userId) if version < _redEnvelopeBomb.conf.minVersion: return increaseUserPlayCount(_redEnvelopeBomb.conf.issueNum, event.userId, bigRoomId, pktimestamp.getCurrentTimestamp())
def _checkSaveCoinTableGameRound(table, result): mixRoomId = _getMixRoomId(table, result) bigRoomId = mixRoomId or gdata.getBigRoomId(table.roomId) info = getReplayMatchs().get(bigRoomId) if ftlog.is_debug(): ftlog.debug('obsystem._checkSaveCoinTableGameRound', 'roomId=', table.roomId, 'bigRoomId=', bigRoomId, 'info=', info) condition = info.get('condiction') if info else None if condition: totalMulti = condition.get('totalMulti') chuntian = condition.get('chuntian') isSlam = condition.get('slam') stageName = info.get('stageName', '') if ftlog.is_debug(): ftlog.debug('obsystem._checkSaveCoinTableGameRound condiction=', condition, 'multi=', totalMulti, 'result.multi=', result.baseScore, 'dizhu.mulit=', result.dizhuStatement.seat.status.totalMulti, 'chuntian=', chuntian, 'result.chuntian=', result.isChuntian, 'isSlam=', isSlam, 'result.winslam=', result.slam, 'userId=', result.dizhuStatement.seat.userId if result.dizhuStatement else 'gameAbort') if not result.dizhuStatement: # 流局不保存 return False, 0, '' if isSlam and not result.slam: return False, 0, '' if chuntian and not result.isChuntian: return False, 0, '' if totalMulti and totalMulti > result.dizhuStatement.seat.status.totalMulti: return False, 0, '' _onMatchingStart(bigRoomId, str(table.tableId) + str(result.dizhuStatement.seat.userId)) return True, result.dizhuStatement.seat.userId, stageName return False, 0, ''
def _handleEnterRoomException(cls, e, userId, gameId, roomId, mixId=None): ''' 进入房间失败处理函数 ''' if isinstance(e, (EnterRoomLessMinKickOutCoinException, EnterRoomLessMinCoinException, EnterRoomLessMinQuickStartCoinException)): #@TODO 要删掉 dizhuVersion = SessionDizhuVersion.getVersionNumber(userId) if not dizhuVersion or dizhuVersion < 5.08: desc = '金币不足' note = '金币不足' todotask = TodoTaskLessBuyOrder(desc, None, note, None) TodoTaskHelper.sendTodoTask(gameId, userId, todotask) bigRoomId = gdata.getBigRoomId(roomId) clientId = sessiondata.getClientId(userId) if roomId != bigRoomId: # 点继续 ctrlRoomId = gdata.roomIdDefineMap()[roomId].parentId or roomId queryRoomId = ctrlRoomId else: queryRoomId = cls._getQueryRoomId(userId, bigRoomId) roomConfig = cls._getRoomConfigure(queryRoomId, mixId) if roomConfig.get('kickOutBurialId'): shareLeftCount = getShareLeftCountByBurialId(gameId, userId, clientId, roomConfig.get('kickOutBurialId')) sharePoint = getSharePointByBurialId(gameId, userId, clientId, roomConfig.get('kickOutBurialId')) if shareLeftCount: items = sharePoint.reward.content.getItems() if sharePoint.reward else [] cls._sendToUserQuickStartRes(userId, gameId, roomId, e.errorCode, e.message, burialId=roomConfig.get('kickOutBurialId'), reward=hallitem.buildItemInfoList(items)) return if isinstance(e, EnterRoomLessMinKickOutCoinException): todoTask = makeTodoTaskluckBuyOrLessBuyChip(gameId, userId, clientId, roomConfig.get('roomId') or bigRoomId, minCoin=roomConfig.get('minCoin')) else: todoTask = makeTodoTaskluckBuyOrLessBuyChip(gameId, userId, clientId, roomConfig.get('roomId') or bigRoomId, minCoin=roomConfig.get('minCoin'), priority='lessbuychip') if todoTask: cls._sendToUserQuickStartRes(userId, gameId, roomId, e.errorCode, e.message, todoTask=todoTask.toDict()) return # @TODO 要删掉 dizhuVersion = SessionDizhuVersion.getVersionNumber(userId) if not dizhuVersion or dizhuVersion < 5.08: todotask = TodoTaskShowInfo(e.message) TodoTaskHelper.sendTodoTask(gameId, userId, todotask) cls._sendToUserQuickStartRes(userId, gameId, roomId, e.errorCode, e.message)
def start(self, roomId, tableId, isMatch=False): gameId = 0 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == roomId: gameId = strutil.getGameIdFromBigRoomId(bigRoomId) else: gameId, _, _, _ = strutil.parseInstanceRoomId(roomId) self.gameId = gameId self.roomId = roomId self.tableId = tableId ftlog.info('robot start', self.snsId, self.roomId, self.tableId, caller=self) self._isMatch = isMatch self._start() try: self._doLogin() if self.isbusy == 0: # 已经关闭 return self._doConnTcp() if self.isbusy == 0: # 已经关闭 return except: ftlog.error('robot start error %s %s %s' % (self.snsId, roomId, tableId)) self.stop()
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 if ftlog.is_debug(): ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) if ftlog.is_debug(): ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: ftlog.debug('onCmdQuickStart re-connected |userId, loc:', userId, loc, '|roomId, tableId:', roomId, tableId, caller=cls) roomId = lroomId tableId = ltableId msg.setParam('isReConnected', True) if ftlog.is_debug(): ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom(userId, gameId, playMode) ftlog.debug("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return bigRoomId = gdata.getBigRoomId(roomId) ftlog.debug('bigRoomId:', bigRoomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if strutil.getGameIdFromBigRoomId(bigRoomId) != gameId: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 if gameId == 6 and roomId != bigRoomId: ctrlRoomId = gdata.roomIdDefineMap()[roomId].parentId queryRoomId = roomId else: ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] queryRoomId = ctrlRoomId reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: if gameId == 6: TYRoomMixin.queryRoomQuickStartReq(msg, queryRoomId, 0) # 请求转给GR或GT else: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT elif reason == TYRoom.ENTER_ROOM_REASON_LESS_MIN or reason == TYRoom.ENTER_ROOM_REASON_GREATER_MAX: if gameId == 6: innerTable = msg.getParam("innerTable", 0) # innerTable 区分不同版本弹窗 if innerTable == 1: roomDef = gdata.roomIdDefineMap()[ctrlRoomId] playMode = roomDef.configure.get('playMode', None) if ftlog.is_debug(): ftlog.debug('enter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode) msgpack = MsgPack() msgpack.setCmd("quick_start") msgpack.setParam("userId", userId) msgpack.setParam("gameId", gameId) msgpack.setParam("clientId", clientId) msgpack.setParam("innerTable", 1) msgpack.setParam("apiver", msg.getParam("apiver", 3.7)) cls.onCmdQuickStart(msgpack, userId, gameId, 0, 0, playMode, clientId) if ftlog.is_debug(): ftlog.debug('reenter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msgpack=', msgpack.pack()) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: if onlineSeat == gdata.roomIdDefineMap()[roomId].configure['tableConf']['maxSeatN'] + 1: # 牌桌里旁观的玩家断线重连,请求转给GT TYRoomMixin.sendTableCallObserveReq(userId, roomId, tableId, clientId) else: # 牌桌里坐着的玩家断线重连,请求转给GT # TYRoomMixin.querySitReq(userId, roomId, tableId, clientId) # GT人多时会有超时异常 TYRoomMixin.sendSitReq(userId, roomId, tableId, clientId) else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) isReconnect = False # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId isReconnect = True ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if (not isReconnect) and roomId > 0 and tableId > 0: reason = cls._canQuickEnterRoom(userId, gameId, roomId, 1) if reason != TYRoom.ENTER_ROOM_REASON_OK: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom(userId, gameId, playMode) ftlog.info("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: # 找到合适的房间 根据roomId找到合适的table TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, gameId, clientId, roomId) return ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT else: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: extParam = {} extParam['seatId'] = onlineSeat moParams = msg.getKey('params') for k, v in moParams.items(): if not k in extParam: extParam[k] = v ftlog.debug('extParam=', extParam) TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, extParam) # 玩家断线重连,请求转给GT else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def handleEvent(self, event): ''' 当收到每局结束发送的event时,在activity.py中调用该方法 处理前台活动返回的配置包括客户端配置和服务器配置 ''' ftlog.debug("TYActivityPlayGamePresentGift handleEvent123:", event.role, event.roomLevel, event.roundNum, event.gameId, event.userId, event.clientId) gameId = event.gameId userId = event.userId activityId = self._clientConf.get("id") if not activityId: ftlog.debug("TYActivityPlayGamePresentGift handleEvent not find adtivityId") return if not self.checkOperative(): ftlog.debug("activity expired:", activityId) return # 对_config开始解析配置,conditions玩的局数,默认为1 for cond in self._serverConf["conditions"]: if cond == self._serverConf['accumulateField']: continue condValue = event.get(cond) if isinstance(self._serverConf[cond], list): if condValue not in self._serverConf[cond]: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, condValue not match,cond:", cond) return else: if condValue != self._serverConf[cond]: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, condValue not match,cond:", cond) return # 有效时间 if "dayTimeLimit" in self._serverConf: if not self._checkDayTime(): ftlog.debug("TYActivityPlayGamePresentGift handleEvent, dayTimeLimit not match") return # 所在房间等级 if "presentBased" in self._serverConf: presentBasedValue = event.get(self._serverConf["presentBased"]) presentBasedValue = gdata.getBigRoomId(presentBasedValue) ftlog.debug("TYActivityPlayGamePresentGift handleEvent11:", presentBasedValue) if not presentBasedValue: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, presentBasedvalue not find, presentBased:", self._serverConf["presentBased"]) return else: if (not isinstance(presentBasedValue, int)) or str(presentBasedValue) not in self._serverConf[ "presentConfig"]: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, presentBasedValue not match:", presentBasedValue) return presentNum = self._serverConf["presentConfig"][str(presentBasedValue)] else: presentNum = self._serverConf["presentNum"] # 是否可连续,1表示1天内连续、0表示可连续 accumulateType = self._serverConf["accumulateType"] # 需要领取奖励的局数 rewardNeedNum = self._serverConf["rewardNeedNum"] accumulateKey = "accumulate" hasRewardedKey = "hasRewarded" if accumulateType == 1: accumulateKey = "%s:%s" % (accumulateKey, time.strftime('%Y-%m-%d', time.localtime(time.time()))) hasRewardedKey = "%s:%s" % (hasRewardedKey, time.strftime('%Y-%m-%d', time.localtime(time.time()))) accumulateValue = event.get(self._serverConf["accumulateField"]) if not accumulateValue: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, accumulateValue not find:", self._serverConf["accumulateField"]) return mustContinuous = 0 maxInterval = 0 accumulateIdentiferValue = "noidentifer" nowTimeStamp = int(time.time()) if 'accumulateMustContinuous' in self._serverConf: if self._serverConf["accumulateMustContinuous"] == 1: mustContinuous = 1 maxInterval = self._serverConf.get("accumulateMaxInterval", 300) # 判定是否是同一房间 if "accumulateIdentifer" in self._serverConf: accumulateIdentifer = self._serverConf["accumulateIdentifer"] accumulateIdentiferValue = event.get(accumulateIdentifer) accumulateIdentiferValue = gdata.getBigRoomId(accumulateIdentiferValue) ftlog.debug("this accumulateIdentiferValue bigRoomId is", accumulateIdentiferValue) if not accumulateIdentiferValue: ftlog.debug("TYActivityPlayGamePresentGift handleEvent, accumulateIdentiferValue not find:", accumulateIdentifer) return else: ftlog.error("TYActivityPlayGamePresentGift handleEvent, accumulateIdentifer not find") return userActivityKey = "TYActivity:%d:%d:%s" % (gameId, userId, activityId) ftlog.debug("playGamePresentGift handleEvent:", presentNum, accumulateKey, accumulateValue, accumulateType, accumulateIdentiferValue, mustContinuous, maxInterval, userActivityKey, rewardNeedNum, nowTimeStamp, hasRewardedKey) ret = daobase.executeUserLua(userId, self.HANDLE_EVENT_SCRIPT, 11, presentNum, accumulateKey, accumulateValue, accumulateType, accumulateIdentiferValue, mustContinuous, maxInterval, userActivityKey, rewardNeedNum, nowTimeStamp, hasRewardedKey) ftlog.debug("TYActivityPlayGamePresentGift handleEvent, executeUserLua ret:", ret)
def selectProcutByRoomId(gameId, userId, clientId, roomId, action): levelName = hallconf.getRoomLevelName(gameId, gdata.getBigRoomId(roomId)) return selectProduct(gameId, userId, clientId, levelName, action)
def _start(self): ftlog.debug("<< |snsId:", self.snsId, caller=self) super(DiFangRobotUser, self)._start() self.bigRoomId = gdata.getBigRoomId(self.roomId) self.responseDelaySecond = 3