-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
43 lines (37 loc) · 930 Bytes
/
option.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
package mcproto
import (
"github.com/Raqbit/mcproto/game"
"github.com/Raqbit/mcproto/packet"
)
// Option is a configuration option for mcproto.
type Option func(conn *connection)
// WithLogger configures the logger for
// mcproto.
func WithLogger(logger Logger) Option {
return func(conn *connection) {
conn.logger = logger
}
}
// WithPackets allows you to add custom
// packets to mcproto's packet registry.
// This will make mcproto automatically parse
// the packet when it is received.
func WithPackets(packets []packet.Packet) Option {
return func(conn *connection) {
for _, pkt := range packets {
conn.registerPacket(pkt)
}
}
}
// WithSide configures the connection side
// of the mcproto Connection.
func WithSide(side Side) Option {
return func(conn *connection) {
conn.side = side
}
}
func WithState(state game.ConnectionState) Option {
return func(conn *connection) {
conn.state = state
}
}