-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpg.go
45 lines (32 loc) · 925 Bytes
/
rpg.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
package main
import (
"github.com/jdaiv/px-server/rpg"
)
func handleGameAction(source *Client, data []byte) (interface{}, error) {
if !source.Authenticated {
return nil, ErrorUnauthenticated
}
var msg rpg.IncomingMessageData
if err := parseIncoming(data, &msg); err != nil {
return nil, err
}
if legal, ok := rpg.PlayerIncomingActions[msg.Type]; !legal || !ok {
return nil, nil
}
game.Incoming <- rpg.IncomingMessage{PlayerId: source.User.Id, Data: msg}
return nil, nil
}
func handleGameEditAction(source *Client, data []byte) (interface{}, error) {
if !source.Authenticated || !source.User.SuperUser {
return nil, ErrorUnauthenticated
}
var msg rpg.IncomingMessageData
if err := parseIncoming(data, &msg); err != nil {
return nil, err
}
if msg.Type != rpg.ACTION_EDIT {
return nil, nil
}
game.Incoming <- rpg.IncomingMessage{PlayerId: source.User.Id, Data: msg}
return nil, nil
}