From bb5612c073c92379dbcd57b9d59062a0a1d09d4c Mon Sep 17 00:00:00 2001 From: GDWR <57012020+GDWR@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:56:20 +0000 Subject: [PATCH] Support Forge clients (#27) * Add nix devshell and .envrc * Add .direnv to .gitignore * Handle forge FML protocol --- .envrc | 1 + .gitignore | 3 ++- flake.lock | 23 +++++++++++++++++++++++ flake.nix | 11 +++++++++++ pkg/router.go | 5 +++++ shell.nix | 4 ++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index cb65a62..173939d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ data -.idea \ No newline at end of file +.idea +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1926c53 --- /dev/null +++ b/flake.lock @@ -0,0 +1,23 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", + "path": "/nix/store/yy5l09gfsagkv8rswblknmsjc2gyr20d-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a82d71d --- /dev/null +++ b/flake.nix @@ -0,0 +1,11 @@ +{ + outputs = { self, nixpkgs, ... }: + let + forAllSystems = function: + nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] + (system: function nixpkgs.legacyPackages.${system}); + in rec { + devShells = + forAllSystems (pkgs: { default = pkgs.callPackage ./shell.nix { }; }); + }; +} diff --git a/pkg/router.go b/pkg/router.go index 66015c5..c6cd359 100644 --- a/pkg/router.go +++ b/pkg/router.go @@ -117,8 +117,13 @@ func (r Router) handleConnection(client net.Conn) { return } serverAddress := string(serverAddressRaw) + + // Its common for proxies or mods to append extra data to the server address after a "///" separator. We ignore this for routing. serverAddress = strings.Split(serverAddress, "///")[0] + // Forge's "FML" protocol appends a marker to the end of the server address prefixed with a null character. + serverAddress = strings.Split(serverAddress, "\x00")[0] + serverPortRaw := make([]byte, 2) _, err = packetReader.Read(serverPortRaw) if err != nil { diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..a5e4798 --- /dev/null +++ b/shell.nix @@ -0,0 +1,4 @@ +{ pkgs ? import { }, ... }: +pkgs.mkShell { + packages = with pkgs; [ go gopls ]; +}