Drop channel path, only use channel IDs for joining.
This commit is contained in:
parent
4825c1c2af
commit
93eb412394
@ -54,7 +54,7 @@ func (b *Bmumble) handleConnect(event *gumble.ConnectEvent) {
|
|||||||
event.Client.Self.SetSelfMuted(true)
|
event.Client.Self.SetSelfMuted(true)
|
||||||
// if the Channel variable is set, this is a reconnect -> rejoin channel
|
// if the Channel variable is set, this is a reconnect -> rejoin channel
|
||||||
if b.Channel != nil {
|
if b.Channel != nil {
|
||||||
if err := b.doJoin(event.Client, b.Channel); err != nil {
|
if err := b.doJoin(event.Client, *b.Channel); err != nil {
|
||||||
b.Log.Error(err)
|
b.Log.Error(err)
|
||||||
}
|
}
|
||||||
b.Remote <- config.Message{
|
b.Remote <- config.Message{
|
||||||
@ -74,7 +74,7 @@ func (b *Bmumble) handleUserChange(event *gumble.UserChangeEvent) {
|
|||||||
}
|
}
|
||||||
// Someone attempted to move the user out of the configured channel; attempt to join back
|
// Someone attempted to move the user out of the configured channel; attempt to join back
|
||||||
if b.Channel != nil {
|
if b.Channel != nil {
|
||||||
if err := b.doJoin(event.Client, b.Channel); err != nil {
|
if err := b.doJoin(event.Client, *b.Channel); err != nil {
|
||||||
b.Log.Error(err)
|
b.Log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
package bmumble
|
package bmumble
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"layeh.com/gumble/gumble"
|
|
||||||
"layeh.com/gumble/gumbleutil"
|
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/mattn/godown"
|
"github.com/mattn/godown"
|
||||||
"github.com/vincent-petithory/dataurl"
|
"github.com/vincent-petithory/dataurl"
|
||||||
@ -147,47 +141,3 @@ func (b *Bmumble) extractFiles(msg *config.Message) []config.Message {
|
|||||||
msg.Extra["file"] = nil
|
msg.Extra["file"] = nil
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmumble) parseChannelPath(client *gumble.Client, name string) ([]string, error) {
|
|
||||||
// Parse the channel name as a numeric ID if passed as "ID:42"
|
|
||||||
if strings.HasPrefix(name, "ID:") {
|
|
||||||
// Parse the ID string into an int
|
|
||||||
channelID, err := strconv.ParseUint(name[3:], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
b.Log.WithError(err).Fatalf("Cannot parse channel ID: %s", name)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Verify that the ID refers to an existing channel
|
|
||||||
c, ok := client.Channels[uint32(channelID)]
|
|
||||||
if !ok {
|
|
||||||
b.Log.Fatalf("No channel with ID %d", channelID)
|
|
||||||
return nil, errors.New("no such channel: " + name)
|
|
||||||
}
|
|
||||||
return gumbleutil.ChannelPath(c)[1:], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(name, "/") {
|
|
||||||
return nil, errors.New("channel path must start with a '/': " + name)
|
|
||||||
}
|
|
||||||
// Special treatment for the root channel: empty slice
|
|
||||||
if name == "/" {
|
|
||||||
return make([]string, 0), nil
|
|
||||||
}
|
|
||||||
// Iterate all path components, discarding the first token, which is the empty string before the leading /
|
|
||||||
tokens := strings.Split(name, "/")
|
|
||||||
var channelPath []string
|
|
||||||
for _, token := range tokens[1:] {
|
|
||||||
// Urldecode each token and append it to the path
|
|
||||||
if channelName, err := url.PathUnescape(token); err == nil && len(channelName) > 0 {
|
|
||||||
channelPath = append(channelPath, channelName)
|
|
||||||
} else {
|
|
||||||
b.Log.WithError(err).Fatalf("Error while decoding path component '%s'", token)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c := client.Channels.Find(channelPath...)
|
|
||||||
if c == nil {
|
|
||||||
return nil, errors.New("no such channel: " + name)
|
|
||||||
}
|
|
||||||
return gumbleutil.ChannelPath(c)[1:], nil
|
|
||||||
}
|
|
||||||
|
@ -27,7 +27,7 @@ type Bmumble struct {
|
|||||||
client *gumble.Client
|
client *gumble.Client
|
||||||
Nick string
|
Nick string
|
||||||
Host string
|
Host string
|
||||||
Channel []string
|
Channel *uint32
|
||||||
local chan config.Message
|
local chan config.Message
|
||||||
running chan error
|
running chan error
|
||||||
connected chan gumble.DisconnectEvent
|
connected chan gumble.DisconnectEvent
|
||||||
@ -76,15 +76,17 @@ func (b *Bmumble) Disconnect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmumble) JoinChannel(channel config.ChannelInfo) error {
|
func (b *Bmumble) JoinChannel(channel config.ChannelInfo) error {
|
||||||
channelPath, err := b.parseChannelPath(b.client, channel.Name)
|
cid, err := strconv.ParseUint(channel.Name, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if b.Channel != nil {
|
channelID := uint32(cid)
|
||||||
b.Log.Fatalf("Cannot join channel '%v', already joined to channel '%v'", channel.Name, b.Channel)
|
if b.Channel != nil && *b.Channel != channelID {
|
||||||
|
b.Log.Fatalf("Cannot join channel ID '%d', already joined to channel ID %d", channelID, *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")
|
||||||
}
|
}
|
||||||
return b.doJoin(b.client, channelPath)
|
b.Channel = &channelID
|
||||||
|
return b.doJoin(b.client, channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmumble) Send(msg config.Message) (string, error) {
|
func (b *Bmumble) Send(msg config.Message) (string, error) {
|
||||||
@ -190,13 +192,12 @@ func (b *Bmumble) doConnect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmumble) doJoin(client *gumble.Client, channelPath []string) error {
|
func (b *Bmumble) doJoin(client *gumble.Client, channelID uint32) error {
|
||||||
c := client.Channels.Find(channelPath...)
|
channel, ok := client.Channels[channelID]
|
||||||
if c == nil {
|
if !ok {
|
||||||
return fmt.Errorf("no such channel: %v", channelPath)
|
return fmt.Errorf("no channel with ID %d", channelID)
|
||||||
}
|
}
|
||||||
b.Channel = gumbleutil.ChannelPath(c)[1:]
|
client.Self.Move(channel)
|
||||||
client.Self.Move(c)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1791,8 +1791,7 @@ enable=true
|
|||||||
# -------------------------------------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------------------------------------
|
||||||
# msteams | threadId | 19:82abcxx@thread.skype | You'll find the threadId in the URL
|
# msteams | threadId | 19:82abcxx@thread.skype | You'll find the threadId in the URL
|
||||||
# -------------------------------------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------------------------------------
|
||||||
# mumble | channel id | ID:42 | The channel ID, as shown in the channel's "Edit" window
|
# mumble | channel id | 42 | The channel ID, as shown in the channel's "Edit" window
|
||||||
# | channel path | /A%20channel/a%20subchannel | The urlencoded channel path, as contained in the channel's URL
|
|
||||||
# -------------------------------------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------------------------------------
|
||||||
# rocketchat | channel | #channel | # is required for private channels too
|
# rocketchat | channel | #channel | # is required for private channels too
|
||||||
# -------------------------------------------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user