From 5743ae55e0e9a2876bd35aba064fda3c6e3bab4c Mon Sep 17 00:00:00 2001 From: Kodi Craft Date: Mon, 7 Oct 2024 13:52:33 +0200 Subject: [PATCH] Update release system --- apps/amethyst/lib/apps/connection_handler.ex | 4 ++-- apps/amethyst/lib/states/macros.ex | 3 ++- config/runtime.exs | 3 ++- flake.nix | 17 ++++++++++++----- mix.exs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/amethyst/lib/apps/connection_handler.ex b/apps/amethyst/lib/apps/connection_handler.ex index 92f1cfc..772a054 100644 --- a/apps/amethyst/lib/apps/connection_handler.ex +++ b/apps/amethyst/lib/apps/connection_handler.ex @@ -245,10 +245,10 @@ defmodule Amethyst.ConnectionHandler do end rescue e -> - if Mix.env() == :dev do + if Application.get_env(:amethyst, :release, false) do + send(self(), {:disconnect, "§cError handling packet #{inspect(id, base: :hex)}:\n#{Exception.format(:error, e, __STACKTRACE__)}"}) Logger.error("Error handling packet with ID #{inspect(id, base: :hex)} in state #{connstate}: #{Exception.format(:error, e, __STACKTRACE__)}") else - send(self(), {:disconnect, "§cError handling packet #{inspect(id, base: :hex)}:\n#{Exception.format(:error, e, __STACKTRACE__)}"}) Logger.error("Error handling packet with ID #{inspect(id, base: :hex)} in state #{connstate}: #{Exception.format(:error, e, __STACKTRACE__)}") end state diff --git a/apps/amethyst/lib/states/macros.ex b/apps/amethyst/lib/states/macros.ex index a21ce1f..0f40a0d 100644 --- a/apps/amethyst/lib/states/macros.ex +++ b/apps/amethyst/lib/states/macros.ex @@ -28,7 +28,8 @@ defmodule Amethyst.ConnectionState.Macros do defmacro defpacket_clientbound(name, id, version, signature, where \\ true) do quote do def serialize(%{packet_type: unquote(name)} = packet, unquote(version)) when unquote(where) do - if Amethyst.ConnectionState.Macros.check_type(packet, unquote(signature)) do + # Don't check types if we are in release mode + if Application.get_env(:amethyst, :release, false) || Amethyst.ConnectionState.Macros.check_type(packet, unquote(signature)) do Amethyst.Minecraft.Write.varint(unquote(id)) <> Amethyst.ConnectionState.Macros.write_signature(packet, unquote(signature)) else raise "Invalid packet type for #{unquote(name)}! Got #{inspect(packet)}" diff --git a/config/runtime.exs b/config/runtime.exs index ba6ab65..9ad42e1 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -6,4 +6,5 @@ config :amethyst, 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 + 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 diff --git a/flake.nix b/flake.nix index 021f378..afb7a54 100644 --- a/flake.nix +++ b/flake.nix @@ -43,14 +43,20 @@ }) ); - #secrets = import ./secrets.nix; - - package = env: pkgs: (pkgs.beamPackages.mixRelease { + package = env: release: pkgs: (pkgs.beamPackages.mixRelease { pname = "amethyst"; version = "0.1.0"; src = ./.; elixir = pkgs.elixir; mixEnv = env; + mixReleaseName = release; + # This should just be part of mixRelease, I don't know why we need to do it here + installPhase = '' + runHook preInstall + mix release ${release} --no-deps-check --path "$out" + runHook postInstall + ''; + meta.mainProgram = "${release}"; erlangDeterministicBuilds = false; # Technically less pure but allows doctests removeCookie = false; # Insecure; Access to the file system can allow the cookie to be read and provides remote control of the Erlang VM mixNixDeps = import ./mix.nix {inherit lib; beamPackages = pkgs.beamPackages;}; @@ -64,8 +70,9 @@ in { packages = eachSystem (pkgs: { - default = package "prod" pkgs; - dev = package "dev" pkgs; + default = package "prod" "amethyst" pkgs; + dev = package "dev" "amethyst" pkgs; + example = package "prop" "example" pkgs; } ); diff --git a/mix.exs b/mix.exs index d2adab0..3b66f81 100644 --- a/mix.exs +++ b/mix.exs @@ -8,7 +8,7 @@ defmodule AmethystUmbrella.MixProject do elixir: "~> 1.17", start_permanent: Mix.env() == :prod, deps: deps(), - default_release: :amethyst, + # default_release: :amethyst, releases: [ amethyst: [