Beispiel #1
0
 def setup(self, interval, action, msgPackParams, cancelLastTimer=True):
     '''
     启动计时器
     interval 倒计时的时间, 单位: 秒
     action table_call命令下(params中)的action值
     msgPackParams 传递的其他的参数数据集合dict, 可以在doTableCall中的msg中使用msg.getParam(key)来取得其中的参数
     '''
     if self._fttimer and cancelLastTimer:
         self._fttimer.cancel()
     self._interval = interval
     userId = msgPackParams.get('userId', 0)
     clientId = msgPackParams.get('clientId', None)
     assert(isinstance(userId, int))
     assert(isinstance(action, (unicode, str)))
     if clientId != None:
         assert(isinstance(clientId, (unicode, str)))
     msg = MsgPack()
     msg.updateParam(msgPackParams)
     msg.setCmdAction('table_call', action)
     msg.setParam('gameId', self._table.gameId)
     msg.setParam('roomId', self._table.roomId)
     msg.setParam('tableId', self._table.tableId)
     msg.setParam('userId', userId)
     msg.setParam('clientId', clientId)
     self._fttimer = ftcore.runOnceDelay(interval, self._onTimeOut, msg)
Beispiel #2
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        assert (isinstance(item, TYExchangeItem))
        if item.isDied(timestamp):
            if item.itemKind.units.isTiming():
                return items.TYItemActionResult(None, None, -30, '道具已经过期',
                                                None)
            else:
                return items.TYItemActionResult(None, None, -31, '道具数量不足',
                                                None)

        if item.state != TYExchangeItem.STATE_NORMAL:
            return items.TYItemActionResult(None, None, -32, '道具审核中', None)

        wechat_red_pack = self.isWechatRedPack()  # 微信红包,无需手机号、地址
        msg = MsgPack()
        msg.setKey('apiVersion', 5.0)
        msg.setCmdAction('exchange5', 'exchange')
        msg.updateParam(self.auditParams)
        msg.setParam(
            'phone',
            str(
                params.get('phoneNumber'
                           ) if not wechat_red_pack else '11111111111'))
        msg.setParam('uName', params.get('uName', ''))
        msg.setParam('bindPhone', params.get('bindPhone', ''))
        msg.setParam('phoneNumber', params.get('phoneNumber', ''))
        msg.setParam('uAddres', params.get('uAddres', ''))
        msg.setParam('gameId', gameId)
        msg.setParam('itemId', item.itemId)
        msg.setParam('userId', userAssets.userId)
        msg.setParam('extabName', '_item_')
        msg.setParam('clientId', clientId)
        msg.setParam('wxappid',
                     hallconf.getWeiXinAppId(userAssets.userId, clientId))
        msg.setParam('proviceId', params.get('proviceId', ''))
        msg.setParam('cityId', params.get('cityId', ''))
        msg.setParam('countyId', params.get('countyId', ''))
        msg.setParam('townId', params.get('townId', ''))
        msg.setParam('proviceName', params.get('proviceName', ''))
        msg.setParam('cityName', params.get('cityName', ''))
        msg.setParam('countyName', params.get('countyName', ''))
        msg.setParam('townName', params.get('townName', ''))

        ftlog.info('TYItemActionExchange->doAction', msg)
        exchangeId, errMsg = pluginCross.hallexchange.doExchangeRequest(
            userAssets.userId, msg)
        if not exchangeId or errMsg:
            return items.TYItemActionResult(None, None, -33, errMsg, None)

        # 兑换开始,成功,转换道具状态
        item.state = TYExchangeItem.STATE_AUDIT
        item.original = 0
        userAssets.getUserBag().updateItem(item, timestamp)

        replaceParams = {'item': item.itemKind.displayName}
        _mail, message, _changed = _action._handleMailAndMessageAndChanged(
            gameId, userAssets, self, None, replaceParams)
        # TGHall.getEventBus().publishEventent(TYItemExchangeEvent(gameId, userAssets.userId, item))
        return TYItemActionExchangeResult(self, item, message, exchangeId)
Beispiel #3
0
def doJoinCreateTable(userId, gameId, clientId, roomId0, tableId0, playMode,
                      msg):
    """用户加入自建牌桌
    """
    loc = onlinedata.checkUserLoc(userId, clientId, gameId)
    lgameId, lroomId, ltableId, lseatId = loc.split('.')
    lgameId, lroomId, ltableId, lseatId = ftstr.parseInts(
        lgameId, lroomId, ltableId, lseatId)
    if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
        ftlog.warn('create_table error, user in table')
        sendPopTipMsg(userId, "请稍候,正在进桌...")
        config = {
            "type": "quickstart",
            "pluginParams": {
                "roomId": lroomId,
                "tableId": ltableId,
                "seatId": lseatId
            }
        }
        todotask = TodoTaskEnterGameNew(lgameId, config)
        mo = MsgPack()
        mo.setCmd('todo_tasks')
        mo.setResult('gameId', gameId)
        mo.setResult('pluginId', lgameId)
        mo.setResult('userId', userId)
        mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
        tyrpcconn.sendToUser(userId, mo)
    else:
        createTableNo = msg.getParam('createTableNo', 0)
        if not createTableNo:
            return
        tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(
            createTableNo)
        if not tableId0 or not roomId0:
            sendPopTipMsg(userId, "找不到您输入的房间号")
            return
        msg1 = MsgPack()
        msg1.setParam("shadowRoomId", roomId0)
        msg1.setParam("roomId", roomId0)
        msg1.setParam("tableId", tableId0)
        msg1.setParam("createTableNo", createTableNo)
        msg1.setCmdAction("room", "join_create_table")
        router.sendRoomServer(msg1, roomId0)
Beispiel #4
0
 def doExchangeExchange(self, request):
     mo = MsgPack()
     mi = self.checkExchange.check(request)
     if mi.error:
         mo.setError(1, mi.error)
     else:
         clientId = tysessiondata.getClientId(mi.userId)
         msg = MsgPack()
         msg.setKey('apiVersion', 5.0)
         msg.setCmdAction('exchange5', 'exchange')
         msg.setParam('phone', request.getParamStr('phone'))
         msg.setParam('uName', request.getParamStr('uName'))
         msg.setParam('uAddres', request.getParamStr('uAddres'))
         msg.setParam('gameId', tyglobal.gameId())
         msg.setParam('itemId', mi.itemId)
         msg.setParam('userId', mi.userId)
         msg.setParam('extabName', request.getParamStr('extabName'))
         msg.setParam('clientId', clientId)
         msg.setParam('wxappid',
                      hallconf.getWeiXinAppId(mi.userId, clientId))
         msg.setParam('proviceId', request.getParamStr('proviceId'))
         msg.setParam('cityId', request.getParamStr('cityId'))
         msg.setParam('countyId', request.getParamStr('countyId'))
         msg.setParam('townId', request.getParamStr('townId'))
         msg.setParam('proviceName', request.getParamStr('proviceName'))
         msg.setParam('cityName', request.getParamStr('cityName'))
         msg.setParam('countyName', request.getParamStr('countyName'))
         msg.setParam('townName', request.getParamStr('townName'))
         msg = msg.getDict()
         try:
             ret = hallRpcOne.hallexchange.doExchangeRequest(mi.userId, msg)
             datas = ret.getResult()
             if datas:
                 exchangeId, errMsg = datas[0], datas[1]
                 if exchangeId:
                     mo.setResult('exchangeId', exchangeId)
                     mo.setResult('info', errMsg)
                 else:
                     mo.setError(1, errMsg)
             else:
                 mo.setError(1, 'doExchangeRequest return is None')
         except Exception, e:
             mo.setError(1, str(e))
Beispiel #5
0
def doCreateTable(userId,
                  gameId,
                  clientId,
                  roomId0,
                  tableId0,
                  playMode,
                  hasRobot=0,
                  msg=None):
    """房主创建牌桌"""
    if not playMode:
        ftlog.error('game_handler, cat not create table without playMode...')

    loc = onlinedata.checkUserLoc(userId, clientId, gameId)
    lgameId, lroomId, ltableId, lseatId = loc.split('.')
    lgameId, lroomId, ltableId, lseatId = ftstr.parseInts(
        lgameId, lroomId, ltableId, lseatId)
    if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
        ftlog.warn('create_table error, user in table', lgameId, lroomId,
                   ltableId, lseatId)
        sendPopTipMsg(userId, "请稍候,正在进桌...")
        config = {
            "type": "quickstart",
            "pluginParams": {
                "roomId": lroomId,
                "tableId": ltableId,
                "seatId": lseatId
            }
        }
        todotask = TodoTaskEnterGameNew(lgameId, config)
        mo = MsgPack()
        mo.setCmd('todo_tasks')
        mo.setResult('gameId', gameId)
        mo.setResult('pluginId', lgameId)
        mo.setResult('userId', userId)
        mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
        router.sendToUser(mo, userId)
    elif _canEnterGame(userId, gameId):
        # 保存建桌时间戳
        gamedata.setGameAttr(userId, gameId, 'createTableTime',
                             fttime.getCurrentTimestamp())

        itemParams = msg.getParam("itemParams")

        playerCount = 4
        playerTypeId = itemParams.get(MFTDefine.PLAYER_TYPE, 1)
        playerTypeConfig = majiang_conf.getCreateTableConfig(
            gameId, playMode, MFTDefine.PLAYER_TYPE, playerTypeId)
        if not playerTypeConfig:
            ftlog.info('MajiangCreateTable.doCreateTable playerTypeId:',
                       playerTypeId, ' playerTypeConfig:', playerTypeConfig)

            sendPopTipMsg(userId, '人数配置有误,请稍后重试')
            return

        playerCount = playerTypeConfig.get('count', 4)
        ftlog.debug('MajiangCreateTable.create_table playerCount:',
                    playerCount)
        cardCountKey = playerTypeConfig.get(MFTDefine.CARD_COUNT,
                                            MFTDefine.CARD_COUNT)

        cardCountId = itemParams.get(cardCountKey, 0)
        cardCountConfig = majiang_conf.getCreateTableConfig(
            gameId, playMode, cardCountKey, cardCountId)
        if not cardCountConfig:
            sendPopTipMsg(userId, '房卡配置有误,请稍后重试')
            return

        if hasRobot == 1 and 'hasRobot' in cardCountConfig:
            cardCountConfig = cardCountConfig.get('hasRobot', {})
            ftlog.debug('MajiangCreateTable.create_table hasRobot == 1:')
        fangka_count = cardCountConfig.get('fangka_count', 1)
        ftlog.debug('MajiangCreateTable.create_table fangka_count:',
                    fangka_count, ' cardCountConfig:', cardCountConfig)

        msg.setParam('isCreateTable', 1)  # 标记创建的桌子是 自建桌
        '''
        根据五个因素筛选合适的房间
        1)gameId         游戏ID
        2)playMode       游戏玩法
        3)playerCount    玩家个数
        4)hasRobot       是否有机器人
        5)itemId         房卡道具
        '''
        itemId = hall_fangka.queryFangKaItem(gameId, userId, clientId)
        if itemId:
            ftlog.debug('MajiangCreateTable._chooseCreateRoom fangKa itemId:',
                        itemId)
        roomId, checkResult = MajiangCreateTable._chooseCreateRoom(
            userId, gameId, playMode, playerCount, hasRobot, itemId)
        ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId,
                    ' checkResult:', checkResult)

        if checkResult == TYRoom.ENTER_ROOM_REASON_OK:
            msg1 = MsgPack()
            msg1.setCmdAction("room", "create_table")
            msg1.setParam("roomId", roomId)
            msg1.setParam("itemParams", itemParams)
            msg1.setParam('needFangka', fangka_count)
            ftlog.debug(
                'MajiangCreateTable._chooseCreateRoom send message to room:',
                msg1)

            router.sendRoomServer(msg1, roomId)
        else:
            sendPopTipMsg(userId, "暂时无法创建请稍后重试")

    else:
        ftlog.info('majiang2 game_handler, ignore enter game request...')