mirror of
https://github.com/ibratabian17/OpenParty.git
synced 2026-01-15 14:22:54 -03:00
Improve DOTW and Leaderboard
This commit is contained in:
@@ -296,6 +296,7 @@ exports.initroute = (app) => {
|
|||||||
// Entry exists for this profile, update if the new score is higher
|
// Entry exists for this profile, update if the new score is higher
|
||||||
if ((currentScores[existingEntryIndex].score < song.score) && song.score <= 13334) {
|
if ((currentScores[existingEntryIndex].score < song.score) && song.score <= 13334) {
|
||||||
currentScores[existingEntryIndex].score = song.score;
|
currentScores[existingEntryIndex].score = song.score;
|
||||||
|
currentScores[existingEntryIndex].weekOptain = getWeekNumber()
|
||||||
console.log(`[DOTW] Updated score dotw list on map ${song.mapName}`);
|
console.log(`[DOTW] Updated score dotw list on map ${song.mapName}`);
|
||||||
} else {
|
} else {
|
||||||
return res.send('1'); // Do nothing if the new score is lower
|
return res.send('1'); // Do nothing if the new score is lower
|
||||||
|
|||||||
@@ -12,26 +12,15 @@ const LEADERBOARD_PATH = path.join(core.getSavefilePath(), 'leaderboard/leaderbo
|
|||||||
const DOTW_PATH = path.join(core.getSavefilePath(), 'leaderboard/dotw.json');
|
const DOTW_PATH = path.join(core.getSavefilePath(), 'leaderboard/dotw.json');
|
||||||
|
|
||||||
const { getSavefilePath } = require('../helper');
|
const { getSavefilePath } = require('../helper');
|
||||||
const { encrypt, decrypt } = require('../lib/encryptor')
|
|
||||||
|
|
||||||
const secretKey = require('../../database/encryption.json').encrpytion.userEncrypt;
|
const secretKey = require('../../database/encryption.json').encrpytion.userEncrypt;
|
||||||
decryptedData = {};
|
decryptedData = {};
|
||||||
|
|
||||||
function generateToolNickname() {
|
function getWeekNumber() {
|
||||||
const prefixes = ["Wordkeeper", "Special", "Krakenbite", "DinosaurFan", "Definehub", "Termtracker", "Lexiconet", "Vocabvault", "Lingolink", "Glossarygenius", "Thesaurustech", "Synonymster", "Definitionary", "Jargonjot", "Idiomizer", "Phraseforge", "Meaningmaker", "Languageledger", "Etymologyengine", "Grammarguard", "Syntaxsense", "Semanticsearch", "Orthographix", "Phraseology", "Vernacularvault", "Dictionet", "Slangscroll", "Lingualist", "Grammargrid", "Lingoledge", "Termtoolbox", "Wordware", "Lexigizmo", "Synosearch", "Thesaurustech", "Phrasefinder", "Vocabvortex", "Meaningmatrix", "Languageledger", "Etymologist", "Grammargate", "Syntaxsphere", "Semanticsearch", "Orthographix", "Phraseplay", "Vernacularvault", "Dictionator", "Slangstack", "Lingolink", "Grammarguide", "Lingopedia", "Termtracker", "Wordwizard", "Lexilist", "Synomate", "Thesaurustool", "Definitizer", "Jargonjunction", "Idiomgenius", "Phrasemaker", "Meaningmate", "Duolingo", "Languagelink", "Etymoengine", "Grammarguru", "Syntaxsage", "Semanticsuite", "Orthography", "Phrasefinder", "Vocabverse", "Lexipedia", "Synoscribe", "Thesaurusware", "Definitionary", "Jargonscribe", "Idiomster", "Phrasetech", "Meaningmax", "Flop", "Slayguy", "Languagelex", "Etymoedge", "Grammargenie", "Syntaxsync", "Semanticsearch", "Orthography", "Phraseforge", "Vernacularex", "Dictionmaster", "Slangster", "Lingoware", "Grammargraph", "Lingomate", "Termmate", "Wordwork", "Lexixpert", "Synostar", "Thesaurusmax", "OculusVision", "FlowerPower", "RustySilver", "Underfire", "Shakeawake", "Truthhand", "Kittywake", "Definize", "Jargonize", "Idiomify", "Phrasemaster", "Meaningmark", "Lingualine", "Etymogenius", "Grammarguard", "Syntaxsmart", "Semanticsearch", "Orthography", "Phrasedex", "Vocabmax", "Lexilock", "Synomind", "Thesaurusmart", "Definify", "Jargonmatrix", "Idiomnet", "Phraseplay", "Meaningmate", "Lingolink", "Etymoexpert", "Grammargetter", "Syntaxsage", "Semanticsearch", "Orthography", "Phrasepad", "Vernacularvibe", "Dictiondom", "Slangster", "Lingolytics", "Grammargenie", "Lingotutor", "Termtracker", "Wordwarp", "Lexisync", "Synomind", "Thesaurusmate", "Definizer", "Jargonify", "Idiomster", "Phraselab", "Meaningmark", "Languageleaf", "Etymoedge", "Grammargrid", "Syntaxsync", "Semanticsuite", "Orthographix", "Phraseforge", "Vernacularvibe", "Dictiondom", "Slangster", "Lingolytics", "Grammargenie", "Lingotutor", "Termtracker", "Wordwarp", "Lexisync", "Synomind", "Thesaurusmate", "Definizer", "Jargonify", "Idiomster", "Phraselab", "Meaningmark", "Languageleaf", "Etymoedge", "Grammargrid", "Syntaxsync", "Semanticsuite", "Orthographix"];
|
const now = new Date();
|
||||||
const suffixes = ["", "K", "Eja", "Guru", "Master", "Expert", "Ninja", "Pro", "Genius", "Champion", "Mega", "Super", "Ultra", "Ok", "Boomer"];
|
const startOfWeek = new Date(now.getFullYear(), 0, 1);
|
||||||
const numbers = Math.floor(Math.random() * 10000); // Generate a random 4-digit number
|
const daysSinceStartOfWeek = Math.floor((now - startOfWeek) / (24 * 60 * 60 * 1000));
|
||||||
|
return Math.ceil((daysSinceStartOfWeek + 1) / 7);
|
||||||
const randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];
|
|
||||||
const randomSuffix = suffixes[Math.floor(Math.random() * suffixes.length)];
|
|
||||||
|
|
||||||
var name = "";
|
|
||||||
if (Math.floor(Math.random() * 2) == 1) {
|
|
||||||
return randomPrefix + numbers;
|
|
||||||
} else {
|
|
||||||
return randomSuffix + numbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGameVersion = (req) => {
|
const getGameVersion = (req) => {
|
||||||
@@ -40,37 +29,57 @@ const getGameVersion = (req) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const initroute = (app) => {
|
const initroute = (app) => {
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
app.get("/leaderboard/v1/maps/:mapName/:type", async (req, res) => {
|
app.get("/leaderboard/v1/maps/:mapName/:type", async (req, res) => {
|
||||||
const { mapName } = req.params;
|
const { mapName } = req.params;
|
||||||
|
const currentWeekNumber = getWeekNumber(); // Get the current week number
|
||||||
|
|
||||||
switch (req.params.type) {
|
switch (req.params.type) {
|
||||||
case "dancer-of-the-week":
|
case "dancer-of-the-week":
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(DOTW_PATH)) {
|
if (fs.existsSync(DOTW_PATH)) {
|
||||||
const data = fs.readFileSync(DOTW_PATH, 'utf-8');
|
const data = fs.readFileSync(DOTW_PATH, 'utf-8');
|
||||||
const leaderboard = JSON.parse(data);
|
const leaderboard = JSON.parse(data);
|
||||||
|
|
||||||
// Check if the map exists in the leaderboard
|
// Check if the map exists in the leaderboard
|
||||||
if (leaderboard[mapName] && leaderboard[mapName].length > 0) {
|
if (leaderboard[mapName] && leaderboard[mapName].length > 0) {
|
||||||
// Find the highest score entry for this map
|
// Filter entries for the current week
|
||||||
const highestEntry = leaderboard[mapName].reduce((max, entry) => entry.score > max.score ? entry : max);
|
const currentWeekEntries = leaderboard[mapName].filter(
|
||||||
|
entry => entry.weekOptain === currentWeekNumber
|
||||||
const dancerOfTheWeek = {
|
);
|
||||||
"__class": "DancerOfTheWeek",
|
|
||||||
"profileId": highestEntry.profileId,
|
// Check if there are any entries for the current week
|
||||||
"score": highestEntry.score,
|
if (currentWeekEntries.length > 0) {
|
||||||
"gameVersion": highestEntry.gameVersion || "jd2020",
|
// Find the highest score entry for this map and current week
|
||||||
"rank": highestEntry.rank, // Since it's the highest, assign rank 1
|
const highestEntry = currentWeekEntries.reduce((max, entry) =>
|
||||||
"name": highestEntry.name,
|
entry.score > max.score ? entry : max
|
||||||
"avatar": highestEntry.avatar,
|
);
|
||||||
"country": highestEntry.country,
|
|
||||||
"platformId": highestEntry.platformId,
|
const dancerOfTheWeek = {
|
||||||
"alias": highestEntry.alias,
|
"__class": "DancerOfTheWeek",
|
||||||
"aliasGender": highestEntry.aliasGender,
|
"profileId": highestEntry.profileId,
|
||||||
"jdPoints": highestEntry.jdPoints,
|
"score": highestEntry.score,
|
||||||
"portraitBorder": highestEntry.portraitBorder
|
"gameVersion": highestEntry.gameVersion || "jd2020",
|
||||||
};
|
"rank": highestEntry.rank || 1, // Since it's the highest, assign rank 1
|
||||||
|
"name": highestEntry.name,
|
||||||
res.json(dancerOfTheWeek);
|
"avatar": highestEntry.avatar,
|
||||||
|
"country": highestEntry.country,
|
||||||
|
"platformId": highestEntry.platformId,
|
||||||
|
"alias": highestEntry.alias,
|
||||||
|
"aliasGender": highestEntry.aliasGender,
|
||||||
|
"jdPoints": highestEntry.jdPoints,
|
||||||
|
"portraitBorder": highestEntry.portraitBorder
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(dancerOfTheWeek);
|
||||||
|
} else {
|
||||||
|
// No entries for the current week, return default response
|
||||||
|
res.json({
|
||||||
|
"__class": "DancerOfTheWeek",
|
||||||
|
"gameVersion": "jd2019",
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res.json({
|
res.json({
|
||||||
"__class": "DancerOfTheWeek",
|
"__class": "DancerOfTheWeek",
|
||||||
@@ -78,7 +87,7 @@ const initroute = (app) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('[ACC] Unable to find DOTW Files')
|
console.log('[ACC] Unable to find DOTW Files');
|
||||||
// If leaderboard file does not exist, return default "NO DOTW" response
|
// If leaderboard file does not exist, return default "NO DOTW" response
|
||||||
res.json({
|
res.json({
|
||||||
"__class": "DancerOfTheWeek",
|
"__class": "DancerOfTheWeek",
|
||||||
@@ -89,57 +98,66 @@ const initroute = (app) => {
|
|||||||
console.error("Error:", error.message);
|
console.error("Error:", error.message);
|
||||||
res.status(500).send("Internal Server Error");
|
res.status(500).send("Internal Server Error");
|
||||||
}
|
}
|
||||||
break; // <--- Add this break
|
break; // Ensure break is here
|
||||||
|
|
||||||
case "friends":
|
case "friends":
|
||||||
res.send({ __class: "LeaderboardList", entries: [] });
|
res.send({ __class: "LeaderboardList", entries: [] });
|
||||||
break; // <--- Add this break
|
break;
|
||||||
|
|
||||||
case "world": {
|
case "world": {
|
||||||
let leaderboardData = {
|
let leaderboardData = {
|
||||||
"__class": "LeaderboardList",
|
"__class": "LeaderboardList",
|
||||||
"entries": []
|
"entries": []
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Read the leaderboard file
|
// Read the leaderboard file
|
||||||
const leaderboardFilePath = LEADERBOARD_PATH;
|
const leaderboardFilePath = LEADERBOARD_PATH;
|
||||||
if (fs.existsSync(leaderboardFilePath)) {
|
if (fs.existsSync(leaderboardFilePath)) {
|
||||||
const data = fs.readFileSync(leaderboardFilePath, 'utf-8');
|
const data = fs.readFileSync(leaderboardFilePath, 'utf-8');
|
||||||
const leaderboard = JSON.parse(data);
|
const leaderboard = JSON.parse(data);
|
||||||
|
|
||||||
// Check if there are entries for the mapName
|
// Check if there are entries for the mapName
|
||||||
if (leaderboard[mapName]) {
|
if (leaderboard[mapName]) {
|
||||||
// Sort the leaderboard entries by score in descending order
|
// Sort the leaderboard entries by score in descending order
|
||||||
const sortedEntries = leaderboard[mapName].sort((a, b) => b.score - a.score);
|
const sortedEntries = leaderboard[mapName].sort((a, b) => b.score - a.score);
|
||||||
|
|
||||||
leaderboardData.entries = sortedEntries.map(entry => ({
|
// Limit the sorted entries to the first 6
|
||||||
"__class": "LeaderboardEntry_Online",
|
const topSixEntries = sortedEntries.slice(0, 6);
|
||||||
"profileId": entry.profileId,
|
let rank = 0;
|
||||||
"score": entry.score,
|
|
||||||
"name": entry.nickname,
|
leaderboardData.entries = topSixEntries.map(entry => {
|
||||||
"avatar": entry.avatar,
|
rank++;
|
||||||
"country": entry.country,
|
const newLeaderboard = {
|
||||||
"platformId": entry.platformId,
|
"__class": "LeaderboardEntry_Online",
|
||||||
"alias": entry.alias,
|
"profileId": entry.profileId,
|
||||||
"aliasGender": entry.aliasGender,
|
"score": entry.score,
|
||||||
"jdPoints": entry.jdPoints,
|
"name": entry.name || entry.nickname,
|
||||||
"portraitBorder": entry.portraitBorder,
|
"avatar": entry.avatar,
|
||||||
"mapName": mapName
|
"rank": rank,
|
||||||
}));
|
"country": entry.country,
|
||||||
|
"platformId": entry.platformId,
|
||||||
|
"alias": entry.alias,
|
||||||
|
"aliasGender": entry.aliasGender,
|
||||||
|
"jdPoints": entry.jdPoints,
|
||||||
|
"portraitBorder": entry.portraitBorder,
|
||||||
|
"mapName": mapName
|
||||||
|
}
|
||||||
|
return newLeaderboard;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(leaderboardData);
|
res.json(leaderboardData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error.message);
|
console.error("Error:", error.message);
|
||||||
res.status(500).send("Internal Server Error");
|
res.status(500).send("Internal Server Error");
|
||||||
}
|
}
|
||||||
break; // <--- Add this break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user