-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (62 loc) · 1.96 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"os"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/internal/hosting"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/bossbar"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/core"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/fallback"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/motd"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/permissions"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/resourcepack"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/tab"
"github.com/Community-Sourced-Minecraft/Gate-Proxy/plugins/whitelist"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"go.minekube.com/gate/cmd/gate"
"go.minekube.com/gate/pkg/edition/java/proxy"
)
type PluginCreator = func(h *hosting.Hosting) (proxy.Plugin, error)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
if os.Getenv("LOG_FORMAT") != "json" {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
if os.Getenv("LOG_LEVEL") != "" {
lvl, err := zerolog.ParseLevel(os.Getenv("LOG_LEVEL"))
if err != nil {
log.Fatal().Err(err).Msg("Failed to parse log level")
}
log.Logger = log.Level(lvl)
}
h, err := hosting.Init()
if err != nil {
log.Fatal().Err(err).Msg("Failed to initialize hosting")
}
perms, err := permissions.NewKVPermissions(context.Background(), h)
if err != nil {
log.Fatal().Err(err).Msg("Failed to initialize permissions")
}
var plugins = []PluginCreator{
core.New,
fallback.New,
func(_ *hosting.Hosting) (proxy.Plugin, error) {
return permissions.New(perms)
},
func(h *hosting.Hosting) (proxy.Plugin, error) {
return whitelist.New(h, perms)
},
motd.New,
tab.New,
bossbar.New,
resourcepack.New,
}
for _, create := range plugins {
p, err := create(h)
if err != nil {
log.Fatal().Err(err).Msg("Failed to create plugin")
}
proxy.Plugins = append(proxy.Plugins, p)
}
gate.Execute()
}