forked from mumble-voip/grumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel.go
85 lines (69 loc) · 1.79 KB
/
channel.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
83
84
85
// Copyright (c) 2010 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.
package main
import (
"encoding/hex"
)
// A Mumble channel
type Channel struct {
Id int
Name string
Temporary bool
Position int
clients map[uint32]*Client
parent *Channel
children map[int]*Channel
// ACL
ACL []*ChannelACL
InheritACL bool
// Groups
Groups map[string]*Group
// Links
Links map[int]*Channel
// Blobs
DescriptionBlob string
}
func NewChannel(id int, name string) (channel *Channel) {
channel = new(Channel)
channel.Id = id
channel.Name = name
channel.clients = make(map[uint32]*Client)
channel.children = make(map[int]*Channel)
channel.ACL = []*ChannelACL{}
channel.Groups = map[string]*Group{}
return
}
// Add a child channel to a channel
func (channel *Channel) AddChild(child *Channel) {
child.parent = channel
channel.children[child.Id] = child
}
// Remove a child channel from a parent
func (channel *Channel) RemoveChild(child *Channel) {
child.parent = nil
channel.children[child.Id] = nil, false
}
// Add client
func (channel *Channel) AddClient(client *Client) {
channel.clients[client.Session] = client
client.Channel = channel
}
// Remove client
func (channel *Channel) RemoveClient(client *Client) {
channel.clients[client.Session] = nil, false
client.Channel = nil
}
// Does the channel have a description?
func (channel *Channel) HasDescription() bool {
return len(channel.DescriptionBlob) > 0
}
// Get the channel's blob hash as a byte slice for sending via a protobuf message.
// Returns nil if there is no blob.
func (channel *Channel) DescriptionBlobHashBytes() (buf []byte) {
buf, err := hex.DecodeString(channel.DescriptionBlob)
if err != nil {
return nil
}
return buf
}