-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_client_config.go
52 lines (44 loc) · 1.35 KB
/
handler_client_config.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
package kite
import (
"github.com/mworzala/kite/pkg/proto"
"github.com/mworzala/kite/pkg/proto/packet"
)
type ClientConfigHandler[T any] struct {
Player *Player[T]
PlayHandlerFunc func(*Player[T]) proto.Handler
}
func NewClientConfigHandler[T any](p *Player[T]) proto.Handler {
return &ClientConfigHandler[T]{Player: p}
}
func (h *ClientConfigHandler[T]) HandlePacket(pp proto.Packet) (err error) {
switch pp.Id {
case packet.ClientConfigPluginMessageID:
p := new(packet.ClientPluginMessage)
if err = pp.Read(p); err != nil {
return
}
return h.HandlePluginMessage(p)
case packet.ClientConfigFinishConfigurationID:
p := new(packet.ClientConfigFinishConfiguration)
if err = pp.Read(p); err != nil {
return
}
return h.HandleFinishConfiguration(p)
default:
println("unhandled config packet from client", pp.Id)
return proto.Forward
}
}
func (h *ClientConfigHandler[T]) HandlePluginMessage(p *packet.ClientPluginMessage) error {
return proto.Forward
}
func (h *ClientConfigHandler[T]) HandleFinishConfiguration(_ *packet.ClientConfigFinishConfiguration) error {
println("client moving to play")
if h.PlayHandlerFunc != nil {
h.Player.SetState(packet.Play, h.PlayHandlerFunc(h.Player))
} else {
h.Player.SetState(packet.Play, NewClientPlayHandler(h.Player))
}
return proto.Forward
}
var _ proto.Handler = (*ClientConfigHandler[any])(nil)