/// <summary> /// build message from raw data /// </summary> /// <param name="rawdata"></param> public PackedMessage(byte[] rawdata) : this() { if (FidonetHelpers.GetUShort(rawdata, 0) != 2) { return; } orig.node = FidonetHelpers.GetUShort(rawdata, 2); dest.node = FidonetHelpers.GetUShort(rawdata, 4); orig.net = FidonetHelpers.GetUShort(rawdata, 6); dest.net = FidonetHelpers.GetUShort(rawdata, 8); attr = new MsgAttributes(FidonetHelpers.GetUShort(rawdata, 10)); Cost = FidonetHelpers.GetUShort(rawdata, 12); Timestamp = FidonetHelpers.BytesToString(rawdata, 14, 20); int ptr = 34; DestUser = FidonetHelpers.NullTerminatedBytesToString(rawdata, ptr); ptr += DestUser.Length + 1; FromUser = FidonetHelpers.NullTerminatedBytesToString(rawdata, ptr); ptr += FromUser.Length + 1; Subject = FidonetHelpers.NullTerminatedBytesToString(rawdata, ptr); ptr += Subject.Length + 1; Text = new MsgText(FidonetHelpers.NullTerminatedBytesToString(rawdata, ptr)); }
/// <summary> /// Empty constructor /// </summary> public PackedMessage() { orig = new FidoAddress(); dest = new FidoAddress(); attr = new MsgAttributes(); Cost = 0; FromUser = string.Empty; DestUser = string.Empty; Text = new MsgText(); Timestamp = FidonetHelpers.FidoFormatDatetime(DateTime.Now); }
/// <summary> /// Parses packet from raw data /// </summary> /// <param name="rawdata"></param> public MsgPacket(byte[] rawdata) : this() { if (FidonetHelpers.GetUShort(rawdata, 18) != 2) { return; } orig.node = FidonetHelpers.GetUShort(rawdata, 0); dest.node = FidonetHelpers.GetUShort(rawdata, 2); orig.net = FidonetHelpers.GetUShort(rawdata, 20); dest.net = FidonetHelpers.GetUShort(rawdata, 22); orig.zone = FidonetHelpers.GetUShort(rawdata, 34); dest.zone = FidonetHelpers.GetUShort(rawdata, 36); Baud = FidonetHelpers.GetUShort(rawdata, 16); Timestamp = new DateTime(FidonetHelpers.GetUShort(rawdata, 4), FidonetHelpers.GetUShort(rawdata, 6) + 1, FidonetHelpers.GetUShort(rawdata, 8), FidonetHelpers.GetUShort(rawdata, 10), FidonetHelpers.GetUShort(rawdata, 12), FidonetHelpers.GetUShort(rawdata, 14)); Password = FidonetHelpers.BytesToString(rawdata, 24, 8); // Scan messages int ptr = 58; while (FidonetHelpers.GetUShort(rawdata, ptr) == 2) { int end = ptr + 34; // skip msg header int zerofound = 0; while (zerofound < 4) { if (rawdata[end] == 0) { zerofound++; } end++; } byte[] msg = new byte[end - ptr]; Array.Copy(rawdata, ptr, msg, 0, end - ptr); AddMessage(msg); ptr = end; } }