-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
76 lines (65 loc) · 1.72 KB
/
main.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
package main
import (
"amongusmumble/socket"
"crypto/tls"
"fmt"
"net"
"os"
"github.com/spf13/viper"
"layeh.com/gumble/gumble"
"layeh.com/gumble/gumbleutil"
)
func main() {
var tlsConfig tls.Config
tlsConfig.InsecureSkipVerify = true
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
if err, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println("Cannot Find Config file")
os.Exit(3)
} else {
fmt.Println("error loading config", err)
}
}
server := viper.GetString("mumbleserver")
listenaddress := viper.GetString("listenaddress")
listenport := viper.GetString("listenport")
config := gumble.NewConfig()
config.Username = viper.GetString("username")
certificateFile := viper.GetString("cert")
keyFile := viper.GetString("key")
if certificateFile != "" {
if keyFile == "" {
keyFile = certificateFile
}
if certificate, err := tls.LoadX509KeyPair(certificateFile, keyFile); err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
os.Exit(1)
} else {
tlsConfig.Certificates = append(tlsConfig.Certificates, certificate)
}
}
keepAlive := make(chan bool)
exitStatus := 0
config.Attach(gumbleutil.Listener{
Disconnect: func(e *gumble.DisconnectEvent) {
if e.Type != gumble.DisconnectUser {
exitStatus = int(e.Type) + 1
}
keepAlive <- true
},
})
client, err := gumble.DialWithDialer(new(net.Dialer), server, config, &tlsConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
if reject, ok := err.(*gumble.RejectError); ok {
os.Exit(100 + int(reject.Type))
}
os.Exit(99)
}
go socket.SocketioServer(client, listenaddress, listenport)
<-keepAlive
os.Exit(exitStatus)
}