initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user