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 endCLientGame(self, msg): if _DEBUG: debug("In synClientInfo @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('endCLientGame the msg params error !', mi.error) else: #todo 1: add loc 2:客户端上行的第一条end_game消息作为判断依据,对双方结算 room = tyglobal.rooms()[mi.roomId] if room.maptable.has_key(mi.tableId): table = room.maptable.pop(mi.tableId) for userid in table.playersInfo.keys(): mo = MsgPack() mo.setCmd('end_game') mo.setResult('result', 'ok') mo.setResult('gameResult', msg.getParamStr('gameResult')) if _DEBUG: debug("OUT endCLientGame @@@ table_info = ", msg) tyrpcconn.sendToUser(userid, mo) else: pass # mo = MsgPack() # mo.setCmd('end_game') # mo.setResult('result', 'has finished') # mo.setResult('msg', msg) # if _DEBUG: # debug("OUT endCLientGame @@@ table_info = ", msg) # tyrpcconn.sendToUser(mi.userid, mo) return 1
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 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 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 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 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 synClientInfo(self, msg): if _DEBUG: debug("In synClientInfo @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('synClientInfo the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] if _DEBUG: ftlog.debug("IN synClientInfo @@ synClientInfo =", table.playersInfo.keys()) userId_b = 0 for userid in table.playersInfo.keys(): if userid != mi.userId: mo = MsgPack() mo.setCmd('syn_info') mo.setResult('gdata', msg.getParamStr('gdata')) if _DEBUG: debug("OUT synClientInfo @@@ table_info = ", msg) tyrpcconn.sendToUser(userid, mo) userId_b = userid if table._timer == None: table._timer = MiniMatchProcess(7, mi.userId, userId_b, mi.roomId, mi.tableId) table._timer.stop() table._timer.start() return 1
def notifyMatchCancelled(self, signer, reason): """ 通知用户比赛由于reason取消了 """ try: ftlog.info('PokerMatchPlayerNotifier.notifyMatchCancelled', 'userId=', signer.userId, 'reason=', reason) userId = signer.userId # TODO 确认用户已经上线 player = self.room.matchArea.findPlayer(userId) if player and player.isQuit: return self.notifyMatchSignsUpdate(userId) msg = MsgPack() msg.setCmd('match') msg.setResult('action', 'cancel') msg.setResult('gameId', self.room.gameId) msg.setResult('roomId', self.room.bigRoomId) msg.setResult('reason', reason) msg.setResult('info', MatchFinishReason.toString(reason)) tyrpcconn.sendToUser(msg, userId) except: ftlog.error('PokerMatchPlayerNotifier.notifyMatchCancelled', 'userId=', signer.userId, 'instId=', signer.instId, 'reason=', reason)
def __do_answer_again_game_message(self, user_id, target_user_id, code, message_id): resp = MsgPack() resp.setCmd('chat') resp.setResult('action', 'answer_again_game_push') resp.setResult('userId', user_id) resp.setResult('targetUserId', target_user_id) resp.setResult('code', code) resp.setResult('msgId', message_id) tyrpcconn.sendToUser(target_user_id, resp)
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 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 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 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 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 getHallGameManager(userId, intClientId, apiVersion): ipstr = sessiondata.getClientIp(userId) location = getIpLocation(ipstr) mo = MsgPack() mo.setCmd('hall_gamelist5') mo.setKey('apiVersion', apiVersion) mo.setResult('action', "get") mo.setResult('gameId', HALL_GAMEID) mo.setResult('intClientId', intClientId) mo.setResult('userId', userId) mo.setResult('gamelist', _getListGames(userId, intClientId, location)) tyrpcconn.sendToUser(userId, mo)
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 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 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 quitCLientGame(self, msg): if _DEBUG: debug("In quitCLientGame @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('quitCLientGame the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] loserId = 0 winnerId =0 if room.maptable.has_key(mi.tableId): table = room.maptable.pop(mi.tableId) for userid in table.playersInfo.keys(): if userid == mi.userId: loserId = userid else: winnerId = userid mo = MsgPack() mo.setCmd('table/quit_game') mo.setResult('winnerId', self.winnerId) mo.setResult('userId_a', self.loserId) mo.setResult('userId_b', self.winnerId) mo.setResult('table_msgId', table.tableMsgId) if _DEBUG: debug("OUT quitCLientGame @@@ winnerId = ", winnerId) tyrpcconn.sendToUser(winnerId, mo) tyrpcconn.sendToUser(loserId, mo) else: pass return 1
def _sendMatchDataResponse(userId, gameId, intClientId, apiVersion): """ 仅发送match_data命令, USER的我的比赛数据至客户端 """ mo = MsgPack() mo.setCmd('match_data5') mo.setResult('action', 'list') mo.setKey('apiVersion', apiVersion) mo.setResult('intClientId', intClientId) mo.setResult('gameId', gameId) mo.setResult('userId', userId) match_history_list = _dao.loadHistoryRecord(userId) match_sigin_list = _dao.loadSiginRecord(userId) if _DEBUG: if len(match_history_list) == 0: match_history_list = [{ "gameId": 6, "roomList": [6666, 6888] }, { "gameId": 701, "roomList": [701230, 701250] }] debug('_sendMatchDataResponse OUT match_history_list=', match_history_list, 'match_sigin_list=', match_sigin_list) mock_match_list = { "historyList": match_history_list, "signinList": match_sigin_list } mo.setResult('matchData', mock_match_list) if _DEBUG: debug('_sendMatchDataResponse OUT userId=', userId, 'Msg=', mo) tyrpcconn.sendToUser(userId, mo)
def _notifyMatchRank(self, player): msg = MsgPack() msg.setCmd('match') msg.setResult('action', 'rank') msg.setResult('gameId', self.room.gameId) msg.setResult('roomId', self.room.bigRoomId) ranktops = [] # 首位添加自己的排名信息 ranktops.append({ 'userId': player.userId, 'name': player.userName, 'score': player.score, 'rank': player.rank }) # 添加TOP10信息 for i, p in enumerate(player.group.rankList[0:10]): ranktops.append({ 'userId': p.userId, 'name': p.userName, 'score': p.score, 'rank': i + 1 }) # TODO 自己在Top10中需要处理 msg.setResult('mranks', ranktops) tyrpcconn.sendToUser(msg, player.userId)
def doExchangeRequestCmd(self, msg): mo = MsgPack() mo.setCmd('exchange5') mo.setResult('action', 'exchange') mi = self.checkExchange.check(msg) if mi.error: mo.setError(1, mi.error) else: exchangeId, errMsg = _exchange.doExchangeRequest(mi.userId, mi) mo.setResult('exchangeId', exchangeId) if errMsg: mo.setError(1, errMsg) tyrpcconn.sendToUser(mi.userId, mo) return 1
def _onTimeout(self, lostUserId): if _DEBUG: debug("In MiniMatchProcess @@@@ onTimeOut, lostUserId = ", lostUserId) room = tyglobal.rooms()[self._roomId] if room.maptable.has_key(self.tableId): room.maptable.pop(self.tableId) if lostUserId == self.userId_a: self.winnerId = self.userId_b mo = MsgPack() mo.setCmd('game_finish_result') mo.setResult('result', 'other player lost internet') mo.setResult('winnerId', self.winnerId) if _DEBUG: debug("OUT game_finish_result @@@ winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, mo) else: self.winnerId = self.userId_a mo = MsgPack() mo.setCmd('game_finish_result') mo.setResult('result', 'other player lost internet') mo.setResult('winnerId', self.winnerId) if _DEBUG: debug("OUT game_finish_result @@@ self.winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, 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
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