Compare commits
12 Commits
744439c351
...
dev
Author | SHA1 | Date | |
---|---|---|---|
7c067839af
|
|||
22fd87a07a
|
|||
1d825c97f3
|
|||
044cd3082e
|
|||
e7c4dc58b7
|
|||
2722e85a6a
|
|||
dcec80c184
|
|||
016dfaf14d
|
|||
b8487b766b
|
|||
a537906a17
|
|||
81d81b8a03
|
|||
f6ac467265
|
68
.gitea/workflows/build.yaml
Normal file
68
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,68 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Pre Setup NodeJS
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
- name: For act to work
|
||||
run: npm -g install yarn
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: frontend
|
||||
- name: Build Frontend
|
||||
run: |
|
||||
make assets
|
||||
rm -rf /host/${{ gitea.workspace }} && mkdir -p /host/${{ gitea.workspace }}
|
||||
cp -a . /host/${{ gitea.workspace }}/
|
||||
- name: Build Yggdrasil Server
|
||||
uses: crazy-max/ghaction-xgo@v2
|
||||
with:
|
||||
xgo_version: latest
|
||||
go_version: 1.24
|
||||
dest: build
|
||||
prefix: yggdrasil
|
||||
targets: linux/amd64,linux/arm64
|
||||
v: true
|
||||
x: false
|
||||
race: false
|
||||
ldflags: -s -w -buildid=
|
||||
tags: nomsgpack sqlite mysql
|
||||
trimpath: true
|
||||
- name: Store Back Binaries
|
||||
run: |
|
||||
cp -a /host/${{ gitea.workspace }}/build/. build
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: docker.sunxinao.cn
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: docker.sunxinao.cn/gardel/yggdrasil-go:latest
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@@ -45,14 +45,14 @@ jobs:
|
||||
- name: Create ZIP archive
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
cp -v ./config_example.ini ./assets ./build/ || exit 1
|
||||
cp -rv ./config_example.ini ./assets ./build/ || exit 1
|
||||
pushd build || exit 1
|
||||
ls -1 yggdrasil-* | while read LINE; do
|
||||
PREFIX="${LINE%.*}"
|
||||
SUFFIX="$(echo "$LINE" | grep -osE '\.\w+' || printf '')"
|
||||
cp -v "$LINE" "yggdrasil$SUFFIX"
|
||||
FILE="../$PREFIX.zip"
|
||||
zip -9v "$FILE" "yggdrasil$SUFFIX" *.ini assets
|
||||
zip -9rv "$FILE" "yggdrasil$SUFFIX" *.ini assets
|
||||
DGST="$FILE.dgst"
|
||||
openssl dgst -md5 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
||||
openssl dgst -sha1 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
||||
|
@@ -1,13 +1,14 @@
|
||||
FROM alpine:latest
|
||||
FROM debian:12-slim
|
||||
|
||||
LABEL maintainer="Gardel <sunxinao@hotmail.com>"
|
||||
LABEL "Description"="Go Yggdrasil Server"
|
||||
|
||||
RUN apt-get update && apt-get install -y ca-certificates
|
||||
RUN update-ca-certificates
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG BINARY="yggdrasil-${TARGETOS}-${TARGETARCH}"
|
||||
RUN mkdir -p /app
|
||||
COPY $BINARY /app/yggdrasil
|
||||
COPY "build/yggdrasil-${TARGETOS}-${TARGETARCH}" /app/yggdrasil
|
||||
|
||||
EXPOSE 8080
|
||||
VOLUME /app/data
|
||||
|
84
Jenkinsfile
vendored
84
Jenkinsfile
vendored
@@ -1,84 +0,0 @@
|
||||
podTemplate(yaml: '''
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- image: docker.sunxinao.cn/gardel/nodejs-ci:latest
|
||||
name: nodejs
|
||||
command:
|
||||
- sleep
|
||||
args:
|
||||
- 99d
|
||||
volumeMounts:
|
||||
- name: npm-cache
|
||||
mountPath: /root/.npm
|
||||
- image: golang:1.19-alpine
|
||||
name: golang
|
||||
command:
|
||||
- sleep
|
||||
args:
|
||||
- 99d
|
||||
- image: gcr.io/kaniko-project/executor:debug
|
||||
name: kaniko
|
||||
command:
|
||||
- /busybox/sleep
|
||||
args:
|
||||
- 99d
|
||||
volumeMounts:
|
||||
- name: kaniko-cache
|
||||
mountPath: /cache
|
||||
- name: docker-config
|
||||
mountPath: /kaniko/.docker
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: kaniko-cache
|
||||
persistentVolumeClaim:
|
||||
claimName: build-cache-docker
|
||||
- name: npm-cache
|
||||
persistentVolumeClaim:
|
||||
claimName: build-cache-npm
|
||||
- name: docker-config
|
||||
secret:
|
||||
secretName: docker-config
|
||||
optional: false
|
||||
items:
|
||||
- key: config.json
|
||||
path: config.json
|
||||
''') {
|
||||
|
||||
properties([
|
||||
buildDiscarder(logRotator(artifactDaysToKeepStr: '4', artifactNumToKeepStr: '3', daysToKeepStr: '4', numToKeepStr: '5')),
|
||||
disableConcurrentBuilds()
|
||||
])
|
||||
|
||||
node(POD_LABEL) {
|
||||
stage('克隆仓库') {
|
||||
git branch: env.BRANCH_NAME, credentialsId: 'gardel', url: 'git@sunxinao.cn:gardel/yggdrasil-go.git'
|
||||
}
|
||||
stage('编译') {
|
||||
container('nodejs') {
|
||||
sh 'make assets'
|
||||
}
|
||||
container('golang') {
|
||||
sh 'apk --no-cache add build-base'
|
||||
sh 'make package'
|
||||
}
|
||||
archiveArtifacts artifacts: 'yggdrasil.tar.gz', fingerprint: true, followSymlinks: false, onlyIfSuccessful: true
|
||||
}
|
||||
stage('发布镜像') {
|
||||
container('kaniko') {
|
||||
stage('准备缓存') {
|
||||
sh '/kaniko/warmer --cache-dir=/cache --image=alpine:latest ' +
|
||||
'--registry-mirror=docker.sunxinao.cn'
|
||||
}
|
||||
stage('构建') {
|
||||
sh "/kaniko/executor --cache-dir=/cache --context `pwd` " +
|
||||
"--destination docker.sunxinao.cn/gardel/yggdrasil-go:latest " +
|
||||
"--registry-mirror docker.sunxinao.cn " +
|
||||
"--build-arg 'BINARY=yggdrasil-linux-amd64'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@ GO_CLEAN = $(GO_CMD) clean
|
||||
GO_TEST = $(GO_CMD) test
|
||||
GO_GET = $(GO_CMD) get
|
||||
|
||||
BINARY = yggdrasil-linux-amd64
|
||||
BINARY = yggdrasil
|
||||
|
||||
PACKAGE_NAME = yggdrasil.tar.gz
|
||||
|
||||
|
14
README.md
14
README.md
@@ -16,6 +16,12 @@
|
||||
|
||||
禁止其他违反 [EULA](https://account.mojang.com/documents/minecraft_eula) 的行为。
|
||||
|
||||
## 准备
|
||||
|
||||
+ 运行 Linux, Windows 或 MacOS 的主机
|
||||
+ SMTP 服务器和账号用于发送密码找回邮件
|
||||
+ MySQL 数据库(如果使用 sqlite 则不需要)
|
||||
|
||||
## 用法
|
||||
|
||||
下载或编译得到可执行文件并运行,将会自动生成所需的配置文件和数据库文件。
|
||||
@@ -33,3 +39,11 @@
|
||||
```shell
|
||||
docker run -d --name yggdrasil-go -v $(pwd)/data:/app/data -p 8080:8080 gardel/yggdrasil-go:latest
|
||||
```
|
||||
|
||||
## 计划
|
||||
|
||||
- [x] 支持密码重置
|
||||
- [ ] 支持不同的数据库如 PostgreSQL 等
|
||||
- [ ] 添加选项以支持完全离线模式(不检查 Mojang 接口)
|
||||
- [ ] 添加选项以禁用邮箱验证
|
||||
- [ ] 令牌持久化防止升级和重启时令牌生效
|
@@ -30,7 +30,7 @@
|
||||
"@types/react": "^19.0.12",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/three": "^0.175.0",
|
||||
"@vitejs/plugin-react": "^3.0.0",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.2.3",
|
||||
"vite-plugin-mock-dev-server": "^1.8.4"
|
||||
|
@@ -24,7 +24,7 @@
|
||||
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.26.8.tgz#821c1d35641c355284d4a870b8a4a7b0c141e367"
|
||||
integrity sha512-oH5UPLMWR3L2wEFLnFJ1TZXqHufiTKAiLfqw5zkhS4dKXLJ10yVztfil/twG8EDTA4F/tvVNw9nOl4ZMslB8rQ==
|
||||
|
||||
"@babel/core@^7.20.12":
|
||||
"@babel/core@^7.26.0":
|
||||
version "7.26.10"
|
||||
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.26.10.tgz#5c876f83c8c4dcb233ee4b670c0606f2ac3000f9"
|
||||
integrity sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==
|
||||
@@ -112,21 +112,21 @@
|
||||
"@babel/template" "^7.27.0"
|
||||
"@babel/types" "^7.27.0"
|
||||
|
||||
"@babel/parser@^7.26.10", "@babel/parser@^7.27.0":
|
||||
"@babel/parser@^7.1.0", "@babel/parser@^7.20.7", "@babel/parser@^7.26.10", "@babel/parser@^7.27.0":
|
||||
version "7.27.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.27.0.tgz#3d7d6ee268e41d2600091cbd4e145ffee85a44ec"
|
||||
integrity sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg==
|
||||
dependencies:
|
||||
"@babel/types" "^7.27.0"
|
||||
|
||||
"@babel/plugin-transform-react-jsx-self@^7.18.6":
|
||||
"@babel/plugin-transform-react-jsx-self@^7.25.9":
|
||||
version "7.25.9"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.25.9.tgz#c0b6cae9c1b73967f7f9eb2fca9536ba2fad2858"
|
||||
integrity sha512-y8quW6p0WHkEhmErnfe58r7x0A70uKphQm8Sp8cV7tjNQwK56sNVK0M73LK3WuYmsuyrftut4xAkjjgU0twaMg==
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.25.9"
|
||||
|
||||
"@babel/plugin-transform-react-jsx-source@^7.19.6":
|
||||
"@babel/plugin-transform-react-jsx-source@^7.25.9":
|
||||
version "7.25.9"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.25.9.tgz#4c6b8daa520b5f155b5fb55547d7c9fa91417503"
|
||||
integrity sha512-+iqjT8xmXhhYv4/uiYd8FNQsraMFZIfxVSqxxVSZP0WbbSAWvBXAul0m/zu+7Vv4O/3WtApy9pmaTMiumEZgfg==
|
||||
@@ -162,7 +162,7 @@
|
||||
debug "^4.3.1"
|
||||
globals "^11.1.0"
|
||||
|
||||
"@babel/types@^7.25.9", "@babel/types@^7.26.10", "@babel/types@^7.27.0":
|
||||
"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.25.9", "@babel/types@^7.26.10", "@babel/types@^7.27.0":
|
||||
version "7.27.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.27.0.tgz#ef9acb6b06c3173f6632d993ecb6d4ae470b4559"
|
||||
integrity sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg==
|
||||
@@ -431,7 +431,7 @@
|
||||
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.2.1.tgz#558fb6472ed16a4c850b889530e6b36438c49280"
|
||||
integrity sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==
|
||||
|
||||
"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.13", "@jridgewell/sourcemap-codec@^1.4.14":
|
||||
"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14":
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a"
|
||||
integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==
|
||||
@@ -739,6 +739,39 @@
|
||||
resolved "https://registry.yarnpkg.com/@tweenjs/tween.js/-/tween.js-23.1.3.tgz#eff0245735c04a928bb19c026b58c2a56460539d"
|
||||
integrity sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==
|
||||
|
||||
"@types/babel__core@^7.20.5":
|
||||
version "7.20.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
|
||||
integrity sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==
|
||||
dependencies:
|
||||
"@babel/parser" "^7.20.7"
|
||||
"@babel/types" "^7.20.7"
|
||||
"@types/babel__generator" "*"
|
||||
"@types/babel__template" "*"
|
||||
"@types/babel__traverse" "*"
|
||||
|
||||
"@types/babel__generator@*":
|
||||
version "7.6.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/babel__generator/-/babel__generator-7.6.8.tgz#f836c61f48b1346e7d2b0d93c6dacc5b9535d3ab"
|
||||
integrity sha512-ASsj+tpEDsEiFr1arWrlN6V3mdfjRMZt6LtK/Vp/kreFLnr5QH5+DhvD5nINYZXzwJvXeGq+05iUXcAzVrqWtw==
|
||||
dependencies:
|
||||
"@babel/types" "^7.0.0"
|
||||
|
||||
"@types/babel__template@*":
|
||||
version "7.4.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/babel__template/-/babel__template-7.4.4.tgz#5672513701c1b2199bc6dad636a9d7491586766f"
|
||||
integrity sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==
|
||||
dependencies:
|
||||
"@babel/parser" "^7.1.0"
|
||||
"@babel/types" "^7.0.0"
|
||||
|
||||
"@types/babel__traverse@*":
|
||||
version "7.20.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.20.7.tgz#968cdc2366ec3da159f61166428ee40f370e56c2"
|
||||
integrity sha512-dkO5fhS7+/oos4ciWxyEyjWe48zmG6wbCheo/G2ZnHx4fs3EU6YC6UM8rk56gAjNJ9P3MTH2jo5jb92/K6wbng==
|
||||
dependencies:
|
||||
"@babel/types" "^7.20.7"
|
||||
|
||||
"@types/draco3d@^1.4.0":
|
||||
version "1.4.10"
|
||||
resolved "https://registry.yarnpkg.com/@types/draco3d/-/draco3d-1.4.10.tgz#63ec0ba78b30bd58203ec031f4e4f0198c596dca"
|
||||
@@ -820,16 +853,16 @@
|
||||
dependencies:
|
||||
"@use-gesture/core" "10.3.1"
|
||||
|
||||
"@vitejs/plugin-react@^3.0.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@vitejs/plugin-react/-/plugin-react-3.1.0.tgz#d1091f535eab8b83d6e74034d01e27d73c773240"
|
||||
integrity sha512-AfgcRL8ZBhAlc3BFdigClmTUMISmmzHn7sB2h9U1odvc5U/MjWXsAaz18b/WoppUTDBzxOJwo2VdClfUcItu9g==
|
||||
"@vitejs/plugin-react@^4.3.4":
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/@vitejs/plugin-react/-/plugin-react-4.3.4.tgz#c64be10b54c4640135a5b28a2432330e88ad7c20"
|
||||
integrity sha512-SCCPBJtYLdE8PX/7ZQAs1QAZ8Jqwih+0VBLum1EGqmCCQal+MIUqLCzj3ZUy8ufbC0cAM4LRlSTm7IQJwWT4ug==
|
||||
dependencies:
|
||||
"@babel/core" "^7.20.12"
|
||||
"@babel/plugin-transform-react-jsx-self" "^7.18.6"
|
||||
"@babel/plugin-transform-react-jsx-source" "^7.19.6"
|
||||
magic-string "^0.27.0"
|
||||
react-refresh "^0.14.0"
|
||||
"@babel/core" "^7.26.0"
|
||||
"@babel/plugin-transform-react-jsx-self" "^7.25.9"
|
||||
"@babel/plugin-transform-react-jsx-source" "^7.25.9"
|
||||
"@types/babel__core" "^7.20.5"
|
||||
react-refresh "^0.14.2"
|
||||
|
||||
"@webgpu/types@*":
|
||||
version "0.1.60"
|
||||
@@ -1524,13 +1557,6 @@ maath@^0.6.0:
|
||||
resolved "https://registry.yarnpkg.com/maath/-/maath-0.6.0.tgz#7841d0fb95bbb37d19b08b7c5458ef70190950d2"
|
||||
integrity sha512-dSb2xQuP7vDnaYqfoKzlApeRcR2xtN8/f7WV/TMAkBC8552TwTLtOO0JTcSygkYMjNDPoo6V01jTw/aPi4JrMw==
|
||||
|
||||
magic-string@^0.27.0:
|
||||
version "0.27.0"
|
||||
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.27.0.tgz#e4a3413b4bab6d98d2becffd48b4a257effdbbf3"
|
||||
integrity sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==
|
||||
dependencies:
|
||||
"@jridgewell/sourcemap-codec" "^1.4.13"
|
||||
|
||||
math-intrinsics@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz#a0dd74be81e2aa5c2f27e65ce283605ee4e2b7f9"
|
||||
@@ -1770,7 +1796,7 @@ react-reconciler@^0.31.0:
|
||||
dependencies:
|
||||
scheduler "^0.25.0"
|
||||
|
||||
react-refresh@^0.14.0:
|
||||
react-refresh@^0.14.2:
|
||||
version "0.14.2"
|
||||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.2.tgz#3833da01ce32da470f1f936b9d477da5c7028bf9"
|
||||
integrity sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==
|
||||
|
@@ -62,8 +62,9 @@ type HomeRouter interface {
|
||||
}
|
||||
|
||||
type homeRouterImpl struct {
|
||||
serverMeta ServerMeta
|
||||
myPubKey KeyPair
|
||||
serverMeta ServerMeta
|
||||
myPubKey KeyPair
|
||||
cachedPubKey *PublicKeys
|
||||
}
|
||||
|
||||
func NewHomeRouter(meta *ServerMeta) HomeRouter {
|
||||
@@ -81,6 +82,10 @@ func (h *homeRouterImpl) Home(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
|
||||
if h.cachedPubKey != nil {
|
||||
c.JSON(http.StatusOK, h.cachedPubKey)
|
||||
return
|
||||
}
|
||||
publicKeys := PublicKeys{}
|
||||
err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
|
||||
if err != nil {
|
||||
@@ -90,4 +95,5 @@ func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
|
||||
publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
|
||||
publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
|
||||
c.JSON(http.StatusOK, publicKeys)
|
||||
h.cachedPubKey = &publicKeys
|
||||
}
|
||||
|
@@ -118,7 +118,7 @@ func (u *userServiceImpl) Register(username, password, profileName, ip string) (
|
||||
} else if _, err := mojangUsernameToUUID(profileName); err == nil {
|
||||
return nil, util.NewForbiddenOperationError("profileName duplicate")
|
||||
}
|
||||
matched, err := regexp.MatchString("^(\\w){3,}(\\.\\w+)*@(\\w){2,}((\\.\\w+)+)$", username)
|
||||
matched, err := regexp.MatchString("^\\w+@(\\w){2,}((\\.\\w+)+)$", username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -394,29 +394,35 @@ func (u *userServiceImpl) QueryProfile(profileId uuid.UUID, unsigned bool, textu
|
||||
|
||||
func (u *userServiceImpl) ProfileKey(accessToken string) (resp *ProfileKeyResponse, err error) {
|
||||
token, ok := u.tokenService.GetToken(accessToken)
|
||||
var profileId uuid.UUID
|
||||
if ok && token.GetAvailableLevel() == model.Valid {
|
||||
resp = new(ProfileKeyResponse)
|
||||
now := time.Now().UTC()
|
||||
resp.RefreshedAfter = now
|
||||
resp.ExpiresAt = now.Add(time.Hour * 24 * 90)
|
||||
keyPair, err := u.getProfileKey(token.SelectedProfile.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.KeyPair = keyPair
|
||||
signStr := fmt.Sprintf("%d%s", resp.ExpiresAt.UnixMilli(), keyPair.PublicKey)
|
||||
sign, err := util.Sign(signStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.PublicKeySignature = sign
|
||||
resp.PublicKeySignatureV2 = sign
|
||||
profileId = token.SelectedProfile.Id
|
||||
} else {
|
||||
err = util.PostForString("https://api.minecraftservices.com/player/certificates", accessToken, []byte(""), resp)
|
||||
id, _, err := util.ParseOfficialToken(accessToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profileId, err = util.ToUUID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
resp = new(ProfileKeyResponse)
|
||||
now := time.Now().UTC()
|
||||
resp.RefreshedAfter = now
|
||||
resp.ExpiresAt = now.Add(90 * 24 * time.Hour)
|
||||
keyPair, err := u.getProfileKey(profileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.KeyPair = keyPair
|
||||
signStr := fmt.Sprintf("%d%s", resp.ExpiresAt.UnixMilli(), keyPair.PublicKey)
|
||||
sign, err := util.Sign(signStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.PublicKeySignature = sign
|
||||
resp.PublicKeySignatureV2 = sign
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
75
util/token_utils.go
Normal file
75
util/token_utils.go
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2025. Gardel <sunxinao@hotmail.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type officialTokenPayload struct {
|
||||
Xuid string `json:"xuid"`
|
||||
Agg string `json:"agg"`
|
||||
Sub string `json:"sub"`
|
||||
Auth string `json:"auth"`
|
||||
Ns string `json:"ns"`
|
||||
Roles []interface{} `json:"roles"`
|
||||
Iss string `json:"iss"`
|
||||
Flags []string `json:"flags"`
|
||||
Profiles struct {
|
||||
Mc string `json:"mc"`
|
||||
} `json:"profiles"`
|
||||
Platform string `json:"platform"`
|
||||
Pfd []struct {
|
||||
Type string `json:"type"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"pfd"`
|
||||
Nbf int `json:"nbf"`
|
||||
Exp int `json:"exp"`
|
||||
Iat int `json:"iat"`
|
||||
}
|
||||
|
||||
func ParseOfficialToken(token string) (id, name string, err error) {
|
||||
firstDot := strings.IndexRune(token, '.')
|
||||
if firstDot == -1 {
|
||||
return id, name, errors.New("invalid token")
|
||||
}
|
||||
secondDot := 1 + firstDot + strings.IndexRune(token[firstDot+1:], '.')
|
||||
if secondDot == -1 {
|
||||
return id, name, errors.New("invalid token")
|
||||
}
|
||||
jsonBase64 := token[firstDot+1 : secondDot]
|
||||
jsonDecoded, err := base64.RawURLEncoding.DecodeString(jsonBase64)
|
||||
if err != nil {
|
||||
return id, name, err
|
||||
}
|
||||
payload := officialTokenPayload{}
|
||||
err = json.Unmarshal(jsonDecoded, &payload)
|
||||
if err != nil {
|
||||
return id, name, err
|
||||
}
|
||||
if payload.Pfd == nil || len(payload.Pfd) == 0 {
|
||||
return id, name, errors.New("invalid token")
|
||||
}
|
||||
id = payload.Pfd[0].Id
|
||||
name = payload.Pfd[0].Name
|
||||
return id, name, nil
|
||||
}
|
Reference in New Issue
Block a user