Example #1
0
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)
Example #2
0
 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
Example #3
0
    def doCheckBigMatchQueueTimeOut(cls):
        if _DEBUG:
            ftlog.info("doCheckBigMatchQueueTimeOut")

        now_time = int(time.time())

        female_KeyStr = cls._getMatchQueueFemaleKeyHash()
        datas_female = cls._ftredis.executeClusterCmd(cls.DBNAME, 0,
                                                      'smembers',
                                                      female_KeyStr)

        if len(datas_female) >= 1:
            for user_str in datas_female:
                split_str = user_str.rsplit(":", 3)
                userId = int(split_str[0])
                join_time = int(split_str[2])
                if abs(now_time - join_time) >= BIG_GAME_QUEUE_TIMEOUT:
                    result = cls._ftredis.executeClusterCmd(
                        cls.DBNAME, 0, 'srem', female_KeyStr, user_str)
                    if _DEBUG:
                        debug(
                            "IN doCheckBigMatchQueueTimeOut @@ after srem @@ female_KeyStr = ",
                            female_KeyStr, " user_str = ", user_str,
                            " result = ", result)
                    mo = MsgPack()
                    mo.setCmd('big_gamequeue_timeout')
                    mo.setResult('userId', userId)
                    mo.setResult('result', 'ok')
                    tyrpcconn.sendToUser(userId, mo)

        male_KeyStr = cls._getMatchQueueMaleKeyHash()
        datas_male = cls._ftredis.executeClusterCmd(cls.DBNAME, 0, 'smembers',
                                                    male_KeyStr)

        if len(datas_male) >= 1:
            for user_str in datas_male:
                split_str = user_str.rsplit(":", 3)
                userId = int(split_str[0])
                join_time = int(split_str[2])
                if abs(now_time - join_time) >= BIG_GAME_QUEUE_TIMEOUT:
                    result = cls._ftredis.executeClusterCmd(
                        cls.DBNAME, 0, 'srem', female_KeyStr, user_str)
                    if _DEBUG:
                        debug(
                            "IN doCheckBigMatchQueueTimeOut @@ after srem @@ female_KeyStr = ",
                            female_KeyStr, " user_str = ", user_str,
                            " result = ", result)
                    mo = MsgPack()
                    mo.setCmd('big_gamequeue_timeout')
                    mo.setResult('userId', userId)
                    mo.setResult('result', 'ok')
                    tyrpcconn.sendToUser(userId, mo)
Example #4
0
 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
Example #5
0
def _sendUserInfoResponse(userId, gameId, intClientId, apiVersion):
    '''
    仅发送user_info命令, USER的主账户信息和游戏账户信息至客户端
    '''
    udatas = pluginCross.halldata.getUserDataDict(userId, USERATTS)
    mo = MsgPack()
    mo.setCmd('user_info5')
    mo.setKey('apiVersion', apiVersion)
    mo.setResult('intClientId', intClientId)
    mo.setResult('gameId', gameId)
    mo.setResult('userId', userId)
    mo.setResult('udata', udatas)
    tyrpcconn.sendToUser(userId, mo)
Example #6
0
 def sync_server_time(self, msg):
     """
     同步某些指定messageID的消息.
     """
     debug("ChatListSrv : sync_server_time : msg = ", msg)
     user_id = msg.getParamInt('userId')
     resp = MsgPack()
     resp.setCmd('chat')
     resp.setResult('action', 'sync_server_time')
     #TODO 切换到redis时间
     now = current_milli_time()
     resp.setResult('serverTime', now)
     resp.setResult('status', "ok")
     tyrpcconn.sendToUser(user_id, resp)
Example #7
0
 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
Example #8
0
 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
Example #9
0
def _sendSetUserInfoResponse(userId, gameId, intClientId, apiVersion, retCode):
    mo = MsgPack()
    mo.setCmd('user5')
    mo.setKey('apiVersion', apiVersion)
    mo.setResult('action', 'setinfo')
    if retCode == 0:
        mo.setResult('ok', 1)
    else:
        mo.setError(1, '设置失败')

    tyrpcconn.sendToUser(userId, mo)

    if retCode == 0:
        _sendUserInfoResponse(userId, gameId, intClientId, apiVersion)
Example #10
0
 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
Example #11
0
def _sendGameDataResponse(userId, gameId, intClientId, apiVersion):
    '''
    仅发送game_data命令, USER的大厅游戏数据至客户端
    '''
    gdatas = pluginCross.halldata.getUserDataDict(userId, GAMEATTS)
    gdatas['vipInfo'] = pluginCross.hallvip.getVipInfo(userId)
    mo = MsgPack()
    mo.setCmd('game_data5')
    mo.setKey('apiVersion', apiVersion)
    mo.setResult('intClientId', intClientId)
    mo.setResult('gameId', gameId)
    mo.setResult('userId', userId)
    mo.setResult('gdata', gdatas)
    tyrpcconn.sendToUser(userId, mo)
    return gdatas[UserKeys.ATT_CHIP], gdatas[UserKeys.ATT_COUPON]
Example #12
0
def delHallGameManager(userId, intClientId, apiVersion, gameIds):
    mo = MsgPack()
    mo.setCmd('hall_gamelist5')
    mo.setKey('apiVersion', apiVersion)
    mo.setResult('action', "del")
    mo.setResult('gameId', HALL_GAMEID)
    mo.setResult('intClientId', intClientId)
    mo.setResult('userId', userId)
    code = _delGames(userId, gameIds)
    if code != 1:
        mo.setResult('ok', 0)
        mo.setError(code, "")
    else:
        mo.setResult('ok', 1)
    tyrpcconn.sendToUser(userId, mo)
Example #13
0
 def doGetJdAddressInfo(self, msg):
     mo = MsgPack()
     mo.setCmd('exchange5')
     mo.setResult('action', 'jdaddress')
     mi = self.checkJdAddr.check(msg)
     if mi.error:
         mo.setError(1, mi.error)
     else:
         address = _addr.getJdAddress(mi.proviceId, mi.cityId, mi.countyId)
         mo.setResult('proviceId', mi.proviceId)
         mo.setResult('cityId', mi.cityId)
         mo.setResult('countyId', mi.countyId)
         mo.setResult('address', address)
     tyrpcconn.sendToUser(mi.userId, mo)
     return 1
Example #14
0
def doRoomList(userId, gameId, playMode):
    # 金币卓
    room_infos = room_list.fetchAllRoomInfos(userId, gameId, playMode)
    # 比赛
    match_infos = room_list.fetchAllMatchInfos(userId, gameId, playMode)

    mo = MsgPack()
    mo.setCmd('room_list')
    mo.setResult('gameId', gameId)
    mo.setResult('baseUrl', 'http://www.tuyoo.com/')
    mo.setResult('play_mode', playMode)
    mo.setResult('rooms', room_infos)
    mo.setResult('match', match_infos)
    mo.setResult('friend', [])
    tyrpcconn.sendToUser(userId, mo)
Example #15
0
def createNewTable(userId_A, userId_B):
    for roomId, roomIns in tyglobal.rooms().items():
        if _DEBUG:
            debug("In createNewTable @@@@ roomId = ", roomId, " roomIns = ",
                  roomIns, " userId_A = ", userId_A, " userId_B = ", userId_B)
        global tableId
        if not roomIns.maptable:
            baseid = roomId * 10000 + 1
            tableId = baseid
        if tableId >= roomId * 10000 + 9999:
            tableId = roomId * 10000 + 1
        tableId += 1
        tblIns = TYTable(roomIns, tableId)
        roomIns.maptable[tableId] = tblIns
        table_Info = {}
        for userId in [userId_A, userId_B]:
            name, purl, sex, addr, citycode = _rpc_user_info.getUserBaseInfo(
                userId)
            table_Info[userId] = (name, purl, sex, addr, citycode)

        tblIns.playersInfo = table_Info

        time_seed = fttime.getCurrentTimestamp()

        mo = MsgPack()
        mo.setCmd('start_game')
        mo.setResult('gameId', tyglobal.gameId())
        mo.setResult('roomId', tblIns.roomId)
        mo.setResult('tableId', tblIns.tableId)
        mo.setResult('seatId', 1)
        mo.setResult('time_seed', time_seed)
        mo.setResult('table_info', table_Info)
        if _DEBUG:
            debug("OUT createNewTable  @@@ table_info = ", table_Info)
        tyrpcconn.sendToUser(userId_A, mo)

        mo = MsgPack()
        mo.setCmd('start_game')
        mo.setResult('gameId', tyglobal.gameId())
        mo.setResult('roomId', tblIns.roomId)
        mo.setResult('tableId', tblIns.tableId)
        mo.setResult('seatId', 2)
        mo.setResult('time_seed', time_seed)
        mo.setResult('table_info', table_Info)
        if _DEBUG:
            debug("OUT createNewTable  @@@ table_info = ", table_Info)
        tyrpcconn.sendToUser(userId_B, mo)
        break
Example #16
0
 def _doMatchState(self, userId, gameId, roomId, match_id):
     '''
     获取比赛状态
     '''
     if match_id:  # 老比赛,由于前端新比赛也会发此消息,但没有match_id导致的问题,这里处理下
         state = tyglobal.rooms()[roomId].getMatchState(
             userId, gameId, match_id)
         current_ts = int(time.time())
         msg = MsgPack()
         msg.setCmd('match_state')
         msg.setResult('gameId', gameId)
         msg.setResult('userId', userId)
         msg.setResult('state', state)
         msg.setResult('match_id', match_id)
         msg.setResult('current_ts', current_ts)
         tyrpcconn.sendToUser(userId, msg)
Example #17
0
 def change_game(self, msg):
     """
     换个游戏.
     :param msg: userId,targetUserId,messageId
     :return: msgId,ok
     """
     debug("ChatGameSrv change_game", msg)
     user_id = msg.getParamInt('userId')
     target_user_id = msg.getParamInt('targetUserId')
     self.clean_channel(user_id, target_user_id)
     resp = MsgPack()
     resp.setCmd('chat')
     resp.setResult('action', 'change_game')
     resp.setResult('userId', user_id)
     resp.setResult('targetUserId', target_user_id)
     tyrpcconn.sendToUser(target_user_id, resp)
Example #18
0
 def _sendQuickStartRes(self,
                        gameId,
                        userId,
                        reason,
                        roomId=0,
                        tableId=0,
                        info=""):
     mp = MsgPack()
     mp.setCmd('quick_start')
     mp.setResult('info', info)
     mp.setResult('userId', userId)
     mp.setResult('gameId', gameId)
     mp.setResult('roomId', roomId)
     mp.setResult('tableId', tableId)
     mp.setResult('reason', reason)
     tyrpcconn.sendToUser(mp, userId)
Example #19
0
 def __do_leave_game_message(self, user_id, target_user_id):
     """
     清理多余的游戏邀请.
     """
     now = current_milli_time()
     before = now - LIFE_CYCLE*60*1000
     message_ids = self.service.do_leave_chat_record(user_id,target_user_id,before)
     resp = MsgPack()
     resp.setCmd('chat')
     resp.setResult('action', 'leave_game_message')
     resp.setResult('uid1', user_id)
     resp.setResult('uid2', target_user_id)
     resp.setResult('messageIds', message_ids)
     debug("ChatSrv __do_leave_game_message", user_id, target_user_id,resp)
     tyrpcconn.sendToUser(user_id, resp)
     tyrpcconn.sendToUser(target_user_id, resp)
Example #20
0
 def doCheckJdAddressInfo(self, msg):
     mo = MsgPack()
     mo.setCmd('exchange5')
     mo.setResult('action', 'checkjdaddress')
     mi = self.checkJdAddr.check(msg)
     if mi.error:
         mo.setError(1, mi.error)
     else:
         isOk = _addr.checkJdAddress(mi.proviceId, mi.cityId, mi.countyId,
                                     mi.townId)
         if isOk:
             mo.setResult('ok', 1)
         else:
             mo.setError(1, 'check false')
     tyrpcconn.sendToUser(mi.userId, mo)
     return 1
Example #21
0
def notifyMsg(userId, gameId, roomId, data, config, ratio):
    '''
    通知客户端
    '''
    mp = MsgPack()
    mp.setCmd('game')
    mp.setResult('action', 'loopWinTimesTask')
    mp.setResult('gameId', gameId)
    mp.setResult('roomId', roomId)
    mp.setResult('userId', userId)
    mp.setResult(ROUND_COUNT, config.get(ROUND_COUNT))
    mp.setResult(WINTIMES, data[WINTIMES])
    mp.setResult('prize', getTreasureTableTip(gameId, roomId))
    awardItems = config['reward']['items'] if 'reward' in config and 'items' in config['reward'] else None
    mp.setResult('awardItems', awardItems)
    tyrpcconn.sendToUser(userId, mp)
Example #22
0
 def _sendDesc(self, userId):
     resp = MsgPack()
     resp.setCmd('match')
     resp.setResult('action', 'desc')
     resp.setResult('roomId', self.bigRoomId)
     resp.setResult('gameId', self.gameId)
     resp.setResult('userId', userId)
     signinCount = self.matchArea.getTotalSignerCount()  # 房间实时报名人数
     resp.setResult('signinCount', signinCount)
     matchDef = _buildMatchDesc(self.conf)
     resp.updateResult(matchDef)  # 比赛配置
     record = MatchRecordDaoRedis.loadRecord(self.gameId, userId,
                                             self.bigRoomId)
     if record:
         ret = MatchRecordDaoRedis.loadHistory(self.gameId, userId,
                                               self.bigRoomId)
         # ret = [ {"time":_["time"],"desc":"第%s名,获得%s" % (_["rank"],_["desc"]),"rank":_["rank"],"info":_["desc"] }
         #         for _ in ret]
         ret = map(
             lambda _: {
                 "time": _["time"],
                 "desc": "第%s名" % (_["rank"], ),
                 "rank": _["rank"],
                 "info": _["desc"]
             } if _["desc"] == "" else {
                 "time": _["time"],
                 "desc": "第%s名,获得%s" % (_["rank"], _["desc"]),
                 "rank": _["rank"],
                 "info": _["desc"]
             }, ret)
         histories = {
             "crownCount": record.crownCount,
             "playCount": record.playCount,
             "bestRank": record.bestRank,
             "bestRankDate": record.bestRankDate,
             "records": ret
         }
     else:
         histories = {
             "crownCount": 0,
             "playCount": 0,
             "bestRank": 0,
             "bestRankDate": 0,
             "records": []
         }
     resp.setResult('histories', histories)
     tyrpcconn.sendToUser(resp, userId)
Example #23
0
 def doExchangeQueryUiItems(self, msg):
     mo = MsgPack()
     mo.setCmd('exchange5')
     mo.setResult('action', 'ui_items')
     mi = self.checkUi.check(msg)
     if mi.error:
         mo.setError(1, mi.error)
     else:
         items = _conf.getExchangeQueryUiItems(mi.tabName, mi.pageNum,
                                               mi.clientId)
         counts = _counts.getItemCounts(items)
         mo.setResult('tabName', mi.tabName)
         mo.setResult('pageNum', mi.pageNum)
         mo.setResult('items', items)
         mo.setResult('counts', counts)
     tyrpcconn.sendToUser(mi.userId, mo)
     return 1
Example #24
0
    def doStoreQueryUserHistory(self, msg):
        '''
        查询个人的商城充值、金币兑换记录
        '''
        mo = MsgPack()
        mo.setCmd('store5')
        mo.setResult('action', 'history')

        mi = hallchecker.CHECK_BASE.check(msg)
        if mi.error:
            mo.setError(1, mi.error)
        else:
            orders = self.storeSystem.getUserOrderList(mi.userId)
            mo.setResult('orders', orders)

        tyrpcconn.sendToUser(mi.userId, mo)
        return 1
Example #25
0
 def sendQuickStartRes(cls,
                       gameId,
                       userId,
                       reason,
                       roomId=0,
                       tableId=0,
                       info=""):
     mpQuickRes = MsgPack()
     mpQuickRes.setCmd('quick_start')
     mpQuickRes.setResult('info', info)
     mpQuickRes.setResult('userId', userId)
     mpQuickRes.setResult('gameId', gameId)
     mpQuickRes.setResult('roomId', roomId)
     mpQuickRes.setResult('tableId', tableId)
     mpQuickRes.setResult('seatId', 0)  # 兼容检查seatId参数的地主客户端
     mpQuickRes.setResult('reason', reason)
     tyrpcconn.sendToUser(userId, mpQuickRes)
Example #26
0
 def doClientHallInfo(self, msg):
     '''
     老版本兼容 获取大厅列表信息
     '''
     if _DEBUG:
         debug('doClientHallInfo->', msg)
     mi = self.checker.check(msg)
     if mi.error:
         ftlog.error('doClientHallInfo the msg params error !', mi.error)
     else:
         mo = MsgPack()
         mo.setCmd('hall_info')
         mo.setResult('gameId', tyglobal.gameId())
         mo.setResult('userId', mi.userId)
         mo.setResult('sessions', None)
         tyrpcconn.sendToUser(mi.userId, mo)
     return 1
Example #27
0
    def doGetShareReward(self, msg):
        '''
        客户端回调奖励
        '''
        mo = MsgPack()
        mo.setCmd('hall5_share2')
        mo.setResult('action', 'get_reward')

        mi = self.checkGetShareReward.check(msg)
        if mi.error:
            mo.setError(1, mi.error)
        else:
            mo = self._doGetShareReward(mi.gameId, mi.userId, mi.clientId,
                                        mi.pointId, mo)

        if mo:
            tyrpcconn.sendToUser(mi.userId, mo)
Example #28
0
 def startGameInfo(self, msg):
     if _DEBUG:
         debug("In startGameInfo @@@ msg = ", msg)
     mi = self.checkStartGameInfo.check(msg)
     if mi.error:
         ftlog.error('startGameInfo the msg params error !', mi.error)
     else:
         room = tyglobal.rooms()[mi.roomId]
         table = room.maptable[mi.tableId]
         if _DEBUG:
             ftlog.debug("IN startGameInfo @@ startGameInfo =", table.playersInfo.keys(), " MsgId = ", mi.MsgId)
         table.tableMsgId = mi.MsgId
         mo = MsgPack()
         mo.setCmd('start_game_info')
         mo.setResult('result', "ok")
         tyrpcconn.sendToUser(mi.userid, mo)
     return 1
Example #29
0
 def doBindGame(self, msg):
     '''
     未指定房间的 快速开始
     '''
     if _DEBUG:
         debug('doBindGame->', msg)
     mi = self.basechecker.check(msg)
     if mi.error:
         ftlog.error('doBindGame the msg params error !', mi.error)
     else:
         mo = MsgPack()
         mo.setCmd('bind_game')
         mo.setResult('gameId', mi.gameId)
         mo.setResult('userId', mi.userId)
         mo.setResult('result', 'ok')
         tyrpcconn.sendToUser(mi.userId, mo)
     return 1
Example #30
0
    def doGetShareUrl(self, msg):
        '''
        客户端获取短连接
        '''
        mo = MsgPack()
        mo.setCmd('hall5_share2')
        mo.setResult('action', 'get_share_url')

        mi = self.checkGetShareUrl.check(msg)
        if mi.error:
            mo.setError(1, mi.error)
        else:
            mo = self._doGetShareUrl(mi.gameId, mi.userId, mi.clientId,
                                     mi.pointId, mi.shareId, mi.urlParams, mo)

        if mo:
            tyrpcconn.sendToUser(mi.userId, mo)