using System.Collections.Generic;
using System.Text;
namespace Adrenak.UniVoice {
public class VoiceSettings {
#region GLOBAL
///
/// If true, we don't want to listen to any peer
///
public bool muteAll;
///
/// If true, we don't want any peer to listen to us
///
public bool deafenAll;
#endregion
#region ID BASED
///
/// The peers we don't want to listen to
///
public List mutedPeers = new List();
///
/// The peers we don't want listening to us
///
public List deafenedPeers = new List();
///
/// Sets the deaf status of a peer
///
public void SetDeaf(int peerId, bool state) {
if (state) {
if (!deafenedPeers.Contains(peerId))
deafenedPeers.Add(peerId);
}
else {
if (deafenedPeers.Contains(peerId))
deafenedPeers.Remove(peerId);
}
}
///
/// Sets the mute status of a peer
///
public void SetMute(int peerId, bool state) {
if (state) {
if (!mutedPeers.Contains(peerId))
mutedPeers.Add(peerId);
}
else {
if (mutedPeers.Contains(peerId))
mutedPeers.Remove(peerId);
}
}
#endregion
#region TAG BASED
private List _myTags = new List();
private List _mutedTags = new List();
private List _deafenedTags = new List();
///
/// List of tags associated with this client.
/// Use and
/// to add or remove tags.
///
public List myTags { get { return _myTags; } set { _myTags = value; } }
///
/// List of tags muted by this client.
/// Use and
/// to add or remove tags.
///
public List mutedTags { get { return _mutedTags; } set { _mutedTags = value; } }
///
/// List of tags deafened by this client.
/// Use and
/// to add or remove tags.
///
public List deafenedTags { get { return _deafenedTags; } set { _deafenedTags = value; } }
private bool IsTagValid(string tag) {
if (string.IsNullOrEmpty(tag) || tag.Contains(","))
return false;
return true;
}
///
/// Adds/Removes a tag from myTags list
///
///
///
///
public bool SetMyTag(string tag, bool enable) {
if (enable)
return AddMyTag(tag);
else
return RemoveMyTag(tag);
}
///
/// Adds a tag to the myTags list. Commas (',') and null/empty values are not allowed!
///
/// The tag to add.
///
/// TRUE: If the tag was accepted and added.
/// FALSE: If tag wasn't added because the tag is not allowed or was already in the myTags list
///
public bool AddMyTag(string tag) {
if (!IsTagValid(tag))
return false;
if (!_myTags.Contains(tag)) {
_myTags.Add(tag);
return true;
}
return false;
}
///
/// Removes a tag from the myTags list.
///
/// The tag to be removed.
///
/// TRUE: If the tag was removed.
/// FALSE: If the tag was not removed because it's not in the myTags list
///
public bool RemoveMyTag(string tag) {
if (!_myTags.Contains(tag)) {
return false;
}
_myTags.Remove(tag);
return false;
}
///
/// Adds/Removes a tag from mutedTags list
///
///
///
///
public bool SetMutedTag(string tag, bool enable) {
if (enable)
return AddMutedTag(tag);
else
return RemoveMutedTag(tag);
}
///
/// Adds a tag to the mutedTags list. Commas (',') and null/empty values are not allowed!
///
/// The tag to add.
///
/// TRUE: If the tag was accepted and added.
/// FALSE: If tag wasn't added because the tag is not allowed or was already in the mutedTags list
///
public bool AddMutedTag(string tag) {
if (!IsTagValid(tag))
return false;
if (!_mutedTags.Contains(tag)) {
_mutedTags.Add(tag);
return true;
}
return false;
}
///
/// Removes a tag from the mutedTags list.
///
/// The tag to be removed.
///
/// TRUE: If the tag was removed.
/// FALSE: If the tag was not removed because it's not in the mutedTags list
///
public bool RemoveMutedTag(string tag) {
if (!_mutedTags.Contains(tag)) {
return false;
}
_mutedTags.Remove(tag);
return false;
}
///
/// Adds/Removes a tag from deafenedTags list
///
///
///
///
public bool SetDeafenedTag(string tag, bool enable) {
if (enable)
return AddDeafenedTag(tag);
else
return RemoveDeafenedTag(tag);
}
///
/// Adds a tag to the deafenedTags list. Commas (',') and null/empty values are not allowed!
///
/// The tag to add.
///
/// TRUE: If the tag was accepted and added.
/// FALSE: If tag wasn't added because the tag is not allowed or was already in the deafenedTags list
///
public bool AddDeafenedTag(string tag) {
if (!IsTagValid(tag))
return false;
if (!_deafenedTags.Contains(tag)) {
_deafenedTags.Add(tag);
return true;
}
return false;
}
///
/// Removes a tag from the deafenedTags list.
///
/// The tag to be removed.
///
/// TRUE: If the tag was removed.
/// FALSE: If the tag was not removed because it's not in the deafenedTags list
///
public bool RemoveDeafenedTag(string tag) {
if (!_deafenedTags.Contains(tag)) {
return false;
}
_deafenedTags.Remove(tag);
return false;
}
#endregion
public override string ToString() {
return new StringBuilder()
.Append("muteAll: ").Append(muteAll).Append("\n")
.Append("deafenAll: ").Append(deafenAll).Append("\n")
.Append("mutedPeers: ").Append(string.Join(", ", mutedPeers)).Append("\n")
.Append("deafenedPeers: ").Append(string.Join(", ", deafenedPeers)).Append("\n")
.Append("myTags: ").Append(string.Join(", ", myTags)).Append("\n")
.Append("mutedTags: ").Append(string.Join(", ", mutedTags)).Append("\n")
.Append("deafenedTags: ").Append(string.Join(", ", deafenedTags))
.ToString();
}
}
}