def _moveHall51DataBack(self, userId, gameId, clientId): try: flag = DaoGameDataHall.HGET(userId, 'userChipMoveGame') ftlog.info('_moveHall51DataBack', userId, gameId, flag) if flag > 0: # 当前用户登录过HALL51 chip, exp, charm, coupon = DaoGameDataHall.HMGET( userId, ['chip', 'exp', 'charm', 'coupon']) chip, exp, charm, coupon = ftstr.parseInts( chip, exp, charm, coupon) ftlog.info('_moveHall51DataBack data->', userId, gameId, chip, exp, charm, coupon) if charm > 0: self.incrCharm(userId, charm) if exp > 0: self.incrExp(userId, exp) if coupon > 0: trueDelta, finalCount = self.incrCoupon( userId, gameId, coupon, ChipNotEnoughOpMode.NOOP, 'SYSTEM_REPAIR', 0) ftlog.info('_moveHall51DataBack data coupon->', userId, gameId, coupon, trueDelta, finalCount) if chip > 0: trueDelta, finalCount = self.incrChip( userId, gameId, chip, ChipNotEnoughOpMode.NOOP, 'SYSTEM_REPAIR', 0) ftlog.info('_moveHall51DataBack data chip->', userId, gameId, chip, trueDelta, finalCount) DaoGameDataHall.HDEL( userId, ['chip', 'exp', 'charm', 'coupon', 'userChipMoveGame']) pluginCross.halldatanotify.sendDataChangeNotify( userId, gameId, 'chip') except: ftlog.error()
def destoryPlugin(self): ''' 当插件被动态卸载时,执行此方法,进行清理工作 ''' DaoUserData.finalize() DaoGameDataHall.finalize() DaoTableChip.finalize()
def getHallDataList(self, userId, keys): """ 取得用户的大厅数据内容(即游戏gamedata:9999:<userId>存储的数据内容) @param userId: 用户ID @param keys: 数据字段列表,如果为空,则获取所有信息, 请使用HallKeys中定义的KEY值 """ if isinstance(keys, (str, unicode)): ret = DaoGameDataHall.HGET(userId, keys) else: ret = DaoGameDataHall.HMGET(userId, keys) return ret
def onHallUserEventLogin(self, event): # 记录上线时间 ct = fttime.formatTimeMs() DaoGameDataHall.HMSET(event.userId, { HallKeys.ATT_ALIVE_TIME: ct, HallKeys.ATT_AUTHOR_TIME: ct }) # 登录天数加1 if event.isDayfirst: DaoGameDataHall.HINCRBY(event.userId, HallKeys.ATT_LOGIN_DAYS, 1) # 登录次数加1 DaoGameDataHall.HINCRBY(event.userId, HallKeys.ATT_LOGIN_SUM, 1)
def on_user_logout(self, event): # 记录下线时间 ct = fttime.formatTimeMs() DaoGameDataHall.HMSET(event.userId, { HallKeys.ATT_ALIVE_TIME: ct, HallKeys.ATT_OFFLINE_TIME: ct })
def incrPlayTime(self, userId, detalTime, gameId, roomId, tableId): """ 各个游戏向大厅汇报玩家的游戏时长 """ DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_TOTAL_TIME, detalTime) datas = DaoGameDataHall.HGET(userId, HallKeys.ATT_TODAY_TIME) today = datetime.now().strftime('%Y%m%d')[-6:] if today in datas: datas[today] += detalTime else: datas[today] = detalTime oldday = (datetime.now() - timedelta(days=7)).strftime('%Y%m%d')[-6:] for k in datas.keys()[:]: if k < oldday: del datas[k] DaoGameDataHall.HSET(userId, HallKeys.ATT_TODAY_TIME, datas) return 1
def saveVipGiftStatus(self, userId, vipGiftStatus): ''' 保存用户VIP礼包状态 @param userId: 哪个用户 @param vipGiftStatus: 用户VIP礼包状态 ''' return DaoGameDataHall.HSET(userId, HallKeys.ATT_VIP_GIFT_STATES, vipGiftStatus)
def incrVipExp(self, userId, count): ''' 给用户增加count个经验值,count可以为负数 @param userId: 哪个用户 @param count: 数量 @return: 变化后的值 ''' return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_VIP_EXP, count)
def doBindUser(self, userId, gameId, intClientId): ''' 用户TCP连接建立,绑定用户,检查并建立用户的主游戏基础数据,并返回是否是新用户 ''' self._moveHall51DataBack(userId, gameId, intClientId) ret = DaoGameDataHall.checkAndInit(userId) if ret: tybireport.reportGameEvent('CREATE_GAME_DATA', userId, gameId, 0, 0, 0, 0, 0, 0, [], intClientId, 0, 0) return ret
def setBiggestHallVersion(self, userId, version): return DaoGameDataHall.HSET(userId, HallKeys.ATT_BIGGEST_HALL5_VERSION, version)
def setReliefShareDate(self, userId, timestamp): ''' ''' return DaoGameDataHall.HSET(userId, HallKeys.ATT_RELIEF_SHARE_DATE, timestamp)
def setLoginBeforeVersion511flag(self, userId): return DaoGameDataHall.HSET(userId, HallKeys.ATT_LOGIN_BEFORE_VERSION_TO_511, 1)
def getBiggestHallVersion(self, userId): """ 取得用户登录过的最高客户端版本 """ return DaoGameDataHall.HGET(userId, HallKeys.ATT_BIGGEST_HALL5_VERSION)
def roulette_soldier_reward(self, userId): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_GET_REWARD_NUM, 1)
def setBeneFitsInfo(self, userId, datas): ''' ''' return DaoGameDataHall.HSET(userId, HallKeys.ATT_BENEFITS, datas)
def first_gold_roulette(self, userId): return DaoGameDataHall.HSETNX(userId, HallKeys.ATT_FIRST_GOLD_ROULETTE, 1)
def _setDataValue(self, userId, attName, attValue): return DaoGameDataHall.HSET(userId, attName, attValue)
def incrLoginDays(self, userId, deltaCount): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_LOGIN_DAYS, deltaCount)
def incrSetNameSum(self, userId, detal): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_SET_NAME_SUM, detal)
def getReliefShareDate(self, userId): ''' ''' return DaoGameDataHall.HGET(userId, HallKeys.ATT_RELIEF_SHARE_DATE)
def getSetNameSum(self, userId): return DaoGameDataHall.HGET(userId, HallKeys.ATT_SET_NAME_SUM)
def isFirstGamelist5(self, userId): """ 判定该用户是否第一次使用gamelist5 """ return DaoGameDataHall.HGET(userId, HallKeys.ATT_FIRST_GAME_LIST5)
def incrLoginSum(self, userId, deltaCount): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_LOGIN_SUM, deltaCount)
def changeFirstGamelist5(self, userId): return DaoGameDataHall.HSET(userId, HallKeys.ATT_FIRST_GAME_LIST5, 1)
def set_monthcheckin(self, userId, d): return DaoGameDataHall.HSET(userId, HallKeys.ATT_MONTH_CHECKIN, d)
def getUpdateToVersion511flag(self, userId): """ 判定该用户是否升级到5.11 """ return DaoGameDataHall.HGET(userId, HallKeys.ATT_UPDATE_CLIENT_VERSION_TO_511)
def roulette_attend_soldier_lottery(self, userId): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_CHECKIN_SOLDIERS, 1)
def setUpdateToVersion511flag(self, userId): return DaoGameDataHall.HSET(userId, HallKeys.ATT_UPDATE_CLIENT_VERSION_TO_511, 1)
def getNewMsgId(self, userId): return DaoGameDataHall.HINCRBY(userId, HallKeys.ATT_MESSAGE_ID_MAX, 1)
def getLoginBeforeVersion511flag(self, userId): """ 判定该用户是否在5.11版本之前登录过 """ return DaoGameDataHall.HGET(userId, HallKeys.ATT_LOGIN_BEFORE_VERSION_TO_511)