Begin work on data generator
All checks were successful
Build & Test / nix-build (push) Successful in 1m47s
All checks were successful
Build & Test / nix-build (push) Successful in 1m47s
This commit is contained in:
parent
47bb453178
commit
827004e145
45
apps/amethyst/lib/datagen.ex
Normal file
45
apps/amethyst/lib/datagen.ex
Normal 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
|
@ -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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user