forked from layeh/gumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textmessage.go
45 lines (42 loc) · 1.08 KB
/
textmessage.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 gumble
import (
"github.com/bmmcginty/gumble/gumble/MumbleProto"
)
// TextMessage is a chat message that can be received from and sent to the
// server.
type TextMessage struct {
// User who sent the message (can be nil).
Sender *User
// Users that receive the message.
Users []*User
// Channels that receive the message.
Channels []*Channel
// Channels that receive the message and send it recursively to sub-channels.
Trees []*Channel
// Chat message.
Message string
}
func (t *TextMessage) writeMessage(client *Client) error {
packet := MumbleProto.TextMessage{
Message: &t.Message,
}
if t.Users != nil {
packet.Session = make([]uint32, len(t.Users))
for i, user := range t.Users {
packet.Session[i] = user.Session
}
}
if t.Channels != nil {
packet.ChannelId = make([]uint32, len(t.Channels))
for i, channel := range t.Channels {
packet.ChannelId[i] = channel.ID
}
}
if t.Trees != nil {
packet.TreeId = make([]uint32, len(t.Trees))
for i, channel := range t.Trees {
packet.TreeId[i] = channel.ID
}
}
return client.Conn.WriteProto(&packet)
}