Added Sharding support
This commit is contained in:
@@ -179,7 +179,7 @@ namespace Discord.API
|
||||
{
|
||||
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>
|
||||
{
|
||||
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user