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 answer_again_game(self, msg): """ 再来一局应答. :param msg: userId,targetUserId,miniGameId :return: msgId,ok """ debug("ChatGameSrv answer_again_game", msg) user_id = msg.getParamInt('userId') target_user_id = msg.getParamInt('targetUserId') msg_id = msg.getParamStr('msgId') code = msg.getParamStr('code') resp = MsgPack() resp.setCmd('chat') resp.setResult('action', 'answer_again_game') try: self.clean_channel(user_id,target_user_id) info = self.service.get_record(msg_id) if info: game_message = GameChatMessage.load_info(info) game_message.code = code self.service.save_record(user_id, target_user_id, msg_id, game_message) ftcore.runOnceDelay(0.1, self.__do_answer_again_game_message, user_id, target_user_id, code, msg_id) push_game_message(user_id, target_user_id, msg_id, game_message) resp.setResult('msgId', msg_id) resp.setResult('userId', user_id) resp.setResult('targetUserId', target_user_id) resp.setResult('status', 'ok') else: resp.setResult('status', 'error msgId') except TYBizException, e: resp.setResult('status', 'error') resp.setError(e.errorCode, e.message)
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 doHappyBagList(self, msg): if _DEBUG: debug('doHappyBagList IN->', msg) mi = hallchecker.CHECK_BASE.check(msg) mo = MsgPack() mo.setCmd('happybag5') mo.setResult('action', 'list') if mi.error: mo.setError(1, mi.error) else: userTaskUnit = self.loadUserTaskUnit(mi.userId, mi.clientId) taskList = _ui.encodeUserTaskList(userTaskUnit) mo.setResult('tasks', taskList) tyrpcconn.sendToUser(mi.userId, mo) # 记录BI统计,仅为数据统计 if not mi.error: flg = pluginCross.hallday1st.getHappyBagFlg(mi.userId) if flg == 0: pluginCross.hallday1st.setHappyBagFlg(mi.userId) tybireport.reportGameSimpleEvent('HAPPY_BAG_TASK_LIST', mi.userId, mi.gameId, mi.clientId) if _DEBUG: debug('doHappyBagList OUT', mo) return 1
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 doWeiXinShare(self, msg): ''' 客户端通知服务器,完成了一次微信分享 ''' mi = hallchecker.CHECK_BASE.check(msg) if _DEBUG: debug('doWeiXinShare IN->', mi) mo = MsgPack() mo.setCmd('share5') mo.setResult('action', 'weixin') if mi.error: mo.setError(1, mi.error) else: event = tygame.WeiXinSharedEvent(mi.userId, mi.gameId) typlugin.syncTrigerEvent(event) mo.setResult('ok', 1) if mi.hasUserId: tyrpcconn.sendToUser(mi.userId, mo) if _DEBUG: debug('doWeiXinShare OUT') return 1
def doStoreBuy(self, request): mo = MsgPack() mi = self.checkStoreBuy.check(request) if mi.error: mo.setError(1, mi.error) else: clientId = tysessiondata.getClientId(mi.userId) orderId = ftstr.uuid() params = { 'appId': tyglobal.gameId(), 'realGameId': tyglobal.gameId(), 'clientId': clientId, 'userId': mi.userId, 'prodId': mi.productId, 'prodCount': mi.count, 'prodOrderId': orderId, '_test_': 1, } url = tyglobal.httpGame( ) + '/api/hall5/store/consume/transaction?' + ftstr.toHttpStr( params) _, ret = fthttp.queryHttp('GET', url, None, None, 5) if ret != 'ok': mo.setError(1, ret) else: mo.setResult('ok', 1) return mo
def _do_match__signin(self, msg): """ 比赛报名协议监听器. 调用赛区进行报名,成功返回roomId,userId;失败返回ec信息 :param msg: tcp消息 """ userId = msg.getParam('userId') feeIndex = msg.getParam('fee', 0) signinParams = msg.getParam('signinParams', {}) ftlog.info('StageMatchRoomMixin._do_match__signin roomId=', self.roomId, 'userId=', userId) # if not signinParams and tyglobal.enableTestHtml(): # signinParams = gamedata.getGameAttrJson(userId, self.gameId, 'test.signinParams') resp = MsgPack() resp.setCmd('match') resp.setResult('action', 'signin') resp.setResult('roomId', self.bigRoomId) resp.setResult('userId', userId) resp.setResult('gameId', self.gameId) try: self.matchArea.signin(userId, feeIndex, signinParams) resp.setResult('ok', 1) PokerMatchReport.reportMatchEvent('MATCH_SIGN_UP', userId, self.gameId, self.matchId, 0, 0, 0) except TYBizException, e: ftlog.info('StageMatchRoomMixin._do_match__signin Exception=', e) resp.setResult('ok', 0) resp.setError(e.errorCode, e.message)
def setRedPointRead(self, msg): ''' 客户端通知:某一个项目已经被看过了,消除对应的小红点标记 ''' if _DEBUG: debug('HallPluginRedPoint.setRedPointRead IN', msg) mi = self.checkRead.check(msg) mo = MsgPack() mo.setCmd('redpoint5') mo.setResult('action', 'read') if mi.error: mo.setError(1, mi.error) else: # 设置已读数据 changed = self.redPointSys.readPoint(mi.userId, mi.moduleId, mi.itemId) if changed: self._sendRedPointNotify(mi.userId) mo.setResult('moduleId', mi.moduleId) mo.setResult('itemId', mi.itemId) if mi.hasUserId: tyrpcconn.sendToUser(mi.userId, mo) if _DEBUG: debug('HallPluginRedPoint.setRedPointRead OUT') return 1
def doStoreQueryUi(self, msg): ''' 查询商城界面列表配置信息 ''' mo = MsgPack() mo.setCmd('store5') mo.setResult('action', 'ui') mi = hallchecker.CHECK_BASE.check(msg) if mi.error: mo.setError(1, mi.error) else: filteredList = self.storeSystem.getShelvesListByClientId( mi.clientId) tabs = [] for shelf in filteredList: tabs.append({ 'name': shelf.name, 'displayName': shelf.displayName, 'items': shelf.productIdList }) mo.setResult('tabs', tabs) tyrpcconn.sendToUser(mi.userId, mo) return 1
def getExchangeHistory(self, msg): mo = MsgPack() mo.setCmd('exchange5') mo.setResult('action', 'history') mi = hallchecker.CHECK_BASE.check(msg) if mi.error: mo.setError(1, mi.error) else: orders = [] exchangeIds = _dao.getReordKeys(mi.userId) exchangeIds.sort(reverse=True) for exchangeId in exchangeIds: order = _dao.loadRecord(mi.userId, exchangeId) orders.append([ exchangeId, # 兑换ID fttime.formatTimeSecond( datetime.fromtimestamp(order.createTime)), # 兑换时间 order.state, # 兑换状态 order.params[ 'type'], # 兑换类型 0-手机充值卡 1-手工兑换 2-比赛等线下邀请函、门票等 3-京东卡 4-未使用 5-微信红包 6-京东实物 99-金币 order.params['displayName'], # 兑换物品名称 order.params['uName'], # 昵称 order.params['phone'], # 电话 order.params.get('jdAddres', []), # 京东收货地址数组 [1级,2级,3级,4级,输入地址] order.extOrderId, # 京东实物交易单号 order.extCardId, # 京东卡卡号 order.extCardPwd, # 京东卡卡密 ]) mo.setResult('userId', mi.userId) mo.setResult('orders', orders) tyrpcconn.sendToUser(mi.userId, mo) return 1
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 doGdssListItem(self, request): mo = MsgPack() mi = self.checkHttpGdss.check(request) if mi.error: mo.setError(1, mi.error) else: mo.setResult('items', hallRpcRandom.hallitem._gdssListItem().getResult()) return mo
def doHappyBagList(self, request): mo = MsgPack() mi = self.checkHttpUser.check(request) if mi.error: mo.setError(1, mi.error) else: clientId = tysessiondata.getClientId(mi.userId) tasks = hallRpcOne.halltaskhappybag._doHappyBagListFull(mi.userId, clientId).getResult() mo.setResult('tasks', tasks) return mo
def doHttpUserItemAddAll(self, request): mo = MsgPack() mi = self.checkHttpUser.check(request) if mi.error: mo.setError(1, mi.error) else: result = hallRpcOne.hallitem.addAllItem(mi.userId, HALL_GAMEID, "GM_ADJUST").getResult() mo.setKey('result', result) return mo
def doGdssListUserItem(self, request): mo = MsgPack() mi = self.checkHttpUser.check(request) if mi.error: mo.setError(1, mi.error) else: result = hallRpcOne.hallitem._gdssListUserItem( mi.userId).getResult() mo.setResult('items', result) return mo
def doStoreSuccess(self, request): mo = MsgPack() mi = self.checkStoreAction.check(request) if mi.error: mo.setError(1, mi.error) else: clientId = tysessiondata.getClientId(mi.userId) if mi.buyType == '1': # 钻石 chargedRmbs = 0 chargedDiamonds = 0 consumeCoin = mi.price else: chargedRmbs = mi.price chargedDiamonds = mi.count * mi.prodDiamond consumeCoin = 0 params = { 'userId': mi.userId, 'appId': tyglobal.gameId(), 'realGameId': tyglobal.gameId(), 'clientId': clientId, 'prodOrderId': mi.orderId, 'prodId': mi.productId, 'prodCount': 1, 'chargeType': 'tester', 'chargedRmbs': chargedRmbs, 'chargedDiamonds': chargedDiamonds, 'consumeCoin': consumeCoin, '_test_': 1, } url = tyglobal.httpGame( ) + '/api/hall5/store/consume/delivery?' + ftstr.toHttpStr(params) _, ret = fthttp.queryHttp('GET', url, None, None, 5) if ret != 'success': mo.setError(1, ret) else: mo.setResult('ok', 1) if chargedRmbs > 0 or chargedDiamonds > 0: params = { 'appId': tyglobal.gameId(), 'clientId': clientId, 'userId': mi.userId, 'realGameId': tyglobal.gameId(), 'prodId': mi.productId, 'chargedRmbs': chargedRmbs, 'chargedDiamonds': chargedDiamonds, '_test_': 1, } url = tyglobal.httpGame( ) + '/api/hall5/store/consume/notify?' + ftstr.toHttpStr( params) ret = fthttp.queryHttp('GET', url, None, None, 5) return mo
def doStoreQuery(self, request): mo = MsgPack() mi = self.checkStoreUser.check(request) if mi.error: mo.setError(1, mi.error) else: clientId = tysessiondata.getClientId(mi.userId) datas = hallRpcOne.hallstore._doStoreQueryUi(mi.userId, clientId).getResult() mo.updateResult(datas) return mo
def doExchangeAddrList(self, request): userId = request.getParamInt('userId') proviceId = request.getParamStr('proviceId') cityId = request.getParamStr('cityId') countyId = request.getParamStr('countyId') mo = MsgPack() try: address = hallRpcOne.hallexchange._doGetJdAddressList( userId, proviceId, cityId, countyId).getResult() mo.setResult('address', address) except Exception, e: mo.setError(1, str(e))
def doExchangeLedCmd(self, msg): mo = MsgPack() mo.setCmd('exchange5') mo.setResult('action', 'led') mi = hallchecker.CHECK_BASE.check(msg) if mi.error: mo.setError(1, mi.error) else: leds = _dao.loadLedList() mo.setResult('leds', leds) tyrpcconn.sendToUser(mi.userId, mo) return 1
def doDelete(self, request): mo = MsgPack() mi = self.checkExchange.check(request) if mi.error: mo.setError(1, mi.error) else: try: hallRpcOne.hallexchange._doDelete(mi.userId, mi.exchangeId).getResult() mo.setResult('ok', 1) except Exception, e: mo.setError(1, str(e))
def doHappyBagRemoveAll(self, request): mo = MsgPack() mi = self.checkHttpUser.check(request) if mi.error: mo.setError(1, mi.error) else: ret = hallRpcOne.halltaskhappybag._doRemoveAll(mi.userId).getResult() if ret == 'ok': mo.setResult('ok', 1) else: mo.setError(1, ret) return mo
def talk_message1(self, msg): """ 聊天消息. :param msg: userId,targetUserId,msgType,content,cid :return: msgId,ok """ debug("ChatSrv talk_message", msg) user_id = msg.getParamInt('userId') target_user_id = msg.getParamInt('targetUserId') msg_type = msg.getParamInt('msgType') content = msg.getParamStr('content') #客户端消息序号 sn = msg.getParamStr('sn') is_friend = _check_friend(user_id,target_user_id) debug("ChatSrv talk_message", user_id, target_user_id, msg_type, content, sn, is_friend) resp = MsgPack() resp.setCmd('chat') resp.setResult('action', 'send_message') try: msg_id, content, now = self.do_verify(msg) channel_key = _get_channel_key(user_id, target_user_id) if not is_friend and channel_key not in self.channels : # 临时会话已关闭,不允许发送消息 resp.setResult("status", "notFriend") else: obj = ftstr.loads(content) game_code = obj.get("code", "") if game_code == "" or game_code == "invite": info = { "time": now, "userId": user_id, "targetUserId": target_user_id, "msgType": msg_type, "content": content } else: # 游戏更新不更改初始来源 info = { "time": now, "userId": target_user_id, "targetUserId": user_id, "msgType": msg_type, "content": content } self.write(user_id,target_user_id,msg_id,info) self.service.save_record(user_id, target_user_id, msg_id, info) resp.setResult('sn', sn) resp.setResult('time', now) resp.setResult('msgId', msg_id) resp.setResult('status', "ok") except TYBizException, e: resp.setResult("status", "error") resp.setError(e.errorCode, e.message)
def doHttpUserItemAction(self, request): mo = MsgPack() mi = self.checkHttpDoAction.check(request) if mi.error: mo.setError(1, mi.error) else: params = request.getDict() result = hallRpcOne.hallitem.doActionByItemId( mi.userId, mi.gameId, mi.itemId, mi.action, fttime.getCurrentTimestamp(), params).getResult() mo.setKey('result', result) return mo
def doExchangeQueryUiTabs(self, msg): mo = MsgPack() mo.setCmd('exchange5') mo.setResult('action', 'ui_tabs') mi = hallchecker.CHECK_BASE.check(msg) if mi.error: mo.setError(1, mi.error) else: bannerIds, tabIds = _conf.getExchangeQueryUiTabs(mi.clientId) mo.setResult('banners', bannerIds) mo.setResult('tabs', tabIds) tyrpcconn.sendToUser(mi.userId, mo) return 1
def doHttpUserItemCreateTime(self, request): mo = MsgPack() mi = self.checkHttpSetCreateTime.check(request) if mi.error: mo.setError(1, mi.error) else: ec, msg = hallRpcOne.hallitem.setItemCreateTime( mi.userId, mi.itemId, mi.createTime).getResult() if ec: mo.setError(ec, msg) else: mo.setResult('ok', msg) return mo
def doStoreDelete(self, request): mo = MsgPack() mi = self.checkStoreActionDel.check(request) if mi.error: mo.setError(1, mi.error) else: ret = hallRpcOne.hallstore._doDelete(mi.userId, mi.orderId).getResult() if ret == 'ok': mo.setResult('ok', 1) else: mo.setError(1, ret) return mo
def doConsumeTransactionHttp(self, request): """ 购买流程之一:client请求sdk,sdk调用游戏服,游戏服检查商品有效性并存储订单信息 成功返回:标准MsgPack,需要result中有相同的prodOrderId """ ftlog.info('doConsumeTransactionHttp IN->', request.getDict()) mo = MsgPack() mo.setCmd('buy_prod5') mi = self.checkTransactionStart.check(request) if mi.error: mo.setError(1, str(mi.error)) else: try: rfc = hallRpcOne.hallstore.doConsumeTransaction( mi.userId, mi.appId, mi.realGameId, mi.clientId, mi.prodOrderId, mi.prodId, mi.prodCount) if rfc.getException(): mo.setError(2, str(rfc.getException())) else: result = rfc.getResult() if result != 'ok': mo.setError(3, str(result)) else: mo.setResult('appId', mi.appId) mo.setResult('userId', mi.userId) mo.setResult('prodId', mi.prodId) mo.setResult('prodCount', mi.prodCount) mo.setResult('prodOrderId', mi.prodOrderId) except Exception, e: ftlog.error() mo.setError(4, str(e))
def doHappyBagSetUpdateTime(self, request): mo = MsgPack() mi = self.checkHttpTaskUpTime.check(request) if mi.error: mo.setError(1, mi.error) else: ret = hallRpcOne.halltaskhappybag._setUpdateTime(mi.userId, mi.taskId, mi.updateTime).getResult() if ret == 'ok': mo.setResult('ok', 1) else: mo.setError(1, ret) return mo
def doHappyBagFinish(self, request): mo = MsgPack() mi = self.checkHttpTaskAction.check(request) if mi.error: mo.setError(1, mi.error) else: ret = hallRpcOne.halltaskhappybag._setProgress(mi.userId, mi.taskId, -1).getResult() if ret == 'ok': mo.setResult('ok', 1) else: mo.setError(1, ret) return mo