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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
package protocol
import (
"github.com/golang/protobuf/proto"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
. "github.com/Philipp15b/go-steam/steamid"
"io"
)
// Interface for all messages, typically outgoing. They can also be created by
// using the Read* methods in a PacketMsg.
type IMsg interface {
Serializer
IsProto() bool
GetMsgType() EMsg
GetTargetJobId() JobId
SetTargetJobId(JobId)
GetSourceJobId() JobId
SetSourceJobId(JobId)
}
// Interface for client messages, i.e. messages that are sent after logging in.
// ClientMsgProtobuf and ClientMsg implement this.
type IClientMsg interface {
IMsg
GetSessionId() int32
SetSessionId(int32)
GetSteamId() SteamId
SetSteamId(SteamId)
}
// Represents a protobuf backed client message with session data.
type ClientMsgProtobuf struct {
Header *MsgHdrProtoBuf
Body proto.Message
}
func NewClientMsgProtobuf(eMsg EMsg, body proto.Message) *ClientMsgProtobuf {
hdr := NewMsgHdrProtoBuf()
hdr.Msg = eMsg
return &ClientMsgProtobuf{
Header: hdr,
Body: body,
}
}
func (c *ClientMsgProtobuf) IsProto() bool {
return true
}
func (c *ClientMsgProtobuf) GetMsgType() EMsg {
return NewEMsg(uint32(c.Header.Msg))
}
func (c *ClientMsgProtobuf) GetSessionId() int32 {
return c.Header.Proto.GetClientSessionid()
}
func (c *ClientMsgProtobuf) SetSessionId(session int32) {
c.Header.Proto.ClientSessionid = &session
}
func (c *ClientMsgProtobuf) GetSteamId() SteamId {
return SteamId(c.Header.Proto.GetSteamid())
}
func (c *ClientMsgProtobuf) SetSteamId(s SteamId) {
c.Header.Proto.Steamid = proto.Uint64(uint64(s))
}
func (c *ClientMsgProtobuf) GetTargetJobId() JobId {
return JobId(c.Header.Proto.GetJobidTarget())
}
func (c *ClientMsgProtobuf) SetTargetJobId(job JobId) {
c.Header.Proto.JobidTarget = proto.Uint64(uint64(job))
}
func (c *ClientMsgProtobuf) GetSourceJobId() JobId {
return JobId(c.Header.Proto.GetJobidSource())
}
func (c *ClientMsgProtobuf) SetSourceJobId(job JobId) {
c.Header.Proto.JobidSource = proto.Uint64(uint64(job))
}
func (c *ClientMsgProtobuf) Serialize(w io.Writer) error {
err := c.Header.Serialize(w)
if err != nil {
return err
}
body, err := proto.Marshal(c.Body)
if err != nil {
return err
}
_, err = w.Write(body)
return err
}
// Represents a struct backed client message.
type ClientMsg struct {
Header *ExtendedClientMsgHdr
Body MessageBody
Payload []byte
}
func NewClientMsg(body MessageBody, payload []byte) *ClientMsg {
hdr := NewExtendedClientMsgHdr()
hdr.Msg = body.GetEMsg()
return &ClientMsg{
Header: hdr,
Body: body,
Payload: payload,
}
}
func (c *ClientMsg) IsProto() bool {
return true
}
func (c *ClientMsg) GetMsgType() EMsg {
return c.Header.Msg
}
func (c *ClientMsg) GetSessionId() int32 {
return c.Header.SessionID
}
func (c *ClientMsg) SetSessionId(session int32) {
c.Header.SessionID = session
}
func (c *ClientMsg) GetSteamId() SteamId {
return c.Header.SteamID
}
func (c *ClientMsg) SetSteamId(s SteamId) {
c.Header.SteamID = s
}
func (c *ClientMsg) GetTargetJobId() JobId {
return JobId(c.Header.TargetJobID)
}
func (c *ClientMsg) SetTargetJobId(job JobId) {
c.Header.TargetJobID = uint64(job)
}
func (c *ClientMsg) GetSourceJobId() JobId {
return JobId(c.Header.SourceJobID)
}
func (c *ClientMsg) SetSourceJobId(job JobId) {
c.Header.SourceJobID = uint64(job)
}
func (c *ClientMsg) Serialize(w io.Writer) error {
err := c.Header.Serialize(w)
if err != nil {
return err
}
err = c.Body.Serialize(w)
if err != nil {
return err
}
_, err = w.Write(c.Payload)
return err
}
type Msg struct {
Header *MsgHdr
Body MessageBody
Payload []byte
}
func NewMsg(body MessageBody, payload []byte) *Msg {
hdr := NewMsgHdr()
hdr.Msg = body.GetEMsg()
return &Msg{
Header: hdr,
Body: body,
Payload: payload,
}
}
func (m *Msg) GetMsgType() EMsg {
return m.Header.Msg
}
func (m *Msg) IsProto() bool {
return false
}
func (m *Msg) GetTargetJobId() JobId {
return JobId(m.Header.TargetJobID)
}
func (m *Msg) SetTargetJobId(job JobId) {
m.Header.TargetJobID = uint64(job)
}
func (m *Msg) GetSourceJobId() JobId {
return JobId(m.Header.SourceJobID)
}
func (m *Msg) SetSourceJobId(job JobId) {
m.Header.SourceJobID = uint64(job)
}
func (m *Msg) Serialize(w io.Writer) error {
err := m.Header.Serialize(w)
if err != nil {
return err
}
err = m.Body.Serialize(w)
if err != nil {
return err
}
_, err = w.Write(m.Payload)
return err
}
|