Skip to content

Commit

Permalink
Support Forge clients (#27)
Browse files Browse the repository at this point in the history
* Add nix devshell and .envrc

* Add .direnv to .gitignore

* Handle forge FML protocol
  • Loading branch information
GDWR authored Apr 22, 2024
1 parent df7f23b commit bb5612c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data


.idea
.idea
.direnv
23 changes: 23 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 { }; });
};
}
5 changes: 5 additions & 0 deletions pkg/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ pkgs ? import <nixpkgs> { }, ... }:
pkgs.mkShell {
packages = with pkgs; [ go gopls ];
}

0 comments on commit bb5612c

Please sign in to comment.