allow top 10 users to place on top maps, even when they are Private
fix #36
This commit is contained in:
parent
4406829c0a
commit
5ea71d01b4
|
@ -44,29 +44,19 @@ class Ranks {
|
||||||
// pixels placed by day
|
// pixels placed by day
|
||||||
pDailyStats: [],
|
pDailyStats: [],
|
||||||
};
|
};
|
||||||
|
this.prevTopIds = [];
|
||||||
/*
|
/*
|
||||||
* we go through socketEvents for sharding
|
* we go through socketEvents for sharding
|
||||||
*/
|
*/
|
||||||
socketEvents.on('rankingListUpdate', (rankings) => {
|
socketEvents.on('rankingListUpdate', (rankings) => {
|
||||||
this.ranks = {
|
this.mergeIntoRanks(rankings);
|
||||||
...this.ranks,
|
|
||||||
...rankings,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
try {
|
try {
|
||||||
let someRanks = await Ranks.dailyUpdateRanking();
|
this.mergeIntoRanks(await Ranks.dailyUpdateRanking());
|
||||||
this.ranks = {
|
this.mergeIntoRanks(await Ranks.hourlyUpdateRanking());
|
||||||
...this.ranks,
|
|
||||||
...someRanks,
|
|
||||||
};
|
|
||||||
someRanks = await Ranks.hourlyUpdateRanking();
|
|
||||||
this.ranks = {
|
|
||||||
...this.ranks,
|
|
||||||
...someRanks,
|
|
||||||
};
|
|
||||||
await Ranks.updateRanking();
|
await Ranks.updateRanking();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
@ -77,6 +67,21 @@ class Ranks {
|
||||||
DailyCron.hook(Ranks.setDailyRanking);
|
DailyCron.hook(Ranks.setDailyRanking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mergeIntoRanks(newRanks) {
|
||||||
|
if (!newRanks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { prevTopIds } = newRanks;
|
||||||
|
if (prevTopIds) {
|
||||||
|
this.prevTopIds = prevTopIds;
|
||||||
|
delete newRanks.prevTopIds;
|
||||||
|
}
|
||||||
|
this.ranks = {
|
||||||
|
...this.ranks,
|
||||||
|
...newRanks,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static async updateRanking() {
|
static async updateRanking() {
|
||||||
// only main shard does it
|
// only main shard does it
|
||||||
if (!socketEvents.amIImportant()) {
|
if (!socketEvents.amIImportant()) {
|
||||||
|
@ -121,9 +126,9 @@ class Ranks {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async dailyUpdateRanking() {
|
static async dailyUpdateRanking() {
|
||||||
const prevTop = await populateRanking(
|
const prevTopData = await getPrevTop();
|
||||||
await getPrevTop(),
|
const prevTopIds = prevTopData.map((d) => d.id);
|
||||||
);
|
const prevTop = await populateRanking(prevTopData);
|
||||||
const pDailyStats = await getDailyPixelStats();
|
const pDailyStats = await getDailyPixelStats();
|
||||||
const histStats = await getTopDailyHistory();
|
const histStats = await getTopDailyHistory();
|
||||||
histStats.users = await populateRanking(histStats.users);
|
histStats.users = await populateRanking(histStats.users);
|
||||||
|
@ -134,6 +139,7 @@ class Ranks {
|
||||||
prevTop,
|
prevTop,
|
||||||
pDailyStats,
|
pDailyStats,
|
||||||
histStats,
|
histStats,
|
||||||
|
prevTopIds,
|
||||||
};
|
};
|
||||||
if (socketEvents.amIImportant()) {
|
if (socketEvents.amIImportant()) {
|
||||||
// only main shard sends to others
|
// only main shard sends to others
|
||||||
|
|
|
@ -126,7 +126,7 @@ export default async function drawByOffsets(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canvas.req === 'top'
|
if (canvas.req === 'top'
|
||||||
&& !rankings.ranks.prevTop.find((r) => r.id === user.id)
|
&& !rankings.prevTopIds.includes(user.id)
|
||||||
) {
|
) {
|
||||||
// not in top ten
|
// not in top ten
|
||||||
throw new Error(12);
|
throw new Error(12);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user