blob: 260e120152fed76bfe647329776340120003439e (
plain) (
blame)
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
|
package gamecoordinator
import (
"bytes"
. "github.com/Philipp15b/go-steam/protocol"
. "github.com/Philipp15b/go-steam/protocol/protobuf"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
"github.com/golang/protobuf/proto"
)
// An incoming, partially unread message from the Game Coordinator.
type GCPacket struct {
AppId uint32
MsgType uint32
IsProto bool
GCName string
Body []byte
TargetJobId JobId
}
func NewGCPacket(wrapper *CMsgGCClient) (*GCPacket, error) {
packet := &GCPacket{
AppId: wrapper.GetAppid(),
MsgType: wrapper.GetMsgtype(),
GCName: wrapper.GetGcname(),
}
r := bytes.NewReader(wrapper.GetPayload())
if IsProto(wrapper.GetMsgtype()) {
packet.MsgType = packet.MsgType & EMsgMask
packet.IsProto = true
header := NewMsgGCHdrProtoBuf()
err := header.Deserialize(r)
if err != nil {
return nil, err
}
packet.TargetJobId = JobId(header.Proto.GetJobidTarget())
} else {
header := NewMsgGCHdr()
err := header.Deserialize(r)
if err != nil {
return nil, err
}
packet.TargetJobId = JobId(header.TargetJobID)
}
body := make([]byte, r.Len())
r.Read(body)
packet.Body = body
return packet, nil
}
func (g *GCPacket) ReadProtoMsg(body proto.Message) {
proto.Unmarshal(g.Body, body)
}
func (g *GCPacket) ReadMsg(body MessageBody) {
body.Deserialize(bytes.NewReader(g.Body))
}
|