Example #1
0
def checkUserData(userId, clientId=None, appId=0):
    '''
    检查当前用户的数据是否是热数据(即存储在REDIS), 
    如果不是热数据, 那么重MYSQL中读取冷数据导入至热数据中
    同时更新当前用户的数据生命时间
    导入导出的用户数据包括user和个个游戏的所有数据
    返回:
        如果用户数据的最终状态为热数据,返回1
        如果用户数据不存在,返回0
    '''
    ftlog.debug('MySqlSwap checkUserData->userId=', userId, 'clientId=',
                clientId, 'appId=', appId)
    userId = int(userId)
    ctfull = timestamp.formatTimeMs()
    isok = daobase.executeUserLua(userId,
                                  dataswap_scripts.CHECK_USER_DATA_LUA_SCRIPT,
                                  2, userId, ctfull)
    ftlog.debug('MySqlSwap checkUserData->userId=', userId, 'clientId=',
                clientId, 'appId=', appId, 'isok=', isok)
    if isok == 1:
        return 1
    if clientId:
        intClientId = pokerconf.clientIdToNumber(clientId)
    else:
        intClientId = configure.DEFAULT_CLIENT_ID
    appId = int(appId)
    return _tryReadDataFromMySql(userId, intClientId, appId, ctfull)
Example #2
0
def _updateUserGameDataAuthorTime(userId, gameId):
    ctfull = timestamp.formatTimeMs()
    daobase.sendUserCmd(
        userId, 'HSET',
        daoconst.HKEY_GAMEDATA + str(gameId) + ':' + str(userId), 'authorTime',
        ctfull)
    return ctfull
Example #3
0
def updateStatus(status):
    stfile = None
    try:
        sid = ftcon.global_config["server_id"]
        log_path = ftcon.global_config["log_path"]
        stpath = log_path + '/status.' + sid
        if os.path.isfile(stpath):
            stfile = open(stpath, 'r')
            datas = json.load(stfile)
            stfile.close()
            stfile = None
        else:
            datas = {'creatTime': timestamp.formatTimeMs()}

        _updateProcessStatus(datas)

        datas['status'] = status
        datas['updateTime'] = timestamp.formatTimeMs()

        ide_print("updateStatus(%s)" % status)

        stfile = open(stpath, 'w')
        fcntl.flock(stfile, fcntl.LOCK_EX)
        stfile.write(
            json.dumps(datas,
                       sort_keys=True,
                       indent=4,
                       separators=(', ', ' : ')))
        fcntl.flock(stfile, fcntl.LOCK_UN)
        stfile.close()
        stfile = None
    except:
        ftlog.error()
    finally:
        try:
            if stfile:
                fcntl.flock(stfile, fcntl.LOCK_UN)
        except:
            pass
        try:
            if stfile:
                stfile.close()
        except:
            pass
Example #4
0
def updateStatus(status):
    stfile = None
    try:
        sid = ftcon.global_config["server_id"]
        log_path = ftcon.global_config["log_path"]
        stpath = log_path + '/status.' + sid
        if os.path.isfile(stpath):
            stfile = open(stpath, 'r')
            datas = json.load(stfile)
            stfile.close()
            stfile = None
        else:
            datas = {'creatTime': timestamp.formatTimeMs()}

        _updateProcessStatus(datas)

        datas['status'] = status
        datas['updateTime'] = timestamp.formatTimeMs()

        ide_print("updateStatus(%s)" % status)

        stfile = open(stpath, 'w')
        fcntl.flock(stfile, fcntl.LOCK_EX)
        stfile.write(json.dumps(datas, sort_keys=True, indent=4, separators=(', ', ' : ')))
        fcntl.flock(stfile, fcntl.LOCK_UN)
        stfile.close()
        stfile = None
    except:
        ftlog.error()
    finally:
        try:
            if stfile:
                fcntl.flock(stfile, fcntl.LOCK_UN)
        except:
            pass
        try:
            if stfile:
                stfile.close()
        except:
            pass
Example #5
0
def reportChatLog(userId, message, gameId, roomId, tableId, seatId=0, *argl, **argd):
    if integrate.isEnabled('chatlog') :
        try:
            datas = {'uid' : userId,
                     'gid' : gameId,
                     'rid' : roomId,
                     'tid' : tableId,
                     'sid' : seatId,
                     'msg' : message,
                     'time' : timestamp.formatTimeMs(),
                     'argl' : argl,
                     'argd' : argd
                     }
            integrate.sendTo('chatlog', datas)
        except:
            ftlog.error()
Example #6
0
def reportChatLog(userId, message, gameId, roomId, tableId, seatId=0, *argl, **argd):
    if integrate.isEnabled('chatlog'):
        try:
            datas = {'uid': userId,
                     'gid': gameId,
                     'rid': roomId,
                     'tid': tableId,
                     'sid': seatId,
                     'msg': message,
                     'time': timestamp.formatTimeMs(),
                     'argl': argl,
                     'argd': argd
                     }
            integrate.sendTo('chatlog', datas)
        except:
            ftlog.error()
Example #7
0
def ensureGameDataExists(userId, gameId, clientId):
    '''
    判定用户游戏数据是否存在, 若不存在则初始化该游戏的所有的相关游戏数据
    包括: 主游戏数据gamedata, 道具, 勋章等
    '''
    isCreate = False
    gaccount = TYGame(gameId)
    # 以游戏主数据的前2个字段为判定条件
    ukeys = gaccount.getInitDataKeys()[0:2]
    d1, d2 = gamedata.getGameAttrs(userId, gameId, ukeys)
    if d1 is None or d2 is None:
        gdkeys, gdata = gaccount.createGameData(userId, gameId)
        gdkeys.append('createTime')
        gdata.append(timestamp.formatTimeMs())
        bireport.creatGameData(gameId, userId, clientId, gdkeys, gdata)
        bireport.reportGameEvent('CREATE_GAME_DATA',
                                 userId, gameId, 0, 0, 0, 0, 0, 0, [], clientId)
        isCreate = True
    return isCreate
Example #8
0
def _report(arglist, argdict, isHinfo=0):
    if _ENABLE_BIFILE:
        global _BILOGER
        if _BILOGER is None:
            log_file_fullpath = gdata.globalConfig()['log_path']
            log_file_fullpath = log_file_fullpath + '/bi.' + gdata.serverId() + '.log'
            _BILOGER = ftlog.openNormalLogfile(log_file_fullpath)
        jsondata = [timestamp.formatTimeMs(), gdata.serverId()]
        jsondata.extend(arglist)
        jsondata.append(argdict)
        msg = strutil.dumps(jsondata)
        _BILOGER.info(msg)
    else:
        jsondata = ['BIREPORT', gdata.serverId()]
        jsondata.extend(arglist)
        jsondata.append(argdict)
        msg = strutil.dumps(jsondata)
        if isHinfo:
            ftlog.hinfo(msg)
        else:
            ftlog.info(msg)
Example #9
0
def checkUserData(userId, clientId=None, appId=0):
    '''
    检查当前用户的数据是否是热数据(即存储在REDIS), 
    如果不是热数据, 那么重MYSQL中读取冷数据导入至热数据中
    同时更新当前用户的数据生命时间
    导入导出的用户数据包括user和个个游戏的所有数据
    返回:
        如果用户数据的最终状态为热数据,返回1
        如果用户数据不存在,返回0
    '''
    ftlog.debug('MySqlSwap checkUserData->userId=', userId, 'clientId=', clientId, 'appId=', appId)
    userId = int(userId)
    ctfull = timestamp.formatTimeMs()
    isok = daobase.executeUserLua(userId, dataswap_scripts.CHECK_USER_DATA_LUA_SCRIPT, 2, userId, ctfull)
    ftlog.debug('MySqlSwap checkUserData->userId=', userId, 'clientId=', clientId, 'appId=', appId, 'isok=', isok)
    if isok == 1:
        return 1
    if clientId:
        intClientId = pokerconf.clientIdToNumber(clientId)
    else:
        intClientId = configure.DEFAULT_CLIENT_ID
    appId = int(appId)
    return _tryReadDataFromMySql(userId, intClientId, appId, ctfull)
Example #10
0
def processOnLineTcpChangedEvent(evt):
    userId = evt.userId
    isOnline = evt.isOnline
    # 设置在线状态和在线用户集合列表, 离线时,所有通过setGameOnline设置的该用户数据均已经被删除
    onlinedata.setOnlineState(userId, isOnline)
    if not isOnline:
        ctfull = timestamp.formatTimeMs()
        gamedata.setGameAttr(userId, HALL_GAMEID, 'offlineTime', ctfull)
        return
    # 计算其他的数据在线分组
    # 分金币数量级别列表 — 德州等LED引导
    richchip = hallconf.getHallPublic().get('online_rich_limit', 100000)
    if richchip > 0:
        chip = userchip.getUserChipAll(userId)
        if chip > richchip:
            onlinedata.setGameOnline(userId, HALL_GAMEID, 'rich_online_users')
    # 分版本
    # 分等级(可能是大师分,或经验值)
    # 新老用户(是否第一天注册)
    # 有没有玩过某些游戏
    # 是否有道具
    # 是否充值
    # 是否满足比赛报名条件
    pass
Example #11
0
    def openRedEnvelope(self, userId, itemId=''):
        '''
        打开红包
        '''
        global _redEnvelopeConfig

        # 是否领取过
        receivers = daobase.executeMixCmd(
            'LRANGE', self.dbPrefix + self.id + self.RECEIVER, 0, -1)
        if receivers:
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope receivers:',
                            receivers)

            for receiverJson in receivers:
                receiver = json.loads(receiverJson)
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope receiver:',
                                receiver)
                if userId == receiver['userId']:
                    return False, _redEnvelopeConfig['tips']['opened']

        # 构造添加给获取红包用户的奖励清单
        contentItemList = []
        prizesJson = self._getPrize(itemId)
        # prizesJson = daobase.executeMixCmd('LPOP', self.dbPrefix + self.id + self.PACKAGES)
        daobase.executeMixCmd('expire',
                              self.dbPrefix + self.id + self.PACKAGES,
                              self.expiredTime)

        if prizesJson:
            prizes = json.loads(prizesJson)
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizes:', prizes)
            for prize in prizes:
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize:', prize)

                result, _itemId = self.getAssetID(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err1: ',
                                prize, ' left: ', self.contents)
                    continue

                result, value = self.getItemValue(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err2: ',
                                prize, ' left: ', self.contents)
                    continue

                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope itemId:',
                                _itemId)
                    ftlog.debug('TYRedEnvelope.openRedEnvelope count:',
                                prizes[prize] * value)

                contentItemList.append(
                    TYContentItem.decodeFromDict({
                        'itemId': _itemId,
                        'count': prizes[prize] * value
                    }))

            if ftlog.is_debug():
                ftlog.debug('contentItemList:', contentItemList)

            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            # 添加奖励
            results = userAssets.sendContentItemList(
                HALL_GAMEID, contentItemList, 1, True,
                pktimestamp.getCurrentTimestamp(), self.EVENTID, 0)
            # notify
            datachangenotify.sendDataChangeNotify(
                HALL_GAMEID, userId, TYAssetUtils.getChangeDataNames(results))
            # 构造奖励字符串
            prizeString = TYAssetUtils.buildContentsString(results)

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizeString:',
                            prizeString)

            # add receiver
            re = {}
            re['userId'] = userId
            re['prize'] = prizes
            re['prizeStr'] = prizeString
            re['time'] = pktimestamp.formatTimeMs()

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope add receiver re: ',
                            re)
            daobase.executeMixCmd('LPUSH',
                                  self.dbPrefix + self.id + self.RECEIVER,
                                  json.dumps(re))
            daobase.executeMixCmd('expire',
                                  self.dbPrefix + self.id + self.RECEIVER,
                                  self.expiredTime)

            # make response
            response = {}
            response['envelopeId'] = self.id
            response['prizes'] = prizes
            response['prizeStr'] = prizeString

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope response: ',
                            response)

            return True, response
        else:
            if self.state != self.STATE_FINISH:
                self.state = self.STATE_FINISH
                self.save2DB()

            return False, _redEnvelopeConfig['tips']['finished']
Example #12
0
    def openRedEnvelope(self, userId, itemId=''):
        '''
        打开红包
        '''
        global _redEnvelopeConfig

        # 是否领取过
        receivers = daobase.executeMixCmd('LRANGE', self.dbPrefix + self.id + self.RECEIVER, 0, -1)
        if receivers:
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope receivers:', receivers)

            for receiverJson in receivers:
                receiver = json.loads(receiverJson)
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope receiver:', receiver)
                if userId == receiver['userId']:
                    return False, _redEnvelopeConfig['tips']['opened']

        # 构造添加给获取红包用户的奖励清单        
        contentItemList = []
        prizesJson = self._getPrize(itemId)
        # prizesJson = daobase.executeMixCmd('LPOP', self.dbPrefix + self.id + self.PACKAGES)
        daobase.executeMixCmd('expire', self.dbPrefix + self.id + self.PACKAGES, self.expiredTime)

        if prizesJson:
            prizes = json.loads(prizesJson)
            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizes:', prizes)
            for prize in prizes:
                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize:', prize)

                result, _itemId = self.getAssetID(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err1: ', prize, ' left: ', self.contents);
                    continue

                result, value = self.getItemValue(prize)
                if result == False:
                    ftlog.debug('TYRedEnvelope.openRedEnvelope prize err2: ', prize, ' left: ', self.contents);
                    continue

                if ftlog.is_debug():
                    ftlog.debug('TYRedEnvelope.openRedEnvelope itemId:', _itemId)
                    ftlog.debug('TYRedEnvelope.openRedEnvelope count:', prizes[prize] * value)

                contentItemList.append(
                    TYContentItem.decodeFromDict({'itemId': _itemId, 'count': prizes[prize] * value}))

            if ftlog.is_debug():
                ftlog.debug('contentItemList:', contentItemList)

            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            # 添加奖励
            results = userAssets.sendContentItemList(HALL_GAMEID, contentItemList, 1, True,
                                                     pktimestamp.getCurrentTimestamp(), self.EVENTID, 0)
            # notify
            datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, TYAssetUtils.getChangeDataNames(results))
            # 构造奖励字符串
            prizeString = TYAssetUtils.buildContentsString(results)

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope prizeString:', prizeString)

            # add receiver
            re = {}
            re['userId'] = userId
            re['prize'] = prizes
            re['prizeStr'] = prizeString
            re['time'] = pktimestamp.formatTimeMs()

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope add receiver re: ', re)
            daobase.executeMixCmd('LPUSH', self.dbPrefix + self.id + self.RECEIVER, json.dumps(re))
            daobase.executeMixCmd('expire', self.dbPrefix + self.id + self.RECEIVER, self.expiredTime)

            # make response
            response = {}
            response['envelopeId'] = self.id
            response['prizes'] = prizes
            response['prizeStr'] = prizeString

            if ftlog.is_debug():
                ftlog.debug('TYRedEnvelope.openRedEnvelope response: ', response)

            return True, response
        else:
            if self.state != self.STATE_FINISH:
                self.state = self.STATE_FINISH
                self.save2DB()

            return False, _redEnvelopeConfig['tips']['finished']
Example #13
0
def _updateUserDataAliveTime(userId):
    ctfull = timestamp.formatTimeMs()
    daobase.sendUserCmd(userId, 'HSET', daoconst.HKEY_USERDATA + str(userId),
                        'aliveTime', ctfull)
    return ctfull