[ci skip] style: run code cleanup

This commit is contained in:
Oliver Booth 2024-02-12 17:40:15 +00:00
parent 32fecb5ace
commit 0c5c2087b9
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
8 changed files with 38 additions and 32 deletions

View File

@ -239,7 +239,8 @@ public abstract class ClientNode : Node
requestPacket.CallbackId = _callbackIdGenerator.GetId(packetToSend, out _);
var completionSource = new TaskCompletionSource<Packet>();
if (!_packetCompletionSources.TryGetValue(attribute.Id, out List<TaskCompletionSource<Packet>>? completionSources))
if (!_packetCompletionSources.TryGetValue(attribute.Id,
out List<TaskCompletionSource<Packet>>? completionSources))
{
completionSources = new List<TaskCompletionSource<Packet>>();
_packetCompletionSources.TryAdd(attribute.Id, completionSources);
@ -292,7 +293,8 @@ public abstract class ClientNode : Node
if (attribute is null)
throw new ArgumentException($"The packet type {typeof(TPacket).Name} is not a valid packet.");
if (!_packetCompletionSources.TryGetValue(attribute.Id, out List<TaskCompletionSource<Packet>>? completionSources))
if (!_packetCompletionSources.TryGetValue(attribute.Id,
out List<TaskCompletionSource<Packet>>? completionSources))
{
completionSources = new List<TaskCompletionSource<Packet>>();
_packetCompletionSources.TryAdd(attribute.Id, completionSources);

View File

@ -38,7 +38,8 @@ public abstract class Node : IDisposable
/// <value>The registered packets.</value>
public IReadOnlyDictionary<Type, IReadOnlyCollection<PacketHandler>> RegisteredPacketHandlers =>
new ReadOnlyDictionary<Type, IReadOnlyCollection<PacketHandler>>(
_registeredPacketHandlers.ToDictionary(p => p.Key, p => (IReadOnlyCollection<PacketHandler>) p.Value.AsReadOnly()));
_registeredPacketHandlers.ToDictionary(p => p.Key,
p => (IReadOnlyCollection<PacketHandler>)p.Value.AsReadOnly()));
/// <summary>
/// Closes the base socket connection and releases all associated resources.
@ -124,7 +125,8 @@ public abstract class Node : IDisposable
var attribute = packetType.GetCustomAttribute<PacketAttribute>();
if (attribute is null) throw new ArgumentException($"{packetType.Name} is not a valid packet.");
if (_registeredPackets.TryGetValue(attribute.Id, out Type? registeredPacket))
throw new ArgumentException($"The packet type {attribute.Id:X8} is already registered to {registeredPacket.Name}.");
throw new ArgumentException(
$"The packet type {attribute.Id:X8} is already registered to {registeredPacket.Name}.");
_registeredPackets.TryAdd(attribute.Id, packetType);
}

View File

@ -22,7 +22,8 @@ internal sealed class HandshakeRequestPacketHandler : PacketHandler<HandshakeReq
if (packet.ProtocolVersion != Node.ProtocolVersion)
{
response = new HandshakeResponsePacket(packet.ProtocolVersion, HandshakeResponse.UnsupportedProtocolVersion);
response = new HandshakeResponsePacket(packet.ProtocolVersion,
HandshakeResponse.UnsupportedProtocolVersion);
await client.SendPacketAsync(response, cancellationToken);
client.Close();
return;

View File

@ -1,4 +1,4 @@
using System.Net;
using System.Net;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;

View File

@ -35,7 +35,8 @@ public sealed partial class ProtocolListener
foreach (Type packetType in ParentListener.RegisteredPackets.Values)
RegisterPacket(packetType);
foreach ((Type packetType, IReadOnlyCollection<PacketHandler>? handlers) in ParentListener.RegisteredPacketHandlers)
foreach ((Type packetType, IReadOnlyCollection<PacketHandler>? handlers) in ParentListener
.RegisteredPacketHandlers)
foreach (PacketHandler handler in handlers)
RegisterPacketHandler(packetType, handler);