def getTableSitdown(self, player): self._logger.info('TableManager.getTableSitdown player.userId=', player.userId, 'idleTableCount=', self.idleTableCount, 'allTableCount=', self.allTableCount) sitTable = None for t in xrange(self.waitTableCount): table = self.waitTableList[t] playerList = table.getPlayerList() isMeet = False isSameIp = False # 休闲赛中,桌子内不能匹配当场比赛已经在一起打过的人,同时相同ip的不会坐在一起 for onePlayer in playerList: if sessiondata.getClientIp(onePlayer.userId) == sessiondata.getClientIp(player.userId): isSameIp = True if onePlayer.meetPlayersMap.get(player.userId, None) == player: isMeet = True if (not isMeet) and (not isSameIp): table.sitdown(player) sitTable = table if table.getPlayerCount() == table.seatCount: self._busyTableList.append(table) del self.waitTableList[t] break # 如果在self.waitTableList 找到位置,那么就取self._idleTables里的 if not sitTable: sitTable = self._borrowOneTable() if sitTable: sitTable.sitdown(player) self.waitTableList.append(sitTable) return sitTable
def getTableSitdown(self, player): self._logger.info('TableManager.getTableSitdown player.userId=', player.userId, 'idleTableCount=', self.idleTableCount, 'allTableCount=', self.allTableCount) sitTable = None for t in xrange(self.waitTableCount): table = self.waitTableList[t] playerList = table.getPlayerList() isMeet = False isSameIp = False # 休闲赛中,桌子内不能匹配当场比赛已经在一起打过的人,同时相同ip的不会坐在一起 for onePlayer in playerList: if sessiondata.getClientIp( onePlayer.userId) == sessiondata.getClientIp( player.userId): isSameIp = True if onePlayer.meetPlayersMap.get(player.userId, None) == player: isMeet = True if (not isMeet) and (not isSameIp): table.sitdown(player) sitTable = table if table.getPlayerCount() == table.seatCount: self._busyTableList.append(table) del self.waitTableList[t] break # 如果在self.waitTableList 找到位置,那么就取self._idleTables里的 if not sitTable: sitTable = self._borrowOneTable() if sitTable: sitTable.sitdown(player) self.waitTableList.append(sitTable) return sitTable
def getTableSitdown(self, player): self._logger.info('TableManager.getTableSitdown player.userId=', player.userId, 'idleTableCount=', self.idleTableCount, 'allTableCount=', self.allTableCount) for countN in xrange(5): isLock = daobase.executeMixCmd('HGET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId)) if isLock: FTTasklet.getCurrentFTTasklet().sleepNb(0.2) if countN >= 4: return None else: break try: # 加锁 daobase.executeMixCmd('HSET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId), 1) sitTable = None for t in xrange(self.waitTableCount): table = self.waitTableList[t] playerList = table.getPlayerList() isMeet = False isSameIp = False # 休闲赛中,桌子内不能匹配当场比赛已经在一起打过的人,同时相同ip的不会坐在一起 for onePlayer in playerList: if sessiondata.getClientIp( onePlayer.userId) == sessiondata.getClientIp( player.userId): isSameIp = True if onePlayer.meetPlayersMap.get(player.userId, None) == player: isMeet = True if (not isMeet) and (not isSameIp) and table.idleSeatCount > 0: table.sitdown(player) sitTable = table if table.idleSeatCount <= 0: self._busyTableList.append(table) del self.waitTableList[t] break # 如果在self.waitTableList 找到位置,那么就取self._idleTables里的 if not sitTable: sitTable = self._borrowOneTable() if sitTable: sitTable.sitdown(player) self.waitTableList.append(sitTable) return sitTable finally: # 解锁 daobase.executeMixCmd('HSET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId), 0)
def _isfilterConditions_group1(userId, clientId): conf = configure.getGameJson(HALL_GAMEID, 'gamelistipfilter', {}, configure.DEFAULT_CLIENT_ID) ipstr = sessiondata.getClientIp(userId) if not iploc.isBjSzIp(ipstr): if _DEBUG: ftlog.debug('_isfilterConditions_group1', userId, ipstr, 'enableIpCheck !') adjustVIP = 0 adjustPlayTime = 0 group1_passVipLevel = conf.get('group1_passVipLevel', 0) if group1_passVipLevel > 0: vipLevel = _getVIpLevel(userId) if vipLevel >= group1_passVipLevel: if _DEBUG: ftlog.debug('_isfilterConditions_group1', userId, vipLevel, group1_passVipLevel, 'group1_passVipLevel !') adjustVIP = 1 group1_passTotalPlayTime = conf.get('group1_passTotalPlayTime', 0) if group1_passTotalPlayTime > 0: totalTime = _getPlayTimes(userId) if totalTime >= group1_passTotalPlayTime: if _DEBUG: ftlog.debug('gamelistipfilter', userId, totalTime, group1_passTotalPlayTime, 'group1_passTotalPlayTime !') adjustPlayTime = 1 return adjustVIP == 1 and adjustPlayTime == 1 else: if _DEBUG: ftlog.debug('_isfilterConditions_group1 is in beijing or shenzhe!! userId = ', userId , 'enableIpCheck !') return 0
def getInfo(self): item = {} item["seatId"] = self.seatIndex # 德州客户端 seatId 从0开始 ! item["userId"] = self.userId if self.userId == 0: return item # user信息 if gdata.mode() == gdata.RUN_MODE_ONLINE: item["name"] = self.name else: item["name"] = '%s_%s_%s' % (self.userId, self.seatIndex, self.name) item["purl"] = self.purl item["sex"] = self.sex item["ip"] = sessiondata.getClientIp(self.userId) # 需要实时更新ip数据 # 牌桌筹码信息 item["chips"] = self.tableChips item["state"] = self.state # game信息 # 统计信息 # 手牌信息 # 状态信息 item["managed"] = self.isManaged # 以插件形式来填充palyerInfo数据 TYPluginCenter.event(TYPluginUtils.updateMsg(cmd=PluginEvents.EV_GET_PLAYER_INFO, params=TYPluginUtils.mkdict( table=self.table, userId=self.userId, player=self, playerInfo=item)), self.table.gameId) return item
def checkIsKillPig(tableId, killPigLevel, userIds): try: ftlog.info('checkIsKillPig->', tableId, killPigLevel, userIds) lcount = 0 devids = set() ips = set() for userId in userIds: devId = sessiondata.getDeviceId(userId) ip = sessiondata.getClientIp(userId) score = gamedata.getGameAttrInt(userId, 6, 'skillscore') if score < killPigLevel: lcount += 1 devids.add(devId) ips.add(ip) ftlog.info('checkIsKillPig->uid=', userId, 'level=', killPigLevel, 'score=', score, 'ip=', ip, 'devid=', devId) if lcount >= 2: ftlog.info('checkIsKillPig-> is pig level !!') return 1 if len(devids) != len(userIds): ftlog.info('checkIsKillPig-> is pig devids !!') return 1 if len(ips) != len(userIds): ftlog.info('checkIsKillPig-> is pig ip !!') return 1 except: ftlog.error() return 0
def getTableSitdown(self, player): self._logger.info('TableManager.getTableSitdown player.userId=', player.userId, 'idleTableCount=', self.idleTableCount, 'allTableCount=', self.allTableCount) for countN in xrange(5): isLock = daobase.executeMixCmd('HGET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId)) if isLock: FTTasklet.getCurrentFTTasklet().sleepNb(0.2) if countN >= 4: return None else: break try: # 加锁 daobase.executeMixCmd('HSET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId), 1) sitTable = None for t in xrange(self.waitTableCount): table = self.waitTableList[t] playerList = table.getPlayerList() isMeet = False isSameIp = False # 休闲赛中,桌子内不能匹配当场比赛已经在一起打过的人,同时相同ip的不会坐在一起 for onePlayer in playerList: if sessiondata.getClientIp(onePlayer.userId) == sessiondata.getClientIp(player.userId): isSameIp = True if onePlayer.meetPlayersMap.get(player.userId, None) == player: isMeet = True if (not isMeet) and (not isSameIp) and table.idleSeatCount > 0: table.sitdown(player) sitTable = table if table.idleSeatCount <= 0: self._busyTableList.append(table) del self.waitTableList[t] break # 如果在self.waitTableList 找到位置,那么就取self._idleTables里的 if not sitTable: sitTable = self._borrowOneTable() if sitTable: sitTable.sitdown(player) self.waitTableList.append(sitTable) return sitTable finally: # 解锁 daobase.executeMixCmd('HSET', RELAXATION_MATCH_LOCK_KEY, str(self._room.roomId), 0)
def _isOutOfBeijingIp(userId, clientId): conf = configure.getGameJson(HALL_GAMEID, 'gamelistipfilter', {}, configure.DEFAULT_CLIENT_ID) if not conf.get('enableIpCheck', 0): return 1 # intClientId = pokerconf.clientIdToNumber(clientId) # if intClientId not in conf.get('filterClientIds', []): # return 1 passHall = conf.get('passHall', []) if passHall: for ph in passHall: if clientId.find(ph) > 0: if _DEBUG: ftlog.debug('gamelistipfilter', userId, clientId, ph, 'passHall !') return 1 passClientVer = conf.get('passClientVer', 0) if passClientVer > 0: _, cver, _ = strutil.parseClientId(clientId) if cver < passClientVer: if _DEBUG: ftlog.debug('gamelistipfilter', userId, clientId, passClientVer, 'passClientVer !') return 1 ipstr = sessiondata.getClientIp(userId) if not iploc.isBeijingIp(ipstr): if _DEBUG: ftlog.debug('gamelistipfilter', userId, ipstr, 'enableIpCheck !') return 1 passTotalPlayTime = conf.get('passTotalPlayTime', 0) if passTotalPlayTime > 0: totalTime = gamelistipfilter._getPlayTimes(userId) if totalTime >= passTotalPlayTime: if _DEBUG: ftlog.debug('gamelistipfilter', userId, totalTime, passTotalPlayTime, 'passTotalPlayTime !') return 1 passVipLevel = conf.get('passVipLevel', 0) if passVipLevel > 0: vipLevel = gamelistipfilter._getVIpLevel(userId) if vipLevel >= passVipLevel: if _DEBUG: ftlog.debug('gamelistipfilter', userId, vipLevel, passVipLevel, 'passVipLevel !') return 1 if _DEBUG: ftlog.debug('filtergamelist go filter !', userId, ipstr) return 0
def refreshUserData(userId): """ 刷新用户是否存在地区限制 """ location = config.getPublic("locationLimit", []) requestUrl = "http://iploc.ywdier.com/api/iploc5/search/city" postData = {"ip": sessiondata.getClientIp(userId)} result = util.doHttpQuery(requestUrl, postData, timeout=3) isLocationLimit = 0 if not result or set(location) & set(result.get("loc", [])): isLocationLimit = 1 gamedata.setGameAttr(userId, FISH_GAMEID, GameData.isLocationLimit, isLocationLimit)
def _doUserConnect(self, userId, gameId, clientId): """ 更新用户的TCP链接 """ ftlog.info('doUpdateUserTcpConnection userId=', userId, 'address=', self.clientAddress) ipaddress = self.transport.getPeer().host if ftlog.is_debug(): ftlog.debug("|userId, ip:", userId, ipaddress, caller=self) if userId <= 0: _sendLogOutMsg(self, ERROR_SYS_LOGOUT_USERID_ERROR, 1) return # try: # conns = gdata.getUserConnIpPortList() # idx = userId % len(conns) # if idx != gdata.serverNumIdx() : # raise Exception('the user ip port error, this is ' + str(gdata.serverNumIdx()) \ # + ' idx=' + str(idx) + ' sid=' + str(gdata.serverId()) + ' ' \ # + str(userId) + ' ' + str(gameId) + ' ' + str(clientId) + ' ' + str(ipaddress)) # except: # ftlog.error() # _sendLogOutMsg(self, ERROR_SYS_LOGOUT_TIME_OUT, 1) # return intClientId = pokerconf.clientIdToNumber(clientId) if intClientId <= 0: ftlog.warn('the user clientid error ! ' + str(userId) + ' ' + \ str(gameId) + ' ' + str(clientId) + ' ' + str(ipaddress)) _sendLogOutMsg(self, ERROR_SYS_LOGOUT_CLIENTID_ERROR, 1) return _checkLastedConnId(userId) session = {'ip': ipaddress, 'ci': clientId, 'conn': gdata.serverId()} try: if not userdata.checkUserData(userId, clientId, session=session): # 冷数据导入失败, 关闭连接TCP连接 _sendLogOutMsg(self, ERROR_SYS_LOGOUT_DATASWAP_ERROR, 0) return except: # 冷数据导入失败, 关闭连接TCP连接 ftlog.error() _sendLogOutMsg(self, ERROR_SYS_LOGOUT_DATASWAP_ERROR, 0) return if ftlog.is_debug(): from poker.entity.dao import sessiondata ftlog.debug("|userId, ip:", userId, sessiondata.getClientIp(userId), caller=self) # 建立当前进程内的userid和tcp链接的对应关系 1:1的对应关系 user = None if _ONLINE_USERS.has_key(userId): user = _ONLINE_USERS[userId] user.hbcounter = 0 else: user = TcpUser(userId) _ONLINE_USERS[userId] = user oldProtocol = user.tcpProtocol user.tcpProtocol = self user.clientId = str(clientId) user.cid = '{"clientId":"' + user.clientId + '",' user.gameId = gameId self.userId = userId if self in _NEW_PROTOCOLS: del _NEW_PROTOCOLS[self] ftlog.info('User Protocol update : userId=', userId, ' newProtocol=', self.clientAddress) _notifyUserOnlineStatus(user, 1) if oldProtocol and oldProtocol.userId > 0 and self != oldProtocol: ftlog.info('User Protocol close old : userId=', userId, ' oldProtocol=', oldProtocol.clientAddress) user.firstUserInfo = 0 oldProtocol.userId = 0 _sendLogOutMsg(oldProtocol, ERROR_SYS_LOGOUT_OTHER_LOGIN, 0) # TODO 还需要发出room_leave的消息么? return 1
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