private static void BanKickMuteWrapper(Guid guid, PacketOption option, string Reason = null) { if (!ClientInfo.IsAdmin) { return; } PacketFormat packet; if (option != PacketOption.UserUnmuted) { if (Reason == null) { Reason = "Place Holder Reason"; } packet = new PacketFormat(option) { Sender = ClientInfo.Guid, Guid = guid, Content = Reason }; } else { packet = new PacketFormat(PacketOption.UserUnmuted) { Sender = ClientInfo.Guid, Guid = guid }; } Send(packet); }
/// <summary> /// The Packet Block is marked obsolete, better use the Enhanced Packet Block instead! /// A Packet Block is the standard container for storing the packets coming from the network. The Packet Block is optional because /// packets can be stored either by means of this block or the Simple Packet Block, which can be used to speed up dump generation. /// </summary> public PacketBlock(short InterfaceID, TimestampHelper Timestamp, byte[] Data, int PacketLength, PacketOption Options, long PositionInStream = 0) { CustomContract.Requires <ArgumentNullException>(Timestamp != null, "Timestamp cannot be null"); CustomContract.Requires <ArgumentNullException>(Options != null, "Options cannot be null"); CustomContract.Requires <ArgumentNullException>(Data != null, "Data cannot be null"); this.InterfaceID = InterfaceID; this.Timestamp = Timestamp; this.PacketLength = PacketLength; this.Data = Data; this.options = Options; this.PositionInStream = PositionInStream; }
public static PacketBlock Parse(BaseBlock baseBlock, Action <Exception> ActionOnException) { CustomContract.Requires <ArgumentNullException>(baseBlock != null, "BaseBlock cannot be null"); CustomContract.Requires <ArgumentNullException>(baseBlock.Body != null, "BaseBlock.Body cannot be null"); CustomContract.Requires <ArgumentException>(baseBlock.BlockType == BaseBlock.Types.Packet, "Invalid packet type"); long positionInStream = baseBlock.PositionInStream; using (Stream stream = new MemoryStream(baseBlock.Body)) { using (BinaryReader binaryReader = new BinaryReader(stream)) { short interfaceID = binaryReader.ReadInt16().ReverseByteOrder(baseBlock.ReverseByteOrder); short dropCount = binaryReader.ReadInt16().ReverseByteOrder(baseBlock.ReverseByteOrder); byte[] timestamp = binaryReader.ReadBytes(8); if (timestamp.Length < 8) { throw new EndOfStreamException("Unable to read beyond the end of the stream"); } TimestampHelper timestampHelper = new TimestampHelper(timestamp, baseBlock.ReverseByteOrder); int capturedLength = binaryReader.ReadInt32().ReverseByteOrder(baseBlock.ReverseByteOrder); int packetLength = binaryReader.ReadInt32().ReverseByteOrder(baseBlock.ReverseByteOrder); byte[] data = binaryReader.ReadBytes(capturedLength); if (data.Length < capturedLength) { throw new EndOfStreamException("Unable to read beyond the end of the stream"); } int remainderLength = capturedLength % BaseBlock.AlignmentBoundary; if (remainderLength > 0) { int paddingLength = BaseBlock.AlignmentBoundary - remainderLength; binaryReader.ReadBytes(paddingLength); } PacketOption options = PacketOption.Parse(binaryReader, baseBlock.ReverseByteOrder, ActionOnException); PacketBlock packetBlock = new PacketBlock(interfaceID, timestampHelper, data, packetLength, options, positionInStream); return(packetBlock); } } }
public PacketFormat(PacketOption packetOption) => Option = packetOption;