Exemple #1
0
        /// <summary>
        /// Processes a message received from a chat room -- SNAC(0E,06)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(0E,06)</param>
        internal void ProcessIncomingMessage(DataPacket dp)
        {
            UserInfo sender = new UserInfo();

            byte[]   message;
            Encoding encoding = Encoding.ASCII;
            string   language = "";

            byte[] cookie  = dp.Data.ReadByteArray(8);
            ushort channel = dp.Data.ReadUshort();

            using (TlvBlock outerTlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd()))
            {
                using (ByteStream userStream = new ByteStream(outerTlvs.ReadByteArray(0x0003)))
                {
                    sender = userStream.ReadUserInfo();
                }

                using (TlvBlock innerTlvs = new TlvBlock(outerTlvs.ReadByteArray(0x0005)))
                {
                    message  = innerTlvs.ReadByteArray(0x0001);
                    encoding = Marshal.AolMimeToEncoding(innerTlvs.ReadString(0x0002, Encoding.ASCII));
                    language = innerTlvs.ReadString(0x0003, Encoding.ASCII);
                }
            }

            if (MessageReceived != null)
            {
                IM msg = new IM(sender);
                msg.Message = Encoding.Unicode.GetString(Encoding.Convert(encoding, Encoding.Unicode, message));
                msg.Cookie  = Cookie.GetReceivedCookie(cookie);
                MessageReceived(this, new MessageReceivedEventArgs(msg));
            }
        }
Exemple #2
0
        /// <summary>
        /// Processes user information sent by the server -- SNAC(02,06)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(02,06)</param>
        private void ProcessUserInfo(DataPacket dp)
        {
            if (dp.SNAC.Flags != 0)
            {
                Logging.DumpFLAP(dp.Data.GetBytes(), "You've got to be s******g me");
            }

            // Apparently, the userinfo block will always be first,
            // and then possibly TLVs 0x0001 - 0x0005, depending on the request
            byte[]   awaymessage         = null;
            Encoding awaymessageencoding = Encoding.ASCII;

            byte[]       profile         = null;
            Encoding     profileencoding = Encoding.ASCII;
            Capabilities caps            = Capabilities.None;

            UserInfo ui = dp.Data.ReadUserInfo();

            using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd()))
            {
                profileencoding     = Marshal.AolMimeToEncoding(tlvs.ReadString(LOCATION_PROFILE_ENCODING, Encoding.ASCII));
                profile             = tlvs.ReadByteArray(LOCATION_PROFILE);
                awaymessageencoding = Marshal.AolMimeToEncoding(tlvs.ReadString(LOCATION_AWAYMESSAGE_ENCODING, Encoding.ASCII));
                awaymessage         = tlvs.ReadByteArray(LOCATION_AWAYMESSAGE);
                caps = CapabilityProcessor.ProcessCLSIDList(tlvs.ReadByteArray(LOCATION_CAPABILITIES));
            }

            UserInfoResponse uir = new UserInfoResponse();

            uir.Info = ui;
            if (profile != null)
            {
                uir.Profile         = profileencoding.GetString(profile, 0, profile.Length);
                uir.ProfileEncoding = profileencoding;
            }
            if (awaymessage != null)
            {
                uir.AwayMessage         = awaymessageencoding.GetString(awaymessage, 0, awaymessage.Length);
                uir.AwayMessageEncoding = awaymessageencoding;
            }
            uir.ClientCapabilities = caps;

            if (UserInfoReceived != null)
            {
                UserInfoReceived(this, uir);
            }
        }