def getRankingListByRankNumberList(cls, rankingMax, rankNumberList): ''' 获得指定排名的玩家和分数 :param rankingMax: 最大排名,加载的TopN人数 :param rankNumberList: 指定名次的列表, 从1开始[1,2,3,10,50] ''' issueNum = cls.getYesterdayRankingIssueNumber() replays = replay_service.getTopNReplayWithViewsCount(issueNum, rankingMax) if ftlog.is_debug(): ftlog.debug('RankingProxy.getRankingListByRankNumberList:', 'issueNum=', issueNum, 'rankingMax=', rankingMax, 'rankNumberList=', rankNumberList, 'replays.length', len(replays)) rankingList = [] for index, item in enumerate(replays): replay, replayCount = item rankNumber = index + 1 if rankNumber in rankNumberList: if ftlog.is_debug(): ftlog.debug('RankingProxy.getRankingListByRankNumberList', 'replay.userId=', replay.userId, 'replayCount=', replayCount) rankingList.append({ 'rankNumber': rankNumber, 'nickname': UserInfo.getNickname(replay.userId), 'rankValue': replayCount, }) if ftlog.is_debug(): ftlog.debug('RankingProxy.getRankingListByRankNumberList:rankingList=', rankingList) return rankingList
def buildSuccessMessagePack(cls, userId, itemconf): ''' 构建抽奖成功的result结果 @param: itemconf - 抽到的奖励项 ''' return {'success':True, 'message': cls.buildLuckyDrawMessage(itemconf), 'name': UserInfo.getNickname(userId), 'mychip': UserInfo.getChip(userId)}
def sendLedText(self, activityGameId, userId, prize): ledsMap = Tool.dictGet(self._clientConf, 'config.server.ledsMap', {}) prizes = Tool.dictGet(self._clientConf, 'config.server.prizes', []) for item in prizes: # 根据奖励itemId找到奖励配置 if item['itemId'] != prize['itemId']: continue # 获取led发送的配置 ledItem = ledsMap.get(item.get('ledKey')) if not ledItem: continue # 查看是否满足LED发送条件 if ledItem.get('minCount', 0) > prize['count']: continue text = ledItem.get('text') if not text: continue prizeContent = hallitem.buildContent(prize['itemId'], prize['count'], True) ledtext = strutil.replaceParams( text, { 'nickname': UserInfo.getNickname(userId), 'prizeContent': prizeContent }) hallled.sendLed(activityGameId, ledtext, 0, scope='hall6') if ftlog.is_debug(): ftlog.debug('LuckyMoneyNew.sendLedText', 'activityGameId=', activityGameId, 'activityId=', self._clientConf['id'], 'userId=', userId, 'ledtext=', ledtext) break
def onUpdate(cls): ftlog.debug( "RankingPriorityLedSender.onUpdate", "cls.currentRankingUser="******"cls.rankingRewardList=", cls.rankingRewardList, "cls.ledFormatText=", cls.ledFormatText, "ifok=", not not (not cls.currentRankingUser or not cls.ledFormatText or not cls.rankingRewardList)) if not cls.currentRankingUser or not cls.ledFormatText or not cls.rankingRewardList: cls.currentRankingUser = None cls.oldRankingUser = None cls.loopTimerCounter = 0 if cls.loopTimer: cls.loopTimer.cancel() return ftlog.debug("RankingPriorityLedSender.onUpdate", "userId=", cls.currentRankingUser.userId, "cls.loopTimerCounter", cls.loopTimerCounter) helper = RankingRewardHelper(cls.currentRankingUser.userId, cls.rankingRewardList) reachedlist = helper.getReachedConfList() currentconf = {} if reachedlist and len(reachedlist) > 0: currentconf = reachedlist[-1] dictionary = {} dictionary['ranking_current_item'] = Tool.dictGet( currentconf, 'rewardContent.desc') dictionary['newuser_nickname'] = UserInfo.getNickname( cls.currentRankingUser.userId) dictionary['newuser_ranknumber'] = str( DumplingsUtil.getRankingWithUserId(cls.currentRankingUser.userId)) dictionary['olduser_nickname'] = UserInfo.getNickname( cls.oldRankingUser.userId) led = strutil.replaceParams(cls.ledFormatText, dictionary) Tool.sendLed(led) cls.loopTimerCounter += 1 if cls.loopTimerCounter >= 5: ftlog.debug("RankingPriorityLedSender.onUpdate ", "cls.loopTimerCounter>=5:", "userId=", cls.currentRankingUser.userId) cls.currentRankingUser = None cls.oldRankingUser = None cls.loopTimer.cancel() cls.loopTimerCounter = 0
def sendLedIfNeed(self, userId, itemconf, count): ''' 如果满足情况则,发送LED :param itemconf: 红包奖励配置项{"type":"random.fixed", "itemId": "item:2003", "desc":"记牌器", "num":500, "count":1, "led": "led1"} :param count: 拆红包真实领取的物品个数 :return: Bool, 是否发送 ''' settingkey = itemconf.get("led", False) if not settingkey: return False ftlog.debug("TYActivityDdzRedEnvelope.sendLedIfNeed: settingkey=", settingkey) clientconf = self._clientConf settingmap = Tool.dictGet(clientconf, "config.activate.ledSetting") if not settingmap: return False ftlog.debug("TYActivityDdzRedEnvelope.sendLedIfNeed: settingmap=", settingmap) setting = settingmap.get(settingkey) if not setting: return False ftlog.debug("TYActivityDdzRedEnvelope.sendLedIfNeed: setting=", setting) text = setting.get("text") if (not text) or len(text) <= 0: return False ftlog.debug("TYActivityDdzRedEnvelope.sendLedIfNeed: text=", text, "mincount", setting.get("min", 0)) mincount = setting.get("min", 0) if count >= mincount: leddict = { "assets": str(itemconf.get('desc')), "count": str(count), "userId": str(userId), "nickname": str(UserInfo.getNickname(userId)) } text = strutil.replaceParams(text, leddict) Tool.sendLed(text) return True return False
def buildRecord(cls, userId, itemconf): return {'message': WarmUpSystemHelper.buildLuckyDrawMessage(itemconf), 'name': UserInfo.getNickname(userId)}
def handleRequestGetting(self, model, userId, poolItem): ''' 已经投入资本,领取奖励 :param userId: :return: ''' clientconf = strutil.deepcopy(self._clientConf) serverconf = self._serverConf uniquekey = Utility.buildUniqueKey(serverconf) ftlog.debug('WishingWell.handleRequestGetting:start', 'userId=', userId, 'model=', model.dict()) ## 判断计时是否完成 countingSeconds = model.getCountingSeconds() if countingSeconds < poolItem.get('duration', 0): ## 计时未完成 return Utility.buildError(Tool.dictGet(clientconf, 'config.countingDownError')) ## 发送用户奖励 led = Tool.dictGet(clientconf, 'config.led') mail = Tool.dictGet(clientconf, 'config.mail') rewardconf = poolItem.get('reward', {}) rtype = rewardconf.get('type', 'fixed') clz = self.rewardHandlerMap[rtype] ftlog.debug('WishingWell.handleRequestGetting:send', 'userId=', userId, 'rewardconf=', rewardconf, 'rtype=', rtype, 'clz=', clz) if not clz: return Utility.buildError(None) sendcount = clz(rewardconf, mail).sendToUser(userId) ## 是否触发LED ledTrigger = poolItem.get('ledTrigger', -1) if ledTrigger>=0 and ledTrigger<=sendcount: nickname = UserInfo.getNickname(userId) Tool.sendLed(strutil.replaceParams(led, {'nickname':nickname})) ftlog.debug('WishingWell.handleRequestGetting:led', 'userId=', userId, 'ledTrigger=', ledTrigger, 'sendcount=', sendcount, 'led-trigger-ok', (ledTrigger>=0 and ledTrigger<=sendcount)) ftlog.info('WishingWell.handleRequestGetting, ', 'userId', userId, 'poolstepindex', model.poolStepIndex, 'sendcount', sendcount, 'model=', model.dict()) model.isAlreadyPutted = False model.poolStepIndex += 1 model.dumpsToRedis(userId, uniquekey) ftlog.debug('WishingWell.handleRequestGetting:end', 'userId=', userId, 'model=', model.dict()) response = self.getActivityUserStatus(userId, model) gettingSuccess = Tool.dictGet(clientconf, 'config.gettingSuccess') rewardDescription = strutil.replaceParams(Tool.dictGet(poolItem, 'reward.desc'), {'count': sendcount}) if gettingSuccess and len(gettingSuccess) > 0: response['message'] = strutil.replaceParams(gettingSuccess, {'assets_reward_desc':rewardDescription}) response['operate'] = 'getting' return response
def _doReport(cls, gameId, userId, otherPlayerId, reasons): mo = MsgPack() mo.setCmd('dizhu') mo.setResult('action', 'user_report') # 检测举报条件 reportDetail = gamedata.getGameAttr(userId, gameId, 'report') reportDetail = strutil.loads(reportDetail) if reportDetail else {} reportCount = reportDetail.setdefault('count', 0) reportTimestamp = reportDetail.setdefault('timestamp', 1356969600) currentTimestamp = pktimestamp.getCurrentTimestamp() if not pktimestamp.is_same_day(currentTimestamp, reportTimestamp): reportDetail['count'] = 0 else: if reportCount >= 10: mo.setError(1, '举报过于频繁,系统正在核实举报信息') router.sendToUser(mo, userId) return if currentTimestamp - reportTimestamp < 180: mo.setError(2, '举报过于频繁,系统正在核实举报信息') mo.setResult('remaining', 180 - (currentTimestamp - reportTimestamp)) router.sendToUser(mo, userId) return # 发送消息给举报者, 增加举报者举报次数 reportDetail['count'] += 1 reportDetail['timestamp'] = currentTimestamp gamedata.setGameAttr(userId, gameId, 'report', strutil.dumps(reportDetail)) reportStr = '' for reason in reasons: reportStr += cls._getTipByReason(reason) tip = '举报反馈:\n 您举报了玩家【%s】。\n 我们会核实原因,进行相应处理。' % ( UserInfo.getNickname(otherPlayerId)) mo.setResult('success', 1) mo.setResult('tip', tip) router.sendToUser(mo, userId) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, tip) # 发送消息给被举报者,只有在原因①/③的情况下,被举报玩家才会收到信息,若被举报玩家同时因①③被举报,则优先使用①的被举报文本。 # 增加被举报者举报次数 reportedDetail = gamedata.getGameAttr(otherPlayerId, gameId, 'reported') reportedDetail = strutil.loads( reportedDetail) if reportedDetail else {} reportedDetail.setdefault('count', 0) for r in reasons: if r in [UserReportReason.NEGATIVE, UserReportReason.OFFLINE]: reportedDetail['count'] += 1 if not pktimestamp.is_same_day(currentTimestamp, reportTimestamp): reportedDetail.setdefault(str(r), 0) reportedDetail[str(r)] = 0 else: reportedDetail.setdefault(str(r), 0) reportedDetail[str(r)] += 1 gamedata.setGameAttr(otherPlayerId, gameId, 'reported', strutil.dumps(reportedDetail)) tip = '' if UserReportReason.NEGATIVE in reasons: tip = '举报信息:\n 您因<%s>被玩家举报。\n 系统已记录,下次要认真一些喔~' % cls._getTipByReason( UserReportReason.NEGATIVE) if reportedDetail.setdefault(str(UserReportReason.NEGATIVE), 0) > 5: tip = '' if UserReportReason.OFFLINE in reasons: if reportedDetail.setdefault(str(UserReportReason.OFFLINE), 0) > 5: tip = tip else: tip = '举报信息:\n 您因<%s>被玩家举报。\n 快去找一个好的网络环境吧~' % cls._getTipByReason( UserReportReason.OFFLINE) if tip: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, otherPlayerId, tip)