Beispiel #1
0
        public override void HandlePacket(IPacketStream packet)
        {
            if (this.Socket == null)
            {
                _logger.LogTrace("Skip to handle packet. Reason: client is no more connected.");
                return;
            }

            try
            {
                PacketDeserializeHandler handler;

                if (PacketHandlers.TryGetValue(packet.PacketType, out handler))
                {
                    var deserializedPacket = handler.Invoke(packet);
                    OnPacketArrived?.Invoke(this, deserializedPacket);
                }
                else
                {
                    if (Enum.IsDefined(typeof(PacketType), packet.PacketType))
                    {
                        _logger.LogWarning("Received an unimplemented packet {0} from {1}.", packet.PacketType, this.RemoteEndPoint);
                    }
                    else
                    {
                        _logger.LogWarning("Received an unknown packet 0x{0} from {1}.", ((ushort)packet.PacketType).ToString("X2"), this.RemoteEndPoint);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.LogError("Packet handle error from {0}. {1}", this.RemoteEndPoint, exception.Message);
                _logger.LogDebug(exception.InnerException?.StackTrace);
            }
        }
Beispiel #2
0
        public override void HandlePacket(IPacketStream packet)
        {
            PacketDeserializeHandler handler;

            if (PacketHandlers.TryGetValue(packet.PacketType, out handler))
            {
                var deserializedPacket = handler.Invoke(packet);
                OnPacketArrived?.Invoke(deserializedPacket);
            }
            else
            {
                if (Enum.IsDefined(typeof(PacketType), packet.PacketType))
                {
                    this.logger.LogWarning("Received an unimplemented packet {0}.", packet.PacketType);
                }
                else
                {
                    this.logger.LogWarning("Received an unknown packet 0x{0}.", ((ushort)packet.PacketType).ToString("X2"));
                }
            }
        }