Exemplo n.º 1
0
        public void FirePacket(IInPacket packet)
        {
            var methods = GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)
                          .Where(m => m.GetCustomAttributes(typeof(PacketMethodAttribute), false).Length > 0)
                          .ToImmutableArray();
            var packetMethod =
                methods.FirstOrDefault(m => m.GetParameters().All(p => p.ParameterType == packet.GetType()));

            if (packetMethod == null)
            {
                packetMethod = GetType().GetMethod(nameof(Fallback));
            }

            if (packetMethod == null)
            {
                throw new NullReferenceException("Fallback method is null");
            }

            var attr = packetMethod.GetCustomAttribute <PacketMethodAttribute>(true);

            if (attr.RunAsync)
            {
                Task.Run(() => packetMethod.Invoke(this, new object[] { packet }));
            }
            else
            {
                packetMethod.Invoke(this, new object[] { packet });
            }
        }
Exemplo n.º 2
0
 public abstract void Fallback(IInPacket packet);
Exemplo n.º 3
0
 public override void Fallback(IInPacket packet)
 {
     _logger.Info($"Unknown packet received! {packet.GetType().FullName}");
 }