Begin work on data generator
All checks were successful
Build & Test / nix-build (push) Successful in 1m47s

This commit is contained in:
Kodi Craft 2024-10-10 14:42:40 +02:00
parent 47bb453178
commit 827004e145
Signed by: kodi
GPG Key ID: 69D9EED60B242822
3 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,45 @@
# Amethyst - An experimental Minecraft server written in Elixir.
# Copyright (C) 2024 KodiCraft
#
# 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/>.
defmodule Amethyst.DataGenerator do
@moduledoc """
This module allows Amethyst to download the vanilla Minecraft server and generate
necessary data files.
"""
@spec get_version_meta(String.t() | :latest) :: {:ok, map()} | {:error, term}
def get_version_meta(version) do
version = if version == :latest, do: get_latest_version(), else: {:ok, version}
case version do
{:ok, version} ->
case Req.get(Application.fetch_env!(:amethyst, :mojang_game_meta)) do
{:ok, %{body: %{"versions" => versions}}} ->
case Enum.find(versions, fn %{"id" => id} -> id == version end) do
nil -> {:error, :version_not_found}
version_meta -> {:ok, version_meta}
end
{:error, err} -> {:error, err}
end
{:error, err} -> {:error, err}
end
end
def get_latest_version() do
case Req.get(Application.fetch_env!(:amethyst, :mojang_game_meta)) do
{:ok, %{body: %{"latest" => %{"release" => release}}}} -> {:ok, release}
{:error, err} -> {:error, err}
end
end
end

View File

@ -12,3 +12,7 @@ import Config
level: :debug,
format: "$date $time [$level] $metadata$message\n",
metadata: []
config :amethyst,
mojang_game_meta: "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json",
session_server: "https://sessionserver.mojang.com"

View File

@ -4,7 +4,6 @@ config :amethyst,
port: 25599, # Bogus port for testing, avoids unexpected conflicts
encryption: true, # Whether or not to request encryption from clients.
auth: true, # Whether or not users should be authenticated with Mojang.
session_server: "https://sessionserver.mojang.com", # Base URL to the Mojang session server
compression: 256, # Packets larger than this amount are sent compressed. Set to nil to disable compression.
default_game: Example.Game, # Which game new players should be sent to
release: config_env() == :prod # If this is set to false, Amethyst will perform additional checks at runtime and will handle errors more loosely