From 4ff32100cc195d9a2a033a5eb0f03e9e1d337742 Mon Sep 17 00:00:00 2001 From: Michel Bagnol Date: Wed, 26 Jun 2019 21:00:29 +0200 Subject: [PATCH 1/3] (feature) Allow to send UserState without having to move channel. (refactor) MumbleSharp.User now uses MumbleProto.UserState as backend storage. --- MumbleSharp/Model/User.cs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/MumbleSharp/Model/User.cs b/MumbleSharp/Model/User.cs index 9a65fb0..3dfc20d 100644 --- a/MumbleSharp/Model/User.cs +++ b/MumbleSharp/Model/User.cs @@ -11,13 +11,17 @@ public class User : IEquatable { private readonly IMumbleProtocol _owner; - - public UInt32 Id { get; private set; } - public bool Deaf { get; set; } - public bool Muted { get; set; } - public bool SelfDeaf { get; set; } - public bool SelfMuted { get; set; } - public bool Suppress { get; set; } + private readonly UserState _userstate = new UserState(); + + public UInt32 Id { get => _userstate.Actor; private set { _userstate.Actor = value; } } + public UInt32 ChannelId { get => _userstate.ChannelId; private set { _userstate.ChannelId = value; } } + public string Name { get => _userstate.Name; set { _userstate.Name = value; } } + public string Comment { get => _userstate.Comment; set { _userstate.Comment = value; } } + public bool Deaf { get => _userstate.Deaf; set { _userstate.Deaf = value; } } + public bool Muted { get => _userstate.Mute; set { _userstate.Mute = value; } } + public bool SelfDeaf { get => _userstate.SelfDeaf; set { _userstate.SelfDeaf = value; } } + public bool SelfMuted { get => _userstate.SelfMute; set { _userstate.SelfMute = value; } } + public bool Suppress { get => _userstate.Suppress; set { _userstate.Suppress = value; } } private Channel _channel; public Channel Channel @@ -35,9 +39,6 @@ public Channel Channel } } - public string Name { get; set; } - public string Comment { get; set; } - private readonly CodecSet _codecs = new CodecSet(); public User(IMumbleProtocol owner, uint id) @@ -80,11 +81,17 @@ public void Move(Channel channel) if (_channel == channel) return; - UserState userstate = new UserState(); - userstate.Actor = Id; - userstate.ChannelId = channel.Id; + this.ChannelId = channel.Id; + + SendUserState(); + } - _owner.Connection.SendControl(PacketType.UserState, userstate); + /// + /// Send user state + /// + public void SendUserState() + { + _owner.Connection.SendControl(PacketType.UserState, _userstate); } protected internal IVoiceCodec GetCodec(SpeechCodecs codec) From 116baa412e039b6ec195110b1c95843c52c097ef Mon Sep 17 00:00:00 2001 From: Michel Bagnol Date: Thu, 27 Jun 2019 06:57:41 +0200 Subject: [PATCH 2/3] (feature) Allow to send UserState with SelfMuted and SelfDeaf info. --- MumbleSharp/Model/User.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MumbleSharp/Model/User.cs b/MumbleSharp/Model/User.cs index 3dfc20d..541fa73 100644 --- a/MumbleSharp/Model/User.cs +++ b/MumbleSharp/Model/User.cs @@ -13,7 +13,7 @@ public class User private readonly IMumbleProtocol _owner; private readonly UserState _userstate = new UserState(); - public UInt32 Id { get => _userstate.Actor; private set { _userstate.Actor = value; } } + public UInt32 Id { get => _userstate.UserId; private set { _userstate.UserId = value; } } public UInt32 ChannelId { get => _userstate.ChannelId; private set { _userstate.ChannelId = value; } } public string Name { get => _userstate.Name; set { _userstate.Name = value; } } public string Comment { get => _userstate.Comment; set { _userstate.Comment = value; } } @@ -91,7 +91,12 @@ public void Move(Channel channel) /// public void SendUserState() { - _owner.Connection.SendControl(PacketType.UserState, _userstate); + UserState userstate = new UserState(); + userstate.Actor = this.Id; + userstate.ChannelId = this.ChannelId; + userstate.SelfMute = this.SelfMuted; + userstate.SelfDeaf = this.SelfDeaf; + _owner.Connection.SendControl(PacketType.UserState, userstate); } protected internal IVoiceCodec GetCodec(SpeechCodecs codec) From 82e2ab808de878ed915ed5b8ee30501d5abe86fb Mon Sep 17 00:00:00 2001 From: Michel Bagnol Date: Thu, 27 Jun 2019 18:06:32 +0200 Subject: [PATCH 3/3] (ignore) code formatting. --- MumbleSharp/Model/User.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MumbleSharp/Model/User.cs b/MumbleSharp/Model/User.cs index 541fa73..025e4f7 100644 --- a/MumbleSharp/Model/User.cs +++ b/MumbleSharp/Model/User.cs @@ -91,12 +91,13 @@ public void Move(Channel channel) /// public void SendUserState() { - UserState userstate = new UserState(); - userstate.Actor = this.Id; - userstate.ChannelId = this.ChannelId; - userstate.SelfMute = this.SelfMuted; - userstate.SelfDeaf = this.SelfDeaf; - _owner.Connection.SendControl(PacketType.UserState, userstate); + _owner.Connection.SendControl(PacketType.UserState, new UserState() + { + Actor = this.Id, + ChannelId = this.ChannelId, + SelfMute = this.SelfMuted, + SelfDeaf = this.SelfDeaf, + }); } protected internal IVoiceCodec GetCodec(SpeechCodecs codec)