leaderboard implementado v3

This commit is contained in:
2025-08-28 02:47:07 -06:00
parent 220248b588
commit 318a7847b8
4 changed files with 150 additions and 106 deletions

View File

@@ -938,7 +938,8 @@ async function sendPlayersActionsUpdate(client?: Response) {
total,
detailedHistory,
rawHistory: history,
roomScoreHistory
roomScoreHistory,
shameTokens: nameManager.getShameTokens(uuid)
};
}).filter((p: any) => p.total > 0 || p.name);
@@ -977,23 +978,49 @@ adminRouter.post("/admin/namemanager/import", async (req: Request, res: Response
const nameManager = NameManager.getInstance();
const state = req.body;
if (!state || !state.data) {
return res.status(400).json({ error: 'Invalid state format' });
// Validate request size and format
if (!state) {
return res.status(400).json({ error: 'No data provided' });
}
if (!state.data) {
return res.status(400).json({
error: 'Invalid state format - missing data property',
hint: 'Ensure you are uploading a valid .snatchSave file'
});
}
console.log(`[AdminAPI] Importing nameManager state - Version: ${state.version || 'unknown'}`);
nameManager.importState(state);
// Broadcast update to SSE clients after importing
await sendUuidsUpdate();
await sendPlayersActionsUpdate();
const importedUuids = nameManager.getAllKnownUuids().length;
console.log(`[AdminAPI] Successfully imported nameManager state with ${importedUuids} UUIDs`);
res.json({
success: true,
message: `NameManager state imported successfully. Version: ${state.version || 'unknown'}`
message: `NameManager state imported successfully. Version: ${state.version || 'unknown'}, UUIDs: ${importedUuids}`,
importedUuids
});
} catch (error) {
console.error('[AdminAPI] Error importing nameManager state:', error);
res.status(500).json({ error: 'Failed to import nameManager state', details: error.message });
// Handle specific error types
if (error.message && error.message.includes('PayloadTooLargeError')) {
return res.status(413).json({
error: 'File too large',
details: 'The save file is too large to process. Maximum size: 50MB'
});
}
res.status(500).json({
error: 'Failed to import nameManager state',
details: error.message
});
}
});

View File

@@ -12,7 +12,8 @@ const port = Number(process.env.PORT) || 3000;
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
const server = createServer(app);
const gameServer = new Server({