diff --git a/src/api_s2c/jjc/ApiOpen.ts b/src/api_s2c/jjc/ApiOpen.ts index d9743a8..4002e1a 100644 --- a/src/api_s2c/jjc/ApiOpen.ts +++ b/src/api_s2c/jjc/ApiOpen.ts @@ -27,4 +27,7 @@ export default async function (call: ApiCall) { ...data, ...enemy }); -} + + JJCFun.checkUpdatePlayer() + +} \ No newline at end of file diff --git a/src/public/jjc.ts b/src/public/jjc.ts index 9bf4232..d571417 100644 --- a/src/public/jjc.ts +++ b/src/public/jjc.ts @@ -87,6 +87,45 @@ export class JJCFun { return rankList } + /** + * 每10分钟刷新前一千名玩家的用户数据 + * @param min + * @param max + * @param uTimeOffset + * @param isUpdate 是否更新数据 + */ + static async checkUpdatePlayer(min: number = 0, max: number = 1000, uTimeOffset: number = 600, isUpdate: boolean = true) { + // 获取指定排名用户uid + let sortInfo = await this.getRankListUid(min, max) + if (!sortInfo.length) return [] + let updateArr = [] + + let users = await G.redis.hGetAll('rank:jjc:data') + + for (let i = 0; i < sortInfo.length; i++) { + let uid = sortInfo[i] + let rankInfo = users[uid] + if (!rankInfo?.player) continue + // 比对utime,判断是否更新数据 + if (!rankInfo.player.isNpc) { + if (!rankInfo.utime || (rankInfo.utime && rankInfo.utime < (G.time - uTimeOffset))) { + updateArr.push(rankInfo) + } + } + } + // 更新数据 + if (isUpdate && updateArr.length > 0) { + let playerArrInfo = await G.mongodb.collection("user").find({uid: {$in: updateArr.map(i => i.uid)}}).toArray() + for (let i = 0; i < playerArrInfo.length; i++) { + let playerInfo = playerArrInfo[i] + let index = updateArr.findIndex(x => x.player.uid == playerInfo.uid) + updateArr[index].player = playerInfo + updateArr[index].utime = G.time + this.updatePlayerData(playerInfo.uid, updateArr[index]); + } + } + } + /** * 获取指定范围排名的用户,仅返回uid[] * @param min