-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (52 loc) · 1.22 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
package main
import (
"context"
"fmt"
"github.com/robinbraemer/event"
"go.minekube.com/common/minecraft/color"
"go.minekube.com/common/minecraft/component"
"go.minekube.com/gate/cmd/gate"
"go.minekube.com/gate/pkg/edition/java/proxy"
"mcauth/codes"
)
func main() {
go setupHttpServer()
proxy.Plugins = append(proxy.Plugins, proxy.Plugin{
Name: "MC Auth",
Init: func(ctx context.Context, proxy *proxy.Proxy) error {
event.Subscribe(proxy.Event(), 0, onLogin)
return nil
},
})
gate.Execute()
}
func onLogin(e *proxy.PostLoginEvent) {
code := codes.New(e.Player().ID())
if code == -1 {
e.Player().Disconnect(&component.Text{
Content: "Failed to generate a verification code, try again later",
S: component.Style{
Color: color.Red,
},
})
return
}
e.Player().Disconnect(&component.Text{
Content: "Your one time verification code:\n\n",
Extra: []component.Component{
&component.Text{
Content: fmt.Sprintf("%06d", code),
S: component.Style{
Bold: component.True,
Underlined: component.True,
},
},
&component.Text{
Content: "\n\nThe code will be valid for the next 5 minutes",
S: component.Style{
Color: color.DarkGray,
},
},
},
})
}