Skip to content

Commit

Permalink
Bungeeguard Support (#382)
Browse files Browse the repository at this point in the history
* Fixed Bungeeguard Support

- Fixed incomplete bungeeguard support
- Added bungeeguard options to config.yml

* Updated compatibility docs

- Added bungeeguard as a forwarding option
  • Loading branch information
NixNux123 authored Sep 13, 2024
1 parent 29c16f6 commit 9981869
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .web/docs/guide/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ We highly recommend using [Paper](https://papermc.io/) for running a server in m
Gate is tested with older and most recent versions of it.

You can use `modern` forwarding (like Velocity does) if you run Paper
1.13.2 or higher. If you use Paper 1.12.2 or lower, you must use `legacy` BungeeCord-style forwarding.
1.13.2 or higher. If you use Paper 1.12.2 or lower, you can use `legacy` BungeeCord-style forwarding or the more secure `bungeeguard` [Bungeeguard](https://www.spigotmc.org/resources/bungeeguard.79601/) forwarding.

## Spigot

Spigot is not well-tested with Gate.
However, it is based on vanilla and as it is the base for Paper, it is relatively well-supported.

Spigot does not support Gate/Velocity modern forwarding, but does support legacy BungeeCord forwarding.
Spigot does not support Gate/Velocity modern forwarding, but does support legacy BungeeCord forwarding and the more secure Bungeeguard forwarding when using the [Bungeeguard](https://www.spigotmc.org/resources/bungeeguard.79601/) plugin.

## Forks of Spigot/Paper

Expand Down
4 changes: 3 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ config:
# This allows you to customize how player information such as IPs and UUIDs are forwarded to your server.
# See the documentation for more information.
forwarding:
# Options: legacy, none, velocity
# Options: legacy, none, bungeeguard, velocity
mode: legacy
# The secret used if the mode is velocity.
#velocitySecret: secret_here
# The secret used if the mode is bungeeguard.
#bungeeGuardSecret: secret_here
# Proxy protocol (HA-Proxy) determines whether Gate should support proxy protocol for players.
# Do not enable this if you don't know what it is.
proxyProtocol: false
Expand Down
20 changes: 19 additions & 1 deletion pkg/edition/java/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"go.minekube.com/gate/pkg/edition/java/forge/modernforge"
"go.minekube.com/gate/pkg/edition/java/profile"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -495,7 +496,24 @@ func (s *serverConnection) createLegacyForwardingAddress() string {
}

func (s *serverConnection) createBungeeGuardForwardingAddress(secret string) string {
// TODO see https://github.com/PaperMC/Velocity/blob/e60e2063a87c8904b5ad89680aa51698b1ef8a0c/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java#L154
// Bungeeguard IP forwading is the same as the legacy Bungeecord IP forwarding but with an additional
// property in the profile properties that contains the bungeeguard-token.
playerIP := netutil.Host(s.player.RemoteAddr())
b := new(strings.Builder)
b.WriteString(s.server.ServerInfo().Addr().String())
const sep = "\000"
b.WriteString(sep)
b.WriteString(playerIP)
b.WriteString(sep)
b.WriteString(s.player.profile.ID.Undashed())
b.WriteString(sep)
props, err := json.Marshal(
append(s.player.profile.Properties, profile.Property{Name: "bungeeguard-token", Value: secret}))
if err != nil { // should never happen
panic(err)
}
b.WriteString(string(props)) // first convert props to string
return b.String()
}

// Returns the active backend server connection or false if inactive.
Expand Down
4 changes: 0 additions & 4 deletions pkg/edition/java/proxy/session_client_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func (a *authSessionHandler) Activated() {
// Some connection types may need to alter the game profile.
gameProfile := *a.inbound.delegate.Type().AddGameProfileTokensIfRequired(
a.profile, a.config().Forwarding.Mode)

if a.config().Forwarding.Mode == config.BungeeGuardForwardingMode {
gameProfile.Properties = append(gameProfile.Properties, profile.Property{Name: "bungeeguard-token", Value: a.config().Forwarding.BungeeGuardSecret})
}
profileRequest := NewGameProfileRequestEvent(a.inbound, gameProfile, a.onlineMode)
a.eventMgr.Fire(profileRequest)
conn := a.inbound.delegate.MinecraftConn
Expand Down

0 comments on commit 9981869

Please sign in to comment.