-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca6186d
commit 2dbc981
Showing
7 changed files
with
1,377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
editions: | ||
# Java Minecraft edition is the first popular edition for desktops. | ||
java: | ||
enabled: true | ||
config: | ||
# The bind address to listen for Minecraft client connections. | ||
bind: 0.0.0.0:25565 | ||
# Whether to use the proxy in online (authenticate players with Mojang API) or offline mode (not recommended). | ||
onlineMode: true | ||
# Registers servers with the proxy by giving the address of backend server a custom reference name. | ||
servers: | ||
# Server name: server address | ||
lobby: localhost:25566 | ||
# The list of servers to try (ordered) to connect a player to | ||
# upon login or fallback when a player is kicked from a server. | ||
try: | ||
- lobby | ||
# Configure the response for server list pings. | ||
status: | ||
# The message of the day in legacy '§' format or modern text component '{"text":"...", ...}' json. | ||
motd: | | ||
§bA Gate Proxy | ||
§bVisit ➞ §fgithub.com/minekube/gate | ||
# The maximum players shown (is not the actual player limit!). | ||
showMaxPlayers: 1000 | ||
# The server image (optimal 64x64); a path of an image file or the base64 data uri. | ||
favicon: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEA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ACwEcUYR/RwB/4mTOAgBw43nvR6okSJoj61uyz7RV3T/Pu7uAp2ytln2LrDapiyWudUoLZK2XfbgnnAEo7bb9sKwzC6tfjyy+Um81EMAMST+XdXxeawAAzwM4EcB2AMcDuBXAgn8T8kjhgpUA+ic1CeaFMN89kNudfBGlU2V9UPZcWQ1JeyU9RvInTmk3xdmSWpSeQAC2Hpd9nqxPyjpKsmTtJLlByS+KfFqSKW4OZHAlgcBuAJdTugTAoUWcOwDsLcJ6GMAyAMsLUWYCGAWwragLGwtnYNIOAICbLz4DKe0/0R13+hI8fv+jDVlJ0miWZUOykZLHT3sUQRAUUa3X8OGrvotf3bqyRYlOaSCyLJvoIjIPpd5uoG/uO/DcMzu743i1iHOsk3U6BMffPnXPbEUdyCJigOTL3htM6jD0Sr53+VmQ07gQ432aQiBQq9cAomhdQgBo9bQg7x+eim6AyDJUm00gAikRlLCvswc9noZqT6uozvGyELvvRI5ddhUeufM7ebcgX/k+BXwNCy8pKSkpKSkpKSkpKSkpKSkpKSkpKXkz8k8RHxEbZN/8lgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMC0wOC0wOVQxMDoxMTo0MyswMDowMN6nNEYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjAtMDgtMDlUMTA6MTE6NDMrMDA6MDCv+oz6AAAAAElFTkSuQmCC | ||
# Whether to log ping requests in the console. | ||
logPingRequests: false | ||
# Whether the proxy should present itself as Forge/FML-compatible server. | ||
announceForge: false | ||
# Whether the proxy should support bungee plugin channels. | ||
# (Disable this if your backend servers are untrusted.) | ||
bungeePluginChannelEnabled: true | ||
# Whether to register builtin commands on proxy start. | ||
# Default: true | ||
builtinCommands: true | ||
# Whether players require permissions to | ||
# execute a builtin proxy command like /server. | ||
# Ignore this if `builtinCommands` is set to false. | ||
# (This should be set to true in production environments.) | ||
# Default: false | ||
requireBuiltinCommandPermissions: false | ||
# Declares the proxy commands to 1.13+ clients. | ||
# Default: true | ||
announceProxyCommands: true | ||
# Should the proxy enforce the new public key | ||
# security standard added in Minecraft 1.19? | ||
# Default: true | ||
forceKeyAuthentication: false | ||
# The default disconnect reason to kick player on proxy shutdown when no other reason was given. | ||
# Either in simple legacy '§' format or modern text component '{"text":"...", ...}' json. | ||
shutdownReason: | | ||
§cGate proxy is shutting down... | ||
Please reconnect in a moment! | ||
# Packet compression settings. | ||
compression: | ||
# The minimum size (in bytes) a packet must be before the proxy compresses it. | ||
# The Minecraft vanilla server uses 256 by default. | ||
threshold: 256 | ||
# Indicates what zlib compression level Gate should use. | ||
# It goes from -1 to 9 where zero means no compression and -1 the default. | ||
level: -1 | ||
# The time in milliseconds Gate waits to connect to a server before timing out. | ||
connectionTimeout: 5000 | ||
# The time in milliseconds Gate waits to receive data from a server before timing out. | ||
# If you use Forge, you may need to increase this setting. | ||
readTimeout: 30000 | ||
# Whether to reconnect the player when disconnected from a server. | ||
failoverOnUnexpectedServerDisconnect: true | ||
# Enabled extra debug logging (only for debugging purposes). | ||
debug: false | ||
# 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 | ||
mode: velocity | ||
# The secret used if the mode is velocity. | ||
velocitySecret: test | ||
# 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 | ||
# The quota settings allows rate-limiting IP (last block cut off) for certain operations. | ||
# ops: The allowed operations per second. | ||
# burst: The maximum operations per second (queue like). One burst unit per seconds is refilled. | ||
# maxEntries: The maximum IPs to keep track of in cache for rate-limiting (if full, deletes oldest). | ||
quota: | ||
# Limit how many new connections can be established by the same IP range. | ||
connections: | ||
enabled: true | ||
ops: 5 | ||
burst: 10 | ||
maxEntries: 1000 | ||
# Limit how many login requests can be made by the same IP range. | ||
logins: | ||
enabled: true | ||
burst: 3 | ||
ops: 0.4 | ||
maxEntries: 1000 | ||
# Whether and how Gate should reply to GameSpy 4 (Minecraft query protocol on UDP) requests. | ||
query: | ||
enabled: false | ||
port: 25577 | ||
showPlugins: false | ||
bedrock: | ||
# Bedrock edition is not yet supported! | ||
enabled: false | ||
|
||
# Configuration for Connect, a network that organizes all Minecraft servers/proxies | ||
# and makes them universally accessible for all players. | ||
# Among a lot of other features it even allows players to join locally hosted | ||
# Minecraft servers without having an open port or public IP address. | ||
# | ||
# Visit https://developers.minekube.com/connect | ||
connect: | ||
# Enabling Connect makes Gate register itself to Connect network. | ||
# This feature is disabled by default, but you are encouraged to | ||
# enable it and get empowered by the additional network services | ||
# and by the growing community in this ecosystem. | ||
enabled: false | ||
# The endpoint name is a globally unique identifier of your server. | ||
# If Connect is enabled, but no name is specified a random name is | ||
# generated on every restart (only recommended for testing). | ||
# | ||
# It is supported to run multiple Gates on the same endpoint name for load balancing | ||
# (use the same connect.json token file from first Gate instance). | ||
#name: your-endpoint-name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package game | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"go.minekube.com/common/minecraft/color" | ||
"go.minekube.com/gate/pkg/edition/java/proxy" | ||
"go.minekube.com/gate/pkg/util/netutil" | ||
"go.minekube.com/gate/pkg/util/uuid" | ||
"log" | ||
"simple-proxy/redisdb" | ||
"strings" | ||
|
||
. "go.minekube.com/common/minecraft/component" | ||
|
||
"time" | ||
) | ||
|
||
var ( | ||
ctx = context.Background() | ||
GameMap = make(map[string]string) | ||
) | ||
|
||
func RegisterPubSub(p *proxy.Proxy) { | ||
pubsub := redisdb.RedisClient.Subscribe(ctx, "registergame") | ||
ch := pubsub.Channel() | ||
|
||
go func() { | ||
for msg := range ch { | ||
fmt.Println(msg.Channel, msg.Payload) | ||
|
||
registerGame(p, msg.Payload) | ||
} | ||
}() | ||
|
||
result := redisdb.RedisClient.Publish(ctx, "proxyhello", "") | ||
if result.Err() != nil { | ||
log.Fatal("Redis failed to connect. Stopping...") | ||
} | ||
} | ||
|
||
func registerGame(p *proxy.Proxy, payload string) { | ||
// this is horrible, but I can't think of a better way :D | ||
localAddr := strings.Split(p.Servers()[0].ServerInfo().Addr().String(), ":")[0] | ||
|
||
args := strings.Fields(payload) | ||
gameName := strings.ToLower(args[0]) | ||
serverName := strings.ToLower(args[1]) | ||
port := args[2] | ||
|
||
addr, _ := netutil.Parse(localAddr+":"+port, "tcp") | ||
info := proxy.NewServerInfo(serverName, addr) | ||
|
||
log.Printf("Registered game:%s server:%s port:%s", gameName, serverName, port) | ||
|
||
GameMap[gameName] = serverName | ||
|
||
// TODO: reconnect players in limbo | ||
|
||
p.Register(info) | ||
} | ||
|
||
func SendToServer(p *proxy.Proxy, player proxy.Player, serverName string, game string, spectate bool, playerToSpectate uuid.UUID) { | ||
current := player.CurrentServer() | ||
if current == nil { | ||
log.Println("Not in a server") | ||
player.SendMessage(&Text{ | ||
Extra: []Component{ | ||
&Text{ | ||
Content: "Not in a server", | ||
S: Style{Color: color.Red, Bold: True}, | ||
}, | ||
}, | ||
}) | ||
return | ||
} | ||
|
||
go player.SendActionBar(&Text{ | ||
Extra: []Component{ | ||
&Text{ | ||
Content: fmt.Sprintf("Joining %s!", game), | ||
S: Style{Color: color.Green}, | ||
}, | ||
}, | ||
}) | ||
|
||
if current.Server().ServerInfo().Name() == serverName { | ||
if spectate { | ||
go redisdb.RedisClient.Publish(ctx, "playerpubsub"+serverName, fmt.Sprintf("spectateplayer %s %s", player.ID(), playerToSpectate)) | ||
} else { | ||
go redisdb.RedisClient.Publish(ctx, "playerpubsub"+serverName, fmt.Sprintf("changegame %s %s", player.ID(), game)) | ||
} | ||
return | ||
} | ||
|
||
server := p.Server(serverName) | ||
if server == nil { | ||
log.Printf("Couldn't find %s", serverName) | ||
go player.SendMessage(&Text{ | ||
Extra: []Component{ | ||
&Text{ | ||
Content: fmt.Sprintf("Couldn't find %s", serverName), | ||
S: Style{Color: color.Red, Bold: True}, | ||
}, | ||
}, | ||
}) | ||
return | ||
} | ||
|
||
res := redisdb.RedisClient.SetEX(ctx, fmt.Sprintf("%s-subgame", player.ID()), fmt.Sprintf("%s %s %s", game, spectate, playerToSpectate), time.Second*10) | ||
if res.Err() != nil { | ||
log.Println("Failed to set subgame") | ||
go player.SendMessage(&Text{ | ||
Extra: []Component{ | ||
&Text{ | ||
Content: "Failed to join game", | ||
S: Style{Color: color.Red}, | ||
}, | ||
}, | ||
}) | ||
return | ||
} | ||
|
||
_, err := player.CreateConnectionRequest(server).Connect(ctx) | ||
if err != nil { | ||
log.Printf("Failed to join game. %s", err.Error()) | ||
go player.SendMessage(&Text{ | ||
Extra: []Component{ | ||
&Text{ | ||
Content: fmt.Sprintf("Failed to join game! Error: %s", err.Error()), | ||
S: Style{Color: color.Red}, | ||
}, | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module simple-proxy | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/robinbraemer/event v0.0.1 | ||
go.minekube.com/brigodier v0.0.1 | ||
go.minekube.com/common v0.0.5 | ||
go.minekube.com/gate v0.21.5 | ||
) | ||
|
||
require ( | ||
github.com/agext/levenshtein v1.2.3 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/dboslee/lru v0.0.1 // indirect | ||
github.com/df-mc/atomic v1.10.0 // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/emirpasic/gods v1.18.1 // indirect | ||
github.com/francoispqt/gojay v1.2.13 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gammazero/deque v0.2.1 // indirect | ||
github.com/go-gl/mathgl v1.0.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/zapr v1.2.3 // indirect | ||
github.com/go-redis/redis/v8 v8.11.5 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/klauspost/compress v1.15.12 // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect | ||
github.com/pires/go-proxyproto v0.6.2 // indirect | ||
github.com/rs/xid v1.4.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/sandertv/go-raknet v1.12.0 // indirect | ||
github.com/sandertv/gophertunnel v1.26.0 // indirect | ||
github.com/spf13/afero v1.9.3 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.14.0 // indirect | ||
github.com/subosito/gotenv v1.4.1 // indirect | ||
github.com/urfave/cli/v2 v2.23.5 // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
go.minekube.com/connect v0.5.1 // indirect | ||
go.uber.org/atomic v1.10.0 // indirect | ||
go.uber.org/multierr v1.8.0 // indirect | ||
go.uber.org/zap v1.23.0 // indirect | ||
golang.org/x/image v0.1.0 // indirect | ||
golang.org/x/net v0.2.0 // indirect | ||
golang.org/x/sys v0.2.0 // indirect | ||
golang.org/x/text v0.4.0 // indirect | ||
golang.org/x/time v0.2.0 // indirect | ||
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect | ||
google.golang.org/grpc v1.51.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
nhooyr.io/websocket v1.8.7 // indirect | ||
) |
Oops, something went wrong.