X-Git-Url: https://git.0d.be/?p=barnard.git;a=blobdiff_plain;f=client.go;h=060e059db383d642c85c8a33988d6ab6b321f145;hp=dc1eb1ac42f4d9df7270c61b6fa35da84b4de812;hb=7aaa6f73874a615fdb433e9fc14b62bb1551003d;hpb=562dec1e354872ff4bde9e262e3f8c3f0840b336 diff --git a/client.go b/client.go index dc1eb1a..060e059 100644 --- a/client.go +++ b/client.go @@ -1,25 +1,54 @@ -package barnard +package main import ( "fmt" + "net" + "os" - "github.com/layeh/gumble/gumble" + "layeh.com/gumble/gumble" + "layeh.com/gumble/gumbleopenal" + "layeh.com/gumble/gumbleutil" ) +func (b *Barnard) start() { + b.Config.Attach(gumbleutil.AutoBitrate) + b.Config.Attach(b) + + var err error + _, err = gumble.DialWithDialer(new(net.Dialer), b.Address, b.Config, &b.TLSConfig) + if err != nil { + fmt.Fprintf(os.Stderr, "%s\n", err) + os.Exit(1) + } + + // Audio + if os.Getenv("ALSOFT_LOGLEVEL") == "" { + os.Setenv("ALSOFT_LOGLEVEL", "0") + } + if stream, err := gumbleopenal.New(b.Client); err != nil { + fmt.Fprintf(os.Stderr, "%s\n", err) + os.Exit(1) + } else { + b.Stream = stream + } +} + func (b *Barnard) OnConnect(e *gumble.ConnectEvent) { + b.Client = e.Client + b.Ui.SetActive(uiViewInput) b.UiTree.Rebuild() b.Ui.Refresh() - if b.Client.AudioEncoder().Bitrate() > e.MaximumBitrate { - b.Client.AudioEncoder().SetBitrate(e.MaximumBitrate / 3) + b.UpdateInputStatus(fmt.Sprintf("To: %s", e.Client.Self.Channel.Name)) + b.AddOutputLine(fmt.Sprintf("Connected to %s", b.Client.Conn.RemoteAddr())) + if e.WelcomeMessage != nil { + b.AddOutputLine(fmt.Sprintf("Welcome message: %s", esc(*e.WelcomeMessage))) } - - b.UpdateInputStatus(fmt.Sprintf("To: %s", e.Client.Self().Channel().Name())) - b.AddOutputLine(fmt.Sprintf("Connected to %s", b.Client.Conn().RemoteAddr())) - if e.WelcomeMessage != "" { - b.AddOutputLine(fmt.Sprintf("Welcome message: %s", esc(e.WelcomeMessage))) + if (b.DefaultChannel != "") { + b.Client.Self.Move(b.Client.Channels.Find(b.DefaultChannel)) } + } func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) { @@ -27,24 +56,6 @@ func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) { switch e.Type { case gumble.DisconnectError: reason = "connection error" - case gumble.DisconnectOther: - reason = e.String - case gumble.DisconnectVersion: - reason = "invalid version number" - case gumble.DisconnectUserName: - reason = "invalid user name" - case gumble.DisconnectUserCredentials: - reason = "incorrect user password/certificate" - case gumble.DisconnectServerPassword: - reason = "incorrect server password" - case gumble.DisconnectUsernameInUse: - reason = "user name in use" - case gumble.DisconnectServerFull: - reason = "server full" - case gumble.DisconnectNoCertificate: - reason = "missing certificate" - case gumble.DisconnectAuthenticatorFail: - reason = "authenticator via failed" } if reason == "" { b.AddOutputLine("Disconnected") @@ -60,8 +71,8 @@ func (b *Barnard) OnTextMessage(e *gumble.TextMessageEvent) { } func (b *Barnard) OnUserChange(e *gumble.UserChangeEvent) { - if e.Type.Has(gumble.UserChangeChannel) && e.User == b.Client.Self() { - b.UpdateInputStatus(fmt.Sprintf("To: %s", e.User.Channel().Name())) + if e.Type.Has(gumble.UserChangeChannel) && e.User == b.Client.Self { + b.UpdateInputStatus(fmt.Sprintf("To: %s", e.User.Channel.Name)) } b.UiTree.Rebuild() b.Ui.Refresh() @@ -102,7 +113,7 @@ func (b *Barnard) OnPermissionDenied(e *gumble.PermissionDeniedEvent) { func (b *Barnard) OnUserList(e *gumble.UserListEvent) { } -func (b *Barnard) OnAcl(e *gumble.AclEvent) { +func (b *Barnard) OnACL(e *gumble.ACLEvent) { } func (b *Barnard) OnBanList(e *gumble.BanListEvent) { @@ -110,3 +121,6 @@ func (b *Barnard) OnBanList(e *gumble.BanListEvent) { func (b *Barnard) OnContextActionChange(e *gumble.ContextActionChangeEvent) { } + +func (b *Barnard) OnServerConfig(e *gumble.ServerConfigEvent) { +}