forked from HimbeerserverDE/mt-multiserver-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_interact.go
More file actions
52 lines (41 loc) · 1.05 KB
/
plugin_interact.go
File metadata and controls
52 lines (41 loc) · 1.05 KB
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 proxy
import (
"sync"
"github.com/anon55555/mt"
)
// A InteractionHandler holds information on how to handle a Minetest Interaction.
type InteractionHandler struct {
Type Interaction
Handler func(*ClientConn, *mt.ToSrvInteract) bool
}
type Interaction uint8
const (
Dig Interaction = iota
StopDigging
Dug
Place
Use
Activate
AnyInteraction = 255
)
var interactionHandlers []InteractionHandler
var interactionHandlerMu sync.RWMutex
var interactionHandlerOnce sync.Once
// RegisterInteractionHandler adds a new InteractionHandler.
func RegisterInteractionHandler(handler InteractionHandler) {
interactionHandlerMu.Lock()
defer interactionHandlerMu.Unlock()
interactionHandlers = append(interactionHandlers, handler)
}
func handleInteraction(cmd *mt.ToSrvInteract, cc *ClientConn) bool {
handled := false
for _, handler := range interactionHandlers {
interaction := Interaction(handler.Type)
if interaction == AnyInteraction || interaction == handler.Type {
if handler.Handler(cc, cmd) {
handled = true
}
}
}
return handled
}