Fix some minor issues (fmt strings, rejoin logic errors)

This commit is contained in:
s3lph 2020-09-24 02:00:19 +02:00
parent 05782ce81d
commit db8187b7e5
2 changed files with 14 additions and 21 deletions

View File

@ -8,7 +8,7 @@ import (
func (b *Bmumble) handleServerConfig(event *gumble.ServerConfigEvent) { func (b *Bmumble) handleServerConfig(event *gumble.ServerConfigEvent) {
b.serverConfigUpdate <- *event
} }
@ -60,7 +60,7 @@ func (b *Bmumble) handleUserChange(event *gumble.UserChangeEvent) {
func (b *Bmumble) handleDisconnect(event *gumble.DisconnectEvent) { func (b *Bmumble) handleDisconnect(event *gumble.DisconnectEvent) {
b.connected <- disconnect{event.Type, event.String} b.connected <- *event
} }

View File

@ -7,7 +7,6 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"strconv" "strconv"
// "strings"
"time" "time"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
@ -30,8 +29,8 @@ type Bmumble struct {
Channel string Channel string
local chan config.Message local chan config.Message
running chan error running chan error
connected chan disconnect connected chan gumble.DisconnectEvent
serverConfigUpdate chan *gumble.ServerConfigEvent serverConfigUpdate chan gumble.ServerConfigEvent
serverConfig gumble.ServerConfigEvent serverConfig gumble.ServerConfigEvent
tlsConfig tls.Config tlsConfig tls.Config
@ -39,20 +38,14 @@ type Bmumble struct {
} }
type disconnect struct {
Reason gumble.DisconnectType
Message string
}
func New(cfg *bridge.Config) bridge.Bridger { func New(cfg *bridge.Config) bridge.Bridger {
b := &Bmumble{} b := &Bmumble{}
b.Config = cfg b.Config = cfg
b.Nick = b.GetString("Nick") b.Nick = b.GetString("Nick")
b.local = make(chan config.Message) b.local = make(chan config.Message)
b.running = make(chan error) b.running = make(chan error)
b.connected = make(chan disconnect) b.connected = make(chan gumble.DisconnectEvent)
b.serverConfigUpdate = make(chan *gumble.ServerConfigEvent) b.serverConfigUpdate = make(chan gumble.ServerConfigEvent)
return b return b
} }
@ -104,8 +97,8 @@ func (b *Bmumble) Disconnect() error {
} }
func (b *Bmumble) JoinChannel(channel config.ChannelInfo) error { func (b *Bmumble) JoinChannel(channel config.ChannelInfo) error {
if b.Channel != "" { if b.Channel != "" && channel.Name != b.Channel {
b.Log.Fatalf("Cannot join channel '%s', already joined to channel '%'s", channel.Name, b.Channel) b.Log.Fatalf("Cannot join channel '%s', already joined to channel '%s'", channel.Name, b.Channel)
return errors.New("The Mumble bridge can only join a single channel") return errors.New("The Mumble bridge can only join a single channel")
} }
b.Channel = channel.Name b.Channel = channel.Name
@ -144,15 +137,15 @@ func (b *Bmumble) connectLoop() {
} }
firstConnect = false firstConnect = false
d := <-b.connected d := <-b.connected
switch d.Reason { switch d.Type {
case gumble.DisconnectError: case gumble.DisconnectError:
b.Log.Errorf("Lost connection to the server (%s), attempting reconnect", d.Message) b.Log.Errorf("Lost connection to the server (%s), attempting reconnect", d.String)
continue continue
case gumble.DisconnectKicked: case gumble.DisconnectKicked:
b.Log.Errorf("Kicked from the server (%s), attempting reconnect", d.Message) b.Log.Errorf("Kicked from the server (%s), attempting reconnect", d.String)
continue continue
case gumble.DisconnectBanned: case gumble.DisconnectBanned:
b.Log.Errorf("Banned from the server (%s), not attempting reconnect", d.Message) b.Log.Errorf("Banned from the server (%s), not attempting reconnect", d.String)
break break
case gumble.DisconnectUser: case gumble.DisconnectUser:
b.Log.Infof("Disconnect successful") b.Log.Infof("Disconnect successful")
@ -208,8 +201,8 @@ func (b *Bmumble) doSend() {
for { for {
select { select {
case config := <-b.serverConfigUpdate: case config := <-b.serverConfigUpdate:
b.Log.Debugf("Received server config update: AllowHTML=%d, MaxMessageLength=%d", config.AllowHTML, config.MaximumMessageLength) b.Log.Debugf("Received server config update: AllowHTML=%#v, MaximumMessageLength=%#v", config.AllowHTML, config.MaximumMessageLength)
b.serverConfig = *config b.serverConfig = config
case msg := <-b.local: case msg := <-b.local:
b.processMessage(&msg) b.processMessage(&msg)
} }