Files
crysome/Crysome.Server/Crysome.Server.Network/PacketChannel.cs
T
2026-08-27 11:22:54 -06:00

30 lines
688 B
C#

using System;
using System.Collections.Generic;
using Crysome.Common.Network;
using Crysome.Common.Network.Packets;
namespace Crysome.Server.Network;
public class PacketChannel
{
public readonly Dictionary<Type, Action<CrysomeClient, IPacket>> Handlers;
public PacketChannel()
{
Handlers = new Dictionary<Type, Action<CrysomeClient, IPacket>>();
}
public void HandlePacket(CrysomeClient sender, IPacket packet)
{
if (Handlers.TryGetValue(((object)packet).GetType(), out var value))
{
value(sender, packet);
}
}
public void RegisterHandler<TPacket>(Action<CrysomeClient, IPacket> handler)
{
Handlers[typeof(TPacket)] = handler;
}
}