diff --git a/src/GameCult.Networking/CultNetShardReplication.cs b/src/GameCult.Networking/CultNetShardReplication.cs index 88eaac7a..5bc452f2 100644 --- a/src/GameCult.Networking/CultNetShardReplication.cs +++ b/src/GameCult.Networking/CultNetShardReplication.cs @@ -516,6 +516,16 @@ namespace GameCult.Networking /// public TimeSpan ResponseTimeout { get; set; } = TimeSpan.FromSeconds(5); + /// + /// Gets or sets schema ids to request. Null or empty requests every schema allowed by the shard. + /// + public IReadOnlyList? SchemaIds { get; set; } + + /// + /// Gets or sets record keys to request. Null or empty requests every record allowed by the shard/schema filter. + /// + public IReadOnlyList? RecordKeys { get; set; } + /// /// Gets or sets a callback used to customize each ephemeral fetch client. /// @@ -569,7 +579,8 @@ namespace GameCult.Networking client.SendCultNet(new CultNetSnapshotRequestMessage { MessageId = messageId, - SchemaIds = shard.SchemaIds.Count == 0 ? null : shard.SchemaIds.ToArray(), + SchemaIds = ResolveRequestedSchemaIds(shard), + RecordKeys = ResolveRequestedRecordKeys(), ShardId = shard.ShardId, ShardEpoch = shard.Epoch }); @@ -583,6 +594,33 @@ namespace GameCult.Networking ?? CultNetSchemaClients.CreateForEndpoint(endpoint, _options.Security, _options.ConfigureClient); } + private string[]? ResolveRequestedSchemaIds(CultNetShardDescriptor shard) + { + if (_options.SchemaIds is { Count: > 0 }) + { + return _options.SchemaIds + .Where(value => !string.IsNullOrWhiteSpace(value)) + .Distinct(StringComparer.Ordinal) + .ToArray(); + } + + return shard.SchemaIds.Count == 0 ? null : shard.SchemaIds.ToArray(); + } + + private string[]? ResolveRequestedRecordKeys() + { + if (_options.RecordKeys is not { Count: > 0 }) + { + return null; + } + + var recordKeys = _options.RecordKeys + .Where(value => !string.IsNullOrWhiteSpace(value)) + .Distinct(StringComparer.Ordinal) + .ToArray(); + return recordKeys.Length == 0 ? null : recordKeys; + } + private async Task WaitForConnectionAsync(ICultNetSchemaClient client, string endpoint) { var deadline = DateTimeOffset.UtcNow + _options.ConnectTimeout; diff --git a/src/GameCult.Networking/CultNetTransport.cs b/src/GameCult.Networking/CultNetTransport.cs index b4517204..98da8562 100644 --- a/src/GameCult.Networking/CultNetTransport.cs +++ b/src/GameCult.Networking/CultNetTransport.cs @@ -1837,6 +1837,14 @@ namespace GameCult.Networking { return null; } + catch (SocketException error) when ( + error.SocketErrorCode == SocketError.ConnectionReset || + error.SocketErrorCode == SocketError.ConnectionAborted || + error.SocketErrorCode == SocketError.Shutdown) + { + DisconnectReason = Array.Empty(); + return null; + } _stats.BytesReceived += received; if (_remoteEndPoint == null) @@ -2163,6 +2171,13 @@ namespace GameCult.Networking { return null; } + catch (SocketException error) when ( + error.SocketErrorCode == SocketError.ConnectionReset || + error.SocketErrorCode == SocketError.ConnectionAborted || + error.SocketErrorCode == SocketError.Shutdown) + { + return null; + } _stats.BytesReceived += received; var wire = new byte[received];