Browse Source

Merge pull request #156 from Carbonitex/Sharding

Added Sharding support
tags/1.0-rc
RogueException GitHub 8 years ago
parent
commit
942c3bf0bc
4 changed files with 10 additions and 5 deletions
  1. +5
    -2
      src/Discord.Net/API/DiscordSocketApiClient.cs
  2. +2
    -0
      src/Discord.Net/API/Gateway/IdentifyParams.cs
  3. +1
    -1
      src/Discord.Net/DiscordConfig.cs
  4. +2
    -2
      src/Discord.Net/DiscordSocketClient.cs

+ 5
- 2
src/Discord.Net/API/DiscordSocketApiClient.cs View File

@@ -179,7 +179,7 @@ namespace Discord.API
{ {
return await SendAsync<GetGatewayResponse>("GET", "gateway", options: options).ConfigureAwait(false); return await SendAsync<GetGatewayResponse>("GET", "gateway", options: options).ConfigureAwait(false);
} }
public async Task SendIdentifyAsync(int largeThreshold = 100, bool useCompression = true, RequestOptions options = null)
public async Task SendIdentifyAsync(int largeThreshold = 100, bool useCompression = true, int shardID = 0, int totalShards = 1, RequestOptions options = null)
{ {
var props = new Dictionary<string, string> var props = new Dictionary<string, string>
{ {
@@ -190,8 +190,11 @@ namespace Discord.API
Token = _authToken, Token = _authToken,
Properties = props, Properties = props,
LargeThreshold = largeThreshold, LargeThreshold = largeThreshold,
UseCompression = useCompression
UseCompression = useCompression,
}; };
if (totalShards > 1)
msg.ShardingParams = new int[] { shardID, totalShards };

await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false);
} }
public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null) public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null)


+ 2
- 0
src/Discord.Net/API/Gateway/IdentifyParams.cs View File

@@ -14,5 +14,7 @@ namespace Discord.API.Gateway
public int LargeThreshold { get; set; } public int LargeThreshold { get; set; }
[JsonProperty("compress")] [JsonProperty("compress")]
public bool UseCompression { get; set; } public bool UseCompression { get; set; }
[JsonProperty("shard")]
public Optional<int[]> ShardingParams { get; set; }
} }
} }

+ 1
- 1
src/Discord.Net/DiscordConfig.cs View File

@@ -5,7 +5,7 @@ namespace Discord
public class DiscordConfig public class DiscordConfig
{ {
public const int APIVersion = 6; public const int APIVersion = 6;
public static string Version { get; } = typeof(DiscordRestConfig).GetTypeInfo().Assembly?.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion ?? "Unknown";
public static string Version { get; } = typeof(DiscordRestConfig).GetTypeInfo().Assembly?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";


public static readonly string ClientAPIUrl = $"https://discordapp.com/api/v{APIVersion}/"; public static readonly string ClientAPIUrl = $"https://discordapp.com/api/v{APIVersion}/";
public const string CDNUrl = "https://cdn.discordapp.com/"; public const string CDNUrl = "https://cdn.discordapp.com/";


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

@@ -166,7 +166,7 @@ namespace Discord
if (_sessionId != null) if (_sessionId != null)
await ApiClient.SendResumeAsync(_sessionId, _lastSeq).ConfigureAwait(false); await ApiClient.SendResumeAsync(_sessionId, _lastSeq).ConfigureAwait(false);
else else
await ApiClient.SendIdentifyAsync().ConfigureAwait(false);
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards:TotalShards).ConfigureAwait(false);


await _connectTask.Task.ConfigureAwait(false); await _connectTask.Task.ConfigureAwait(false);
_canReconnect = true; _canReconnect = true;
@@ -534,7 +534,7 @@ namespace Discord


_sessionId = null; _sessionId = null;
_lastSeq = 0; _lastSeq = 0;
await ApiClient.SendIdentifyAsync().ConfigureAwait(false);
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false);
} }
break; break;
case GatewayOpCode.Reconnect: case GatewayOpCode.Reconnect:


Loading…
Cancel
Save