Skip to content

Commit

Permalink
add modern forge
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Feb 3, 2024
1 parent 0e018ae commit 03cad95
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
Expand Down Expand Up @@ -132,8 +130,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs=
github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4=
github.com/pires/go-proxyproto v0.7.1-0.20231012122632-e5b291b295b4 h1:VM7Tse0I0kTEaO/Rk7BPjmDqfiUcpv+RWtiwIY04pgI=
github.com/pires/go-proxyproto v0.7.1-0.20231012122632-e5b291b295b4/go.mod h1:hm9CitpinLa2As6mIQh1AzhxHULm1BCYGUTbNcO6f2Q=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -333,8 +329,6 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
Expand Down
28 changes: 28 additions & 0 deletions pkg/edition/java/forge/modernforge/modern.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package modernforge

import (
"strconv"
"strings"
)

// Token is the token used in the modern forge handshake.
const Token = "FORGE"

// ModernToken aligns the acquisition logic with the internal code of Forge.
func ModernToken(hostName string) string {
natVersion := 0
idx := strings.Index(hostName, "\000")
if idx != -1 {
for _, pt := range strings.Split(hostName, "\000") {
if strings.HasPrefix(pt, Token) {
if len(pt) > len(Token) {
natVersion, _ = strconv.Atoi(pt[len(Token):])
}
}
}
}
if natVersion == 0 {
return "\000" + Token
}
return "\000" + Token + strconv.Itoa(natVersion)
}
4 changes: 4 additions & 0 deletions pkg/edition/java/proxy/phase/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var (
initialBackendPhase: NotStartedLegacyForgeHandshakeBackendPhase,
},
}
ModernForge ConnectionType = &connType{
initialClientPhase: VanillaClientPhase,
initialBackendPhase: VanillaBackendPhase,
}
)

// ConnectionType is a connection type.
Expand Down
3 changes: 3 additions & 0 deletions pkg/edition/java/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"go.minekube.com/gate/pkg/edition/java/forge/modernforge"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -351,6 +352,8 @@ func (s *serverConnection) handshakeAddr(vHost string, player Player) string {
}
if s.player.Type() == phase.LegacyForge {
vHost += forge.HandshakeHostnameToken
} else if s.player.Type() == phase.ModernForge {
vHost = modernforge.ModernToken(vHost)
}
return vHost
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/edition/java/proxy/session_backend_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,3 @@ func disconnectResult(reason component.Component, server RegisteredServer, safe
func (b *backendLoginSessionHandler) config() *config.Config {
return b.configProvider.config()
}

func min(x, y int) int {
if x < y {
return x
}
return y
}
5 changes: 5 additions & 0 deletions pkg/edition/java/proxy/session_client_handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"fmt"
"go.minekube.com/gate/pkg/edition/java/forge/modernforge"
"net"
"strings"
"time"
Expand Down Expand Up @@ -173,6 +174,10 @@ func stateForProtocol(status int) *state.Registry {
}

func handshakeConnectionType(h *packet.Handshake) phase.ConnectionType {
if strings.Contains(h.ServerAddress, modernforge.Token) &&
h.ProtocolVersion >= int(version.Minecraft_1_20_2.Protocol) {
return phase.ModernForge
}
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13).
if h.ProtocolVersion < int(version.Minecraft_1_13.Protocol) &&
strings.HasSuffix(h.ServerAddress, forge.HandshakeHostnameToken) {
Expand Down

0 comments on commit 03cad95

Please sign in to comment.