/
auth_service.go
54 lines (46 loc) · 916 Bytes
/
auth_service.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
/**
* Created: 2019/4/25 0025
* @author: Jason
*/
package common
import (
"github.com/lightning-go/lightning/defs"
"github.com/lightning-go/lightning/example/cluster/msg"
)
func GetAuthorizedData(typ int32, name, key string) []byte {
d := msg.Authorized{
Type: typ,
Name: name,
Key: key,
}
return MarshalDataEx(d)
}
func AuthorizedCallback(conn defs.IConnection, packet defs.IPacket) (bool, int) {
d := &msg.Authorized{}
err := Unmarshal(packet.GetData(), d)
if err != nil {
return false, msg.RESULT_INVALID
}
ok := true
srvType := int(d.Type)
if srvType <= ST_NIL || srvType >= ST_MAX {
conn.Close()
ok = false
} else {
key := getAuthorizedKey(srvType)
if d.Key != key {
conn.Close()
ok = false
}
}
return ok, srvType
}
func getAuthorizedKey(srvType int) string {
switch srvType {
case ST_GATE:
return GateKey
case ST_LOGIC:
return LogicKey
}
return ""
}