Пример #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 });
            }
        }
Пример #2
0
 public override void Fallback(IInPacket packet)
 {
     _logger.Info($"Unknown packet received! {packet.GetType().FullName}");
 }