Browse Source

Use a better method for detecting if a voice socket is needed.

tags/docs-0.9
RogueException 9 years ago
parent
commit
a77f215df2
4 changed files with 12 additions and 6 deletions
  1. +2
    -2
      src/Discord.Net/DiscordClient.cs
  2. +3
    -0
      src/Discord.Net/DiscordClientConfig.cs
  3. +6
    -4
      src/Discord.Net/DiscordSimpleClient.cs
  4. +1
    -0
      src/Discord.Net/DiscordSimpleClientConfig.cs

+ 2
- 2
src/Discord.Net/DiscordClient.cs View File

@@ -52,7 +52,7 @@ namespace Discord

/// <summary> Initializes a new instance of the DiscordClient class. </summary>
public DiscordClient(DiscordClientConfig config = null)
: base(config, enableVoice: config.VoiceMode != DiscordVoiceMode.Disabled && !config.EnableVoiceMultiserver)
: base(config)
{
_rand = new Random();
_api = new DiscordAPIClient(_config.LogLevel, _config.UserAgent, _config.APITimeout);
@@ -740,7 +740,7 @@ namespace Discord
config.EnableVoiceMultiserver = false;
config.VoiceOnly = true;
config.VoiceClientId = unchecked(++_nextVoiceClientId);
return new DiscordSimpleClient(config, true, serverId);
return new DiscordSimpleClient(config, serverId);
});
client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}");
await client.Connect(_gateway, _token).ConfigureAwait(false);


+ 3
- 0
src/Discord.Net/DiscordClientConfig.cs View File

@@ -27,6 +27,9 @@ namespace Discord
public bool AckMessages { get { return _ackMessages; } set { SetValue(ref _ackMessages, value); } }
private bool _ackMessages = false;

//Internal
internal override bool EnableVoice => base.EnableVoice && !EnableVoiceMultiserver;

public new DiscordClientConfig Clone()
{
var config = this.MemberwiseClone() as DiscordClientConfig;


+ 6
- 4
src/Discord.Net/DiscordSimpleClient.cs View File

@@ -51,14 +51,11 @@ namespace Discord

/// <summary> Initializes a new instance of the DiscordClient class. </summary>
public DiscordSimpleClient(DiscordSimpleClientConfig config = null)
: this(config, enableVoice: config.VoiceMode != DiscordVoiceMode.Disabled) { }
internal DiscordSimpleClient(DiscordSimpleClientConfig config = null, bool enableVoice = false, string voiceServerId = null)
{
_config = config ?? new DiscordSimpleClientConfig();
_config.Lock();

_enableVoice = enableVoice;
_voiceServerId = voiceServerId;
_enableVoice = _config.EnableVoice;

_state = (int)DiscordClientState.Disconnected;
_cancelToken = new CancellationToken(true);
@@ -69,6 +66,11 @@ namespace Discord
if (_enableVoice)
_voiceSocket = CreateVoiceSocket();
}
internal DiscordSimpleClient(DiscordSimpleClientConfig config = null, string voiceServerId = null)
: this(config)
{
_voiceServerId = voiceServerId;
}

internal virtual DataWebSocket CreateDataSocket()
{


+ 1
- 0
src/Discord.Net/DiscordSimpleClientConfig.cs View File

@@ -56,6 +56,7 @@ namespace Discord
private bool _voiceOnly;
internal uint VoiceClientId { get { return _voiceClientId; } set { SetValue(ref _voiceClientId, value); } }
private uint _voiceClientId;
internal virtual bool EnableVoice => _voiceMode != DiscordVoiceMode.Disabled;

internal string UserAgent
{


Loading…
Cancel
Save