forked from acien101/barnard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
142 lines (124 loc) · 3.55 KB
/
client.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
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
package main
import (
"fmt"
"net"
"os"
"github.com/cantudo/barnard/gumble/gumble"
"github.com/cantudo/barnard/gumble/gumbleopenal"
"github.com/cantudo/barnard/gumble/gumbleutil"
)
func (b *Barnard) start() error {
b.Config.Attach(gumbleutil.AutoBitrate)
b.Config.Attach(b)
// Audio
if os.Getenv("ALSOFT_LOGLEVEL") == "" {
os.Setenv("ALSOFT_LOGLEVEL", "0")
}
var err error
_, err = gumble.DialWithDialer(new(net.Dialer), b.Address, b.Config, &b.TLSConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
// os.Exit(1)
return err
}
if stream, err := gumbleopenal.New(b.Client, b.InputDevice, b.OutputDevice); err != nil {
fmt.Printf("Error starting stream\n")
fmt.Fprintf(os.Stderr, "%s\n", err)
return err
} else {
b.Stream = stream
if b.InmediateStart {
b.Stream.StartSource()
}
}
return nil
}
func (b *Barnard) OnConnect(e *gumble.ConnectEvent) {
b.Client = e.Client
// If there is a channel on arguments move it
if b.Channel != "" {
target := e.Client.Self.Channel.Find(b.Channel)
if target != nil {
e.Client.Self.Move(e.Client.Self.Channel.Find(b.Channel))
} else if b.Ui != nil {
b.AddOutputLine(fmt.Sprintf("Could not connect to %s, moving to "+
"default channel %s", b.Channel, e.Client.Self.Channel.Name))
}
}
if b.Ui != nil {
b.Ui.SetActive(uiViewInput)
b.UiTree.Rebuild()
b.Ui.Refresh()
b.UpdateInputStatus(fmt.Sprintf("To: %s", e.Client.Self.Channel.Name))
b.AddOutputLine(fmt.Sprintf("Connected to %s", b.Client.Conn.RemoteAddr()))
if e.WelcomeMessage != nil {
b.AddOutputLine(fmt.Sprintf("Welcome message: %s", esc(*e.WelcomeMessage)))
}
}
}
func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) {
var reason string
switch e.Type {
case gumble.DisconnectError:
reason = "connection error"
}
if b.Ui != nil {
if reason == "" {
b.AddOutputLine("Disconnected")
} else {
b.AddOutputLine("Disconnected: " + reason)
}
b.UiTree.Rebuild()
b.Ui.Refresh()
}
}
func (b *Barnard) OnTextMessage(e *gumble.TextMessageEvent) {
b.AddOutputMessage(e.Sender, e.Message)
}
func (b *Barnard) OnUserChange(e *gumble.UserChangeEvent) {
if e.Type.Has(gumble.UserChangeChannel) && e.User == b.Client.Self {
b.UpdateInputStatus(fmt.Sprintf("To: %s", e.User.Channel.Name))
}
b.UiTree.Rebuild()
b.Ui.Refresh()
}
func (b *Barnard) OnChannelChange(e *gumble.ChannelChangeEvent) {
b.UiTree.Rebuild()
b.Ui.Refresh()
}
func (b *Barnard) OnPermissionDenied(e *gumble.PermissionDeniedEvent) {
var info string
switch e.Type {
case gumble.PermissionDeniedOther:
info = e.String
case gumble.PermissionDeniedPermission:
info = "insufficient permissions"
case gumble.PermissionDeniedSuperUser:
info = "cannot modify SuperUser"
case gumble.PermissionDeniedInvalidChannelName:
info = "invalid channel name"
case gumble.PermissionDeniedTextTooLong:
info = "text too long"
case gumble.PermissionDeniedTemporaryChannel:
info = "temporary channel"
case gumble.PermissionDeniedMissingCertificate:
info = "missing certificate"
case gumble.PermissionDeniedInvalidUserName:
info = "invalid user name"
case gumble.PermissionDeniedChannelFull:
info = "channel full"
case gumble.PermissionDeniedNestingLimit:
info = "nesting limit"
}
b.AddOutputLine(fmt.Sprintf("Permission denied: %s", info))
}
func (b *Barnard) OnUserList(e *gumble.UserListEvent) {
}
func (b *Barnard) OnACL(e *gumble.ACLEvent) {
}
func (b *Barnard) OnBanList(e *gumble.BanListEvent) {
}
func (b *Barnard) OnContextActionChange(e *gumble.ContextActionChangeEvent) {
}
func (b *Barnard) OnServerConfig(e *gumble.ServerConfigEvent) {
}