]> git.0d.be Git - barnard.git/blob - cmd/barnard/main.go
8b2a331cdd8eef6a4d95ddd8e30679bd3dd25d79
[barnard.git] / cmd / barnard / main.go
1 package main
2
3 import (
4         "crypto/tls"
5         "flag"
6         "fmt"
7         "os"
8
9         "github.com/layeh/barnard"
10         "github.com/layeh/barnard/uiterm"
11         "github.com/layeh/gumble/gumble"
12         "github.com/layeh/gumble/gumbleutil"
13         "github.com/layeh/gumble/gumble_openal"
14 )
15
16 func main() {
17         // Command line flags
18         server := flag.String("server", "localhost:64738", "the server to connect to")
19         username := flag.String("username", "", "the username of the client")
20         insecure := flag.Bool("insecure", false, "skip server certificate verification")
21         certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
22
23         flag.Parse()
24
25         // Initialize
26         b := barnard.Barnard{}
27         b.Ui = uiterm.New(&b)
28
29         // Gumble
30         b.Config = gumble.NewConfig()
31         b.Config.Username = *username
32         b.Config.Address = *server
33         if *insecure {
34                 b.Config.TLSConfig.InsecureSkipVerify = true
35         }
36         if *certificate != "" {
37                 if cert, err := tls.LoadX509KeyPair(*certificate, *certificate); err != nil {
38                         fmt.Fprintf(os.Stderr, "%s\n", err)
39                         os.Exit(1)
40                 } else {
41                         b.Config.TLSConfig.Certificates = []tls.Certificate{cert}
42                 }
43         }
44
45         b.Client = gumble.NewClient(b.Config)
46         b.Client.Attach(gumbleutil.AutoBitrate)
47         b.Client.Attach(&b)
48         // Audio
49         if os.Getenv("ALSOFT_LOGLEVEL") == "" {
50                 os.Setenv("ALSOFT_LOGLEVEL", "0")
51         }
52         if stream, err := gumble_openal.New(b.Client); err != nil {
53                 fmt.Fprintf(os.Stderr, "%s\n", err)
54                 os.Exit(1)
55         } else {
56                 b.Stream = stream
57         }
58
59         if err := b.Client.Connect(); err != nil {
60                 fmt.Fprintf(os.Stderr, "%s\n", err)
61                 os.Exit(1)
62         }
63
64         b.Ui.Run()
65 }