def _setBigRoomOnlineLoc(userId, roomId, tableId, seatId): bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) loclist = _getOnlineLocList(userId) for locs in loclist: rid, tid, _ = locs[0], locs[1], locs[2] brid = strutil.getBigRoomIdFromInstanceRoomId(rid) if ftlog.is_debug(): ftlog.debug('dbuser._setBigRoomOnlineLoc userId=', userId, 'brid=', brid, 'bigRoomId=', bigRoomId, 'tableId=', tableId, 'seatId=', seatId) if brid == bigRoomId: _removeOnlineLoc(userId, rid, tid) _addOnlineLoc(userId, roomId, tableId, seatId, False)
def lockUser(self, userId, roomId, tableId, seatId, clientId): locList = dizhuonlinedata.getOnlineLocListByGameId( userId, DIZHU_GAMEID, clientId) if locList: for loc in locList: if (strutil.getBigRoomIdFromInstanceRoomId(loc[1]) == strutil.getBigRoomIdFromInstanceRoomId(roomId)): ftlog.warn('UserLockerDizhu.lockUser', 'userId=', userId, 'roomId=', roomId, 'tableId=', tableId, 'seatId=', seatId, 'clientId=', clientId, 'loc=', loc, 'locList=', locList) return False onlinedata.setBigRoomOnlineLoc(userId, roomId, tableId, seatId) return True
def _leave(self, userId, reason, needSendRes): ftlog.hinfo("_leave << |roomId, userId, reason: ", self.roomId, userId, reason, caller=self) self._remoteTableLeave(userId, reason) locList = onlinedata.getOnlineLocList(userId) if ftlog.is_debug(): ftlog.debug("<< |roomId, userId: ", self.roomId, userId, "|locList:", locList, caller=self) for loc in locList: onlineRoomId, onlineTableId = loc[0], loc[1] if strutil.getBigRoomIdFromInstanceRoomId( onlineRoomId) == self.bigRoomId: return False return True
def lockUser(self, userId, roomId, tableId, seatId, clientId): locList = dizhuonlinedata.getOnlineLocListByGameId( userId, DIZHU_GAMEID, clientId) if locList: for loc in locList: if (strutil.getBigRoomIdFromInstanceRoomId(loc[1]) != strutil.getBigRoomIdFromInstanceRoomId(roomId)): ftlog.warn('UserLockerDizhu.lockUser', 'userId=', userId, 'roomId=', roomId, 'tableId=', tableId, 'seatId=', seatId, 'clientId=', clientId, 'loc=', loc, 'locList=', locList) return False room = gdata.rooms()[roomId] player = room.match.findPlayer(userId) if not player or not player.isQuit: onlinedata.setBigRoomOnlineLoc(userId, roomId, tableId, seatId) return True
def lockUserForMatch(gameId, userId, bigRoomId, instId, ctrlRoomId, tableId, seatId, clientId): if ftlog.is_debug(): ftlog.debug('match_remote.lockUserForMatch gameId=', gameId, 'userId=', userId, 'bigRoomId=', bigRoomId, 'instId=', instId, 'ctrlRoomId=', ctrlRoomId, 'tableId=', tableId, 'seatId=', seatId, 'clientId=', clientId) if not clientId: clientId = sessiondata.getClientId(userId) locList = dizhuonlinedata.getOnlineLocListByGameId(userId, gameId, clientId) if locList: # 检查loc loc = locList[0] if strutil.getBigRoomIdFromInstanceRoomId(loc[1]) != bigRoomId: ftlog.debug('match_remote.lockUserForMatch Fail gameId=', gameId, 'userId=', userId, 'bigRoomId=', bigRoomId, 'instId=', instId, 'ctrlRoomId=', ctrlRoomId, 'tableId=', tableId, 'seatId=', seatId, 'clientId=', clientId, 'loc=', loc) return False userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId) if not userMatchInfo: # 此处有异常,正常要有userMatchInfo userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId) userMatchInfo.ctrlRoomId = ctrlRoomId userMatchInfo.instId = instId userMatchInfo.state = UserMatchInfo.ST_SIGNIN userMatchInfo.ctrlRoomId = ctrlRoomId userMatchInfo.state = UserMatchInfo.ST_PLAYING saveUserMatchInfo(userMatchInfo) room = gdata.rooms()[ctrlRoomId] player = room.match.findPlayer(userId) if not player or not player.isQuit: onlinedata.setBigRoomOnlineLoc(userId, ctrlRoomId, tableId, seatId) ftlog.info('match_remote.lockUserForMatch ok gameId=', gameId, 'userId=', userId, 'bigRoomId=', bigRoomId, 'instId=', instId, 'ctrlRoomId=', ctrlRoomId, 'tableId=', tableId, 'seatId=', seatId, 'isQuit=', player.isQuit if player else -1, 'clientId=', clientId) return True
def lockUserForMatch(gameId, userId, bigRoomId, instId, ctrlRoomId, tableId, seatId, clientId): if ftlog.is_debug(): ftlog.debug("match_remote.lockUserForMatch gameId=", gameId, "userId=", userId, "bigRoomId=", bigRoomId, "instId=", instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId, "seatId=", seatId, "clientId=", clientId) if not clientId: clientId = sessiondata.getClientId(userId) loc = None locList = onlinedata.getOnlineLocList(userId) for roomId, tableId, seatId in locList: try: roomGameId = strutil.getGameIdFromInstanceRoomId(roomId) if (roomGameId == gameId and tableId != 0 and seatId != 0): loc = [roomGameId, roomId, tableId, seatId] except: ftlog.error("match_remote.lockUserForMatch userId=", userId, "gameId=", gameId, "clientId=", clientId, "roomId=", roomId) if loc: # 检查loc if strutil.getBigRoomIdFromInstanceRoomId(loc[1]) != bigRoomId: ftlog.debug("match_remote.lockUserForMatch Fail gameId=", gameId, "userId=", userId, "bigRoomId=", bigRoomId, "instId=", instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId, "seatId=", seatId, "clientId=", clientId, "loc=", loc) return False userMatchInfo = loadUserMatchInfo(gameId, userId, bigRoomId) if not userMatchInfo: # 此处有异常,正常要有userMatchInfo userMatchInfo = UserMatchInfo(gameId, userId, bigRoomId) userMatchInfo.ctrlRoomId = ctrlRoomId userMatchInfo.instId = instId userMatchInfo.state = UserMatchInfo.ST_SIGNIN userMatchInfo.ctrlRoomId = ctrlRoomId userMatchInfo.state = UserMatchInfo.ST_PLAYING saveUserMatchInfo(userMatchInfo) room = gdata.rooms()[ctrlRoomId] player = room.match.findPlayer(userId) if not player or not player.isQuit: onlinedata.setBigRoomOnlineLoc(userId, ctrlRoomId, tableId, seatId) ftlog.info("match_remote.lockUserForMatch ok gameId=", gameId, "userId=", userId, "bigRoomId=", bigRoomId, "instId=", instId, "ctrlRoomId=", ctrlRoomId, "tableId=", tableId, "seatId=", seatId, "isQuit=", player.isQuit if player else -1, "clientId=", clientId) return True
def sendUserDailyPlayTimes(userId, roomId, timestamp, dailyplaytimes): try: bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) d = {'timestamp': timestamp, 'dailyplaytimes': dailyplaytimes} return daobase.executeUserCmd( userId, 'HSET', 'dailyplaytimes' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(bigRoomId), strutil.dumps(d)) except: ftlog.error('new_table_remote.sendUserDailyPlayTimes gameId=', DIZHU_GAMEID, 'userId=', userId) return None
def getUserDailyPlayTimes(userId, roomId): try: bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) ret = daobase.executeUserCmd( userId, 'HGET', 'dailyplaytimes' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(bigRoomId)) return strutil.loads(ret) if ret else None except: ftlog.error('new_table_remote.sendDailyPlayTimes gameId=', DIZHU_GAMEID, 'userId=', userId) return
def sendRoomMaxWinStreak(userId, roomId, maxWinStreak): try: bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) d = {'maxWinStreak': maxWinStreak} return daobase.executeUserCmd( userId, 'HSET', 'maxWinStreak' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(bigRoomId), strutil.dumps(d)) except: ftlog.error('new_table_remote.sendRoomMaxWinStreak gameId=', DIZHU_GAMEID, 'userId=', userId) return None
def getRoomMaxWinStreak(userId, roomId): try: bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) ret = daobase.executeUserCmd( userId, 'HGET', 'maxWinStreak' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(bigRoomId)) return strutil.loads(ret) if ret else None except: ftlog.error('new_table_remote.getRoomMaxWinStreak gameId=', DIZHU_GAMEID, 'userId=', userId) return
def _doTableWinloseUT(userId, roomId, tableId, roundNum, clientId, isWin, winStreak, winUserId, isDizhu, fee, cardNoteFee, winlose, systemPaid, winnerTax, baseScore, winDoubles, bomb, chuntian, winslam, playMode, topCardList, **kwargs): bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) treasurebox.updateTreasureBoxWin(DIZHU_GAMEID, userId, kwargs.get('mixConfRoomId') or bigRoomId) exp, deltaExp, _winrate = comm_table_remote.checkSetMedal( DIZHU_GAMEID, userId, baseScore, False, winlose) deltaItems = buildSettlementDeltaItems( kwargs.get('mixConfRoomId') or roomId, fee, cardNoteFee, winlose, winnerTax) skillScoreInfo = _caleSkillScoreByUser( userId, isWin, winStreak, isDizhu, kwargs.get('mixConfRoomId') or bigRoomId, winDoubles) skillLevelUp = skillScoreInfo.get('isLevelUp', False) _reportRoomDelta(userId, roomId, bigRoomId, clientId, systemPaid) finalTableChip = _settlement(userId, kwargs.get('mixConfRoomId') or roomId, tableId, roundNum, clientId, deltaItems) # 纪录连胜 if isWin: gamedata.incrGameAttr(userId, DIZHU_GAMEID, 'winstreak', 1) else: gamedata.setGameAttr(userId, DIZHU_GAMEID, 'winstreak', 0) if ftlog.is_debug(): winstreaklog = gamedata.getGameAttr(userId, DIZHU_GAMEID, 'winstreak') ftlog.debug('_doTableWinloseUT winstreak=', winstreaklog, 'UserID=', userId, 'roomId=', roomId, 'tableId=', tableId, 'isWin=', isWin) # 广播用户结算事件 card = cardrules.CARD_RULE_DICT[playMode] topValidCard = card.validateCards(topCardList, None) finalUserChip = userchip.getChip(userId) _publishWinLoseEvent(roomId, tableId, userId, roundNum, isWin, isDizhu, winUserId, winlose, finalTableChip, winDoubles, bomb, chuntian, winslam, clientId, topValidCard, skillLevelUp, **kwargs) # 更新排名相关数据 _calRankInfoData(userId, winlose, winslam, winDoubles) return finalTableChip, finalUserChip, [exp, deltaExp], skillScoreInfo
def addUserQuitLoc(gameId, userId, roomId, tableId, seatId, timestamp): try: bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) d = { 'timestamp': timestamp, 'roomId': roomId, 'tableId': tableId, 'seatId': seatId } return daobase.executeUserCmd( userId, 'HSET', 'quitol' + ':' + str(gameId) + ':' + str(userId), str(bigRoomId), strutil.dumps(d)) except: ftlog.error('comm_table_remote.addUserQuitLoc gameId=', gameId, 'roomId=', roomId, 'tableId=', tableId, 'seatId=', seatId, 'userId=', userId) return None
def _handleTableWinlose(self, event): # 该局结束了, 按照配置概率给参与该局的玩家发送彩蛋奖励, # 玩家也可能没有获得彩蛋奖励 userId = event.userId roomId = event.roomId tableId = event.tableId # 获取房间奖励配置 # 'reward': {'item': 'item:chip', 'count': n} --> 奖励 # 'prob': p --> 奖励万分比 bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) roomReward = self._rewardConf.get(str(bigRoomId)) if ftlog.is_debug(): ftlog.debug('SkyEggActivityRewardConfig: ', self._rewardConf, 'roomId: ', roomId, ' bigRoomId: ', bigRoomId, ' RoomReward: ', roomReward) if not roomReward: if ftlog.is_debug(): ftlog.debug('SkyEggActivity ', roomId, 'dismatch SkyEggActivity!!!') return rp = roomReward.get('prob') if not rp: ftlog.error('SkyEggActivity Room ', roomId, ' lack of "prob" config item!!!!!') return reward = roomReward.get('reward') contents = roomReward.get('desc') if self._mail and contents: mail = strutil.replaceParams(self._mail, {'rewardContent': contents}) else: mail = None if hit(rp) and self.checkTime(pktimestamp.getCurrentTimestamp()) == 0: ftlog.info('SkyEggActivity User: '******'luckly gain reward: ', reward, ' at room: ', roomId, ' table: ', tableId) self.sendReward(userId, reward, mail) if ftlog.is_debug(): ftlog.debug('SkyEggActivy._handleTableWinlose: UserId = ', userId, 'bigRoomId = ', bigRoomId, 'reward = ', roomReward, 'mail = ', mail, 'reward = ', reward)
def checkUserQuitLoc(gameId, userId, roomId, clientId): gid = strutil.getBigRoomIdFromInstanceRoomId(roomId) ret = daobase.executeUserCmd( userId, 'HGET', 'quitol' + ':' + str(gameId) + ':' + str(userId), str(gid)) retDict = strutil.loads(ret) if ret else None if retDict: rid = retDict.get('roomId') tid = retDict.get('tableId') sid = retDict.get('seatId') gid = strutil.getGameIdFromInstanceRoomId(rid) if gid > 0 and rid > 0 and tid > 0: # 到具体的房间或桌子的服务上去查询, 是否是真的在桌子上 if tid == rid * 10000: # 玩家在队列房间或者比赛房间的等待队列中, 此处不做一致性检查,玩家发起quick_start时检查。 return 1 else: try: seatId, isObserving = roommgr.doCheckUserLoc( userId, gid, rid, tid, clientId) except: ftlog.error() return -1 ftlog.debug('_checkUserLoc->userId=', userId, 'seatId=', seatId, 'isObserving=', isObserving) if seatId > 0 or isObserving == 1: # 还在桌子上游戏 return 1 else: # 已经不再桌子上了, 清理所有的桌子带入金币 if sid > 0: from poker.entity.dao import userchip userchip.moveAllTableChipToChip( userId, gid, 'TABLE_TCHIP_TO_CHIP', 0, clientId, tid) # 清理当前的在线数据 _removeUserQuitLoc(gameId, userId, rid) return 0 else: # 到这儿, 数据是错误的, 删除处理 _removeUserQuitLoc(gameId, userId, rid) return 0
def isSameBigRoom(cls, roomId1, roomId2): return strutil.getBigRoomIdFromInstanceRoomId(roomId1) == strutil.getBigRoomIdFromInstanceRoomId(roomId2)
def _removeUserQuitLoc(gameId, userId, rid): gid = strutil.getBigRoomIdFromInstanceRoomId(rid) daobase.executeUserCmd(userId, 'HDEL', 'quitol' + ':' + str(gameId) + ':' + str(userId), str(gid))
def doInitTablePlayerDatas(userId, roomId, **kwargs): gameId = DIZHU_GAMEID clientId = sessiondata.getClientId(userId) devId = sessiondata.getDeviceId(userId) clientIp = sessiondata.getClientIp(userId) exp, suaddress, susex, suname, sucoin, charm = userdata.getAttrs( userId, ['exp', 'address', 'sex', 'name', 'coin', 'charm']) sugold, slevel, swinrate, winchips, starid, winstreak, lastwinstreak, maxwinstreak, winrate2, firstWin = gamedata.getGameAttrs( userId, gameId, [ 'gold', 'level', 'winrate', 'winchips', 'starid', 'winstreak', 'lastwinstreak', 'maxwinstreak', 'winrate2', 'firstWin' ]) swinrate = strutil.loads(swinrate, ignoreException=True, execptionValue={ 'pt': 0, 'wt': 0 }) winrate2 = strutil.loads(winrate2, ignoreException=True, execptionValue={ 'pt': 0, 'wt': 0 }) firstWin = strutil.loads(firstWin, ignoreException=True, execptionValue={}) suchip = userchip.getChip(userId) bigRoomId = strutil.getBigRoomIdFromInstanceRoomId(roomId) mixConfRoomId = kwargs.get('mixConf', {}).get('roomId') tbplaytimes, tbplaycount = treasurebox.getTreasureBoxState( gameId, userId, mixConfRoomId or bigRoomId) try: supic, isBeauty = halluser.getUserHeadUrl(userId, clientId) except: supic, isBeauty = '', False slevel = recoverUserAttr(slevel, int, 0) datas = {} datas['uid'] = userId datas['clientId'] = clientId datas['devId'] = recoverUserAttr(devId, str, '') datas['clientIp'] = recoverUserAttr(clientIp, str, '') datas['address'] = recoverUserAttr(suaddress, unicode, '') datas['sex'] = recoverUserAttr(susex, int, 0) datas['name'] = recoverUserAttr(suname, unicode, '') datas['coin'] = recoverUserAttr(sucoin, int, 0) datas['headUrl'] = '' datas['purl'] = supic datas['isBeauty'] = isBeauty datas['chip'] = suchip datas['exp'] = recoverUserAttr(exp, int, 0) datas['gold'] = recoverUserAttr(sugold, int, 0) datas['vipzuan'] = [] datas['tbc'] = tbplaycount datas['tbt'] = tbplaytimes datas['level'] = slevel datas['wins'] = swinrate.get('wt', 0) datas['plays'] = swinrate.get('pt', 0) datas['winchips'] = recoverUserAttr(winchips, int, 0) datas['nextexp'] = 0 datas['title'] = '' datas['medals'] = [] datas['skillScoreInfo'] = skillscore.buildUserSkillScoreInfo( skillscore.getUserSkillScore(gameId, userId)) datas['charm'] = 0 if charm == None else recoverUserAttr(charm, int, 0) datas['vipInfo'] = hallvip.userVipSystem.getVipInfo(userId) datas['starid'] = 0 if starid == None else recoverUserAttr(starid, int, 0) datas['winstreak'] = 0 if winstreak == None else recoverUserAttr( winstreak, int, 0) datas['lastwinstreak'] = 0 if lastwinstreak == None else recoverUserAttr( lastwinstreak, int, 0) datas['maxwinstreak'] = 0 if maxwinstreak == None else recoverUserAttr( maxwinstreak, int, 0) datas['gameClientVer'] = gamesession.getGameClientVer(gameId, userId) datas['winrate2'] = winrate2 datas['firstWin'] = firstWin # TODO 查询用户增值位 datas['wearedItems'] = [] userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() timestamp = pktimestamp.getCurrentTimestamp() memberCardItem = userBag.getItemByKindId(hallitem.ITEM_MEMBER_NEW_KIND_ID) datas[ 'memberExpires'] = memberCardItem.expiresTime if memberCardItem else 0 datas['registerDays'] = UserInfo.getRegisterDays(userId, timestamp) item = userBag.getItemByKindId(hallitem.ITEM_CARD_NOTE_KIND_ID) # 新用户的计次记牌器 newUserReward = configure.getGameJson(gameId, 'login.reward', {}).get('newUserReward') if newUserReward: if newUserReward.get('open', 0): cardNoteCount = newUserReward.get('cardNoteCount', 0) if cardNoteCount: pt = swinrate.get('pt', 0) if cardNoteCount - pt >= 1: datas['cardNotCount'] = max(1, cardNoteCount - pt) if item and not item.isDied(timestamp): datas['cardNotCount'] = max(1, item.balance(timestamp)) if ftlog.is_debug(): ftlog.debug('table_remote.doInitTablePlayerDatas', 'userId=', userId, 'clientId=', clientId, 'datas=', datas) return datas