From 64f2b9b0274061cd9690db6b3d2318bd2044044e Mon Sep 17 00:00:00 2001 From: s3lph <5564491+s3lph@users.noreply.github.com> Date: Sun, 6 Nov 2022 18:22:57 +0100 Subject: [PATCH 1/2] mumble: Implement sending of EventJoinLeave both to and from Mumble (Closes #1435) --- bridge/mumble/handlers.go | 44 +++++++++++++++++++++++++++++++++++---- bridge/mumble/mumble.go | 2 +- matterbridge.toml.sample | 37 +++++++++++++++++++------------- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/bridge/mumble/handlers.go b/bridge/mumble/handlers.go index 40272633e4..1d3cc987d3 100644 --- a/bridge/mumble/handlers.go +++ b/bridge/mumble/handlers.go @@ -79,15 +79,51 @@ func (b *Bmumble) handleConnect(event *gumble.ConnectEvent) { } func (b *Bmumble) handleUserChange(event *gumble.UserChangeEvent) { - // Only care about changes to self - if event.User != event.Client.Self { + // Ignore events happening before setup is done + if b.Channel == nil { return } - // Someone attempted to move the user out of the configured channel; attempt to join back - if b.Channel != nil { + // UserChangeEvent is used for both the gumble client itself as well as other clients + if event.User == event.Client.Self { + // Someone attempted to move the user out of the configured channel; attempt to join back if err := b.doJoin(event.Client, *b.Channel); err != nil { b.Log.Error(err) } + } else { + if b.GetBool("nosendjoinpart") { + return + } + b.Log.Debugf("Received gumble user change event: %+v", event) + text := "" + if event.Type & gumble.UserChangeKicked > 0 { + text = " was kicked" + } else if event.Type & gumble.UserChangeBanned > 0 { + text = " was banned" + } else if event.Type & gumble.UserChangeDisconnected > 0 { + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " left" + } + } else if event.Type & gumble.UserChangeConnected > 0 { + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " joined" + } + } else if event.Type & gumble.UserChangeChannel > 0 { + // Treat Mumble channel changes the same as connects/disconnects; as far as matterbridge is concerned, they are identical + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " joined" + } else { + text = " left" + } + } + if text != "" { + b.Remote <- config.Message{ + Username: "system", + Text: event.User.Name + text, + Channel: strconv.FormatUint(uint64(*b.Channel), 10), + Account: b.Account, + Event: config.EventJoinLeave, + } + } } } diff --git a/bridge/mumble/mumble.go b/bridge/mumble/mumble.go index 1943bd39b0..945cf5595c 100644 --- a/bridge/mumble/mumble.go +++ b/bridge/mumble/mumble.go @@ -93,7 +93,7 @@ func (b *Bmumble) JoinChannel(channel config.ChannelInfo) error { func (b *Bmumble) Send(msg config.Message) (string, error) { // Only process text messages b.Log.Debugf("=> Received local message %#v", msg) - if msg.Event != "" && msg.Event != config.EventUserAction { + if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave { return "", nil } diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 97b27d7387..a175893648 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -187,7 +187,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -197,7 +197,7 @@ ShowJoinPart=false VerboseJoinPart=false #Do not send joins/parts to other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) NoSendJoinPart=false @@ -324,7 +324,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -491,12 +491,12 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false #Do not send joins/parts to other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) NoSendJoinPart=false @@ -578,7 +578,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -686,7 +686,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -825,12 +825,12 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false #Do not send joins/parts to other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) NoSendJoinPart=false @@ -1137,7 +1137,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -1274,7 +1274,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -1386,7 +1386,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -1483,7 +1483,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false @@ -1571,6 +1571,15 @@ SkipTLSVerify=false #Default "" MessageClipped="" +#Enable to show users joins/parts from other bridges +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord +#OPTIONAL (default false) +ShowJoinPart=false + +#Do not send joins/parts to other bridges +#OPTIONAL (default false) +NoSendJoinPart=false + ################################################################### #VK ################################################################### @@ -1683,7 +1692,7 @@ Label="" RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #Enable to show users joins/parts from other bridges -#Currently works for messages from the following bridges: irc, mattermost, slack, discord +#Currently works for messages from the following bridges: irc, mattermost, mumble, slack, discord #OPTIONAL (default false) ShowJoinPart=false From af6e353957fe2a00ca59336e851e6fc95e80de51 Mon Sep 17 00:00:00 2001 From: s3lph <5564491+s3lph@users.noreply.github.com> Date: Sun, 6 Nov 2022 18:39:05 +0100 Subject: [PATCH 2/2] mumble: Break handleUserChange into two functions --- bridge/mumble/handlers.go | 94 ++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/bridge/mumble/handlers.go b/bridge/mumble/handlers.go index 1d3cc987d3..8120159a12 100644 --- a/bridge/mumble/handlers.go +++ b/bridge/mumble/handlers.go @@ -78,52 +78,72 @@ func (b *Bmumble) handleConnect(event *gumble.ConnectEvent) { } } -func (b *Bmumble) handleUserChange(event *gumble.UserChangeEvent) { +func (b *Bmumble) handleJoinLeave(event *gumble.UserChangeEvent) { // Ignore events happening before setup is done if b.Channel == nil { return } - // UserChangeEvent is used for both the gumble client itself as well as other clients - if event.User == event.Client.Self { + if b.GetBool("nosendjoinpart") { + return + } + b.Log.Debugf("Received gumble user change event: %+v", event) + + text := "" + switch { + case event.Type&gumble.UserChangeKicked > 0: + text = " was kicked" + case event.Type&gumble.UserChangeBanned > 0: + text = " was banned" + case event.Type&gumble.UserChangeDisconnected > 0: + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " left" + } + case event.Type&gumble.UserChangeConnected > 0: + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " joined" + } + case event.Type&gumble.UserChangeChannel > 0: + // Treat Mumble channel changes the same as connects/disconnects; as far as matterbridge is concerned, they are identical + if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { + text = " joined" + } else { + text = " left" + } + } + + if text != "" { + b.Remote <- config.Message{ + Username: "system", + Text: event.User.Name + text, + Channel: strconv.FormatUint(uint64(*b.Channel), 10), + Account: b.Account, + Event: config.EventJoinLeave, + } + } +} + +func (b *Bmumble) handleUserModified(event *gumble.UserChangeEvent) { + // Ignore events happening before setup is done + if b.Channel == nil { + return + } + + if event.Type&gumble.UserChangeChannel > 0 { // Someone attempted to move the user out of the configured channel; attempt to join back if err := b.doJoin(event.Client, *b.Channel); err != nil { b.Log.Error(err) } + } +} + +func (b *Bmumble) handleUserChange(event *gumble.UserChangeEvent) { + // The UserChangeEvent is used for both the gumble client itself as well as other clients + if event.User != event.Client.Self { + // other users + b.handleJoinLeave(event) } else { - if b.GetBool("nosendjoinpart") { - return - } - b.Log.Debugf("Received gumble user change event: %+v", event) - text := "" - if event.Type & gumble.UserChangeKicked > 0 { - text = " was kicked" - } else if event.Type & gumble.UserChangeBanned > 0 { - text = " was banned" - } else if event.Type & gumble.UserChangeDisconnected > 0 { - if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { - text = " left" - } - } else if event.Type & gumble.UserChangeConnected > 0 { - if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { - text = " joined" - } - } else if event.Type & gumble.UserChangeChannel > 0 { - // Treat Mumble channel changes the same as connects/disconnects; as far as matterbridge is concerned, they are identical - if event.User.Channel != nil && event.User.Channel.ID == *b.Channel { - text = " joined" - } else { - text = " left" - } - } - if text != "" { - b.Remote <- config.Message{ - Username: "system", - Text: event.User.Name + text, - Channel: strconv.FormatUint(uint64(*b.Channel), 10), - Account: b.Account, - Event: config.EventJoinLeave, - } - } + // gumble user + b.handleUserModified(event) } }