Beispiel #1
0
def _incrUserChipFiled(uid, gameid, deltaCount, lowLimit, highLimit, chipNotEnoughOpMode, eventId, chipType,
                       intEventParam, clientId, tableId=0):
    assert (isinstance(uid, int))
    assert (isinstance(gameid, int))
    assert (isinstance(deltaCount, int))
    assert (isinstance(lowLimit, int))
    assert (isinstance(highLimit, int))
    assert (isinstance(chipNotEnoughOpMode, int))
    assert (isinstance(chipType, int))

    if chipType == daoconst.CHIP_TYPE_CHIP:
        filed = daoconst.ATT_CHIP
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_COIN:
        filed = daoconst.ATT_COIN
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_DIAMOND:
        filed = daoconst.ATT_DIAMOND
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_COUPON:
        filed = daoconst.ATT_COUPON
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_TABLE_CHIP:
        mkey = daoconst.HKEY_TABLECHIP + str(uid)
        filed = str(tableId)
    else:
        raise Exception('UserChip unknow chipType of ' + str(chipType))

    trueDelta, finalCount, fixed, appId, numberClientId = dbuser._incrUserDatasLimit(uid, filed, deltaCount, lowLimit,
                                                                                     highLimit, chipNotEnoughOpMode,
                                                                                     mkey)

    ftlog.debug('UserChip->incr_user_chip_filed', uid, gameid, deltaCount, lowLimit, highLimit,
                chipNotEnoughOpMode, eventId, chipType, mkey, filed,
                'result->', trueDelta, finalCount, fixed)
    args = {}
    args['clientId'] = clientId
    args['appId'] = appId
    args['deltaCount'] = deltaCount
    args['lowLimit'] = lowLimit
    args['highLimit'] = highLimit
    args['chipType'] = chipType
    args['mode'] = chipNotEnoughOpMode

    if fixed != 0:
        bireport.reportBiChip(uid, fixed, fixed, 0, EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId, gameid, appId, intEventParam, chipType, argdict=args)
    if trueDelta != 0 or deltaCount == 0:
        bireport.reportBiChip(uid, deltaCount, trueDelta, finalCount, eventId,
                              numberClientId, gameid, appId, intEventParam, chipType, argdict=args)
    return trueDelta, finalCount
Beispiel #2
0
def _tryReadDataFromMySql(userId, intClientId, appId, ctfull):
    # 得到MySQL中的数据
    csize = getMysqlSize()
    dbname = 'user' + str(userId % csize)
    tablename = 't' + str(userId / csize % 200)
    sqlstr = 'select data from %s where userid=%d limit 1' % (tablename,
                                                              userId)
    ftlog.info('_tryReadDataFromMySql', userId, intClientId, appId, dbname,
               sqlstr)
    jsonstr = dbmysql._queryMysql00(userId, dbname, sqlstr)
    ftlog.info('_tryReadDataFromMySql before', userId, jsonstr)
    if not jsonstr:
        ftlog.info('_tryReadDataFromMySql', userId,
                   'the user mysql data not found !')
        return 0
    loaddatas = strutil.loads(jsonstr)
    # 拆解执行数据装载,避免redis的slowlog, 避免挤压redis
    isok, chip, diamond, coin, coupon = 1, 0, 0, 0, 0
    rkeys = loaddatas.keys()
    while (len(rkeys)) > 0:
        subrkeys = rkeys[0:4]
        rkeys = rkeys[4:]
        subdata = {}
        for subkey in subrkeys:
            subdata[subkey] = loaddatas[subkey]
        jsonstr1 = strutil.dumps(subdata)
        isok1, chip1, diamond1, coin1, coupon1 = daobase.executeUserLua(
            userId, dataswap_scripts.DATA_SWAP_LUA_SCRIPT, 3, userId, ctfull,
            jsonstr1)
        ftlog.debug('_tryReadDataFromMySql save to redis->', userId, isok,
                    jsonstr1)
        isok = min(isok, isok1)
        chip = max(chip, chip1)
        diamond = max(diamond, diamond1)
        coin = max(coin, coin1)
        coupon = max(coupon, coupon1)
    ftlog.info('_tryReadDataFromMySql save to redis->', userId, 'isok=', isok,
               'chip=', chip, 'diamond=', diamond, 'coin=', coin, 'coupon=',
               coupon)
    chip, diamond, coin, coupon = strutil.parseInts(chip, diamond, coin,
                                                    coupon)
    if isok == 1:
        from poker.entity.biz import bireport
        bireport.reportBiChip(userId, chip, chip, chip,
                              'DATA_FROM_MYSQL_2_REDIS_CHIP', intClientId,
                              appId, appId, 0, daoconst.CHIP_TYPE_CHIP)
        bireport.reportBiChip(userId, coin, coin, coin,
                              'DATA_FROM_MYSQL_2_REDIS_COIN', intClientId,
                              appId, appId, 0, daoconst.CHIP_TYPE_COIN)
        bireport.reportBiChip(userId, diamond, diamond, diamond,
                              'DATA_FROM_MYSQL_2_REDIS_DIAMOND', intClientId,
                              appId, appId, 0, daoconst.CHIP_TYPE_DIAMOND)
        bireport.reportBiChip(userId, coupon, coupon, coupon,
                              'DATA_FROM_MYSQL_2_REDIS_COUPON', intClientId,
                              appId, appId, 0, daoconst.CHIP_TYPE_COUPON)
        return 1
    return 0
Beispiel #3
0
def _tryReadDataFromMySql(userId, intClientId, appId, ctfull):
    # 得到MySQL中的数据
    csize = getMysqlSize()
    dbname = 'user' + str(userId % csize)
    tablename = 't' + str(userId / csize % 200)
    sqlstr = 'select data from %s where userid=%d limit 1' % (tablename, userId)
    ftlog.info('_tryReadDataFromMySql', userId, intClientId, appId, dbname, sqlstr)
    jsonstr = dbmysql._queryMysql00(userId, dbname, sqlstr)
    ftlog.info('_tryReadDataFromMySql before', userId, jsonstr)
    if not jsonstr:
        ftlog.info('_tryReadDataFromMySql', userId, 'the user mysql data not found !')
        return 0
    loaddatas = strutil.loads(jsonstr)
    # 拆解执行数据装载,避免redis的slowlog, 避免挤压redis
    isok, chip, diamond, coin, coupon = 1, 0, 0, 0, 0
    rkeys = loaddatas.keys()
    while (len(rkeys)) > 0:
        subrkeys = rkeys[0:4]
        rkeys = rkeys[4:]
        subdata = {}
        for subkey in subrkeys:
            subdata[subkey] = loaddatas[subkey]
        jsonstr1 = strutil.dumps(subdata)
        isok1, chip1, diamond1, coin1, coupon1 = daobase.executeUserLua(userId,
                                                                        dataswap_scripts.DATA_SWAP_LUA_SCRIPT, 3,
                                                                        userId, ctfull, jsonstr1)
        ftlog.debug('_tryReadDataFromMySql save to redis->', userId, isok, jsonstr1)
        isok = min(isok, isok1)
        chip = max(chip, chip1)
        diamond = max(diamond, diamond1)
        coin = max(coin, coin1)
        coupon = max(coupon, coupon1)
    ftlog.info('_tryReadDataFromMySql save to redis->', userId,
               'isok=', isok, 'chip=', chip, 'diamond=', diamond,
               'coin=', coin, 'coupon=', coupon)
    chip, diamond, coin, coupon = strutil.parseInts(chip, diamond, coin, coupon)
    if isok == 1:
        from poker.entity.biz import bireport
        bireport.reportBiChip(userId, chip, chip, chip,
                              'DATA_FROM_MYSQL_2_REDIS_CHIP',
                              intClientId, appId, appId, 0,
                              daoconst.CHIP_TYPE_CHIP)
        bireport.reportBiChip(userId, coin, coin, coin,
                              'DATA_FROM_MYSQL_2_REDIS_COIN',
                              intClientId, appId, appId, 0,
                              daoconst.CHIP_TYPE_COIN)
        bireport.reportBiChip(userId, diamond, diamond, diamond,
                              'DATA_FROM_MYSQL_2_REDIS_DIAMOND',
                              intClientId, appId, appId, 0,
                              daoconst.CHIP_TYPE_DIAMOND)
        bireport.reportBiChip(userId, coupon, coupon, coupon,
                              'DATA_FROM_MYSQL_2_REDIS_COUPON',
                              intClientId, appId, appId, 0,
                              daoconst.CHIP_TYPE_COUPON)
        return 1
    return 0
Beispiel #4
0
def _setTableChipToRange(uid, gameid, _min, _max, eventId, intEventParam, clientId, tableId):
    assert (isinstance(_min, int) and (_min >= 0 or _min in (-1, -2, -3)) and
            isinstance(_max, int) and (_max >= 0 or _max in (-1, -2, -3)))

    rfield = str(tableId)
    rhashkey = daoconst.HKEY_TABLECHIP + str(uid)

    tdelta, tfinal, tfixed, delta, final, fixed, appId, numberClientId = \
        dbuser._setTableChipToRange(uid, gameid, _min, _max, eventId, intEventParam,
                                    clientId, tableId, rhashkey, rfield)

    ftlog.debug('UserChip->set_tablechip_to_range', uid, gameid, _min, _max,
                eventId, intEventParam, clientId, tableId, rhashkey,
                'result->', tdelta, tfinal, tfixed, delta, final, fixed)

    args = {}
    args['clientId'] = clientId
    args['appId'] = appId
    args['_min'] = _min
    args['_max'] = _max

    if tfixed != 0:
        bireport.reportBiChip(uid, tfixed, tfixed, 0, EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId, gameid, appId, intEventParam,
                              daoconst.CHIP_TYPE_TABLE_CHIP, argdict=args)
    if fixed != 0:
        bireport.reportBiChip(uid, fixed, fixed, 0, EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId, gameid, appId, intEventParam,
                              daoconst.CHIP_TYPE_CHIP, argdict=args)
    if tdelta != 0:
        bireport.reportBiChip(uid, tdelta, tdelta, tfinal, eventId,
                              numberClientId, gameid, appId, intEventParam,
                              daoconst.CHIP_TYPE_TABLE_CHIP, argdict=args)
    if delta != 0:
        bireport.reportBiChip(uid, delta, delta, final, eventId,
                              numberClientId, gameid, appId, intEventParam,
                              daoconst.CHIP_TYPE_CHIP, argdict=args)

    return tfinal, final, delta
Beispiel #5
0
def _incrUserChipFiled(uid,
                       gameid,
                       deltaCount,
                       lowLimit,
                       highLimit,
                       chipNotEnoughOpMode,
                       eventId,
                       chipType,
                       intEventParam,
                       clientId,
                       tableId=0):
    assert (isinstance(uid, int))
    assert (isinstance(gameid, int))
    assert (isinstance(deltaCount, int))
    assert (isinstance(lowLimit, int))
    assert (isinstance(highLimit, int))
    assert (isinstance(chipNotEnoughOpMode, int))
    assert (isinstance(chipType, int))

    if chipType == daoconst.CHIP_TYPE_CHIP:
        filed = daoconst.ATT_CHIP
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_COIN:
        filed = daoconst.ATT_COIN
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_DIAMOND:
        filed = daoconst.ATT_DIAMOND
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_COUPON:
        filed = daoconst.ATT_COUPON
        mkey = daoconst.HKEY_USERDATA + str(uid)
    elif chipType == daoconst.CHIP_TYPE_TABLE_CHIP:
        mkey = daoconst.HKEY_TABLECHIP + str(uid)
        filed = str(tableId)
    else:
        raise Exception('UserChip unknow chipType of ' + str(chipType))

    trueDelta, finalCount, fixed, appId, numberClientId = dbuser._incrUserDatasLimit(
        uid, filed, deltaCount, lowLimit, highLimit, chipNotEnoughOpMode, mkey)

    ftlog.debug('UserChip->incr_user_chip_filed', uid, gameid, deltaCount,
                lowLimit, highLimit, chipNotEnoughOpMode, eventId, chipType,
                mkey, filed, 'result->', trueDelta, finalCount, fixed)
    args = {}
    args['clientId'] = clientId
    args['appId'] = appId
    args['deltaCount'] = deltaCount
    args['lowLimit'] = lowLimit
    args['highLimit'] = highLimit
    args['chipType'] = chipType
    args['mode'] = chipNotEnoughOpMode

    if fixed != 0:
        bireport.reportBiChip(uid,
                              fixed,
                              fixed,
                              0,
                              EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              chipType,
                              argdict=args)
    if trueDelta != 0 or deltaCount == 0:
        bireport.reportBiChip(uid,
                              deltaCount,
                              trueDelta,
                              finalCount,
                              eventId,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              chipType,
                              argdict=args)
    return trueDelta, finalCount
Beispiel #6
0
def _setTableChipToRange(uid, gameid, _min, _max, eventId, intEventParam,
                         clientId, tableId):
    assert (isinstance(_min, int) and (_min >= 0 or _min in (-1, -2, -3))
            and isinstance(_max, int) and (_max >= 0 or _max in (-1, -2, -3)))

    rfield = str(tableId)
    rhashkey = daoconst.HKEY_TABLECHIP + str(uid)

    tdelta, tfinal, tfixed, delta, final, fixed, appId, numberClientId = \
        dbuser._setTableChipToRange(uid, gameid, _min, _max, eventId, intEventParam,
                                    clientId, tableId, rhashkey, rfield)

    ftlog.debug('UserChip->set_tablechip_to_range', uid, gameid, _min, _max,
                eventId, intEventParam, clientId, tableId, rhashkey,
                'result->', tdelta, tfinal, tfixed, delta, final, fixed)

    args = {}
    args['clientId'] = clientId
    args['appId'] = appId
    args['_min'] = _min
    args['_max'] = _max

    if tfixed != 0:
        bireport.reportBiChip(uid,
                              tfixed,
                              tfixed,
                              0,
                              EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              daoconst.CHIP_TYPE_TABLE_CHIP,
                              argdict=args)
    if fixed != 0:
        bireport.reportBiChip(uid,
                              fixed,
                              fixed,
                              0,
                              EVENT_NAME_SYSTEM_REPAIR,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              daoconst.CHIP_TYPE_CHIP,
                              argdict=args)
    if tdelta != 0:
        bireport.reportBiChip(uid,
                              tdelta,
                              tdelta,
                              tfinal,
                              eventId,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              daoconst.CHIP_TYPE_TABLE_CHIP,
                              argdict=args)
    if delta != 0:
        bireport.reportBiChip(uid,
                              delta,
                              delta,
                              final,
                              eventId,
                              numberClientId,
                              gameid,
                              appId,
                              intEventParam,
                              daoconst.CHIP_TYPE_CHIP,
                              argdict=args)

    return tfinal, final, delta