]> git.0d.be Git - barnard.git/blob - main.go
remove UI stuff, turn into CLI
[barnard.git] / main.go
1 package main
2
3 import (
4         "crypto/tls"
5         "flag"
6         "fmt"
7         "os"
8
9         "layeh.com/gumble/gumble"
10         "layeh.com/gumble/gumbleutil"
11         _ "layeh.com/gumble/opus"
12 )
13
14 func main() {
15         // Command line flags
16         server := flag.String("server", "localhost:64738", "the server to connect to")
17         username := flag.String("username", "", "the username of the client")
18         password := flag.String("password", "", "the password of the server")
19         insecure := flag.Bool("insecure", false, "skip server certificate verification")
20         certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
21         channel := flag.String("channel", "", "initial channel")
22
23         flag.Parse()
24
25         // Initialize
26         b := Barnard{
27                 Config:  gumble.NewConfig(),
28                 Address: *server,
29                 DefaultChannel: *channel,
30         }
31
32         b.Config.Username = *username
33         b.Config.Password = *password
34
35         if *insecure {
36                 b.TLSConfig.InsecureSkipVerify = true
37         }
38         if *certificate != "" {
39                 cert, err := tls.LoadX509KeyPair(*certificate, *certificate)
40                 if err != nil {
41                         fmt.Fprintf(os.Stderr, "%s\n", err)
42                         os.Exit(1)
43                 }
44                 b.TLSConfig.Certificates = append(b.TLSConfig.Certificates, cert)
45         }
46
47         keepAlive := make(chan bool)
48
49         b.Config.Attach(gumbleutil.Listener{
50                 Disconnect: func(e *gumble.DisconnectEvent) {
51                         keepAlive <- true
52                 },
53         })
54
55         b.start()
56         <-keepAlive
57 }