예제 #1
0
        /// <summary>
        /// Creates an ODC2 packet for sending
        /// </summary>
        /// <returns></returns>
        public byte[] ToByteArray()
        {
            int      headerlength = 76, index = 0;
            Encoding encoding   = UtilityMethods.FindBestOscarEncoding(Message);
            int      datalength = encoding.GetByteCount(Message);
            int      buffersize = headerlength + datalength;

            byte[] packet = new byte[buffersize];
            ushort charset = 0, charsubset = 0;

            Marshal.InsertString(packet, "ODC2", Encoding.ASCII, ref index);
            Marshal.InsertUshort(packet, 0x004C, ref index);
            Marshal.InsertUint(packet, 0x00010006, ref index);
            index = 12;
            Marshal.CopyArray(Connection.Cookie.ToByteArray(), packet, 0, ref index);
            index = 28;
            Marshal.InsertUint(packet, (uint)(datalength + GetAttachmentDataLength()), ref index);
            GetCharsetCodesFromEncoding(encoding, out charset, out charsubset);
            Marshal.InsertUshort(packet, charset, ref index);
            Marshal.InsertUshort(packet, charsubset, ref index);
            Marshal.InsertUint(packet, 0x00000060, ref index);
            index = 44;
            Marshal.InsertString(packet, ScreenName, Encoding.ASCII, ref index);
            Marshal.CopyArray(encoding.GetBytes(Message), packet, 0, 76);
            return(packet);
        }