]> git.0d.be Git - barnard.git/blob - cmd/barnard/main.go
prevent openal errors from breaking UI
[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.Config{
31                 Username: *username,
32                 Address:  *server,
33         }
34         if *insecure {
35                 b.Config.TLSConfig.InsecureSkipVerify = true
36         }
37         if *certificate != "" {
38                 if cert, err := tls.LoadX509KeyPair(*certificate, *certificate); err != nil {
39                         fmt.Fprintf(os.Stderr, "%s\n", err)
40                         os.Exit(1)
41                 } else {
42                         b.Config.TLSConfig.Certificates = []tls.Certificate{cert}
43                 }
44         }
45
46         b.Client = gumble.NewClient(&b.Config)
47         b.Client.Attach(gumbleutil.AutoBitrate)
48         b.Client.Attach(&b)
49         // Audio
50         if os.Getenv("ALSOFT_LOGLEVEL") == "" {
51                 os.Setenv("ALSOFT_LOGLEVEL", "0")
52         }
53         if stream, err := gumble_openal.New(b.Client); err != nil {
54                 fmt.Fprintf(os.Stderr, "%s\n", err)
55                 os.Exit(1)
56         } else {
57                 b.Stream = stream
58         }
59
60         if err := b.Client.Connect(); err != nil {
61                 fmt.Fprintf(os.Stderr, "%s\n", err)
62                 os.Exit(1)
63         }
64
65         b.Ui.Run()
66 }