def enterFriendTable(userId, gameId, clientId, ftId): """进入自建桌""" if ftlog.is_debug(): ftlog.debug('hall_friend_table.enterFriendTable userId:', userId, ' pluginId:', gameId, ' clientId:', clientId, ' ftId:', ftId) pluginId = queryFriendTable(ftId) if not pluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('该房间不存在')) return if TYPlayer.isRobot(userId): isValidPluginId = True else: isValidPluginId = False from hall.entity import hallgamelist2 template = hallgamelist2.getUITemplate(gameId, userId, clientId) for version in template.versionList: if pluginId == version.game.gameId: isValidPluginId = True break if not isValidPluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('该安装包不支持此房间号所对应的玩法')) return ftlog.info('hall_friend_table.enterFriendTable userId:', userId, ' lead to pluginId:', pluginId) pluginId = int(pluginId) TYGame(pluginId).enterFriendTable(userId, gameId, clientId, ftId)
def _doChangeNameTry(self, userId, clientId, newName): # renameConf = hallconf.getClientRenameConf(clientId) # if (renameConf # and not renameConf.get('containsSensitive', 1) # and keywords.isContains(newName)): # info = TodoTaskShowInfo(hallrename.stringRenameContainsSensitive) # return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, info) code, info = hallrename.tryRename(HALL_GAMEID, userId, newName) if ftlog.is_debug(): ftlog.debug('hallrename._doChangeNameTry->', code, info) if code == -3: # name not changed !! pass elif code == -2: # 没有改名卡 info = TodoTaskShowInfo(hallrename.stringRenameCardRequired, True) if hallrename.payOrder: product, _ = hallstore.findProductByPayOrder( HALL_GAMEID, userId, clientId, hallrename.payOrder) if product: info.setSubCmd(TodoTaskPayOrder(product)) return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, info) elif code == 0: # 改名成功 return TodoTaskHelper.sendTodoTask( HALL_GAMEID, userId, TodoTaskPopTip(hallrename.stringRenameSuccessed)) else: # SDK改名失败 return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip(info))
def _doChangeNameTry(self, userId, clientId, newName): # renameConf = hallconf.getClientRenameConf(clientId) # if (renameConf # and not renameConf.get('containsSensitive', 1) # and keywords.isContains(newName)): # info = TodoTaskShowInfo(hallrename.stringRenameContainsSensitive) # return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, info) code, info = hallrename.tryRename(HALL_GAMEID, userId, newName) if ftlog.is_debug(): ftlog.debug('hallrename._doChangeNameTry->', code, info) CLIENT_VER = 4.57 _, clientVer, _ = strutil.parseClientId(clientId) if ftlog.is_debug(): ftlog.debug("_doChangeNameTry clientVer", userId, clientId, newName, code, info, clientVer) reInfo = "" if code == -3 : reInfo = "昵称没有变化" elif code == -2 : # 没有改名卡 info = TodoTaskShowInfo(hallrename.stringRenameCardRequired, True) if hallrename.payOrder: product, _ = hallstore.findProductByPayOrder(HALL_GAMEID, userId, clientId, hallrename.payOrder) if product: info.setSubCmd(TodoTaskPayOrder(product)) return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, info) elif code == 0 : reInfo = "昵称修改成功" # 改名成功 if clientVer < CLIENT_VER: if ftlog.is_debug(): ftlog.debug("_doChangeNameTry ok", userId, clientId, newName, code, info, clientVer) return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip(hallrename.stringRenameSuccessed)) else: #reInfo = "修改昵称失败,请重试" reInfo = info # SDK改名失败 if clientVer < CLIENT_VER: if ftlog.is_debug(): ftlog.debug("_doChangeNameTry fail", userId, clientId, newName, code, info, clientVer) return TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip(info)) mo = MsgPack() mo.setCmd('change_name') mo.setResult('action', 'try') mo.setResult('userId', userId) mo.setResult('code', code) mo.setResult('reInfo', reInfo) router.sendToUser(mo, userId) if ftlog.is_debug(): ftlog.debug("_doChangeNameTry result",userId, clientId, newName, code, reInfo)
def throwEmoji(self, userId, seatId, toSeatId, emojiId, count=1): seatFrom = self.checkSeatAndPlayer(seatId, userId) seatTo = self.checkSeat(toSeatId) try: self._throwEmoji(seatFrom, seatTo, emojiId, count) except ChipNotEnoughException: TodoTaskHelper.sendTodoTask(self.table.gameId, userId, TodoTaskPopTip('背包剩余金币不足无法使用互动表情')) except TYBizException, e: self.proto.sendSmilesResError(userId, e.message)
def processInvitees(self, enterParam, note, invitees, userId, gameId): ''' 邀请好友牌桌游戏 invitees - 被邀请者 ''' if not invitees: return uds = userdata.getAttrs(userId, ['name']) # 检查是否在线 for invitee in invitees: # invitee - 被邀请者 state = onlinedata.getOnlineState(invitee) if state: # 在线,则进行下一步操作 ids = userdata.getAttrs(invitee, ['name']) _, clientVer, _, _ = sessiondata.getClientIdInfo(invitee) if clientVer < 3.77: # 版本号小于3.77,则提示升级 TodoTaskHelper.sendTodoTask( gameId, invitee, TodoTaskPopTip(note + ' 请升级至新版本与好友 ' + uds[0] + ' 一起玩耍!')) TodoTaskHelper.sendTodoTask( gameId, userId, TodoTaskPopTip('您的好友 ' + ids[0] + ' 版本较低,提醒他升级到最新版本一起玩耍吧!')) else: # 判断是否在同一牌桌上 if self.isInSameTable(userId, invitee): TodoTaskHelper.sendTodoTask( gameId, userId, TodoTaskPopTip('您的好友 ' + ids[0] + ' 正在跟您一起游戏呢')) else: # 版本号大于3.77,则发送邀请 TodoTaskHelper.sendTodoTask( gameId, invitee, TodoTaskInviteToGame(userId, note, enterParam)) else: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskPopTip('您的好友当前不在线')) ftlog.debug('您的好友当前不在线')
def checkin(userId, gameId, clientId, loginsum, isDisplay, npwId, where=WHERE_NPW): ftlog.info("|newcheckin|login|", userId, gameId, loginsum, clientId) #complementByVip(userId, gameId, clientId) # info = {'type': 3, 'checkDay': 2, 'isCheckIn': True, 'checkDate': '2017-06-23'} ftlog.debug("|newcheckin|login|2", userId, gameId, loginsum, clientId) info = gamedata.getGameAttr(userId, HALL_GAMEID, 'checkin_new') if not info: # loginDays = gamedata.getGameAttrInt(userId, HALL_GAMEID, 'loginDays') # if not loginDays: # ftlog.error("newcheckin|user|havenot|loginDays|",userId,gameId,clientId,loginsum) # return # 新用户人生第一次登陆 ftlog.debug("|newcheckin|login|3", userId, gameId, loginsum, clientId) if loginsum == 1: type = NCI_TYPE_3 checkDay = 0 # 0,1,2 3,4,5,6 info = {'type': type, 'checkDay': checkDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, type, checkDay) clientMsg = {'isCheckIn': False, 'checkDay': checkDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("newcheckin|firstreward|newavatar|ok|", userId, info, checkinId, rewards) else: type = NCI_TYPE_7 if isScriptDoGetReward(userId): TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('亲,签到奖励准备中,请玩几把再来领取吧!')) return checkDay = 0 # 0,1,2 3,4,5,6 info = {'type': type, 'checkDay': checkDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, type, checkDay) clientMsg = {'isCheckIn': False, 'checkDay': checkDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("newcheckin|firstreward|oldavatar|ok|", userId, info, checkinId, rewards) else: info = json.loads(info) checkinImpl(userId, info, clientId, gameId, isDisplay, npwId, where)
def processInviteAnswser(self, inviter, answer, userId, gameId): ''' 对邀请游戏的应答 userId - 当前用户 inviter - 邀请者 向邀请者发送回应 ''' uds = userdata.getAttrs(userId, ['name']) response = '' if answer: response = '您的好友 ' + uds[0] + ' 同意了您的游戏邀请' else: response = '您的好友 ' + uds[0] + ' 拒绝了您的游戏邀请' TodoTaskHelper.sendTodoTask(gameId, inviter, TodoTaskPopTip(response))
def _doItemAction(self, gameId, userId, clientId, itemId, params): from hall.entity.hallitem import TYItemActionExchange from poker.entity.dao import sessiondata try: timestamp = pktimestamp.getCurrentTimestamp() userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(itemId) if not item: raise TYItemNotFoundException(itemId) actionName = runcmd.getMsgPack().getParam('action') if ftlog.is_debug(): ftlog.debug('ItemTcpHandler._doItemAction', 'gameId=', gameId, 'userId=', userId, 'clientId=', clientId, 'itemId=', itemId, 'params=', params) action = item.itemKind.findActionByName(actionName) # 3.9以下不支持京东实物 if action and isinstance( action, TYItemActionExchange) and action.isJdActualProduct(): clientIdVer = sessiondata.getClientIdVer(userBag.userId) if clientIdVer < 3.90: self._doItemActionUnsupportedExchange( gameId, userId, clientId, itemId, params) return actionResult = userBag.doAction(gameId, item, actionName, timestamp, params) mo = ItemHelper.makeItemListResponseV3_7(gameId, userId) router.sendToUser(mo, userId) _, cVer, _ = strutil.parseClientId(clientId) if actionResult: if actionResult.todotask and cVer >= 3.90: TodoTaskHelper.sendTodoTask(gameId, userId, actionResult.todotask) elif actionResult.message: if isinstance(actionResult.action, TYItemActionExchange ) and actionResult.action.isWechatRedPack(): mytodo = TodoTaskShowInfo(actionResult.message) else: mytodo = TodoTaskPopTip(actionResult.message) TodoTaskHelper.sendTodoTask(gameId, userId, mytodo) except TYBizException, e: self.handleException(itemId, gameId, userId, clientId, e)
def enterFriendTable(userId, gameId, clientId, ftId): """进入自建桌""" if ftlog.is_debug(): ftlog.debug('hall_friend_table.enterFriendTable userId:', userId, ' pluginId:', gameId, ' clientId:', clientId, ' ftId:', ftId) pluginId = queryFriendTable(ftId) if not pluginId: TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip(ROOM_NOT_EXIST['info'])) responseEnterFriendTable(userId, ROOM_NOT_EXIST) return ftlog.info('hall_friend_table.enterFriendTable userId:', userId, ' lead to pluginId:', pluginId) pluginId = int(pluginId) TYGame(pluginId).enterFriendTable(userId, gameId, clientId, ftId) responseEnterFriendTable(userId, ENTER_FRIEND_OK)
def _doNewVipGift(cls, gameId, userId, level): try: userVip, _giftStates, gotVipGiftResult = hallvip.userVipSystem.gainUserVipGift( gameId, userId, level) ftlog.debug('VipTcpHandler._doNewVipGift userId=', userId, 'gameId=', gameId, 'giftVipLevel=', gotVipGiftResult.vipGiftState.vipLevel.level) giftInfo = VipHelper.buildGiftInfo(userVip, gotVipGiftResult.vipGiftState) getGiftTodoTask = TodoTaskVipGotGift( gotVipGiftResult.vipGiftState.vipLevel.level, gotVipGiftResult.vipGiftState.vipLevel.vipExp, gotVipGiftResult.vipGiftState.vipLevel.name, gotVipGiftResult.vipGiftState.vipLevel.desc, giftInfo) todotasks = [getGiftTodoTask] needGoldRain = TYAssetUtils.getAssetCount( gotVipGiftResult.giftItemList, hallitem.ASSET_CHIP_KIND_ID) > 0 if needGoldRain: todotasks.append( TodoTaskGoldRain( VipHelper.buildGotGiftDesc(gotVipGiftResult))) else: todotasks.append( TodoTaskPopTip( VipHelper.buildGotGiftDesc(gotVipGiftResult))) mo = TodoTaskHelper.sendTodoTask(gameId, userId, todotasks) # 通知客户端变化 if gotVipGiftResult.giftItemList: datachangenotify.sendDataChangeNotify( gameId, userId, TYAssetUtils.getChangeDataNames( gotVipGiftResult.giftItemList)) return mo except TYBizException, e: return cls.sendErrorResponse(userId, 'newvip', e.errorCode, e.message)
def sendPopTipMsg(userId, msg): task = TodoTaskPopTip(msg) task.setParam('duration', 3) mo = TodoTaskHelper.makeTodoTaskMsg(HALL_GAMEID, userId, task) router.sendToUser(mo, userId)
def sendPopTipMsg(userId, msg): task = TodoTaskPopTip(msg) task.setParam('duration', 3) mo = TodoTaskHelper.makeTodoTaskMsg(HALL_GAMEID, userId, task) router.sendToUser(mo, userId)
def sendPopTip(cls, userId, text): todotask = TodoTaskPopTip(text) mo = TodoTaskHelper.makeTodoTaskMsg(DIZHU_GAMEID, userId, todotask) router.sendToUser(mo, userId)
def sendTip(self, activityGameId, userId, tip): todotask = TodoTaskPopTip(tip) mo = TodoTaskHelper.makeTodoTaskMsg(activityGameId, userId, todotask) router.sendToUser(mo, userId)
def checkinImpl(userId, info, clientId, gameId, isDisplay, npwId, where): ftlog.debug("checkinImpl|enter|", userId, info, clientId, gameId) type = info['type'] checkDay = info['checkDay'] checkDate = info['checkDate'] today = datetime.datetime.now().strftime('%Y-%m-%d') if today == info['checkDate']: clientMsg = {'isCheckIn': True, 'checkDay': info['checkDay'], 'checkinId': getCheckinId(clientId)} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("checkinImpl|already|reward|", userId, info, clientId, gameId) return if type == NCI_TYPE_3 and checkDay < 2: ncheckDay = checkDay + 1 info = {'type': type, 'checkDay': ncheckDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, type, ncheckDay) clientMsg = {'isCheckIn': False, 'checkDay': ncheckDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("checkinImpl|3Day|ok|", userId, info, checkinId, rewards) elif type == NCI_TYPE_3 and checkDay == 2: ntype = NCI_TYPE_7 ncheckDay = 0 info = {'type': ntype, 'checkDay': ncheckDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, ntype, ncheckDay) clientMsg = {'isCheckIn': False, 'checkDay': ncheckDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, ntype, clientMsg, isDisplay, npwId, where) ftlog.debug("checkinImpl|7Day|init|ok|", userId, info, checkinId, rewards) elif type == NCI_TYPE_7: if isScriptDoGetReward(userId): TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, TodoTaskPopTip('亲,签到奖励准备中,请玩几把再来领取吧!')) return delta = datetime.timedelta(days=1) checkDate_dt = datetime.datetime.strptime(checkDate, '%Y-%m-%d') add1Day = checkDate_dt + delta add1Day_str = add1Day.strftime('%Y-%m-%d') ftlog.debug("checkinImpl|7day", userId, info, add1Day_str, today) if add1Day_str == today: if checkDay < 6: ncheckDay = checkDay + 1 elif checkDay == 6: ncheckDay = 0 info = {'type': type, 'checkDay': ncheckDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, type, ncheckDay) clientMsg = {'isCheckIn': False, 'checkDay': ncheckDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("checkinImpl|7Day|ok|", userId, info, checkinId, rewards) else: ncheckDay = 0 info = {'type': type, 'checkDay': ncheckDay, 'isCheckIn': True, 'checkDate': datetime.datetime.now().strftime('%Y-%m-%d')} gamedata.setGameAttr(userId, HALL_GAMEID, 'checkin_new', json.dumps(info)) checkinId, rewards = reward(userId, clientId, type, ncheckDay) clientMsg = {'isCheckIn': False, 'checkDay': ncheckDay, 'checkinId': checkinId, 'rewards': rewards} sendMsg2client(gameId, userId, type, clientMsg, isDisplay, npwId, where) ftlog.debug("checkinImpl|7Day|reset|ok|", userId, info, checkinId, rewards)