From 9b34e4f2b38464e53f0a76eb6932ad7d0843401a Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 29 Jul 2016 10:18:31 -0700 Subject: [PATCH 1/3] Null check wasn't picking up the slack when InformationVersion is not found. --- src/Discord.Net/DiscordConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs index 2f0f50018..fdecde6b4 100644 --- a/src/Discord.Net/DiscordConfig.cs +++ b/src/Discord.Net/DiscordConfig.cs @@ -5,7 +5,7 @@ namespace Discord public class DiscordConfig { public const int APIVersion = 6; - public static string Version { get; } = typeof(DiscordRestConfig).GetTypeInfo().Assembly?.GetCustomAttribute().InformationalVersion ?? "Unknown"; + public static string Version { get; } = typeof(DiscordRestConfig).GetTypeInfo().Assembly?.GetCustomAttribute()?.InformationalVersion ?? "Unknown"; public static readonly string ClientAPIUrl = $"https://discordapp.com/api/v{APIVersion}/"; public const string CDNUrl = "https://cdn.discordapp.com/"; From 80bfe563225a701bcc5e6f72eede536d8694ce74 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 29 Jul 2016 10:25:15 -0700 Subject: [PATCH 2/3] Added Sharding support --- src/Discord.Net/API/DiscordSocketApiClient.cs | 6 ++++-- src/Discord.Net/API/Gateway/IdentifyParams.cs | 2 ++ src/Discord.Net/DiscordSocketClient.cs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net/API/DiscordSocketApiClient.cs b/src/Discord.Net/API/DiscordSocketApiClient.cs index 70d660cd4..f6040081e 100644 --- a/src/Discord.Net/API/DiscordSocketApiClient.cs +++ b/src/Discord.Net/API/DiscordSocketApiClient.cs @@ -179,7 +179,7 @@ namespace Discord.API { return await SendAsync("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 { @@ -190,8 +190,10 @@ namespace Discord.API Token = _authToken, Properties = props, LargeThreshold = largeThreshold, - UseCompression = useCompression + UseCompression = useCompression, + ShardingParams = totalShards > 1 ? new int[] { shardID, totalShards } : null }; + await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); } public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null) diff --git a/src/Discord.Net/API/Gateway/IdentifyParams.cs b/src/Discord.Net/API/Gateway/IdentifyParams.cs index 0a056e225..26e2952a1 100644 --- a/src/Discord.Net/API/Gateway/IdentifyParams.cs +++ b/src/Discord.Net/API/Gateway/IdentifyParams.cs @@ -14,5 +14,7 @@ namespace Discord.API.Gateway public int LargeThreshold { get; set; } [JsonProperty("compress")] public bool UseCompression { get; set; } + [JsonProperty("shard", NullValueHandling = NullValueHandling.Ignore)] + public int[] ShardingParams { get; set; } } } diff --git a/src/Discord.Net/DiscordSocketClient.cs b/src/Discord.Net/DiscordSocketClient.cs index 3d485d7e5..72d48079f 100644 --- a/src/Discord.Net/DiscordSocketClient.cs +++ b/src/Discord.Net/DiscordSocketClient.cs @@ -166,7 +166,7 @@ namespace Discord if (_sessionId != null) await ApiClient.SendResumeAsync(_sessionId, _lastSeq).ConfigureAwait(false); else - await ApiClient.SendIdentifyAsync().ConfigureAwait(false); + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards:TotalShards).ConfigureAwait(false); await _connectTask.Task.ConfigureAwait(false); _canReconnect = true; @@ -534,7 +534,7 @@ namespace Discord _sessionId = null; _lastSeq = 0; - await ApiClient.SendIdentifyAsync().ConfigureAwait(false); + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); } break; case GatewayOpCode.Reconnect: From 4e75b086e17319617f3727302c8cfcbe80577937 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 29 Jul 2016 12:09:50 -0700 Subject: [PATCH 3/3] Using Optional now. --- src/Discord.Net/API/DiscordSocketApiClient.cs | 3 ++- src/Discord.Net/API/Gateway/IdentifyParams.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net/API/DiscordSocketApiClient.cs b/src/Discord.Net/API/DiscordSocketApiClient.cs index f6040081e..be149607d 100644 --- a/src/Discord.Net/API/DiscordSocketApiClient.cs +++ b/src/Discord.Net/API/DiscordSocketApiClient.cs @@ -191,8 +191,9 @@ namespace Discord.API Properties = props, LargeThreshold = largeThreshold, UseCompression = useCompression, - ShardingParams = totalShards > 1 ? new int[] { shardID, totalShards } : null }; + if (totalShards > 1) + msg.ShardingParams = new int[] { shardID, totalShards }; await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); } diff --git a/src/Discord.Net/API/Gateway/IdentifyParams.cs b/src/Discord.Net/API/Gateway/IdentifyParams.cs index 26e2952a1..2681b6708 100644 --- a/src/Discord.Net/API/Gateway/IdentifyParams.cs +++ b/src/Discord.Net/API/Gateway/IdentifyParams.cs @@ -14,7 +14,7 @@ namespace Discord.API.Gateway public int LargeThreshold { get; set; } [JsonProperty("compress")] public bool UseCompression { get; set; } - [JsonProperty("shard", NullValueHandling = NullValueHandling.Ignore)] - public int[] ShardingParams { get; set; } + [JsonProperty("shard")] + public Optional ShardingParams { get; set; } } }