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