add frontend and swap whole stack to sveltekit/nodejs
This commit is contained in:
37
src/lib/server/database.ts
Normal file
37
src/lib/server/database.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { DataTypes, Sequelize } from 'sequelize';
|
||||
import { DATABASE_URI } from '$env/static/private';
|
||||
import { dev } from '$app/environment';
|
||||
|
||||
export const sequelize = new Sequelize(DATABASE_URI, {
|
||||
// only log sql queries in dev mode
|
||||
logging: dev ? console.log : false
|
||||
});
|
||||
|
||||
export const User = sequelize.define('user', {
|
||||
firstname: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
lastname: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
birthday: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
telephone: DataTypes.STRING,
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
playertype: {
|
||||
type: DataTypes.ENUM('java', 'bedrock', 'cracked'),
|
||||
allowNull: false
|
||||
},
|
||||
password: DataTypes.TEXT,
|
||||
uuid: {
|
||||
type: DataTypes.UUIDV4,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
27
src/lib/server/minecraft.test.ts
Normal file
27
src/lib/server/minecraft.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { getBedrockUuid, getCrackedUuid, getJavaUuid } from '$lib/server/minecraft';
|
||||
|
||||
describe('java username', () => {
|
||||
test('is valid', async () => {
|
||||
expect(getJavaUuid('bytedream')).resolves.toBe('9aa026cc-b5dc-4357-a319-ab668101af0d');
|
||||
});
|
||||
test('is invalid', async () => {
|
||||
expect(getJavaUuid('57eoTQaLYchmETrTsWnNZXtZh')).rejects.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('bedrock username', () => {
|
||||
test('is valid', async () => {
|
||||
expect(getBedrockUuid('bytedream')).resolves.toBe('00000000-0000-0000-0009-01F5BF975D37');
|
||||
});
|
||||
test('is invalid', async () => {
|
||||
expect(getBedrockUuid('57eoTQaLYchmETrTsWnNZXtZh')).rejects.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('cracked username', () => {
|
||||
// every username can be converted to an uuid so every user id automatically valid
|
||||
test('is valid', () => {
|
||||
expect(getCrackedUuid('bytedream')).toBe('88de3863-bf47-30f9-a7f4-ab6134feb49a');
|
||||
});
|
||||
});
|
||||
78
src/lib/server/minecraft.ts
Normal file
78
src/lib/server/minecraft.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
export class UserNotFoundError extends Error {
|
||||
constructor(username: string) {
|
||||
super(`Ein Spieler mit dem Namen '${username}' konnte nicht gefunden werden`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getJavaUuid(username: string): Promise<string> {
|
||||
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
||||
if (!response.ok) {
|
||||
throw response.status < 500
|
||||
? new UserNotFoundError(username)
|
||||
: new Error(`mojang server error (${response.status}): ${await response.text()}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
const id: string = json['id'];
|
||||
// prettier-ignore
|
||||
return `${id.substring(0, 8)}-${id.substring(8, 12)}-${id.substring(12, 16)}-${id.substring(16, 20)}-${id.substring(20)}`;
|
||||
}
|
||||
|
||||
// https://github.com/carlop3333/XUIDGrabber/blob/main/grabber.js
|
||||
export async function getBedrockUuid(username: string): Promise<string> {
|
||||
const initialPageResponse = await fetch('https://cxkes.me/xbox/xuid');
|
||||
const initialPageContent = await initialPageResponse.text();
|
||||
const token = /name="_token"\svalue="(?<token>\w+)"/.exec(initialPageContent)?.groups?.token;
|
||||
if (token === undefined) throw new Error("couldn't grab token from xuid converter website");
|
||||
|
||||
const cookies = initialPageResponse.headers.get('set-cookie')?.split(' ');
|
||||
if (cookies === undefined)
|
||||
throw new Error("couldn't get response cookies from xuid converter website");
|
||||
else if (cookies.length < 11) throw new Error('xuid converter website sent unexpected cookies');
|
||||
|
||||
const requestBody = new URLSearchParams();
|
||||
requestBody.set('_token', token);
|
||||
requestBody.set('gamertag', username);
|
||||
|
||||
const resultPageResponse = await fetch('https://cxkes.me/xbox/xuid', {
|
||||
method: 'post',
|
||||
body: requestBody,
|
||||
// prettier-ignore
|
||||
headers: {
|
||||
'Host': 'www.cxkes.me',
|
||||
'Accept-Encoding': 'gzip, deflate,br',
|
||||
'Content-Length': Buffer.byteLength(requestBody.toString()).toString(),
|
||||
'Origin': 'https://www.cxkes.me',
|
||||
'DNT': '1',
|
||||
'Connection': 'keep-alive',
|
||||
'Referer': 'https://www.cxkes.me/xbox/xuid',
|
||||
'Cookie': `${cookies[0]} ${cookies[10].slice(0, cookies[10].length - 1)}`,
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
'Sec-Fectch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-User': '?1',
|
||||
'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-Language': 'es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
const resultPageContent = await resultPageResponse.text();
|
||||
let xuid: string | undefined;
|
||||
if ((xuid = /id="xuidHex">(?<xuid>\w+)</.exec(resultPageContent)?.groups?.xuid) === undefined) {
|
||||
throw new UserNotFoundError(username);
|
||||
}
|
||||
return `00000000-0000-0000-${xuid.substring(0, 4)}-${xuid.substring(4)}`;
|
||||
}
|
||||
|
||||
// https://gist.github.com/yushijinhun/69f68397c5bb5bee76e80d192295f6e0
|
||||
export function getCrackedUuid(username: string): string {
|
||||
const data = createHash('md5').update(`OfflinePlayer:${username}`).digest('binary').split('');
|
||||
data[6] = String.fromCharCode((data[6].charCodeAt(0) & 0x0f) | 0x30);
|
||||
data[8] = String.fromCharCode((data[8].charCodeAt(0) & 0x3f) | 0x80);
|
||||
const uid = Buffer.from(data.join(''), 'ascii').toString('hex');
|
||||
// prettier-ignore
|
||||
return `${uid.substring(0, 8)}-${uid.substring(8, 12)}-${uid.substring(12, 16)}-${uid.substring(16, 20)}-${uid.substring(20)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user