def setting_user_preference(self, request): """ 玩家额外信息. :param request: :return: """ debug("setting_user_preference : request = ", request) user_id = request.getParamInt('userId') preferences = request.getParamStr('preferences') age = request.getParamStr('age') motto = request.getParamStr('motto') debug("SNSHttpAction : setting_user_preference : ", user_id, preferences, age, motto) mi = self.user_checker.check(request) mo = MsgPack() if mi.error: ftlog.warn('setting_user_preference error', request, mi.error) mo.setResult('ok', 0) mo.setError(1, mi.error) else: # self.service.setting_preference_record(user_id, preferences) preferences = {"age": age, "motto": motto} self.service.setting_preference_record(user_id, preferences) mo.setResult('ok', 1) return mo
def encodeUserTaskListFull(userTaskUnit): taskList = [] if userTaskUnit: taskKindPool = userTaskUnit.taskKindPool for taskId in taskKindPool.taskIdList: asserts = None task = userTaskUnit.findTaskByTaskId(taskId) if task: if isinstance(task.taskKind.rewardContent, tycontent.TYChoiceContent): asserts = [] for x in task.taskKind.rewardContent._generators: asserts.append(x._assetKindId) data = [ taskId, # 任务ID task.kindId, # 任务类型ID, task.progress, # 任务进度 task. status, # 显示按钮的序号 0 继续努力 1 可领取 2 已经领取 3 锁定 4 未进行隐藏 5 已领取隐藏 task.taskKind.name, asserts, datetime.fromtimestamp( task.updateTime).strftime('%Y-%m-%d %H:%M:%S'), task.taskKind.progressMax, task.finishCount, task.taskKind.totalLimit, ] taskList.append(data) else: ftlog.warn('encodeUserTaskListFull not found->', userTaskUnit.userId, taskId, task) return taskList
def getWinNodesByDropTile(self, dropTile): tingInfos = None if self.TING in self.__extend: tingInfos = self.__extend[self.TING] if self.GRAB_CHI_TING in self.__extend: tingInfos = self.__extend[self.GRAB_CHI_TING][0][self.TING] if self.GRAB_PENG_TING in self.__extend: tingInfos = self.__extend[self.GRAB_PENG_TING][0][self.TING] if self.GRAB_GANG_TING in self.__extend: tingInfos = self.__extend[self.GRAB_GANG_TING][0][self.TING] if self.GRAB_ZHAN_TING in self.__extend: tingInfos = self.__extend[self.GRAB_ZHAN_TING][0][self.TING] if not tingInfos: ftlog.warn('getWinNodesByDropTile tingInfos is None, need check:', self.__extend) return None,False ftlog.debug('getWinNodesByDropTile tingInfos:', tingInfos) for tingSolution in tingInfos: if tingSolution['dropTile'] == dropTile: return tingSolution['winNodes'],tingSolution.get('ishuAll',False) return None,False
def do_follow_launch(self, request): """ 添加好友. :param request: :return: """ # 源用户ID->目标用户ID,问候语,来源渠道(检索,群, 游戏...) user_id = request.getParamInt('userId') target_user_id = request.getParamInt('targetUserId') debug("SNSHttpAction do_follow_launch ", user_id, target_user_id) mi = self.checkBase.check(request) mo = MsgPack() if mi.error: ftlog.warn('do_follow_launch error', user_id, target_user_id, mi.error) mo.setResult('ok', 0) mo.setError(1, mi.error) else: # 问候语 hello = request.getParamStr('hello') # 搜索添加、游戏互动添加,用于数据分析 origin = request.getParamStr('origin') self.service.do_follow_launch(user_id, target_user_id, hello, origin) mo.setResult('ok', 1) return mo
def dingAbsence(self, seatId, color, actionId): """玩家定缺某个花色 """ # 玩家已经选择过了,不能再次选择 if self.absenceColor[seatId] != self.COLOR_ABSENCE_INIT: ftlog.warn('MAbsenceProcessor.dingAbsence already absenced seatId:', seatId , ' absenceColor:', self.absenceColor) return # 只能缺万筒条中的一个颜色 if color not in (MTile.TILE_WAN, MTile.TILE_TONG, MTile.TILE_TIAO): ftlog.warn('MAbsenceProcessor.dingAbsence wrong color..') return self.absenceColor[seatId] = color self.msgProcessor.table_call_notify_absence(self.players[seatId].userId , seatId , self.absenceColor[seatId] , False , actionId) if self.isAllSelected(): # 所有人都已选择定缺,结束定缺状态 ftlog.debug('MAbsenceProcessor.dingAbsence, all absenced !!!') self.setSchedule(self.SCHEDULE_ABSENCE_END) self.setAbsenceTimeOut(0)
def get_chat_record(self, msg): """ 获取所有的聊天记录. """ debug("ChatListSrv : get_chat_record : msg = ", msg) user_id = msg.getParamInt('userId') target_user_ids = msg.getParam('targetUserIds') resp = MsgPack() resp.setCmd('chat') resp.setResult('action', 'chat_record') mi = self.user_checker.check(msg) if mi.error: ftlog.warn('get_chat_record param error', user_id, target_user_ids, mi.error) resp.setResult('status', "error") resp.setError(1, mi.error) else: try: records = self.service.batch_record_list( user_id, target_user_ids) debug("ChatListSrv get_chat_record", records) resp.setResult('records', records) resp.setResult('status', "ok") except TYBizException, e: resp.setResult('status', "error") resp.setError(e.errorCode, e.message)
def _safeAddGames(userId, intClientId, gameIds, location): """ 安全添加用户自定义数据. 客户端传来的添加项,校验实际存在后再入库. """ # TODO 和 _filterGameNodes 合并 if _DEBUG: debug('_tygamelist5._addSafeGames IN->', userId, intClientId, gameIds) nodes = _getExtendGames(userId, intClientId, location) now = fttime.getCurrentTimestamp() idx = 0 for info in nodes: nodeId = info.get("id", "") if nodeId in gameIds: # 节点数据真实存在才进行添加 _dao.addUserGameListNode(userId, now + idx, nodeId) # 制造一点时间差形成先后顺序 idx += 1 gameIds.remove(nodeId) if len(gameIds) > 0: # 不安全的输入数据,记录下来 ftlog.warn( '_tygamemanager._addSafeGames, the node not found ! userId=', userId, 'clientId=', intClientId, 'gameIds=', gameIds, 'nodes', nodes) return 1
def sendPrivateMessage(userId, msg): """ 发送个人消息 """ # if not isinstance(msg, unicode): # msg = unicode(msg) # message.sendPrivate(9999, userId, 0, msg) ftlog.warn('TODO, HALL51 not support user private message', userId, msg)
def check_friend(self, request): """ 检查2个人是否好友。 :param userId: :param targetId: :return: """ user_id = request.getParamInt('userId') target_user_id = request.getParamInt('targetUserId') debug("SNSHttpAction check_friend ", user_id, target_user_id) mi = self.checkBase.check(request) mo = MsgPack() if mi.error: ftlog.warn('check_friend error', request, mi.error) mo.setResult('ok', 0) mo.setError(1, mi.error) else: ret = self.service.check_friend(user_id, target_user_id) if ret: ret = 1 else: ret = 0 mo.setResult("data", ret) mo.setResult('ok', 1) return mo
def doItemDetailInfo(self, msg): mi = self.checkerCmd.check(msg) if mi.error: ftlog.warn('doItemDetailInfo', msg, mi.error) return 0 mo = ItemHelper.getItemDetailInfo(mi.gameId, mi.clientId, mi.userId, mi.itemId) tyrpcconn.sendToUser(mi.userId, mo)
def doItemList(self, msg): mi = self.checkerCmd.check(msg) if mi.error: ftlog.warn('doItemList', msg, mi.error) return 0 mo = ItemHelper.makeItemListResponse(mi.gameId, mi.clientId, mi.userId, mi.kindGameId) tyrpcconn.sendToUser(mi.userId, mo)
def doAddHallGameManager(self, msg): mi = self.checker.check(msg) if _DEBUG: debug('doAddHallGamemanager IN->', mi) if mi.error: ftlog.warn('doAddHallGameManager', msg, mi.error) return 0 _gamemanager.addHallGameManager(mi.userId, mi.clientId, mi.apiVersion, mi.gameIds) return 1
def numberToClientId(numberId): cid = '' try: cid = tyconfig.numberToClientId(numberId) except: pass if not cid: ftlog.warn('stage_match_remote.numberToClientId failed:', numberId) return cid
def clientIdToNumber(clientId): cid = 0 try: cid = tyconfig.clientIdToNumber(clientId) except: pass if cid == 0: ftlog.warn('stage_match_remote.clientIdToNumber failed:', clientId) return cid
def doActionCheckStartGame(self): '''检查游戏人数是否达到开局要求 Note: 先补足筹码,然后踢掉筹码不足的玩家 ''' ftlog.debug("<<", self.getBasicAttrsLog(), caller=self) if self.__state != self.GAME_PLAY_STATE_WAIT: ftlog.warn("doActionCheckStartGame state error!", self.getBasicAttrsLog()) return False
def doActionGameEnd(self): if ftlog.is_debug(): ftlog.info("doActionGameEnd <<", self.getBasicAttrsLog(), caller=self) if self.__state != self.GAME_PLAY_STATE_FINAL: ftlog.warn("state error!", self.getBasicAttrsLog(), caller=self) return self.transitToStateWait()
def _sendAllRecordToUser(cls, userId, gameId, startRecordIndex, endRecordIndex, playMode=None, targetUserId=None, targetTableNo=None): """全量下发 带分页参数 """ # 获取keys if targetUserId is None: targetUserId = userId if startRecordIndex < 0: startRecordIndex = 0 if endRecordIndex < startRecordIndex: endRecordIndex = startRecordIndex userRecordKeys = pluginCross.mj2dao.getRecordKeyList(targetUserId) rLength = len(userRecordKeys) urKeys = [] for index in range(startRecordIndex, endRecordIndex + 1): newIndex = rLength - index - 1 if newIndex >= 0: urKeys.append(userRecordKeys[rLength - index - 1]) ftlog.debug('createTableRecord.sendAllRecordToUser2 urKeys:', urKeys) msg = MsgPack() msg.setCmd('create_table') msg.setResult('action', 'record') msg.setResult('type', 'update') msg.setResult('gameId', gameId) playerRecordList = [] for userRecordKey in urKeys: playerRecordInfo = pluginCross.mj2dao.getReplayRecord( userRecordKey) if not playerRecordInfo: ftlog.warn('createTableRecord.sendAllRecordToUser2 key:', userRecordKey, ' is null') else: playerRecordDist = json.loads(playerRecordInfo) # playMode过滤 if playMode and playMode != playerRecordDist.get('playMode'): continue # 房间号过滤 if targetTableNo and targetTableNo != playerRecordDist.get( 'tableNo'): continue playerRecordList.append(playerRecordDist) ftlog.debug('createTableRecord.sendAllRecordToUser2 key:', userRecordKey, ' content:', playerRecordDist) msg.setResult('list', playerRecordList) tyrpcconn.sendToUser(userId, msg)
def doGetHallGameManager(self, msg): """ 获取待添加游戏插件列表 """ mi = self.checkBase.check(msg) if _DEBUG: debug('doGetHallGamemanager IN->', mi) if mi.error: ftlog.warn('doGetHallGamemanager', msg, mi.error) return 0 _gamemanager.getHallGameManager(mi.userId, mi.clientId, mi.apiVersion) return 1
def doGiveUp(roomId, tableId, userId): room = tyglobal.rooms()[roomId] if room: table = room.maptable.get(tableId) if table: table.giveUp(userId) else: ftlog.warn("stage_match_table_remote doGiveUp not find table", tableId) else: ftlog.warn("stage_match_table_remote doGiveUp not find room", roomId) return 0
def doClearTable(roomId, tableId, info): room = tyglobal.rooms()[roomId] if room: table = room.maptable.get(tableId) if table: table.clearMatchTable(info) else: ftlog.warn("stage_match_table_remote clearTable not find table", tableId) else: ftlog.warn("stage_match_table_remote clearTable not find room", roomId) return 0
def _getSubGameDataVal(gameId, userId, attrName): rpcproxy = typlugin.getRpcProxy(gameId, typlugin.RPC_CALL_SAFE, typlugin.RPC_TARGET_MOD_ONE) rfc = rpcproxy.gamemgr.getGameData(userId, gameId, attrName) if not rfc: ftlog.warn('ERROR, the target game service not found !') return None elif rfc.getException(): ftlog.warn('ERROR, the target game service got exception !', str(rfc.getException())) return None return rfc.getResult()
def getUserNoiceList(self, msg): mi = hallchecker.CHECK_BASE.check(msg) if mi.error: ftlog.warn('getUserNoiceList', msg, mi.error) return 0 bannerIds, showIds = self.getNoticeInfoByClientId( mi.clientId, mi.userId) mo = MsgPack() mo.setCmd('notice5') mo.setResult('action', 'list') mo.setResult('banners', bannerIds) mo.setResult('notices', showIds) tyrpcconn.sendToUser(mi.userId, mo) return 1
def doMatchQuickStart(self, msg): ftlog.info('StageMatchRoomMixin._do_room__quick_start') assert (self.roomId == msg.getParam('roomId')) userId = msg.getParam('userId') tableId = msg.getParam('tableId') roomId = msg.getParam('roomId') gameId = msg.getParam('gameId') ftlog.info('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId, 'confTableId=', self.conf.tableId) player = self.matchArea.findPlayer(userId) if player is None: ftlog.warn('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId, 'err=', 'NotFoundPlayer') try: # 可能是之前在gt中的tableId unlockUserForMatch(userId, self.roomId, tableId) except: ftlog.error('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId) reason = TYRoom.ENTER_ROOM_REASON_INNER_ERROR info = u'在线状态错误或其他系统内部错误' self._sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, info) return # 确认是在房间掉线 if tableId == self.conf.tableId: # 玩家在队列里时断线重连 reason = TYRoom.ENTER_ROOM_REASON_OK self._sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, self.conf.tableId) # 如果用户已经被分组则发送等待信息 if player.group: self._sendMatchStatas(player.userId) self._sendMatchRanks(player.userId) self._sendDesc(player.userId) self.matchArea.playerNotifier.notifyMatchWait(player, 1) else: # 玩家在牌桌上断线重连,游戏的UT补齐下面的参数 extParams = msg.getKey('params') # 开放给用户的扩展参数 clientId = msg.getParam("clientId") # clientId shadowRoomId = msg.getParam("shadowRoomId") # GT的房间ID self._sendMatchStatas(player.userId) self._sendMatchRanks(player.userId) self._sendDesc(player.userId)
def doNewUserRewardReceive(self, msg): ''' 客户端点击“领取”按钮,领取新手启动资金 ''' mi = hallchecker.CHECK_BASE.check(msg) if mi.error : ftlog.warn('doNewUserRewardReceive', msg, mi.error) return 0 isSend, startChip, _final = self.sendStartChip(mi.userId, mi.gameId, mi.clientId, None) mo = MsgPack() mo.setCmd('new_user_reward5') mo.setResult('action', 'receive') mo.setResult('chip', startChip if isSend else 0) tyrpcconn.sendToUser(mi.userId, mo) return 1
def clearInvalidObservers(self): '''一段防御性代码,防止本桌上一局的旁观者未被及时清理,下一局开局时换到了别的桌子,但收到本桌的协议 ''' invalidObservers = [] for userId in self.observers: onlineSeatId = pluginCross.onlinedata.getOnLineLocSeatId( userId, self.roomId, self.tableId) if onlineSeatId == 0: # Note: 断线的旁观玩家不做清理,table._doClearPlayers会处理 ftlog.warn(self._baseLogStr('invalid observer found', userId), '|locList:', pluginCross.onlinedata.getOnLineLocList(userId), caller=self) invalidObservers.append(userId) for userId in invalidObservers: del self.observers[userId]
def _getExtendGames(userId, intClientId, location): """ 获取扩展位游戏列表. """ nodes = [] gameInfo = gamemgr_pls_conf.getConfigByClientId(intClientId) if not gameInfo: ftlog.warn( '_tygamemanager._getListGames, then pls_gameInfo not found ! userId=', userId, 'clientId=', intClientId) return nodes pls_gameInfo = gameInfo.get('nodes', []) loc_gameInfo = _getlocBylocation(location) if loc_gameInfo: pls_gameInfo.extend(loc_gameInfo) # 合并推荐和地域游戏信息 _filterGameNodes(userId, intClientId, pls_gameInfo, nodes) return nodes
def _onEnterCreateRoomFailed(cls, checkResult, userId, gameId, clientId, roomId=0): '''进入创建房间失败回调函数''' ftlog.warn("|userId, reason, roomId:", userId, checkResult, roomId, caller=cls) mo = MsgPack() mo.setCmd('quick_start') mo.setResult('gameId', gameId) mo.setResult('userId', userId) mo.setResult('reason', checkResult) tyrpcconn.sendToUser(userId, mo)
def verify_friend(self, user_id, target_user_id): """ 验证2个用户是否好友关系,提供给聊天服务RPC调用。 :param user_id: :param target_user_id: :return: 1 是好友 0 不是好友 """ debug("SNSHttpAction verify_friend:", user_id, target_user_id) if isinstance(user_id, int) and user_id > 0 and isinstance( target_user_id, int) and target_user_id > 0: ret = self.service.check_friend(user_id, target_user_id) if ret: return 1 else: return 0 else: ftlog.warn("SNSHttpAction verify_friend error param", user_id, target_user_id) return 0
def _decodeItem(self, userId, itemId, itemDataBytes): kindId = 0 try: kindId = TYItemData.decodeKindId(itemDataBytes) itemKind = self._itemSystem.findItemKind(kindId) if itemKind: itemData = itemKind.newItemData() TYItemData.decodeFromBytes(itemData, itemDataBytes) item = itemKind.newItemForDecode(itemId) item.decodeFromItemData(itemData) return item else: ftlog.warn('TYItemDao._decodeItem kindId NOT FOUND ! userId=', userId, 'itemId=', itemId, 'kindId=', kindId, 'data=[', itemDataBytes, ']') except: ftlog.error('TYItemDao._decodeItem userId=', userId, 'itemId=', itemId, 'kindId=', kindId, 'data=', itemDataBytes) return None
def do_delete_friend(self, request): """ 删除好友. :param request: :return: """ user_id = request.getParamInt('userId') target_user_id = request.getParamInt('targetUserId') debug("SNSHttpAction : do_delete_friend : ", user_id, target_user_id) mi = self.checkBase.check(request) mo = MsgPack() if mi.error: ftlog.warn('do_delete_friend error', request, mi.error) mo.setResult('ok', 0) mo.setError(1, mi.error) else: self.service.del_friend(user_id, target_user_id) mo.setResult('ok', 1) return mo