diff options
author | Sebastian P <5564491+s3lph@users.noreply.github.com> | 2020-10-01 22:50:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 22:50:56 +0200 |
commit | 214a6a13861b9fd495797386f36507373728e577 (patch) | |
tree | a2eb9541924b432ecf7a0807f42281296fa144a4 /vendor/layeh.com/gumble/gumbleutil/main.go | |
parent | e7781dc79c0c556f60eb64a93a95a5da494dcf2d (diff) | |
download | matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.tar.gz matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.tar.bz2 matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.zip |
Add Mumble support (#1245)
Diffstat (limited to 'vendor/layeh.com/gumble/gumbleutil/main.go')
-rw-r--r-- | vendor/layeh.com/gumble/gumbleutil/main.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/layeh.com/gumble/gumbleutil/main.go b/vendor/layeh.com/gumble/gumbleutil/main.go new file mode 100644 index 00000000..36419ea6 --- /dev/null +++ b/vendor/layeh.com/gumble/gumbleutil/main.go @@ -0,0 +1,79 @@ +package gumbleutil + +import ( + "crypto/tls" + "flag" + "fmt" + "net" + "os" + "strconv" + + "layeh.com/gumble/gumble" +) + +// Main aids in the creation of a basic command line gumble bot. It accepts the +// following flag arguments: +// --server +// --username +// --password +// --insecure +// --certificate +// --key +func Main(listeners ...gumble.EventListener) { + server := flag.String("server", "localhost:64738", "Mumble server address") + username := flag.String("username", "gumble-bot", "client username") + password := flag.String("password", "", "client password") + insecure := flag.Bool("insecure", false, "skip server certificate verification") + certificateFile := flag.String("certificate", "", "user certificate file (PEM)") + keyFile := flag.String("key", "", "user certificate key file (PEM)") + + if !flag.Parsed() { + flag.Parse() + } + + host, port, err := net.SplitHostPort(*server) + if err != nil { + host = *server + port = strconv.Itoa(gumble.DefaultPort) + } + + keepAlive := make(chan bool) + + config := gumble.NewConfig() + config.Username = *username + config.Password = *password + address := net.JoinHostPort(host, port) + + var tlsConfig tls.Config + + if *insecure { + tlsConfig.InsecureSkipVerify = true + } + 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) + } + } + config.Attach(AutoBitrate) + for _, listener := range listeners { + config.Attach(listener) + } + config.Attach(Listener{ + Disconnect: func(e *gumble.DisconnectEvent) { + keepAlive <- true + }, + }) + _, err = gumble.DialWithDialer(new(net.Dialer), address, config, &tlsConfig) + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err) + os.Exit(1) + } + + <-keepAlive +} |