diff --git a/NosCore.Networking.sln.DotSettings b/NosCore.Networking.sln.DotSettings
index 53bb462..6e70b1b 100644
--- a/NosCore.Networking.sln.DotSettings
+++ b/NosCore.Networking.sln.DotSettings
@@ -8,4 +8,5 @@
-----------------------------------
True
False
- True
\ No newline at end of file
+ True
+ True
\ No newline at end of file
diff --git a/src/NosCore.Networking/BroadcastableExtension.cs b/src/NosCore.Networking/BroadcastableExtension.cs
index dd186c7..ee413a6 100644
--- a/src/NosCore.Networking/BroadcastableExtension.cs
+++ b/src/NosCore.Networking/BroadcastableExtension.cs
@@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using DotNetty.Transport.Channels.Groups;
using NosCore.Networking.SessionGroup;
using NosCore.Packets.Interfaces;
@@ -34,9 +33,9 @@ public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket pac
///
/// The broadcastable group to send the packet to.
/// The packet to send.
- /// The channel matcher to filter recipients.
+ /// The session matcher to filter recipients.
/// A task representing the asynchronous send operation.
- public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher)
+ public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet, ISessionMatcher matcher)
{
return channelGroup.SendPacketsAsync(new[] { packet }, matcher);
}
@@ -46,29 +45,39 @@ public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket pac
///
/// The broadcastable group to send the packets to.
/// The collection of packets to send.
- /// The optional channel matcher to filter recipients.
+ /// The optional session matcher to filter recipients.
/// A task representing the asynchronous send operation.
public static async Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable packets,
- IChannelMatcher? matcher)
+ ISessionMatcher? matcher)
{
var packetDefinitions = (packets as IPacket[] ?? packets).Where(c => c != null).ToArray();
- if (packetDefinitions.Any())
+ if (packetDefinitions.Length == 0)
{
- Parallel.ForEach(packets, packet => channelGroup.LastPackets.Enqueue(packet));
- Parallel.For(0, channelGroup.LastPackets.Count - channelGroup.MaxPacketsBuffer, (_, __) => channelGroup.LastPackets.TryDequeue(out var ___));
- if (channelGroup.Sessions == null!)
- {
- return;
- }
+ return;
+ }
+
+ foreach (var packet in packetDefinitions)
+ {
+ channelGroup.LastPackets.Enqueue(packet);
+ }
+
+ while (channelGroup.LastPackets.Count > channelGroup.MaxPacketsBuffer)
+ {
+ channelGroup.LastPackets.TryDequeue(out _);
+ }
- if (matcher == null)
- {
- await channelGroup.Sessions.Broadcast(packetDefinitions).ConfigureAwait(false);
- }
- else
- {
- await channelGroup.Sessions.Broadcast(packetDefinitions, matcher).ConfigureAwait(false);
- }
+ if (channelGroup.Sessions == null!)
+ {
+ return;
+ }
+
+ if (matcher == null)
+ {
+ await channelGroup.Sessions.Broadcast(packetDefinitions).ConfigureAwait(false);
+ }
+ else
+ {
+ await channelGroup.Sessions.Broadcast(packetDefinitions, matcher).ConfigureAwait(false);
}
}
diff --git a/src/NosCore.Networking/Encoding/Filter/RequestFilter.cs b/src/NosCore.Networking/Encoding/Filter/RequestFilter.cs
index d4d13ad..7827a28 100644
--- a/src/NosCore.Networking/Encoding/Filter/RequestFilter.cs
+++ b/src/NosCore.Networking/Encoding/Filter/RequestFilter.cs
@@ -1,43 +1,25 @@
-// __ _ __ __ ___ __ ___ ___
+// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
// -----------------------------------
using System;
-using System.Collections.Generic;
-using DotNetty.Buffers;
-using DotNetty.Codecs;
-using DotNetty.Transport.Channels;
+using System.Net;
namespace NosCore.Networking.Encoding.Filter
{
///
- /// Abstract base class for request filters that process incoming byte data.
+ /// Defines a request filter that processes incoming byte data.
///
- public abstract class RequestFilter : MessageToMessageDecoder
+ public interface IRequestFilter
{
///
/// Filters incoming request data.
///
- /// The channel handler context.
+ /// The remote endpoint of the connection.
/// The incoming message bytes.
/// The filtered byte array, or null if the request should be blocked.
- public abstract byte[]? Filter(IChannelHandlerContext context, Span message);
-
- ///
- /// Decodes the incoming byte buffer through the filter.
- ///
- /// The channel handler context.
- /// The byte buffer to decode.
- /// The output list to add filtered results to.
- protected override void Decode(IChannelHandlerContext context, IByteBuffer message, List