Exemple #1
0
        public void StopAllActionsPacket_Initialization()
        {
            const InboundPacketType ExpectedPacketType = InboundPacketType.StopAllActions;

            IActionWithoutContentInfo actionWithoutContentInfo = new StopAllActionsPacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Exemple #2
0
        public void AutoMoveCancelPacket_Initialization()
        {
            const InboundPacketType ExpectedPacketType = InboundPacketType.AutoMoveCancel;

            IActionWithoutContentInfo actionWithoutContentInfo = new AutoMoveCancelPacket();

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

            IActionWithoutContentInfo actionWithoutContentInfo = new HeartbeatResponsePacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Exemple #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(InboundPacketType forPacketType)
        {
            if (this.packetReadersMap.TryGetValue(forPacketType, out IPacketReader reader))
            {
                return(reader);
            }

            return(null);
        }
Exemple #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(InboundPacketType 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;
        }