Skip to content

Commit

Permalink
Linting, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode committed Sep 19, 2023
1 parent 3bb87e6 commit 3d54b13
Show file tree
Hide file tree
Showing 32 changed files with 1,491 additions and 866 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name: Publish Docker image
on:
push:
tags:
- 'v*'
- "v*"

jobs:
push_to_registry:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
nix-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix build
- run: nix flake check
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix build
- run: nix flake check
20 changes: 12 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/tekwizely/pre-commit-golang
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fmt-repo
- repo: https://github.com/kamadorueda/alejandra
- id: go-fmt-repo
- repo: https://github.com/kamadorueda/alejandra
rev: 2.0.0
hooks:
- id: alejandra-system
- id: alejandra-system
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3" # Use the sha or tag you want to point at
hooks:
- id: prettier
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["prettier-plugin-go-template"]
}
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Drasl is an alternative API server for Minecraft that handles authentication, skins, and capes.
You can use it to host Minecraft servers that are completely independent from Mojang's infrastructure.
It's compatible with both [authlib-injector](https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md) and the vanilla Yggdrasil protocol, which means it supports:

- Minecraft launchers that support authlib-injector, such as [HMCL](https://github.com/huanghongxun/HMCL)
- Minecraft servers running authlib-injector
- Vanilla Minecraft servers running version 1.16 or later, via JVM arguments. Vanilla 1.16+ clients are supported too, but most launchers use authlib-injector for third-party accounts.
Expand All @@ -16,8 +17,8 @@ There are many reasons to host your own API server instead of using Mojang's. Yo

- Experience the benefits of offline servers without losing skins, encrypted connections, or account security
- Create additional accounts to allow users to have multiple players logged in to a server simultaneously
- Have a "camera account" spectate your character for content creation
- Program [bots](https://mineflayer.prismarine.js.org/) to automate tedious tasks like AFKing, crafting, or even building map art.
- Have a "camera account" spectate your character for content creation
- Program [bots](https://mineflayer.prismarine.js.org/) to automate tedious tasks like AFKing, crafting, or even building map art.
- Have skins with transparency, or high-resolution skins (this would require a modded client as well)
- Play Minecraft in a country or on a network where Mojang's servers are inaccessible
- Keep your activity private from Mojang. Mojang knows which servers you are active on, when you log on, who else is on those servers, etc. If telemetry is enabled (since 1.18, it cannot be disabled without a [mod](https://github.com/kb-1000/no-telemetry)), they are also notified whenever you load a singleplayer world.
Expand All @@ -32,13 +33,13 @@ There are many reasons to host your own API server instead of using Mojang's. Yo
- Highly configurable
- Fast, minimalist, and highly-accessible web interface. JavaScript is used only for cosmetic effects and is not required.
- Optional: proxy requests to fallback API servers (see [FallbackAPIServers](doc/configuration.md))
- You can configure your Minecraft server to accept users logged in with either a Mojang account or a Drasl account.
- You can configure your Minecraft server to accept users logged in with either a Mojang account or a Drasl account.
- Optional: disable access token and public key expiry (no more "Invalid session" or "Invalid signature for profile public key")
- Optional: sign player public keys to support chat signing and `enforce-secure-profile=true` (see [SignPublicKeys](doc/configuration.md))
- Optional: allow high-resolution skins (see [SkinSizeLimit](doc/configuration.md))
- Optional: allow registering from existing account an another API server (i.e. Mojang's) (see [RegistrationExistingPlayer](doc/configuration.md))
- Useful if you want to keep your UUID
- Optional: require a skin challenge to verify ownership of the existing account (see [RequireSkinVerification](doc/configuration.md))
- Useful if you want to keep your UUID
- Optional: require a skin challenge to verify ownership of the existing account (see [RequireSkinVerification](doc/configuration.md))

## Installation

Expand Down Expand Up @@ -84,11 +85,13 @@ sudo pacman -S make go gcc nodejs npm # Arch Linux
```

Then build the program with:

```
make
```

Run the tests with:

```
make test
```
Expand Down
90 changes: 47 additions & 43 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,72 @@ Other available options:
- `StateDirectory`: directory to store application state, including the database (`drasl.db`), skins, and capes. String. Default value: `"/var/lib/drasl/"`.
- `DataDirectory`: directory where Drasl's static assets are installed. String. Default value: `"/usr/share/drasl"`.
- `ListenAddress`: IP address and port to listen on. You probably want to change this to `"127.0.0.1:25585"` if you run your reverse proxy server on the same host. String. Default value: `"0.0.0.0:25585"`.
- `DefaultAdmins`: Usernames of the instance's permanent admins. Admin rights can be granted to other accounts using the web UI, but admins defined via `DefaultAdmins` cannot be demoted unless they are removed from the config file. Array of strings. Default value: `[]`.
- `DefaultAdmins`: Usernames of the instance's permanent admins. Admin rights can be granted to other accounts using the web UI, but admins defined via `DefaultAdmins` cannot be demoted unless they are removed from the config file. Array of strings. Default value: `[]`.
- `[RateLimit]`: Rate-limit requests per IP address to limit abuse. Only applies to certain web UI routes, not any Yggdrasil routes. Requests for skins, capes, and web pages are also unaffected. Uses [Echo](https://echo.labstack.com)'s [rate limiter middleware](https://echo.labstack.com/middleware/rate-limiter/).
- `Enable`: Boolean. Default value: `true`.
- `RequestsPerSecond`: Number of requests per second allowed per IP address. Integer. Default value: `5`.
- `Enable`: Boolean. Default value: `true`.
- `RequestsPerSecond`: Number of requests per second allowed per IP address. Integer. Default value: `5`.
- `[BodyLimit]`: Limit the maximum size of a request body limit abuse. The default settings should be fine unless you want to support humongous skins (greater than 1024 × 1024 pixels).
- `Enable`: Boolean. Default value: `true`.
- `SizeLimitKiB`: Maximum size of a request body in kibibytes. Integer. Default value: `8192`.
- `Enable`: Boolean. Default value: `true`.
- `SizeLimitKiB`: Maximum size of a request body in kibibytes. Integer. Default value: `8192`.
- `LogRequests`: Log each incoming request on stdout. Boolean. Default value: `true`.
- `ForwardSkins`: When `true`, if a user doesn't have a skin or cape set, Drasl will try to serve a skin from the fallback API servers. Boolean. Default value: `true`.
- Vanilla clients will not accept skins or capes that are not hosted on Mojang's servers. If you want to support vanilla clients, enable `ForwardSkins` and configure Mojang as a fallback API server.
- For players who do not have a account on the Drasl instance, skins will always be forwarded from the fallback API servers.
- Vanilla clients will not accept skins or capes that are not hosted on Mojang's servers. If you want to support vanilla clients, enable `ForwardSkins` and configure Mojang as a fallback API server.
- For players who do not have a account on the Drasl instance, skins will always be forwarded from the fallback API servers.
- `[[FallbackAPIServers]]`: Allows players to authenticate using other API servers. For example, say you had a Minecraft server configured to authenticate players with your Drasl instance. You could configure Mojang's API as a fallback, and a player signed in with either a Drasl account or a Mojang account could play on your server. Does not work with Minecraft servers that have `enforce-secure-profile=true` in server.properties. See [recipes.md](doc/recipes.md) for example configurations.
- You can configure any number of fallback API servers, and they will be tried in sequence, in the order they appear in the config file. By default, none are configured.
- `Nickname`: A name for the API server
- `AccountURL`: The URL of the "account" server. String. Example value: `"https://api.mojang.com"`.
- `SessionURL`: The URL of the "session" server. String. Example value: `"https://sessionserver.mojang.com"`.
- `ServicesURL`: The URL of the "services" server. String. Example value: `"https://api.minecraftservices.com"`.
- `SkinDomains`: Array of domains where skins are hosted. For authlib-injector-compatible API servers, the correct value should be returned by the root of the API, e.g. go to [https://example.com/yggdrasil](https://example.com/yggdrasil) and look for the `skinDomains` field. Array of strings. Example value: `["textures.minecraft.net"]`
- Note: API servers set up for authlib-injector may only give you one URL---if their API URL is e.g. `https://example.com/yggdrasil`, then you would use the following settings:

```
AccountURL = https://example.com/yggdrasil/api
SessionURL = https://example.com/yggdrasil/sessionserver
ServicesURL = https://example.com/yggdrasil/minecraftservices
```

- You can configure any number of fallback API servers, and they will be tried in sequence, in the order they appear in the config file. By default, none are configured.
- `Nickname`: A name for the API server
- `AccountURL`: The URL of the "account" server. String. Example value: `"https://api.mojang.com"`.
- `SessionURL`: The URL of the "session" server. String. Example value: `"https://sessionserver.mojang.com"`.
- `ServicesURL`: The URL of the "services" server. String. Example value: `"https://api.minecraftservices.com"`.
- `SkinDomains`: Array of domains where skins are hosted. For authlib-injector-compatible API servers, the correct value should be returned by the root of the API, e.g. go to [https://example.com/yggdrasil](https://example.com/yggdrasil) and look for the `skinDomains` field. Array of strings. Example value: `["textures.minecraft.net"]`
- Note: API servers set up for authlib-injector may only give you one URL---if their API URL is e.g. `https://example.com/yggdrasil`, then you would use the following settings:

```
AccountURL = https://example.com/yggdrasil/api
SessionURL = https://example.com/yggdrasil/sessionserver
ServicesURL = https://example.com/yggdrasil/minecraftservices
```
<!-- - `[TransientLogin]`: Allow certain usernames to authenticate with a shared password, without registering. Useful for supporting bot accounts. -->
<!-- - `Allow`: Boolean. Default value: `false`. -->
<!-- - `UsernameRegex`: If a username matches this regular expression, it will be allowed to log in with the shared password. Use `".*"` to allow transient login for any username. String. Example value: `"[Bot] .*"`. -->
<!-- - `Password`: The shared password for transient login. Not restricted by `MinPasswordLength`. String. Example value: `"hunter2"`. -->
- `[RegistrationNewPlayer]`: Registration policy for new players.
- `Allow`: Boolean. Default value: `true`.
- `AllowChoosingUUID`: Allow new users to choose the UUID for their account. Boolean. Default value: `false`.
- `RequireInvite`: Whether registration requires an invite. If enabled, users will only be able to create a new account if they use an invite link generated by an admin (see `DefaultAdmins`).
- `Allow`: Boolean. Default value: `true`.
- `AllowChoosingUUID`: Allow new users to choose the UUID for their account. Boolean. Default value: `false`.
- `RequireInvite`: Whether registration requires an invite. If enabled, users will only be able to create a new account if they use an invite link generated by an admin (see `DefaultAdmins`).
- `[RegistrationExistingPlayer]`: Registration policy for signing up using an existing account on another API server. The UUID of the existing account will be used for the new account.
- `Allow`: Boolean. Default value: `false`.
- `Nickname`: A name for the API server used for registration. String. Example value: `"Mojang"`.
- `AccountURL`: The URL of the "account" server. String. Example value: `"https://api.mojang.com"`.
- `SessionURL`: The URL of the "session" server. String. Example value: `"https://sessionserver.mojang.com"`.
- `SetSkinURL`: A link to the web page where you set your skin on the API server. Example value: `"https://www.minecraft.net/msaprofile/mygames/editskin"`.
- `RequireSkinVerification`: Require users to set a skin on the existing account to verify their ownership. Boolean. Default value: `false`.
- `RequireInvite`: Whether registration requires an invite. If enabled, users will only be able to create a new account if they use an invite link generated by an admin (see `DefaultAdmins`).
- Note: API servers set up for authlib-injector may only give you one URL---if their API URL is e.g. `https://example.com/yggdrasil`, then you would use the following settings:
```
SessionURL = https://example.com/yggdrasil/sessionserver
ServicesURL = https://example.com/yggdrasil/minecraftservices
```
- `Allow`: Boolean. Default value: `false`.
- `Nickname`: A name for the API server used for registration. String. Example value: `"Mojang"`.
- `AccountURL`: The URL of the "account" server. String. Example value: `"https://api.mojang.com"`.
- `SessionURL`: The URL of the "session" server. String. Example value: `"https://sessionserver.mojang.com"`.
- `SetSkinURL`: A link to the web page where you set your skin on the API server. Example value: `"https://www.minecraft.net/msaprofile/mygames/editskin"`.
- `RequireSkinVerification`: Require users to set a skin on the existing account to verify their ownership. Boolean. Default value: `false`.
- `RequireInvite`: Whether registration requires an invite. If enabled, users will only be able to create a new account if they use an invite link generated by an admin (see `DefaultAdmins`).
- Note: API servers set up for authlib-injector may only give you one URL---if their API URL is e.g. `https://example.com/yggdrasil`, then you would use the following settings:
```
SessionURL = https://example.com/yggdrasil/sessionserver
ServicesURL = https://example.com/yggdrasil/minecraftservices
```
- `[RequestCache]`: Settings for the cache used for `FallbackAPIServers`. You probably don't need to change these settings. Modify `[[FallbackAPIServers]].CacheTTLSec` instead if you want to disable caching. See [https://pkg.go.dev/github.com/dgraph-io/ristretto#readme-config](https://pkg.go.dev/github.com/dgraph-io/ristretto#readme-config).
- `NumCounters`: The number of keys to track frequency of. Integer. Default value: `10000000` (`1e7`).
- `MaxCost`: The maximum size of the cache in bytes. Integer. Default value: `1073741824` (equal to `1 << 30` or 1 GiB).
- `BufferItems`: The number of keys per Get buffer. Default value: `64`.
- `NumCounters`: The number of keys to track frequency of. Integer. Default value: `10000000` (`1e7`).
- `MaxCost`: The maximum size of the cache in bytes. Integer. Default value: `1073741824` (equal to `1 << 30` or 1 GiB).
- `BufferItems`: The number of keys per Get buffer. Default value: `64`.
- `MinPasswordLength`: Users will not be able to choose passwords shorter than this length. Integer. Default value: `8`.
- `DefaultPreferredLanguage`: Default "preferred language" for user accounts. The Minecraft client expects an account to have a "preferred language", but I have no idea what it's used for. Choose one of the two-letter codes from [https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html](https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html). String. Default value: `"en"`.
- `SkinSizeLimit`: The maximum width, in pixels, of a user-uploaded skin or cape. Normally, Minecraft skins are 128 × 128 pixels, and capes are 128 × 64 pixels. You can raise this limit to support high resolution skins and capes, but you will also need a client-side mod like [MCCustomSkinLoader](https://github.com/xfl03/MCCustomSkinLoader) (untested). Set to `0` to remove the limit entirely, but the size of the skin file will still be limited by `BodyLimit`. Integer. Default value: `128`.
- `SignPublicKeys`: Whether to sign players' public keys. Boolean. Default value: `true`.
- Must be enabled if you want to support servers with `enforce-secure-profile=true` in server.properties.
- Limits servers' ability to forge messages from players.
- Disable if you want clients to be able to send chat messages with plausible deniability and you don't need to support `enforce-secure-profile=true`.
- Note: Minecraft 1.19 can only validate player public keys against Mojang's public key, not ours, so you should use `enforce-secure-profile=false` on versions earlier than 1.20.
- Must be enabled if you want to support servers with `enforce-secure-profile=true` in server.properties.
- Limits servers' ability to forge messages from players.
- Disable if you want clients to be able to send chat messages with plausible deniability and you don't need to support `enforce-secure-profile=true`.
- Note: Minecraft 1.19 can only validate player public keys against Mojang's public key, not ours, so you should use `enforce-secure-profile=false` on versions earlier than 1.20.
- `EnableTokenExpiry`: By default, public keys will never expire and access tokens will stay valid even when you are logged in on multiple devices. If this option is set to `true`, public keys will expire after one day, and access tokens will be invalidated when you sign in on a different device. Enable this option if you are especially security-conscious and don't mind restarting your game more often. Boolean. Default value: `false`.
- `AllowChangingPlayerName`: Allow users to change their "player name" after their account has already been created. Could be useful in conjunction with `RegistrationExistingPlayer` if you want to make users register from an existing (e.g. Mojang) account but you want them to be able to choose a new player name. Boolean. Default value: `true`.
- `AllowSkins`: Allow users to upload skins. You may want to disable this option if you want to rely exclusively on `ForwardSkins`, e.g. to fully support Vanilla clients. Boolean. Default value: `true`.
Expand Down
Loading

0 comments on commit 3d54b13

Please sign in to comment.