Esempio n. 1
0
        public void AutoMoveCancelPacket_Initialization()
        {
            const IncomingPacketType ExpectedPacketType = IncomingPacketType.AutoMoveCancel;

            IActionWithoutContentInfo actionWithoutContentInfo = new AutoMoveCancelPacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Esempio n. 2
0
        public void StopAllActionsPacket_Initialization()
        {
            const IncomingPacketType ExpectedPacketType = IncomingPacketType.StopAllActions;

            IActionWithoutContentInfo actionWithoutContentInfo = new StopAllActionsPacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Esempio n. 3
0
        public void HeartbeatResponsePacket_Initialization()
        {
            const IncomingPacketType ExpectedPacketType = IncomingPacketType.HeartbeatResponse;

            IActionWithoutContentInfo actionWithoutContentInfo = new HeartbeatResponsePacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Esempio n. 4
0
        /// <summary>
        /// Selects the most appropriate packet reader for the specified type.
        /// </summary>
        /// <param name="forPacketType">The type of packet.</param>
        /// <returns>An instance of an <see cref="IPacketReader"/> implementation.</returns>
        public IPacketReader SelectPacketReader(IncomingPacketType forPacketType)
        {
            if (this.packetReadersMap.TryGetValue(forPacketType, out IPacketReader reader))
            {
                return(reader);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers a packet reader to this protocol.
        /// </summary>
        /// <param name="forType">The type of packet to register for.</param>
        /// <param name="packetReader">The packet reader to register.</param>
        public void RegisterPacketReader(IncomingPacketType forType, IPacketReader packetReader)
        {
            packetReader.ThrowIfNull(nameof(packetReader));

            if (this.packetReadersMap.ContainsKey(forType))
            {
                throw new InvalidOperationException($"There is already a reader registered for the packet type {forType}.");
            }

            this.logger.LogTrace($"Registered packet reader for type {forType}.");

            this.packetReadersMap[forType] = packetReader;
        }
Esempio n. 6
0
        /// <summary>
        /// Constructs a new reader and tries to determine the internal header from the packet.
        /// </summary>
        /// <param name="data">The raw packet data</param>
        /// <param name="type">The type of incoming packet</param>
        public PacketReader(ref byte[] data, IncomingPacketType type)
        {
            DataBuffer = data;
            Type       = type;

            switch (type)
            {
            case IncomingPacketType.StaticHeader:
                InternalHeader = ExternalHeader;
                Position      += 2;
                break;

            case IncomingPacketType.DynamicHeader:
                Position += 2;
                break;

            case IncomingPacketType.NoHeader:
            default:
                InternalHeader = 0xFFFF;
                break;
            }
        }
Esempio n. 7
0
 public SplitPacket(IncomingPacketType type, byte[] packet)
 {
     this.Type   = type;
     this.Packet = packet;
 }
Esempio n. 8
0
 public SplitPacket(IncomingPacketType type, byte[] packet)
 {
     this.Type = type;
     this.Packet = packet;
 }