summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorSebastian P <5564491+s3lph@users.noreply.github.com>2022-11-27 00:17:11 +0100
committerGitHub <noreply@github.com>2022-11-27 00:17:11 +0100
commit6da9d567dc9195e9a5211f23a6795a41f56a1bfc (patch)
tree394e52b5a2e6f5c853c642e74774d9719550bb22 /bridge
parent6d5a3dff2279f9cc1e9a846419c6cae2fe563e8d (diff)
downloadmatterbridge-msglm-6da9d567dc9195e9a5211f23a6795a41f56a1bfc.tar.gz
matterbridge-msglm-6da9d567dc9195e9a5211f23a6795a41f56a1bfc.tar.bz2
matterbridge-msglm-6da9d567dc9195e9a5211f23a6795a41f56a1bfc.zip
Implement sending of EventJoinLeave both to and from Mumble (#1915)
* mumble: Implement sending of EventJoinLeave both to and from Mumble (Closes #1435) * mumble: Break handleUserChange into two functions
Diffstat (limited to 'bridge')
-rw-r--r--bridge/mumble/handlers.go66
-rw-r--r--bridge/mumble/mumble.go2
2 files changed, 62 insertions, 6 deletions
diff --git a/bridge/mumble/handlers.go b/bridge/mumble/handlers.go
index 40272633..8120159a 100644
--- a/bridge/mumble/handlers.go
+++ b/bridge/mumble/handlers.go
@@ -78,19 +78,75 @@ 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 {
+func (b *Bmumble) handleJoinLeave(event *gumble.UserChangeEvent) {
+ // 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 {
+ 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 {
+ // gumble user
+ b.handleUserModified(event)
+ }
+}
+
func (b *Bmumble) handleDisconnect(event *gumble.DisconnectEvent) {
b.connected <- *event
}
diff --git a/bridge/mumble/mumble.go b/bridge/mumble/mumble.go
index 1943bd39..945cf559 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
}