Beispiel #1
0
        public void AutoMoveCancelPacket_Initialization()
        {
            const IncomingGamePacketType ExpectedPacketType = IncomingGamePacketType.AutoMoveCancel;

            IActionWithoutContentInfo actionWithoutContentInfo = new AutoMoveCancelPacket();

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

            IActionWithoutContentInfo actionWithoutContentInfo = new HeartbeatResponsePacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Beispiel #3
0
        public void StopAllActionsPacket_Initialization()
        {
            const IncomingGamePacketType ExpectedPacketType = IncomingGamePacketType.StopAllActions;

            IActionWithoutContentInfo actionWithoutContentInfo = new StopAllActionsPacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Beispiel #4
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(byte forType, IPacketReader packetReader)
        {
            packetReader.ThrowIfNull(nameof(packetReader));

            if (!Enum.IsDefined(typeof(IncomingGamePacketType), forType))
            {
                throw new InvalidOperationException($"Unsupported packet type {forType:x2}. Check the types defined in {nameof(IncomingGamePacketType)}.");
            }

            IncomingGamePacketType packetType = (IncomingGamePacketType)forType;

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

            this.logger.Verbose($"Registered packet reader for type {packetType}.");

            this.packetReadersMap[packetType] = packetReader;
        }