bug fixes and added stats viewer to admin leaderboard.

This commit is contained in:
bobbert committed 2025-03-20 19:19:28 +00:00
1 parent 7075a816c3
commit d60f52fef3
7 files changed
+1046 -233

No files matched your search

+34 -17
View File
@@ -354,32 +354,49 @@ export default function CluePage({ params }) {
}
try {
// Handle multiple QR code formats: "QR123", "123", or even "Clue 123"
let scannedClueId;
// Try regex patterns
if (!data || !clue) return;
// Normalize the scanned QR code value
const normalizedInput = data.trim().toUpperCase();
// Try to use the QR code field, but fall back to a generated one if it's missing or empty
let expectedQrCode = (clue.qr_code || "").trim().toUpperCase();
// If QR code is missing or empty, generate a fallback based on the clue ID
if (!expectedQrCode) {
expectedQrCode = `QR${clue.id}`.toUpperCase();
}
// First try a direct match with the QR code
if (normalizedInput === expectedQrCode) {
// Exact match with the clue's QR code
setScanMessage("✓ Correct QR code found!");
markClueAsFound(clueId);
return;
}
// If not a direct match, try to extract the numeric value
const qrPattern = /^QR[^0-9]*(\d+)$/i;
const cluePattern = /^clue[^0-9]*(\d+)$/i;
const numberPattern = /^(\d+)$/;
let match =
data.match(qrPattern) ||
data.match(cluePattern) ||
data.match(numberPattern);
// Extract the number from the scanned input
const inputMatch =
normalizedInput.match(qrPattern) ||
normalizedInput.match(cluePattern) ||
normalizedInput.match(numberPattern);
if (match) {
scannedClueId = parseInt(match[1], 10);
} else {
// Try direct parsing as a last resort
scannedClueId = parseInt(data, 10);
}
// Extract the number from the expected QR code
const expectedMatch = expectedQrCode.match(qrPattern);
if (!isNaN(scannedClueId) && scannedClueId === parseInt(clueId)) {
// Correct QR code scanned, mark as found
if (inputMatch && expectedMatch && inputMatch[1] === expectedMatch[1]) {
// The numeric parts match
setScanMessage("✓ Correct QR code found!");
markClueAsFound(clueId);
} else if (!isNaN(scannedClueId)) {
} else if (inputMatch) {
// Found a number in the input, but it doesn't match
setScanMessage(
`QR code for clue ${scannedClueId} scanned, but you need clue ${clueId}. Please scan the correct code.`
`QR code "${data}" scanned, but you need to scan "${expectedQrCode}". Please scan the correct code.`
);
} else {
setScanMessage(