@@ -18,5 +18,7 @@ namespace Discord.API.Client.GatewaySocket | |||||
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 int[] ShardingParams { get; set; } | |||||
} | } | ||||
} | } |
@@ -47,6 +47,11 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public int LargeThreshold { get; set; } = 250; | public int LargeThreshold { get; set; } = 250; | ||||
/// <summary> Gets or sets the id for this shard. Must be less than TotalShards. </summary> | |||||
public int ShardId { get; set; } = 0; | |||||
/// <summary> Gets or sets the total number of shards for this application. </summary> | |||||
public int TotalShards { get; set; } = 1; | |||||
//Events | //Events | ||||
/// <summary> Gets or sets a handler for all log messages. </summary> | /// <summary> Gets or sets a handler for all log messages. </summary> | ||||
@@ -89,6 +94,9 @@ namespace Discord | |||||
public bool UsePermissionsCache { get; } | public bool UsePermissionsCache { get; } | ||||
public bool EnablePreUpdateEvents { get; } | public bool EnablePreUpdateEvents { get; } | ||||
public int ShardId { get; } | |||||
public int TotalShards { get; } | |||||
internal DiscordConfig(DiscordConfigBuilder builder) | internal DiscordConfig(DiscordConfigBuilder builder) | ||||
{ | { | ||||
LogLevel = builder.LogLevel; | LogLevel = builder.LogLevel; | ||||
@@ -106,6 +114,8 @@ namespace Discord | |||||
MessageCacheSize = builder.MessageCacheSize; | MessageCacheSize = builder.MessageCacheSize; | ||||
UsePermissionsCache = builder.UsePermissionsCache; | UsePermissionsCache = builder.UsePermissionsCache; | ||||
EnablePreUpdateEvents = builder.EnablePreUpdateEvents; | EnablePreUpdateEvents = builder.EnablePreUpdateEvents; | ||||
ShardId = builder.ShardId; | |||||
TotalShards = builder.TotalShards; | |||||
} | } | ||||
private static string GetUserAgent(DiscordConfigBuilder builder) | private static string GetUserAgent(DiscordConfigBuilder builder) | ||||
@@ -51,6 +51,9 @@ namespace Discord.Net.Rest | |||||
} | } | ||||
} | } | ||||
public int ShardId => _config.ShardId; | |||||
public int TotalShards => _config.TotalShards; | |||||
protected RestClient(DiscordConfig config, string baseUrl, ILogger logger = null) | protected RestClient(DiscordConfig config, string baseUrl, ILogger logger = null) | ||||
{ | { | ||||
_config = config; | _config = config; | ||||
@@ -50,7 +50,7 @@ namespace Discord.Net.WebSockets | |||||
Host = url; | Host = url; | ||||
await BeginConnect(parentCancelToken).ConfigureAwait(false); | await BeginConnect(parentCancelToken).ConfigureAwait(false); | ||||
if (SessionId == null) | if (SessionId == null) | ||||
SendIdentify(_rest.Token); | |||||
SendIdentify(_rest.Token, _rest.ShardId, _rest.TotalShards); | |||||
else | else | ||||
SendResume(); | SendResume(); | ||||
} | } | ||||
@@ -148,7 +148,7 @@ namespace Discord.Net.WebSockets | |||||
} | } | ||||
} | } | ||||
public void SendIdentify(string token) | |||||
public void SendIdentify(string token, int shardId = 0, int totalShards = 1) | |||||
{ | { | ||||
var props = new Dictionary<string, string> | var props = new Dictionary<string, string> | ||||
{ | { | ||||
@@ -159,9 +159,11 @@ namespace Discord.Net.WebSockets | |||||
Token = token, | Token = token, | ||||
Properties = props, | Properties = props, | ||||
LargeThreshold = _config.LargeThreshold, | LargeThreshold = _config.LargeThreshold, | ||||
UseCompression = true | |||||
UseCompression = true, | |||||
ShardingParams = new int[] { shardId, totalShards }, | |||||
}; | }; | ||||
QueueMessage(msg); | |||||
QueueMessage(msg); | |||||
} | } | ||||
public void SendResume() | public void SendResume() | ||||