Compare commits
10 commits
6e2ebf7ff3
...
e17632405a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e17632405a | ||
|
|
c39c92e6d3 | ||
|
|
e77167bca4 | ||
|
|
06bf69c167 | ||
|
|
43a650a9b6 | ||
|
|
857003c77b | ||
|
|
02d686ccae | ||
|
|
661df0616b | ||
|
|
9e24d86140 | ||
|
|
4b467cba81 |
24 changed files with 958 additions and 109 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -39,3 +39,6 @@ yarn-error.log*
|
|||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
# clerk configuration (can include secrets)
|
||||
/.clerk/
|
||||
|
|
|
|||
11
bun.lock
11
bun.lock
|
|
@ -5,6 +5,9 @@
|
|||
"name": "web",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.0.0",
|
||||
"@next/swc-darwin-arm64": "^16.1.6",
|
||||
"@vercel/analytics": "^1.6.1",
|
||||
"@vercel/speed-insights": "^1.3.1",
|
||||
"@xboxreplay/xboxlive-api": "^3.4.3",
|
||||
"@yudiel/react-qr-scanner": "^2.5.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
|
|
@ -233,7 +236,7 @@
|
|||
|
||||
"@next/eslint-plugin-next": ["@next/eslint-plugin-next@16.0.10", "", { "dependencies": { "fast-glob": "3.3.1" } }, "sha512-b2NlWN70bbPLmfyoLvvidPKWENBYYIe017ZGUpElvQjDytCWgxPJx7L9juxHt0xHvNVA08ZHJdOyhGzon/KJuw=="],
|
||||
|
||||
"@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@16.0.10", "", { "os": "darwin", "cpu": "arm64" }, "sha512-4XgdKtdVsaflErz+B5XeG0T5PeXKDdruDf3CRpnhN+8UebNa5N2H58+3GDgpn/9GBurrQ1uWW768FfscwYkJRg=="],
|
||||
"@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@16.1.6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-wTzYulosJr/6nFnqGW7FrG3jfUUlEf8UjGA0/pyypJl42ExdVgC6xJgcXQ+V8QFn6niSG2Pb8+MIG1mZr2vczw=="],
|
||||
|
||||
"@next/swc-darwin-x64": ["@next/swc-darwin-x64@16.0.10", "", { "os": "darwin", "cpu": "x64" }, "sha512-spbEObMvRKkQ3CkYVOME+ocPDFo5UqHb8EMTS78/0mQ+O1nqE8toHJVioZo4TvebATxgA8XMTHHrScPrn68OGw=="],
|
||||
|
||||
|
|
@ -507,6 +510,10 @@
|
|||
|
||||
"@unrs/resolver-binding-win32-x64-msvc": ["@unrs/resolver-binding-win32-x64-msvc@1.11.1", "", { "os": "win32", "cpu": "x64" }, "sha512-lrW200hZdbfRtztbygyaq/6jP6AKE8qQN2KvPcJ+x7wiD038YtnYtZ82IMNJ69GJibV7bwL3y9FgK+5w/pYt6g=="],
|
||||
|
||||
"@vercel/analytics": ["@vercel/analytics@1.6.1", "", { "peerDependencies": { "@remix-run/react": "^2", "@sveltejs/kit": "^1 || ^2", "next": ">= 13", "react": "^18 || ^19 || ^19.0.0-rc", "svelte": ">= 4", "vue": "^3", "vue-router": "^4" }, "optionalPeers": ["@remix-run/react", "@sveltejs/kit", "next", "react", "svelte", "vue", "vue-router"] }, "sha512-oH9He/bEM+6oKlv3chWuOOcp8Y6fo6/PSro8hEkgCW3pu9/OiCXiUpRUogDh3Fs3LH2sosDrx8CxeOLBEE+afg=="],
|
||||
|
||||
"@vercel/speed-insights": ["@vercel/speed-insights@1.3.1", "", { "peerDependencies": { "@sveltejs/kit": "^1 || ^2", "next": ">= 13", "react": "^18 || ^19 || ^19.0.0-rc", "svelte": ">= 4", "vue": "^3", "vue-router": "^4" }, "optionalPeers": ["@sveltejs/kit", "next", "react", "svelte", "vue", "vue-router"] }, "sha512-PbEr7FrMkUrGYvlcLHGkXdCkxnylCWePx7lPxxq36DNdfo9mcUjLOmqOyPDHAOgnfqgGGdmE3XI9L/4+5fr+vQ=="],
|
||||
|
||||
"@xboxreplay/errors": ["@xboxreplay/errors@0.1.0", "", {}, "sha512-Tgz1d/OIPDWPeyOvuL5+aai5VCcqObhPnlI3skQuf80GVF3k1I0lPCnGC+8Cm5PV9aLBT5m8qPcJoIUQ2U4y9g=="],
|
||||
|
||||
"@xboxreplay/xboxlive-api": ["@xboxreplay/xboxlive-api@3.4.3", "", { "dependencies": { "@xboxreplay/errors": "^0.1.0", "axios": "^0.21.1" } }, "sha512-+iSmNCN4RHXZXBc48e0tJB+tvUs6XEwEWcXTcECrIttgDVN9fsFxroo+6ET+K38FobEM+5xUOfCVNqQoWQthxQ=="],
|
||||
|
|
@ -1555,6 +1562,8 @@
|
|||
|
||||
"msw/yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="],
|
||||
|
||||
"next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@16.0.10", "", { "os": "darwin", "cpu": "arm64" }, "sha512-4XgdKtdVsaflErz+B5XeG0T5PeXKDdruDf3CRpnhN+8UebNa5N2H58+3GDgpn/9GBurrQ1uWW768FfscwYkJRg=="],
|
||||
|
||||
"next/postcss": ["postcss@8.4.31", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="],
|
||||
|
||||
"npm-run-path/path-key": ["path-key@4.0.0", "", {}, "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ=="],
|
||||
|
|
|
|||
|
|
@ -4,12 +4,18 @@
|
|||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"prebuild": "node scripts/update-last-modified.js",
|
||||
"build": "next build",
|
||||
"postinstall": "node scripts/update-last-modified.js",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
"lint": "eslint",
|
||||
"update-last-modified": "node scripts/update-last-modified.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.0.0",
|
||||
"@next/swc-darwin-arm64": "^16.1.6",
|
||||
"@vercel/analytics": "^1.6.1",
|
||||
"@vercel/speed-insights": "^1.3.1",
|
||||
"@xboxreplay/xboxlive-api": "^3.4.3",
|
||||
"@yudiel/react-qr-scanner": "^2.5.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
|
|
|
|||
BIN
public/font/makesans.ttf
Normal file
BIN
public/font/makesans.ttf
Normal file
Binary file not shown.
89
scripts/update-last-modified.js
Normal file
89
scripts/update-last-modified.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Get the root directory of the git repository
|
||||
function getGitRoot() {
|
||||
try {
|
||||
return execSync('git rev-parse --show-toplevel').toString().trim();
|
||||
} catch (error) {
|
||||
console.error('Error finding git root:', error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getLastCommitDate(filePath) {
|
||||
try {
|
||||
const gitRoot = getGitRoot();
|
||||
if (!gitRoot) {
|
||||
console.error('Could not find git repository root');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the relative path from git root
|
||||
const relativePath = path.relative(gitRoot, path.resolve(process.cwd(), filePath));
|
||||
console.log(`Checking git history for: ${relativePath}`);
|
||||
|
||||
// Check if the file is tracked by git
|
||||
const isTracked = execSync(`git ls-files --error-unmatch "${relativePath}" 2>/dev/null || echo ""`).toString().trim();
|
||||
if (!isTracked) {
|
||||
console.log('File is not tracked by git, using current date');
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
// Get the last commit date for the file
|
||||
const lastCommitDate = execSync(
|
||||
`git log -1 --format="%ad" --date=iso -- "${relativePath}"`,
|
||||
{ cwd: gitRoot }
|
||||
).toString().trim();
|
||||
|
||||
return lastCommitDate || new Date().toISOString();
|
||||
} catch (error) {
|
||||
console.error('Error getting last commit date:', error.message);
|
||||
return new Date().toISOString();
|
||||
}
|
||||
}
|
||||
|
||||
function updateLastModified() {
|
||||
const privacyPagePath = path.join(process.cwd(), 'src/app/privacy/page.tsx');
|
||||
|
||||
try {
|
||||
let content = fs.readFileSync(privacyPagePath, 'utf8');
|
||||
const lastCommitDate = getLastCommitDate(privacyPagePath);
|
||||
|
||||
if (!lastCommitDate) {
|
||||
console.log('Using current date as fallback');
|
||||
return;
|
||||
}
|
||||
|
||||
const formattedDate = new Date(lastCommitDate).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
});
|
||||
|
||||
const lastUpdatedText = `Last updated: ${formattedDate}`;
|
||||
|
||||
// Check if we need to add or update the last updated line
|
||||
if (content.includes('LAST_UPDATED_PLACEHOLDER')) {
|
||||
// Replace the placeholder with the actual date
|
||||
const updatedContent = content.replace(
|
||||
/\{\/\*\s*LAST_UPDATED_PLACEHOLDER\s*\*\/\}/,
|
||||
`<p className="text-sm text-muted-foreground mb-4">
|
||||
${lastUpdatedText}
|
||||
</p>`
|
||||
);
|
||||
|
||||
if (updatedContent !== content) {
|
||||
fs.writeFileSync(privacyPagePath, updatedContent, 'utf8');
|
||||
console.log('✅ Updated last modified date in privacy policy');
|
||||
}
|
||||
} else {
|
||||
console.log('ℹ️ Last modified date is up to date');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating last modified date:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
updateLastModified();
|
||||
15
src/app/.well-known/matrix/client/route.ts
Normal file
15
src/app/.well-known/matrix/client/route.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { NextResponse } from "next/server";
|
||||
|
||||
export function GET() {
|
||||
return NextResponse.json({
|
||||
"m.homeserver": {
|
||||
"base_url": "https://chat.frg.network"
|
||||
},
|
||||
"org.matrix.msc4143.rtc_foci": [
|
||||
{
|
||||
"type": "livekit",
|
||||
"livekit_service_url": "https://livekit.element.io"
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
|
@ -17,6 +17,12 @@ import { useRouter } from "next/navigation";
|
|||
import { cfg } from "@/lib/cfg";
|
||||
import { getAvatarProfile } from "@/lib/avatar";
|
||||
|
||||
import localFont from "next/font/local";
|
||||
|
||||
const makeSans = localFont({
|
||||
src: "../../../../../public/font/makesans.ttf",
|
||||
})
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{
|
||||
method: string;
|
||||
|
|
@ -30,6 +36,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
const method = resolvedParams.method; // 'code' or 'qr'
|
||||
const step = resolvedParams.step; // 'verify', 'details', 'success'
|
||||
|
||||
|
||||
// Access Code State
|
||||
const [length, setLength] = useState(6);
|
||||
const [code, setCode] = useState("");
|
||||
|
|
@ -465,8 +472,8 @@ export default function AccessPage({ params }: PageProps) {
|
|||
<ArrowLeft className="w-4 h-4 mr-2" />
|
||||
Back to home
|
||||
</Link>
|
||||
<h1 className="text-2xl font-semibold">
|
||||
{method === 'code' ? 'Access Code Verification' : 'QR Code Verification'}
|
||||
<h1 className={makeSans.className + " text-2xl text-primary font-extrabold lowercase"}>
|
||||
{method === 'code' ? 'access code verification' : 'qr code verification'}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{method === 'code'
|
||||
|
|
@ -587,7 +594,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
<ArrowLeft className="w-4 h-4 mr-2" />
|
||||
Back to verification
|
||||
</Link>
|
||||
<h1 className="text-2xl font-semibold">Server Details</h1>
|
||||
<h1 className={makeSans.className + " text-2xl text-primary font-extrabold lowercase"}>server details</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Tell us which Minecraft edition you play and your username(s).
|
||||
</p>
|
||||
|
|
@ -621,10 +628,10 @@ export default function AccessPage({ params }: PageProps) {
|
|||
|
||||
{needsJavaName && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="java-username">Java username</Label>
|
||||
<Label htmlFor="java-username">Java Username</Label>
|
||||
<Input
|
||||
id="java-username"
|
||||
placeholder="Your Java username"
|
||||
placeholder="Your Java Username"
|
||||
value={javaName}
|
||||
className="font-mono"
|
||||
onChange={(event) => setJavaName(event.target.value)}
|
||||
|
|
@ -637,7 +644,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
<Label htmlFor="bedrock-username">Bedrock Gamertag</Label>
|
||||
<Input
|
||||
id="bedrock-username"
|
||||
placeholder="Your Xbox name"
|
||||
placeholder="Your Bedrock Gamertag"
|
||||
value={bedrockName}
|
||||
className="font-mono"
|
||||
onChange={(event) => setBedrockName(event.target.value)}
|
||||
|
|
@ -682,7 +689,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
{/* Header */}
|
||||
<div className="text-center space-y-4">
|
||||
<PartyPopper className="w-16 h-16 text-primary mx-auto" />
|
||||
<h1 className="text-2xl font-semibold">You're whitelisted!</h1>
|
||||
<h1 className={makeSans.className + " text-2xl text-primary font-extrabold lowercase"}>you're whitelisted!</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Welcome to FRG Network! You can now join the server.
|
||||
As soon as you join, come back and click "Claim my reward" to get a gift on behalf of the team here.
|
||||
|
|
@ -726,7 +733,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
<Item variant="outline">
|
||||
<ItemMedia>
|
||||
<Avatar size="lg">
|
||||
<AvatarImage src={profileData?.avatarUrl || ""} />
|
||||
<AvatarImage src={cfg.server.bedrockFriendAvatar} />
|
||||
<AvatarFallback>?</AvatarFallback>
|
||||
</Avatar>
|
||||
</ItemMedia>
|
||||
|
|
@ -753,6 +760,8 @@ export default function AccessPage({ params }: PageProps) {
|
|||
</Link>
|
||||
</Button>
|
||||
|
||||
|
||||
|
||||
<Button variant="outline" onClick={handleReset} className="w-full">
|
||||
Start over
|
||||
</Button>
|
||||
|
|
@ -778,7 +787,7 @@ export default function AccessPage({ params }: PageProps) {
|
|||
<ArrowLeft className="w-4 h-4 mr-2" />
|
||||
Back to success
|
||||
</Link>
|
||||
<h1 className="text-2xl font-semibold">Claim Your Reward</h1>
|
||||
<h1 className={makeSans.className + " text-2xl text-primary font-extrabold lowercase"}>claim your reward</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Help us improve your server experience! Complete this survey to receive 2 diamonds as a thank you.
|
||||
</p>
|
||||
|
|
|
|||
41
src/app/api/resolve-player/route.ts
Normal file
41
src/app/api/resolve-player/route.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { minecraftApi, PlayerIdentifierInput } from '@/lib/minecraft-api';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body: PlayerIdentifierInput = await request.json();
|
||||
|
||||
// Validate input
|
||||
if (!body.type || !body.username) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Missing required fields: type and username' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (body.type !== 'java' && body.type !== 'bedrock') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid type. Must be "java" or "bedrock"' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await minecraftApi.resolvePlayerIdentifier(body);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: result
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Player resolution error:', error);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { servertap } from "@/lib/servertap";
|
||||
import { minecraftApi } from "@/lib/minecraft-api";
|
||||
import { verifyAccessCode } from "@/app/actions";
|
||||
|
||||
type WhitelistRequest = {
|
||||
|
|
@ -9,6 +10,13 @@ type WhitelistRequest = {
|
|||
accessCode: string;
|
||||
};
|
||||
|
||||
type ResolvedPlayer = {
|
||||
platform: "java" | "bedrock";
|
||||
username: string;
|
||||
uuid?: string;
|
||||
xuid?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const data = (await request.json()) as WhitelistRequest;
|
||||
|
|
@ -28,25 +36,61 @@ export async function POST(request: Request) {
|
|||
|
||||
const results: string[] = [];
|
||||
const errors: string[] = [];
|
||||
const resolvedPlayers: ResolvedPlayer[] = [];
|
||||
|
||||
// Handle Java whitelist
|
||||
// Resolve Java player if provided
|
||||
if ((preference === "java" || preference === "both") && javaName?.trim()) {
|
||||
const result = await servertap.addToWhitelist(javaName.trim());
|
||||
if (result.success) {
|
||||
results.push(`Successfully whitelisted Java player: ${javaName}`);
|
||||
} else {
|
||||
errors.push(`Failed to whitelist Java player ${javaName}: ${result.error}`);
|
||||
try {
|
||||
const resolved = await minecraftApi.resolvePlayerIdentifier({
|
||||
type: 'java',
|
||||
username: javaName.trim()
|
||||
});
|
||||
resolvedPlayers.push(resolved);
|
||||
} catch (error) {
|
||||
errors.push(`Failed to resolve Java player ${javaName}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Bedrock whitelist (for now, we'll use the same endpoint but could be different)
|
||||
// Resolve Bedrock player if provided
|
||||
if ((preference === "bedrock" || preference === "both") && bedrockName?.trim()) {
|
||||
const bedrockNameWithDot = `.${bedrockName.trim()}`;
|
||||
const result = await servertap.addToWhitelist(bedrockNameWithDot);
|
||||
if (result.success) {
|
||||
results.push(`Successfully whitelisted Bedrock player: ${bedrockNameWithDot}`);
|
||||
} else {
|
||||
errors.push(`Failed to whitelist Bedrock player ${bedrockNameWithDot}: ${result.error}`);
|
||||
try {
|
||||
const resolved = await minecraftApi.resolvePlayerIdentifier({
|
||||
type: 'bedrock',
|
||||
username: bedrockName.trim()
|
||||
});
|
||||
resolvedPlayers.push(resolved);
|
||||
} catch (error) {
|
||||
errors.push(`Failed to resolve Bedrock player ${bedrockName}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Add resolved players to whitelist
|
||||
for (const player of resolvedPlayers) {
|
||||
// Validate player data before sending to server
|
||||
if (!player || !player.username || !player.platform) {
|
||||
errors.push(`Invalid player data: missing username or platform`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.platform === 'bedrock' && !player.xuid) {
|
||||
errors.push(`Bedrock gamertag player ${player.username} missing XUID - resolution may have failed`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.platform === 'java' && !player.uuid) {
|
||||
errors.push(`Java username player ${player.username} missing UUID - resolution may have failed`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await servertap.addToWhitelist(player);
|
||||
if (result.success) {
|
||||
results.push(`Successfully whitelisted ${player.platform === 'java' ? 'Java username' : 'Bedrock gamertag'} player: ${player.username} (${player.uuid || player.xuid})`);
|
||||
} else {
|
||||
errors.push(`Failed to whitelist ${player.platform === 'java' ? 'Java username' : 'Bedrock gamertag'} player ${player.username}: ${result.error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
errors.push(`Failed to whitelist ${player.platform === 'java' ? 'Java username' : 'Bedrock gamertag'} player ${player.username}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,80 +47,95 @@
|
|||
--radius-4xl: calc(var(--radius) + 16px);
|
||||
}
|
||||
|
||||
[data-sonner-toaster][data-sonner-theme="dark"] [data-sonner-toast][data-styled="true"] [data-cancel] {
|
||||
@apply rounded-sm border-border dark:bg-input/30 hover:bg-input/50 hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground;
|
||||
}
|
||||
[data-sonner-toaster][data-sonner-theme="dark"] [data-sonner-toast][data-styled="true"] [data-action] {
|
||||
@apply rounded-sm bg-primary text-primary-foreground hover:bg-primary/80;
|
||||
}
|
||||
|
||||
:root {
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.141 0.005 285.823);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--card-foreground: oklch(0.141 0.005 285.823);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.65 0.18 132);
|
||||
--primary-foreground: oklch(0.99 0.03 121);
|
||||
--popover-foreground: oklch(0.141 0.005 285.823);
|
||||
--primary: oklch(0.646 0.222 41.116);
|
||||
--primary-foreground: oklch(0.98 0.016 73.684);
|
||||
--secondary: oklch(0.967 0.001 286.375);
|
||||
--secondary-foreground: oklch(0.21 0.006 285.885);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.65 0.18 132);
|
||||
--accent-foreground: oklch(0.99 0.03 121);
|
||||
--destructive: oklch(0.58 0.22 27);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.90 0.18 127);
|
||||
--chart-2: oklch(0.85 0.21 129);
|
||||
--chart-3: oklch(0.77 0.20 131);
|
||||
--chart-4: oklch(0.65 0.18 132);
|
||||
--chart-5: oklch(0.53 0.14 132);
|
||||
--radius: 0;
|
||||
--muted: oklch(0.967 0.001 286.375);
|
||||
--muted-foreground: oklch(0.552 0.016 285.938);
|
||||
--accent: oklch(0.967 0.001 286.375);
|
||||
--accent-foreground: oklch(0.21 0.006 285.885);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.92 0.004 286.32);
|
||||
--input: oklch(0.92 0.004 286.32);
|
||||
--ring: oklch(0.705 0.015 286.067);
|
||||
--chart-1: oklch(0.837 0.128 66.29);
|
||||
--chart-2: oklch(0.705 0.213 47.604);
|
||||
--chart-3: oklch(0.646 0.222 41.116);
|
||||
--chart-4: oklch(0.553 0.195 38.402);
|
||||
--chart-5: oklch(0.47 0.157 37.304);
|
||||
--radius: 0.625rem;
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.65 0.18 132);
|
||||
--sidebar-primary-foreground: oklch(0.99 0.03 121);
|
||||
--sidebar-accent: oklch(0.65 0.18 132);
|
||||
--sidebar-accent-foreground: oklch(0.99 0.03 121);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
--sidebar-foreground: oklch(0.141 0.005 285.823);
|
||||
--sidebar-primary: oklch(0.646 0.222 41.116);
|
||||
--sidebar-primary-foreground: oklch(0.98 0.016 73.684);
|
||||
--sidebar-accent: oklch(0.967 0.001 286.375);
|
||||
--sidebar-accent-foreground: oklch(0.21 0.006 285.885);
|
||||
--sidebar-border: oklch(0.92 0.004 286.32);
|
||||
--sidebar-ring: oklch(0.705 0.015 286.067);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--background: oklch(0.141 0.005 285.823);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card: oklch(0.21 0.006 285.885);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover: oklch(0.21 0.006 285.885);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.77 0.20 131);
|
||||
--primary-foreground: oklch(0.27 0.07 132);
|
||||
--primary: oklch(0.7968 0.2119 135.19);
|
||||
--primary-foreground: oklch(0.1566 0.0354 125.31);
|
||||
--secondary: oklch(0.274 0.006 286.033);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.77 0.20 131);
|
||||
--accent-foreground: oklch(0.27 0.07 132);
|
||||
--muted: oklch(0.274 0.006 286.033);
|
||||
--muted-foreground: oklch(0.705 0.015 286.067);
|
||||
--accent: oklch(0.274 0.006 286.033);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.90 0.18 127);
|
||||
--chart-2: oklch(0.85 0.21 129);
|
||||
--chart-3: oklch(0.77 0.20 131);
|
||||
--chart-4: oklch(0.65 0.18 132);
|
||||
--chart-5: oklch(0.53 0.14 132);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--ring: oklch(0.552 0.016 285.938);
|
||||
--chart-1: oklch(0.488 0.243 264.376);
|
||||
--chart-2: oklch(0.696 0.17 162.48);
|
||||
--chart-3: oklch(0.769 0.188 70.08);
|
||||
--chart-4: oklch(0.627 0.265 303.9);
|
||||
--chart-5: oklch(0.645 0.246 16.439);
|
||||
--sidebar: oklch(0.21 0.006 285.885);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.85 0.21 129);
|
||||
--sidebar-primary-foreground: oklch(0.27 0.07 132);
|
||||
--sidebar-accent: oklch(0.77 0.20 131);
|
||||
--sidebar-accent-foreground: oklch(0.27 0.07 132);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.274 0.006 286.033);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
--sidebar-ring: oklch(0.552 0.016 285.938);
|
||||
}
|
||||
|
||||
@supports (corner-shape: squircle) {
|
||||
* {
|
||||
corner-shape: superellipse(2);
|
||||
--radius:1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import "./globals.css";
|
|||
import { Toaster } from "@/components/ui/sonner"
|
||||
import { ThemeProvider } from "@/components/theme-provider";
|
||||
import { Google_Sans_Code, Mona_Sans } from "next/font/google";
|
||||
import localFont from 'next/font/local'
|
||||
import { CookieConsent } from "@/components/cookie-notice";
|
||||
import { ConditionalAnalytics } from "@/components/conditional-analytics";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "FRG Network",
|
||||
|
|
@ -13,7 +16,9 @@ export const googleSansCode = Google_Sans_Code({
|
|||
variable: "--font-google-code",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const makeSans = localFont({
|
||||
src: "../../public/font/makesans.ttf",
|
||||
})
|
||||
export const mona = Mona_Sans({
|
||||
weight: "variable",
|
||||
subsets: ["latin"],
|
||||
|
|
@ -25,20 +30,22 @@ export default function RootLayout({
|
|||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en" className={`${googleSansCode.variable} ${mona.variable}`} suppressHydrationWarning>
|
||||
<body
|
||||
className={`antialiased`}
|
||||
>
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="system"
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
<html lang="en" className={`${googleSansCode.variable} ${mona.variable}`} suppressHydrationWarning>
|
||||
<body
|
||||
className={`antialiased`}
|
||||
>
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="system"
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
<Toaster position="bottom-center" />
|
||||
</body>
|
||||
</html>
|
||||
{children}
|
||||
<CookieConsent />
|
||||
<ConditionalAnalytics />
|
||||
</ThemeProvider>
|
||||
<Toaster position="bottom-center" />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import { Asterisk, QrCode } from "lucide-react";
|
|||
import { DotGothic16 } from "next/font/google";
|
||||
import { cfg } from "@/lib/cfg";
|
||||
import Link from "next/link";
|
||||
import localFont from "next/font/local";
|
||||
|
||||
const dots = DotGothic16({
|
||||
weight: "400",
|
||||
});
|
||||
export const makeSans = localFont({
|
||||
src: "../../public/font/makesans.ttf",
|
||||
})
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
|
@ -16,24 +17,27 @@ export default function Page() {
|
|||
className="font-mona min-w-screen gap-2 min-h-screen flex flex-col items-center p-2 justify-center"
|
||||
>
|
||||
<span className="text-muted-foreground font-medium">Authentication for</span>
|
||||
<h1 className={dots.className + " text-2xl text-primary"}>
|
||||
<h1 className={makeSans.className + " text-2xl text-primary font-extrabold lowercase"}>
|
||||
FRG Network
|
||||
</h1>
|
||||
<p>A private Minecraft server for me and my friends.</p>
|
||||
<div className="flex flex-col sm:flex-row gap-2">
|
||||
{cfg.accessCode.enabled && (
|
||||
<Button asChild>
|
||||
<Button asChild className="h-24 px-6 flex flex-col rounded-t-xl rounded-b-sm sm:rounded-l-xl sm:rounded-r-sm">
|
||||
<Link href="/access/code/verify">
|
||||
<Asterisk /> I have an access code
|
||||
<Asterisk className="size-8" /> I have an access code
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{cfg.qr.enabled && (
|
||||
<Button variant="outline" asChild>
|
||||
<Button asChild className="h-24 px-6 flex flex-col rounded-t-sm rounded-b-xl sm:rounded-l-sm sm:rounded-r-xl" variant="outline">
|
||||
<Link href="/access/qr/verify">
|
||||
<QrCode /> I have a QR code
|
||||
<QrCode className="size-8" /> I have a QR code
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
|
|
|
|||
104
src/app/privacy/page.tsx
Normal file
104
src/app/privacy/page.tsx
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
"use client"
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
|
||||
export default function PrivacyPage() {
|
||||
return (
|
||||
<div className="min-h-screen max-w-3xl mx-auto p-8 flex items-start gap-3 flex-col">
|
||||
<Button variant="ghost" onClick={() => window.history.back()}>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" /> Back to action
|
||||
</Button>
|
||||
<h1 className="text-3xl text-primary font-bold mb-1">Privacy Policy</h1>
|
||||
<p className="text-sm text-muted-foreground mb-4">
|
||||
Last updated: December 21, 2025
|
||||
</p>
|
||||
<p>FRG Network is a private Minecraft server.</p>
|
||||
<div className="text-sm space-y-6">
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold mb-2">What we collect</h2>
|
||||
<p>
|
||||
If you choose to accept our cookie policy, FRG Network use Vercel
|
||||
Analytics and Speed Insights to analyse how people use our website
|
||||
and how we can improve our services. This monitors:
|
||||
</p>
|
||||
<ul className="list-disc list-inside mt-2 space-y-1 ml-4">
|
||||
<li>page views and navigation patterns</li>
|
||||
<li>device type, browser, and operating system</li>
|
||||
<li>approximate location (country level only)</li>
|
||||
<li>performance metrics like page load times</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold mb-2">How we use this data</h2>
|
||||
<p>We use this information to:</p>
|
||||
<ul className="list-disc list-inside mt-2 space-y-1 ml-4">
|
||||
<li>improve website performance and user experience</li>
|
||||
<li>understand how visitors use our site</li>
|
||||
<li>optimise our content and features</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold mb-2">What we don't collect</h2>
|
||||
<p>We don't collect:</p>
|
||||
<ul className="list-disc list-inside space-y-1 ml-4">
|
||||
<li>personal identifiable information</li>
|
||||
<li>IP addresses</li>
|
||||
<li>Minecraft account details or passwords</li>
|
||||
<li>precise location data</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold mb-2">Third party services</h2>
|
||||
<p>
|
||||
We use Vercel Analytics and Speed Insights. You can read their privacy policy {" "}
|
||||
<Link
|
||||
href="https://vercel.com/legal/privacy-policy"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary underline-1 underline decoration-1"
|
||||
>
|
||||
here
|
||||
</Link>.
|
||||
</p>
|
||||
</section>
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold mb-2">Your choices and rights</h2>
|
||||
<div className="space-y-4">
|
||||
<p>Analytics are entirely optional and this website works without them. You may manage your preferences below:</p>
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-4 items-start">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
localStorage.setItem('analytics-enabled', 'false');
|
||||
localStorage.setItem('cookie-consent', 'declined');
|
||||
window.location.reload();
|
||||
}}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
Disable Analytics
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
localStorage.clear();
|
||||
window.location.reload();
|
||||
}}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
Reset All Preferences
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-sm text-muted-foreground">
|
||||
You can also clear your browser's cache at any time to reset all preferences.
|
||||
This will not affect the functionality of the website in any way.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
39
src/components/conditional-analytics.tsx
Normal file
39
src/components/conditional-analytics.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"use client";
|
||||
|
||||
import { Analytics } from "@vercel/analytics/next";
|
||||
import { SpeedInsights } from "@vercel/speed-insights/next";
|
||||
|
||||
export function ConditionalAnalytics() {
|
||||
return (
|
||||
<>
|
||||
<Analytics
|
||||
beforeSend={(event) => {
|
||||
// check if user has consented
|
||||
const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true";
|
||||
|
||||
// if not consented, return null to block the event
|
||||
if (!analyticsEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if consented, return the event to send it
|
||||
return event;
|
||||
}}
|
||||
/>
|
||||
<SpeedInsights
|
||||
beforeSend={(event) => {
|
||||
// check if user has consented
|
||||
const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true";
|
||||
|
||||
// if not consented, return null to block the event
|
||||
if (!analyticsEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if consented, return the event to send it
|
||||
return event;
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
41
src/components/cookie-notice.tsx
Normal file
41
src/components/cookie-notice.tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function CookieConsent() {
|
||||
useEffect(() => {
|
||||
const consent = localStorage.getItem("cookie-consent");
|
||||
if (!consent) {
|
||||
setTimeout(() => {
|
||||
toast("Cookies & Analytics", {
|
||||
description: (
|
||||
<>
|
||||
We use Vercel Analytics to get useful info on how people use this site. Analytics are entirely anonymous and do not track individual users.{" "}
|
||||
<a href="/privacy" className="underline hover:text-primary">
|
||||
Privacy Policy
|
||||
</a>
|
||||
</>
|
||||
),
|
||||
duration: Infinity,
|
||||
action: {
|
||||
label: "Accept",
|
||||
onClick: () => {
|
||||
localStorage.setItem("cookie-consent", "accepted");
|
||||
localStorage.setItem("analytics-enabled", "true");
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: "Opt out",
|
||||
onClick: () => {
|
||||
localStorage.setItem("cookie-consent", "declined");
|
||||
localStorage.setItem("analytics-enabled", "false");
|
||||
},
|
||||
},
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -17,14 +17,14 @@ const buttonVariants = cva(
|
|||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-7 gap-1 px-2 text-xs/relaxed has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
xs: "h-5 gap-1 rounded-sm px-2 text-[0.625rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-2.5",
|
||||
sm: "h-6 gap-1 px-2 text-xs/relaxed has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
lg: "h-8 gap-1 px-2.5 text-xs/relaxed has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-4",
|
||||
icon: "size-7 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
"icon-xs": "size-5 rounded-sm [&_svg:not([class*='size-'])]:size-2.5",
|
||||
"icon-sm": "size-6 [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-lg": "size-8 [&_svg:not([class*='size-'])]:size-4",
|
||||
default: "h-7 gap-1 px-2 py-3 sm:py-2 text-xs/relaxed has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
xs: "h-5 gap-1 rounded-sm px-2 py-2 sm:py-1 text-[0.625rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-2.5",
|
||||
sm: "h-6 gap-1 px-2 py-2 sm:py-1.5 text-xs/relaxed has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
lg: "h-8 gap-1 px-2.5 py-3 sm:py-2 text-xs/relaxed has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-4",
|
||||
icon: "size-7 py-3 sm:py-2 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
"icon-xs": "size-5 rounded-sm py-2 sm:py-1 [&_svg:not([class*='size-'])]:size-2.5",
|
||||
"icon-sm": "size-6 py-2 sm:py-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-lg": "size-8 py-3 sm:py-2 [&_svg:not([class*='size-'])]:size-4",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
|
|
|
|||
|
|
@ -25,5 +25,6 @@ export const cfg = {
|
|||
bedrockIp: process.env.NEXT_PUBLIC_SERVER_BEDROCK_IP ?? "",
|
||||
bedrockPort: process.env.NEXT_PUBLIC_SERVER_BEDROCK_PORT ?? "",
|
||||
bedrockFriend: process.env.NEXT_PUBLIC_SERVER_BEDROCK_FRIEND ?? "",
|
||||
bedrockFriendAvatar: process.env.NEXT_PUBLIC_SERVER_BEDROCK_FRIEND_AVATAR ?? "",
|
||||
},
|
||||
};
|
||||
18
src/lib/git/getLastCommitDate.ts
Normal file
18
src/lib/git/getLastCommitDate.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { execSync } from 'child_process';
|
||||
import path from 'path';
|
||||
|
||||
export function getLastCommitDate(filePath: string): string | null {
|
||||
try {
|
||||
const absolutePath = path.resolve(process.cwd(), filePath);
|
||||
const relativePath = path.relative(process.cwd(), absolutePath);
|
||||
|
||||
const lastCommitDate = execSync(
|
||||
`git log -1 --format="%ad" --date=iso -- "${relativePath}"`
|
||||
).toString().trim();
|
||||
|
||||
return lastCommitDate || null;
|
||||
} catch (error) {
|
||||
console.error('Error getting last commit date:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,156 @@ interface ApiResponse<T = any> {
|
|||
data?: T;
|
||||
}
|
||||
|
||||
interface PlayerIdentifierInput {
|
||||
type: 'java' | 'bedrock';
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface PlayerIdentifierOutput {
|
||||
platform: 'java' | 'bedrock';
|
||||
username: string;
|
||||
uuid?: string;
|
||||
xuid?: string;
|
||||
}
|
||||
|
||||
interface MojangResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface GeyserResponse {
|
||||
xuid: string;
|
||||
gamertag: string;
|
||||
}
|
||||
|
||||
class MinecraftApiClient {
|
||||
private cache = new Map<string, PlayerIdentifierOutput>();
|
||||
private readonly CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
private isCacheValid(timestamp: number): boolean {
|
||||
return Date.now() - timestamp < this.CACHE_TTL;
|
||||
}
|
||||
|
||||
private getCacheKey(type: string, username: string): string {
|
||||
return `${type}:${username.toLowerCase()}`;
|
||||
}
|
||||
|
||||
private formatUUID(uuid: string): string {
|
||||
// Convert UUID from Mojang format (no dashes) to dashed format
|
||||
return `${uuid.slice(0,8)}-${uuid.slice(8,12)}-${uuid.slice(12,16)}-${uuid.slice(16,20)}-${uuid.slice(20)}`;
|
||||
}
|
||||
|
||||
private async resolveJavaUsername(username: string): Promise<PlayerIdentifierOutput> {
|
||||
const cacheKey = this.getCacheKey('java', username);
|
||||
const cached = this.cache.get(cacheKey);
|
||||
if (cached && this.isCacheValid((cached as any).timestamp)) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`, {
|
||||
headers: {
|
||||
'User-Agent': 'MinecraftResolver/1.0'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
throw new Error('Player not found');
|
||||
}
|
||||
|
||||
if (response.status === 429) {
|
||||
throw new Error('Rate limit exceeded');
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Mojang API error: ${response.status}`);
|
||||
}
|
||||
|
||||
const data: MojangResponse = await response.json();
|
||||
const result: PlayerIdentifierOutput = {
|
||||
platform: 'java',
|
||||
username: data.name,
|
||||
uuid: this.formatUUID(data.id)
|
||||
};
|
||||
|
||||
// Cache with timestamp
|
||||
(result as any).timestamp = Date.now();
|
||||
this.cache.set(cacheKey, result);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to resolve Java username: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveBedrockGamertag(gamertag: string): Promise<PlayerIdentifierOutput> {
|
||||
const cacheKey = this.getCacheKey('bedrock', gamertag);
|
||||
const cached = this.cache.get(cacheKey);
|
||||
if (cached && this.isCacheValid((cached as any).timestamp)) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
try {
|
||||
// Try GeyserMC API first (most reliable for public use)
|
||||
const response = await fetch(`https://api.geysermc.org/v2/xbox/xuid/${encodeURIComponent(gamertag)}`, {
|
||||
headers: {
|
||||
'User-Agent': 'MinecraftResolver/1.0'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
throw new Error(`Gamertag "${gamertag}" not found on Xbox Live`);
|
||||
}
|
||||
|
||||
if (response.status === 429) {
|
||||
throw new Error('Xbox Live API rate limit exceeded - please try again later');
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`GeyserMC API error: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data: GeyserResponse = await response.json();
|
||||
|
||||
// Validate the response data - GeyserMC API only returns XUID, not gamertag
|
||||
if (!data.xuid) {
|
||||
throw new Error('Invalid response from GeyserMC API - missing XUID');
|
||||
}
|
||||
|
||||
const result: PlayerIdentifierOutput = {
|
||||
platform: 'bedrock',
|
||||
username: gamertag, // Use the input gamertag since API doesn't return it
|
||||
xuid: data.xuid
|
||||
};
|
||||
|
||||
// Cache with timestamp
|
||||
(result as any).timestamp = Date.now();
|
||||
this.cache.set(cacheKey, result);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new Error(`Failed to resolve Bedrock gamertag "${gamertag}": ${error.message}`);
|
||||
}
|
||||
throw new Error(`Failed to resolve Bedrock gamertag "${gamertag}": Unknown error`);
|
||||
}
|
||||
}
|
||||
|
||||
async resolvePlayerIdentifier(input: PlayerIdentifierInput): Promise<PlayerIdentifierOutput> {
|
||||
if (!input.username || input.username.trim().length === 0) {
|
||||
throw new Error('Username is required');
|
||||
}
|
||||
|
||||
const trimmedUsername = input.username.trim();
|
||||
|
||||
if (input.type === 'java') {
|
||||
return this.resolveJavaUsername(trimmedUsername);
|
||||
} else if (input.type === 'bedrock') {
|
||||
return this.resolveBedrockGamertag(trimmedUsername);
|
||||
} else {
|
||||
throw new Error('Invalid platform type. Must be "java" or "bedrock"');
|
||||
}
|
||||
}
|
||||
private async request<T = any>(
|
||||
endpoint: string,
|
||||
options: RequestInit = {}
|
||||
|
|
@ -90,4 +239,4 @@ class MinecraftApiClient {
|
|||
}
|
||||
|
||||
export const minecraftApi = new MinecraftApiClient();
|
||||
export type { ApiResponse };
|
||||
export type { ApiResponse, PlayerIdentifierInput, PlayerIdentifierOutput };
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@ type MinecraftPlayer = {
|
|||
name: string;
|
||||
};
|
||||
|
||||
type ResolvedPlayer = {
|
||||
platform: "java" | "bedrock";
|
||||
username: string;
|
||||
uuid?: string;
|
||||
xuid?: string;
|
||||
};
|
||||
|
||||
type MinecraftResponse<T> = {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
|
|
@ -72,17 +79,90 @@ class MinecraftClient {
|
|||
}
|
||||
}
|
||||
|
||||
async addToWhitelist(playerName: string): Promise<MinecraftResponse<void>> {
|
||||
async addToWhitelist(player: string | ResolvedPlayer): Promise<MinecraftResponse<void>> {
|
||||
// Handle legacy string input for backward compatibility
|
||||
if (typeof player === 'string') {
|
||||
if (!player || player.trim() === '') {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Player name is required'
|
||||
};
|
||||
}
|
||||
return this.makeRequest("/api/whitelist/add", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ player: player.trim() }),
|
||||
});
|
||||
}
|
||||
|
||||
// Validate resolved player data
|
||||
if (!player || !player.username || !player.platform) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Player data is incomplete: username and platform are required'
|
||||
};
|
||||
}
|
||||
|
||||
// Validate platform-specific identifiers
|
||||
if (player.platform === 'bedrock' && !player.xuid) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Bedrock gamertag players require an XUID'
|
||||
};
|
||||
}
|
||||
|
||||
if (player.platform === 'java' && !player.uuid) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Java username players require a UUID'
|
||||
};
|
||||
}
|
||||
|
||||
// Send resolved player data with UUID/XUID
|
||||
const payload: any = {
|
||||
player: player.username.trim(),
|
||||
platform: player.platform, // Send 'java' and 'bedrock' as platform names
|
||||
};
|
||||
|
||||
if (player.uuid) {
|
||||
payload.uuid = player.uuid;
|
||||
}
|
||||
|
||||
if (player.xuid) {
|
||||
payload.xuid = player.xuid;
|
||||
}
|
||||
|
||||
return this.makeRequest("/api/whitelist/add", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ player: playerName }),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
async removeFromWhitelist(playerName: string): Promise<MinecraftResponse<void>> {
|
||||
async removeFromWhitelist(player: string | ResolvedPlayer): Promise<MinecraftResponse<void>> {
|
||||
// Handle legacy string input for backward compatibility
|
||||
if (typeof player === 'string') {
|
||||
return this.makeRequest("/api/whitelist/remove", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ player }),
|
||||
});
|
||||
}
|
||||
|
||||
// Send resolved player data with UUID/XUID
|
||||
const payload: any = {
|
||||
player: player.username.trim(),
|
||||
platform: player.platform, // Send 'java' and 'bedrock' as platform names
|
||||
};
|
||||
|
||||
if (player.uuid) {
|
||||
payload.uuid = player.uuid;
|
||||
}
|
||||
|
||||
if (player.xuid) {
|
||||
payload.xuid = player.xuid;
|
||||
}
|
||||
|
||||
return this.makeRequest("/api/whitelist/remove", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ player: playerName }),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -111,4 +191,4 @@ export const minecraft = new MinecraftClient();
|
|||
|
||||
// Legacy exports for backward compatibility
|
||||
export const servertap = minecraft;
|
||||
export type { MinecraftPlayer as ServerTapPlayer, MinecraftResponse as ServerTapResponse };
|
||||
export type { MinecraftPlayer as ServerTapPlayer, MinecraftResponse as ServerTapResponse, ResolvedPlayer };
|
||||
|
|
|
|||
28
test-api.sh
Executable file
28
test-api.sh
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Test script for the player resolver API endpoint
|
||||
# Start the dev server first with: npm run dev
|
||||
|
||||
echo "Testing Java player resolution..."
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type": "java", "username": "Notch"}' \
|
||||
| jq .
|
||||
|
||||
echo -e "\nTesting Bedrock player resolution..."
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type": "bedrock", "username": "TestGamertag"}' \
|
||||
| jq .
|
||||
|
||||
echo -e "\nTesting invalid input..."
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type": "invalid", "username": ""}' \
|
||||
| jq .
|
||||
|
||||
echo -e "\nTesting missing fields..."
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}' \
|
||||
| jq .
|
||||
65
test-integrated-whitelist.sh
Normal file
65
test-integrated-whitelist.sh
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Test script for the integrated whitelist with player resolver
|
||||
# This tests the full flow: resolve player -> send UUID/XUID to server
|
||||
|
||||
echo "Testing integrated whitelist with player resolver..."
|
||||
|
||||
# Test Java player with valid access code (you'll need to replace with actual access code)
|
||||
echo -e "\n=== Testing Java Player Resolution + Whitelist ==="
|
||||
curl -X POST http://localhost:3000/api/whitelist \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"javaName": "Notch",
|
||||
"preference": "java",
|
||||
"accessCode": "YOUR_ACCESS_CODE_HERE"
|
||||
}' \
|
||||
| jq .
|
||||
|
||||
# Test Bedrock player with valid access code
|
||||
echo -e "\n=== Testing Bedrock Player Resolution + Whitelist ==="
|
||||
curl -X POST http://localhost:3000/api/whitelist \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"bedrockName": "TestGamertag",
|
||||
"preference": "bedrock",
|
||||
"accessCode": "YOUR_ACCESS_CODE_HERE"
|
||||
}' \
|
||||
| jq .
|
||||
|
||||
# Test both platforms
|
||||
echo -e "\n=== Testing Both Platforms Resolution + Whitelist ==="
|
||||
curl -X POST http://localhost:3000/api/whitelist \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"javaName": "Notch",
|
||||
"bedrockName": "TestGamertag",
|
||||
"preference": "both",
|
||||
"accessCode": "YOUR_ACCESS_CODE_HERE"
|
||||
}' \
|
||||
| jq .
|
||||
|
||||
# Test invalid access code
|
||||
echo -e "\n=== Testing Invalid Access Code ==="
|
||||
curl -X POST http://localhost:3000/api/whitelist \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"javaName": "Notch",
|
||||
"preference": "java",
|
||||
"accessCode": "invalid_code"
|
||||
}' \
|
||||
| jq .
|
||||
|
||||
# Test invalid username
|
||||
echo -e "\n=== Testing Invalid Username ==="
|
||||
curl -X POST http://localhost:3000/api/whitelist \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"javaName": "nonexistentplayer12345",
|
||||
"preference": "java",
|
||||
"accessCode": "YOUR_ACCESS_CODE_HERE"
|
||||
}' \
|
||||
| jq .
|
||||
|
||||
echo -e "\n=== Test completed ==="
|
||||
echo "Note: Replace YOUR_ACCESS_CODE_HERE with a valid access code from your system"
|
||||
23
test-platform-names.sh
Normal file
23
test-platform-names.sh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Test script to verify platform names are sent correctly to server
|
||||
|
||||
echo "Testing platform name mapping..."
|
||||
|
||||
# Test Java player - should send "java username" as platform
|
||||
echo -e "\n=== Java Player Platform Test ==="
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type": "java", "username": "Notch"}' \
|
||||
| jq .
|
||||
|
||||
# Test Bedrock player - should send "bedrock gamertag" as platform
|
||||
echo -e "\n=== Bedrock Player Platform Test ==="
|
||||
curl -X POST http://localhost:3000/api/resolve-player \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type": "bedrock", "username": "TestGamertag"}' \
|
||||
| jq .
|
||||
|
||||
echo -e "\n=== Platform Mapping Complete ==="
|
||||
echo "Java platform should be: 'java username'"
|
||||
echo "Bedrock platform should be: 'bedrock gamertag'"
|
||||
59
test-player-resolver.js
Normal file
59
test-player-resolver.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// Simple test script for the player resolver
|
||||
// Run with: node test-player-resolver.js
|
||||
|
||||
const { minecraftApi } = require('./src/lib/minecraft-api.ts');
|
||||
|
||||
async function testJavaPlayer() {
|
||||
console.log('Testing Java player resolution...');
|
||||
try {
|
||||
const result = await minecraftApi.resolvePlayerIdentifier({
|
||||
type: 'java',
|
||||
username: 'Notch' // Famous Minecraft player
|
||||
});
|
||||
console.log('Java player result:', result);
|
||||
} catch (error) {
|
||||
console.error('Java player error:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function testBedrockPlayer() {
|
||||
console.log('Testing Bedrock player resolution...');
|
||||
try {
|
||||
const result = await minecraftApi.resolvePlayerIdentifier({
|
||||
type: 'bedrock',
|
||||
username: 'TestGamertag' // This will likely fail but tests the API
|
||||
});
|
||||
console.log('Bedrock player result:', result);
|
||||
} catch (error) {
|
||||
console.error('Bedrock player error:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function testInvalidInput() {
|
||||
console.log('Testing invalid input...');
|
||||
try {
|
||||
await minecraftApi.resolvePlayerIdentifier({
|
||||
type: 'invalid',
|
||||
username: ''
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Expected error for invalid input:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function runTests() {
|
||||
console.log('Starting player resolver tests...\n');
|
||||
|
||||
await testJavaPlayer();
|
||||
console.log('\n');
|
||||
|
||||
await testBedrockPlayer();
|
||||
console.log('\n');
|
||||
|
||||
await testInvalidInput();
|
||||
console.log('\n');
|
||||
|
||||
console.log('Tests completed!');
|
||||
}
|
||||
|
||||
runTests().catch(console.error);
|
||||
Loading…
Add table
Reference in a new issue