diff --git a/.env.example b/.env.example index d3ac174..2d1829e 100644 --- a/.env.example +++ b/.env.example @@ -17,4 +17,8 @@ SUPPORT_LEGACY_SKIN_API=TRUE #[legacy_skin_api] SUPPORT_MOJANG_FALLBACK=FALSE #[no_mojang_namespace] SUPPORT_MOJANG_TELEMETRY_BLOCKER=TRUE #[enable_mojang_anti_features] SUPPORT_PROFILE_KEY=TRUE #[enable_profile_key] -SUPPORT_ONLY_DEFAULT_USERNAME=true #[username_check] \ No newline at end of file +SUPPORT_ONLY_DEFAULT_USERNAME=true #[username_check] +SUPPORT_REGISTER=TRUE +REGISTER_ENDPOINT="/register" +HOMEPAGE_URL= +SERVER_NAME="Yggdrasil" \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index e9a609f..b47f6c9 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,7 +3,7 @@ const globals = require("globals") module.exports = [ { - ignores: ["node_modules", "logs", "coverage", ".env", "*.log"], + ignores: ["node_modules", "data", "logs", "coverage", ".env", "*.log"], }, js.configs.recommended, { diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..a752da6 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,17 @@ +const express = require("express") +const router = express.Router() +const utils = require("../modules/utils") +const serverService = require("../services/serverService") + +if (utils.isTrueFromDotEnv("SUPPORT_AUTHLIB_INJECTOR")) { + router.get("", (req, res) => { + const hostname = req.hostname + const metadata = serverService.getServerMetadata(hostname) + res.header("X-Authlib-Injector-Date", new Date().toISOString()) + return res.status(200).json(metadata) + }) +} else { + router.get("", (req, res, next) => next()) +} + +module.exports = router \ No newline at end of file diff --git a/services/serverService.js b/services/serverService.js new file mode 100644 index 0000000..383f6ac --- /dev/null +++ b/services/serverService.js @@ -0,0 +1,39 @@ +const certs = require("../modules/certificatesManager") +const utils = require("../modules/utils") +const package = require("../package.json") + +function getServerMetadata(hostname) { + const keys = certs.getKeys() + const publicKeyPEM = keys.playerCertificateKeys.public + + const serverMeta = { + meta: { + serverName: process.env.SERVER_NAME || "Yggdrasil Server", + implementationName: package.name, + implementationVersion: package.version, + + "feature.legacy_skin_api": utils.isTrueFromDotEnv("SUPPORT_LEGACY_SKIN_API"), + "feature.no_mojang_namespace": utils.isTrueFromDotEnv("SUPPORT_MOJANG_FALLBACK"), + "feature.enable_mojang_anti_features": utils.isTrueFromDotEnv("SUPPORT_MOJANG_TELEMETRY_BLOCKER"), + "feature.enable_profile_key": utils.isTrueFromDotEnv("SUPPORT_PROFILE_KEY"), + "feature.username_check": utils.isTrueFromDotEnv("SUPPORT_ONLY_DEFAULT_USERNAME"), + + links: { + homepage: process.env.HOMEPAGE_URL || `http://${hostname}`, + } + }, + skinDomains: [ + hostname, + `.${hostname}` + ], + signaturePublickey: publicKeyPEM + } + if (utils.isTrueFromDotEnv("SUPPORT_REGISTER")) { + serverMeta.meta.links.register = process.env.REGISTER_ENDPOINT || `http://${hostname}/register` + } + return serverMeta +} + +module.exports = { + getServerMetadata +} \ No newline at end of file