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}."); }
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}."); }
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}."); }
/// <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); }
/// <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; }