Compare commits
No commits in common. "63605e23b19633f0492693bb464bbf3714d2905e" and "f53dc28597031975141a110219422d3d49717b1c" have entirely different histories.
63605e23b1
...
f53dc28597
@ -26,7 +26,7 @@
|
|||||||
onDestroy(() => clearInterval(intervalId));
|
onDestroy(() => clearInterval(intervalId));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-flow-col gap-5 text-center auto-cols-max text-white">
|
<div class="grid grid-flow-col gap-5 text-center auto-cols-max text-black dark:text-white">
|
||||||
<div class="flex flex-col p-2 bg-gray-200 rounded-box bg-opacity-5 backdrop-blur-sm">
|
<div class="flex flex-col p-2 bg-gray-200 rounded-box bg-opacity-5 backdrop-blur-sm">
|
||||||
<span class="countdown font-mono text-3xl sm:text-6xl">
|
<span class="countdown font-mono text-3xl sm:text-6xl">
|
||||||
<span class="m-auto" style="--value:{days};" />
|
<span class="m-auto" style="--value:{days};" />
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
|
|
||||||
export class UserNotFoundError extends Error {
|
export class UserNotFoundError extends Error {
|
||||||
readonly username: string;
|
|
||||||
|
|
||||||
constructor(username: string) {
|
constructor(username: string) {
|
||||||
super(`couldn't find a player with the username '${username}'`);
|
super(`Ein Spieler mit dem Namen '${username}' konnte nicht gefunden werden`);
|
||||||
this.username = username;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ApiError extends Error {}
|
|
||||||
|
|
||||||
export async function getJavaUuid(username: string): Promise<string> {
|
export async function getJavaUuid(username: string): Promise<string> {
|
||||||
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw response.status < 500
|
throw response.status < 500
|
||||||
? new UserNotFoundError(username)
|
? new UserNotFoundError(username)
|
||||||
: new ApiError(`mojang server error (${response.status}): ${await response.text()}`);
|
: new Error(`mojang server error (${response.status}): ${await response.text()}`);
|
||||||
}
|
}
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
const id: string = json['id'];
|
const id: string = json['id'];
|
||||||
@ -29,13 +24,12 @@ export async function getBedrockUuid(username: string): Promise<string> {
|
|||||||
const initialPageResponse = await fetch('https://cxkes.me/xbox/xuid');
|
const initialPageResponse = await fetch('https://cxkes.me/xbox/xuid');
|
||||||
const initialPageContent = await initialPageResponse.text();
|
const initialPageContent = await initialPageResponse.text();
|
||||||
const token = /name="_token"\svalue="(?<token>\w+)"/.exec(initialPageContent)?.groups?.token;
|
const token = /name="_token"\svalue="(?<token>\w+)"/.exec(initialPageContent)?.groups?.token;
|
||||||
if (token === undefined) throw new ApiError("couldn't grab token from xuid converter website");
|
if (token === undefined) throw new Error("couldn't grab token from xuid converter website");
|
||||||
|
|
||||||
const cookies = initialPageResponse.headers.get('set-cookie')?.split(' ');
|
const cookies = initialPageResponse.headers.get('set-cookie')?.split(' ');
|
||||||
if (cookies === undefined)
|
if (cookies === undefined)
|
||||||
throw new ApiError("couldn't get response cookies from xuid converter website");
|
throw new Error("couldn't get response cookies from xuid converter website");
|
||||||
else if (cookies.length < 11)
|
else if (cookies.length < 11) throw new Error('xuid converter website sent unexpected cookies');
|
||||||
throw new ApiError('xuid converter website sent unexpected cookies');
|
|
||||||
|
|
||||||
const requestBody = new URLSearchParams();
|
const requestBody = new URLSearchParams();
|
||||||
requestBody.set('_token', token);
|
requestBody.set('_token', token);
|
||||||
@ -61,7 +55,7 @@ export async function getBedrockUuid(username: string): Promise<string> {
|
|||||||
'Sec-Fetch-User': '?1',
|
'Sec-Fetch-User': '?1',
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
||||||
'Accept-Language': 'en-US,es;q=0.8,en-US;q=0.5,en;q=0.3',
|
'Accept-Language': 'es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import { ApiError, getJavaUuid, getNoAuthUuid, UserNotFoundError } from '$lib/server/minecraft';
|
import {
|
||||||
|
getBedrockUuid,
|
||||||
|
getJavaUuid,
|
||||||
|
getNoAuthUuid,
|
||||||
|
UserNotFoundError
|
||||||
|
} from '$lib/server/minecraft';
|
||||||
import { error, type RequestHandler } from '@sveltejs/kit';
|
import { error, type RequestHandler } from '@sveltejs/kit';
|
||||||
import { User } from '$lib/server/database';
|
import { User } from '$lib/server/database';
|
||||||
|
|
||||||
@ -22,36 +27,31 @@ export const POST = (async ({ request }) => {
|
|||||||
throw error(400, 'Ungültige Parameter');
|
throw error(400, 'Ungültige Parameter');
|
||||||
}
|
}
|
||||||
|
|
||||||
let uuid: string | null;
|
let uuid: string;
|
||||||
try {
|
try {
|
||||||
// available playertypes are 'java', 'bedrock' and 'noauth'
|
// available playertypes are 'java', 'bedrock' and 'noauth'
|
||||||
switch (data.get('playertype')) {
|
switch (data.get('playertype')) {
|
||||||
case 'java':
|
case 'java':
|
||||||
uuid = await getJavaUuid(username);
|
uuid = await getJavaUuid(data.get('username') as string);
|
||||||
break;
|
break;
|
||||||
case 'bedrock':
|
case 'bedrock':
|
||||||
uuid = null;
|
uuid = await getBedrockUuid(data.get('username') as string);
|
||||||
// uuid = await getBedrockUuid(username);
|
|
||||||
break;
|
break;
|
||||||
case 'noauth':
|
case 'noauth':
|
||||||
uuid = getNoAuthUuid(username);
|
uuid = getNoAuthUuid(data.get('username') as string);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`invalid player type (${playertype})`);
|
throw new Error(`invalid player type (${data.get('playertype')})`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof UserNotFoundError) {
|
if (e instanceof UserNotFoundError) {
|
||||||
throw error(400, `Ein Spieler mit dem Namen '${username}' konnte nicht gefunden werden`);
|
throw error(400, e.message);
|
||||||
} else if (e instanceof ApiError) {
|
|
||||||
console.error((e as Error).message);
|
|
||||||
uuid = null;
|
|
||||||
} else {
|
|
||||||
console.error((e as Error).message);
|
|
||||||
throw error(500);
|
|
||||||
}
|
}
|
||||||
|
console.error((e as Error).message);
|
||||||
|
throw error(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid && (await User.findOne({ where: { uuid: uuid } }))) {
|
if (await User.findOne({ where: { uuid: uuid } })) {
|
||||||
throw error(400, 'Dieser Spieler wurde bereits registriert');
|
throw error(400, 'Dieser Spieler wurde bereits registriert');
|
||||||
} else if (
|
} else if (
|
||||||
await User.findOne({
|
await User.findOne({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user