Skip to content

Commit

Permalink
golt: add GOLT_BIND_PORT option
Browse files Browse the repository at this point in the history
  • Loading branch information
chowder committed May 26, 2024
1 parent 458a41a commit bbfa05b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# Why?

[The official recommendation](https://help.jagex.com/hc/en-gb/articles/13413514881937-Downloading-the-Jagex-Launcher-on-Linux)
points to several community projects, most of which involve running the launcher in Wine or a similar environment. However, I really wanted a native solution, or one
points to several community projects, most of which involve running the launcher in Wine or a similar environment.
However, I really wanted a native solution, or one
that didn't require installing a 1.5GB compatibility layer solely for launcher functionality.

While there is a project that served as the inspiration for this one, and functions seamlessly on Linux, there were some boxes that it didn't tick for me:
While there is a project that served as the inspiration for this one, and functions seamlessly on Linux, there were some
boxes that it didn't tick for me:

- Its installation size is ~460MB
- Lack of support for overriding the client launch command/environment
Expand All @@ -18,7 +20,8 @@ In comparison, the linux-amd64 build for `golt` is a single 6.8MB binary.

# Installation

Either download the latest binary from the [Releases](https://github.com/chowder/golt/releases) page (or build it yourself), and add it to a directory on your `PATH`.
Either download the latest binary from the [Releases](https://github.com/chowder/golt/releases) page (or build it
yourself), and add it to a directory on your `PATH`.

Then, create a desktop entry for the application:

Expand Down Expand Up @@ -52,17 +55,18 @@ The login flow is currently done in the browser:
- The OAuth login redirects to a page which invokes a scheme handler
- The game login step redirects to `http://localhost`

These redirect URLs are validated server side, so cannot be modified on the client side.
These redirect URLs are validated server side, so cannot be modified on the client side.

As for the iptable entry, most Linux distros don't allow binding to port 80, so `golt` binds to port 8080 instead.
As for the iptable entry, most Linux distros don't allow binding to port 80, so `golt` binds to port 8080 instead.

</details>

# Configuration

| Environment Variable | Default | Description |
|----------------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `GOLT_GAME_PATH` | `RuneLite.AppImage` | Either a binary on `PATH`, or an absolute path to the client to launch.<br/>This value is passed to `exec.Command`([docs](https://pkg.go.dev/os/exec#Command)) |
| Environment Variable | Default | Description |
|----------------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `GOLT_GAME_PATH` | `RuneLite.AppImage` | Either a binary on `PATH`, or an absolute path to the client to launch.<br/>This value is passed to `exec.Command`([docs](https://pkg.go.dev/os/exec#Command)) |
| `GOLT_BIND_PORT` | `8080` | Local port to which `golt` will bind to to receive the OAuth response callback.<br/>If this is not `80`, you must set up an iptable entry to redirect inbound traffic from port `80` to this port. |

# Disclaimer

Expand Down
16 changes: 15 additions & 1 deletion internal/golt/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/pkg/browser"
"golang.org/x/oauth2"
"log"
"os"
"net/http"
"strconv"
"strings"
)

Expand Down Expand Up @@ -179,10 +181,22 @@ func StandardLogin(idToken string) (*Tuple[string, string], error) {
channel <- Tuple[string, string]{code, idToken}
})

port := 8080

if val, exists := os.LookupEnv("GOLT_BIND_PORT"); exists {
var err error
port, err = strconv.Atoi(val)
if err != nil {
Die(errors.New("could not parse GOLT_BIND_PORT as integer"))
}
}

log.Println("Binding to port:", port)

// Start the server
server := &http.Server{
// TODO: sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
Addr: ":8080",
Addr: ":" + strconv.Itoa(port),
Handler: nil,
}
go func() {
Expand Down

0 comments on commit bbfa05b

Please sign in to comment.