Update go dependencies to latest version
This commit is contained in:
@@ -17,14 +17,14 @@ import (
|
||||
"go.minekube.com/gate/cmd/gate"
|
||||
"go.minekube.com/gate/pkg/command"
|
||||
"go.minekube.com/gate/pkg/edition/java/proxy"
|
||||
"go.minekube.com/gate/pkg/runtime/event"
|
||||
"github.com/robinbraemer/event"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Add our "plug-in" to be initialized on Gate start.
|
||||
proxy.Plugins = append(proxy.Plugins, proxy.Plugin{
|
||||
Name: "FenceProxy",
|
||||
Init: func(proxy *proxy.Proxy) error {
|
||||
Init: func(ctx context.Context, proxy *proxy.Proxy) error {
|
||||
return newFenceProxy(proxy).init()
|
||||
},
|
||||
})
|
||||
@@ -171,16 +171,31 @@ func (p *FenceProxy) registerCommands() {
|
||||
var ctx = context.Background()
|
||||
var localPlayers int64 = 0
|
||||
|
||||
// Register event subscribers
|
||||
func (p *FenceProxy) registerSubscribers() error {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
|
||||
func getRedis() *redis.Client {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: getEnv("REDIS_ADDR", "localhost:6379"),
|
||||
Password: "", // no password set
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
return rdb
|
||||
}
|
||||
|
||||
p.Event().Subscribe(&proxy.PingEvent{}, 0, func(ev event.Event) {
|
||||
e := ev.(*proxy.PingEvent)
|
||||
func pingHandler() func(p *proxy.PingEvent) {
|
||||
motd := &Text{Content: "Simple Proxy!\nJoin and test me."}
|
||||
return func(e *proxy.PingEvent) {
|
||||
p := e.Ping()
|
||||
p.Description = motd
|
||||
p.Players.Max = p.Players.Online + 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Register event subscribers
|
||||
func (p *FenceProxy) registerSubscribers() error {
|
||||
rdb := getRedis()
|
||||
|
||||
event.Subscribe(p.Event(), 0, func(e *proxy.PingEvent) {
|
||||
p := e.Ping()
|
||||
val, err := rdb.Get(ctx, "players").Result()
|
||||
if err == redis.Nil {
|
||||
@@ -192,25 +207,25 @@ func (p *FenceProxy) registerSubscribers() error {
|
||||
p.Players.Online, _ = strconv.Atoi(val)
|
||||
p.Players.Max = p.Players.Online + 1
|
||||
})
|
||||
p.Event().Subscribe(&proxy.LoginEvent{}, 0, func(ev event.Event) {
|
||||
//p.Event().Subscribe(&proxy.LoginEvent{}, 0, func(ev event.Event) {
|
||||
//e := ev.(*proxy.LoginEvent)
|
||||
//e.Deny(&Text{Content: "&cMaintenance mode"})
|
||||
})
|
||||
p.Event().Subscribe(&proxy.PlayerChooseInitialServerEvent{}, 0, func(ev event.Event) {
|
||||
e := ev.(*proxy.PlayerChooseInitialServerEvent)
|
||||
//})
|
||||
event.Subscribe(p.Event(), 0, func(e *proxy.PlayerChooseInitialServerEvent) {
|
||||
e.SetInitialServer(p.Servers()[0])
|
||||
localPlayers += 1
|
||||
rdb.Incr(ctx, "players")
|
||||
})
|
||||
|
||||
p.Event().Subscribe(&proxy.DisconnectEvent{}, 0, func(ev event.Event) {
|
||||
event.Subscribe(p.Event(), 0, func(e *proxy.DisconnectEvent) {
|
||||
localPlayers -= 1
|
||||
rdb.Decr(ctx, "players")
|
||||
})
|
||||
|
||||
p.Event().Subscribe(&proxy.ShutdownEvent{}, 0, func(ev event.Event) {
|
||||
rdb.DecrBy(ctx, "players", localPlayers)
|
||||
})
|
||||
event.Subscribe(p.Event(), 0, func(e *proxy.ShutdownEvent) {
|
||||
rdb.DecrBy(ctx, "players", localPlayers)
|
||||
})
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user