reset UUID y shame persistente

This commit is contained in:
2025-08-16 00:56:16 -06:00
parent b18397deb4
commit 730c7bda9e
5 changed files with 291 additions and 6 deletions

View File

@@ -336,6 +336,32 @@ adminRouter.post("/admin/send-all-to-lobby", async (req: Request, res: Response)
}
});
// Reset all stored UUID profiles (name, color, shame tokens)
adminRouter.post("/admin/reset-uuid-profiles", async (req: Request, res: Response) => {
try {
const allowlist = listAllowedUuids();
const known = NameManager.getInstance().getAllKnownUuids();
const all = Array.from(new Set([...(allowlist || []), ...(known || [])]));
let resetCount = 0;
all.forEach(uuid => {
if (uuid) {
NameManager.getInstance().clearPlayerProfile(uuid);
resetCount++;
}
});
// Optionally, we could also update active rooms, but we keep it as future joins behavior.
// Broadcast dashboard update so clients refresh any derived data
setTimeout(() => { try { broadcastDashboardUpdate(); } catch {} }, 100);
res.json({ success: true, message: `Reset profiles for ${resetCount} UUIDs` });
} catch (error) {
console.error("[AdminAPI] Error resetting UUID profiles:", error);
res.status(500).json({ error: "Failed to reset UUID profiles" });
}
});
adminRouter.post("/admin/shuffle-players", async (req: Request, res: Response) => {
try {
console.log("[AdminAPI] Starting player shuffle...");

View File

@@ -71,6 +71,15 @@ export class NameManager {
return Array.from(this.uuidToName.values());
}
// List all UUIDs that have any stored profile data
getAllKnownUuids(): string[] {
const set = new Set<string>();
this.uuidToName.forEach((_, k) => set.add(k));
this.uuidToColor.forEach((_, k) => set.add(k));
this.uuidToShame.forEach((_, k) => set.add(k));
return Array.from(set.values());
}
// Sticky shame tokens per UUID
setShameTokens(uuid: string, count: number): void {
const n = Math.max(0, Math.floor(count || 0));
@@ -81,6 +90,14 @@ export class NameManager {
return this.uuidToShame.get(uuid) || 0;
}
// Clear stored profile data for a UUID (name, color, shame)
clearPlayerProfile(uuid: string): void {
if (!uuid) return;
this.uuidToName.delete(uuid);
this.uuidToColor.delete(uuid);
this.uuidToShame.set(uuid, 0);
}
// Current game room assignment (for reconnection by UUID)
setCurrentRoom(uuid: string, roomId: string): void {
if (!uuid || !roomId) return;