-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (36 loc) · 890 Bytes
/
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
package main
import (
"github.com/bedrock-gophers/tebex/tebex"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/player/chat"
"log/slog"
"os"
"time"
)
func main() {
chat.Global.Subscribe(chat.StdoutSubscriber{})
logger := slog.Default()
conf, err := server.DefaultConfig().Config(logger)
if err != nil {
panic(err)
}
srv := conf.New()
srv.CloseOnProgramEnd()
store := loadStore(os.Getenv("TEBEX_KEY"), logger)
srv.Listen()
for p := range srv.Accept() {
store.ExecuteCommands(p)
}
}
// loadStore initializes the Tebex store connection.
func loadStore(key string, log *slog.Logger) *tebex.Client {
store := tebex.NewClient(log, time.Second*5, key)
name, domain, err := store.Information()
if err != nil {
log.Error("tebex: %v", err)
os.Exit(1)
return nil
}
log.Info("Connected to Tebex under %v (%v).", name, domain)
return store
}