forked from paralin/go-dota2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_sender.go
82 lines (70 loc) · 1.91 KB
/
msg_sender.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"strings"
"github.com/fatih/camelcase"
"github.com/paralin/go-dota2/protocol"
)
// MsgSender is the sender type of a message.
type MsgSender uint32
//go:generate stringer -type=MsgSender
const (
MsgSenderNone MsgSender = iota
MsgSenderGC
MsgSenderClient
)
// GetMessageSender determines which party (GC, Client, None) would send this message in a session.
func GetMessageSender(msg protocol.EDOTAGCMsg) MsgSender {
if !IsValidMsg(msg) {
return MsgSenderNone
}
if sender, ok := msgSenderOverrides[msg]; ok {
return sender
}
msgName := msg.String()
msgName = msgName[6:]
if strings.HasPrefix(msgName, "DOTA") {
msgName = msgName[4:]
}
switch {
case strings.HasPrefix(msgName, "SQL"):
return MsgSenderNone
case strings.Contains(msgName, "ClientToGC"):
if strings.HasSuffix(msgName, "Response") {
return MsgSenderGC
}
return MsgSenderClient
case strings.Contains(msgName, "GCResponseTo"):
return MsgSenderNone
case strings.Contains(msgName, "GCRequestTo"):
return MsgSenderNone
case strings.Contains(msgName, "GCToGC"):
return MsgSenderNone
case strings.HasPrefix(msgName, "Server"):
return MsgSenderNone
case strings.HasPrefix(msgName, "Gameserver"):
return MsgSenderNone
case strings.Contains(msgName, "ServerToGC"):
return MsgSenderNone
case strings.Contains(msgName, "GCToServer"):
return MsgSenderNone
case strings.Contains(msgName, "GC_GameServer"):
return MsgSenderNone
case strings.Contains(msgName, "GCToClient"):
return MsgSenderGC
case strings.Contains(msgName, "SignOut"):
return MsgSenderNone
case strings.HasSuffix(msgName, "Request"):
return MsgSenderClient
case strings.HasSuffix(msgName, "Response"):
return MsgSenderGC
case strings.HasPrefix(msgName, "GC"):
words := camelcase.Split(msgName[2:])
for _, w := range words {
if IsWordVerb(w) {
return MsgSenderClient
}
}
return MsgSenderGC
}
return MsgSenderClient
}