예제 #1
0
        /// <summary>
        /// Sets the away message and/or profile of the client
        /// </summary>
        /// <param name="awayMessage">The away message to set</param>
        /// <param name="profile">The profile to set</param>
        private void SetAwayMessageProfileInternal(string awayMessage, string profile)
        {
            // Build the SNAC header
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = SNAC_LOCATION_FAMILY;
            sh.FamilySubtypeID = LOCATION_PARAMETER_USERINFO;

            ByteStream stream = new ByteStream();

            using (TlvBlock tlvs = new TlvBlock())
            {
                if (profile != null)
                {
                    Encoding profileEncoding = UtilityMethods.FindBestOscarEncoding(profile);
                    tlvs.WriteString(LOCATION_PROFILE_ENCODING, Marshal.EncodingToAolMime(profileEncoding), Encoding.ASCII);
                    tlvs.WriteString(LOCATION_PROFILE, profile, profileEncoding);
                }
                if (awayMessage != null)
                {
                    Encoding awayMessageEncoding = UtilityMethods.FindBestOscarEncoding(awayMessage);
                    tlvs.WriteString(LOCATION_AWAYMESSAGE_ENCODING, Marshal.EncodingToAolMime(awayMessageEncoding),
                                     Encoding.ASCII);
                    tlvs.WriteString(LOCATION_AWAYMESSAGE, awayMessage, awayMessageEncoding);
                }
                stream.WriteByteArray(tlvs.GetBytes());
            }

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
예제 #2
0
        /// <summary>
        /// Send a message to this chatroom using a specific character set and language
        /// </summary>
        /// <param name="message">The message to send</param>
        /// <param name="charset">The character set in which to encode the message</param>
        /// <param name="language">The two-letter code of the language of the message</param>
        private void SendMessage(string message, Encoding charset, string language)
        {
            if (!Connection.Connected)
            {
                // TODO:  The semantics here aren't right
                throw new NotLoggedInException();
            }

            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = 0x000E;
            sh.FamilySubtypeID = (ushort)ChatService.MessageFromClient;

            byte[] cookie = new byte[8];
            Random r      = new Random();

            r.NextBytes(cookie);

            ByteStream stream = new ByteStream();

            stream.WriteByteArray(cookie);
            stream.WriteUshort(0x0003);

            TlvBlock tlvs = new TlvBlock();

            using (TlvBlock messageBlock = new TlvBlock())
            {
                Encoding messageEncoding = UtilityMethods.FindBestOscarEncoding(message);

                messageBlock.WriteString(CHATMESSAGE_MESSAGE, message, messageEncoding);
                messageBlock.WriteString(CHATMESSAGE_CHARSET,
                                         UtilityMethods.OscarEncodingToString(messageEncoding), Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_LANGUAGE, language, Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_CONTENTTYPE, "text/x-aolrtf", Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_ENCODING, "binary", Encoding.ASCII);

                tlvs.WriteByteArray(0x0005, messageBlock.GetBytes());
            }
            tlvs.WriteEmpty(0x0001);

            stream.WriteTlvBlock(tlvs);

            DataPacket dp = Marshal.BuildDataPacket(Connection.ParentSession, sh, stream);

            dp.ParentConnection = Connection;
            SNACFunctions.BuildFLAP(dp);
        }
예제 #3
0
        /// <summary>
        /// Sends authorization request -- SNAC(17,02)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(17,07)</param>
        void SendAuthorizationRequest(DataPacket dp)
        {
            // Pull apart SNAC(17,07)
            byte[] key = dp.Data.ReadByteArray(dp.Data.ReadUshort());

            // Construct SNAC(17,02)
            SNACHeader header = new SNACHeader();

            header.FamilyServiceID = SNAC_AUTH_FAMILY;
            header.FamilySubtypeID = AUTH_LOGIN_REQUEST;

            OSCARIdentification id = parent.ClientIdentification;

            ByteStream stream = new ByteStream();

            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteString(0x0001, parent.ScreenName, Encoding.ASCII);
                tlvs.WriteString(0x0003, id.ClientName, Encoding.ASCII);
                tlvs.WriteString(0x000F, "en", Encoding.ASCII);
                tlvs.WriteString(0x000E, "us", Encoding.ASCII);
                tlvs.WriteUint(0x0014, id.ClientDistribution);
                tlvs.WriteUshort(0x0016, id.ClientId);
                tlvs.WriteUshort(0x0017, id.ClientMajor);
                tlvs.WriteUshort(0x0018, id.ClientMinor);
                tlvs.WriteUshort(0x0019, id.ClientLesser);
                tlvs.WriteUshort(0x001A, id.ClientBuild);
                tlvs.WriteByteArray(0x0025, parent.HashPassword(key));
                tlvs.WriteByte(0x004A, 0x01);
                tlvs.WriteEmpty(0x004C);
                stream.WriteTlvBlock(tlvs);
            }

            DataPacket newPacket = Marshal.BuildDataPacket(parent, header, stream);

            newPacket.ParentConnection = dp.ParentConnection;
            SNACFunctions.BuildFLAP(newPacket);
        }
예제 #4
0
        /// <summary>
        /// Writes the ChatRoomInfo's parameters to a byte stream for transmission
        /// </summary>
        internal void WriteToByteStream(ByteStream stream)
        {
            // Write the basic info header
            stream.WriteUshort(exchangeNumber);
            stream.WriteByte((byte)"create".Length);
            stream.WriteString("create", Encoding.ASCII);
            stream.WriteUshort(instance);

            // Write details
            stream.WriteByte(0x01);     // Detail level
            stream.WriteUshort(0x0003); // An unknown code, AIM 5.9 sets this to 0x0003
            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteString(CHATROOM_CHARSET1, UtilityMethods.OscarEncodingToString(charSet1), Encoding.ASCII);
                tlvs.WriteString(CHATROOM_DISPLAYNAME, displayName, Encoding.ASCII);
                tlvs.WriteString(CHATROOM_LANGUAGE1, language1, Encoding.ASCII);

                // Everything else is optional
                if (contentType != "text/x-aolrtf")
                {
                    tlvs.WriteString(CHATROOM_CONTENTTYPE, contentType, Encoding.ASCII);
                }

                if (Flags != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_FLAGS, Flags);
                }
                if (MaxMessageLength != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_MESSAGE_LENGTH, MaxMessageLength);
                }
                if (MaxOccupants != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_MAX_OCCUPANTS, MaxOccupants);
                }
                if (CreationPermissions != 0xFF)
                {
                    tlvs.WriteByte(CHATROOM_PERMISSIONS, CreationPermissions);
                }
                if (charSet2 != null)
                {
                    tlvs.WriteString(CHATROOM_CHARSET2, charSet2.WebName, Encoding.ASCII);
                }
                if (!String.IsNullOrEmpty(language2))
                {
                    tlvs.WriteString(CHATROOM_LANGUAGE2, language2, Encoding.ASCII);
                }

                //stream.WriteUshort((ushort) tlvs.GetByteCount());
                stream.WriteTlvBlock(tlvs);
            }
        }
예제 #5
0
        /// <summary>
        /// Kicks off the authorization hash request when the initial connection is complete
        /// </summary>
        void loginConnection_ServerConnectionCompleted(Connection conn)
        {
            conn.ReadyForData = true;

            /*** Send SNAC(17,06) to get the auth key ***/
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = SNAC_AUTH_FAMILY;
            sh.FamilySubtypeID = AUTH_KEY_REQUEST;

            ByteStream stream = new ByteStream();

            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteString(0x0001, parent.ScreenName, Encoding.ASCII);
                tlvs.WriteEmpty(0x004B);
                tlvs.WriteEmpty(0x005A);
                stream.WriteTlvBlock(tlvs);
            }

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));

            conn.ReadHeader();
        }
예제 #6
0
        /// <summary>
        /// Send a message to this chatroom using a specific character set and language
        /// </summary>
        /// <param name="message">The message to send</param>
        /// <param name="charset">The character set in which to encode the message</param>
        /// <param name="language">The two-letter code of the language of the message</param>
        private void SendMessage(string message, Encoding charset, string language)
        {
            if (!Connection.Connected)
            {
                // TODO:  The semantics here aren't right
                throw new NotLoggedInException();
            }

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = 0x000E;
            sh.FamilySubtypeID = (ushort) ChatService.MessageFromClient;

            byte[] cookie = new byte[8];
            Random r = new Random();
            r.NextBytes(cookie);

            ByteStream stream = new ByteStream();
            stream.WriteByteArray(cookie);
            stream.WriteUshort(0x0003);

            TlvBlock tlvs = new TlvBlock();
            using (TlvBlock messageBlock = new TlvBlock())
            {
                Encoding messageEncoding = UtilityMethods.FindBestOscarEncoding(message);

                messageBlock.WriteString(CHATMESSAGE_MESSAGE, message, messageEncoding);
                messageBlock.WriteString(CHATMESSAGE_CHARSET,
                    UtilityMethods.OscarEncodingToString(messageEncoding), Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_LANGUAGE, language, Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_CONTENTTYPE, "text/x-aolrtf", Encoding.ASCII);
                messageBlock.WriteString(CHATMESSAGE_ENCODING, "binary", Encoding.ASCII);

                tlvs.WriteByteArray(0x0005, messageBlock.GetBytes());
            }
            tlvs.WriteEmpty(0x0001);

            stream.WriteTlvBlock(tlvs);

            DataPacket dp = Marshal.BuildDataPacket(Connection.ParentSession, sh, stream);
            dp.ParentConnection = Connection;
            SNACFunctions.BuildFLAP(dp);
        }
예제 #7
0
        /// <summary>
        /// Writes the ChatRoomInfo's parameters to a byte stream for transmission
        /// </summary>
        internal void WriteToByteStream(ByteStream stream)
        {
            // Write the basic info header
            stream.WriteUshort(exchangeNumber);
            stream.WriteByte((byte) "create".Length);
            stream.WriteString("create", Encoding.ASCII);
            stream.WriteUshort(instance);

            // Write details
            stream.WriteByte(0x01); // Detail level
            stream.WriteUshort(0x0003); // An unknown code, AIM 5.9 sets this to 0x0003
            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteString(CHATROOM_CHARSET1, UtilityMethods.OscarEncodingToString(charSet1), Encoding.ASCII);
                tlvs.WriteString(CHATROOM_DISPLAYNAME, displayName, Encoding.ASCII);
                tlvs.WriteString(CHATROOM_LANGUAGE1, language1, Encoding.ASCII);

                // Everything else is optional
                if (contentType != "text/x-aolrtf")
                {
                    tlvs.WriteString(CHATROOM_CONTENTTYPE, contentType, Encoding.ASCII);
                }

                if (Flags != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_FLAGS, Flags);
                }
                if (MaxMessageLength != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_MESSAGE_LENGTH, MaxMessageLength);
                }
                if (MaxOccupants != 0xFFFF)
                {
                    tlvs.WriteUshort(CHATROOM_MAX_OCCUPANTS, MaxOccupants);
                }
                if (CreationPermissions != 0xFF)
                {
                    tlvs.WriteByte(CHATROOM_PERMISSIONS, CreationPermissions);
                }
                if (charSet2 != null)
                {
                    tlvs.WriteString(CHATROOM_CHARSET2, charSet2.WebName, Encoding.ASCII);
                }
                if (!String.IsNullOrEmpty(language2))
                {
                    tlvs.WriteString(CHATROOM_LANGUAGE2, language2, Encoding.ASCII);
                }

                //stream.WriteUshort((ushort) tlvs.GetByteCount());
                stream.WriteTlvBlock(tlvs);
            }
        }
예제 #8
0
        /// <summary>
        /// Set my icq contact informations.
        /// </summary>
        /// <param name="ui">My Details</param>
        /// <remarks>
        /// <para>The following properties can't be set:</para>
        /// <para><seealso cref="FullUserInfo.Screenname"/>, <seealso cref="FullUserInfo.Email"/> (use <seealso cref="SendUserEmail"/> instead), <seealso cref="FullUserInfo.Age"/>, <seealso cref="FullUserInfo.CodePage"/>,
        /// <seealso cref="FullUserInfo.Timezone"/></para>
        /// </remarks>
        public void SendUserInfo(FullUserInfo ui)
        {
            TlvBlock tlvs = new TlvBlock();

            // Names
            tlvs.WriteString(0x64, ui.Firstname, Encoding.UTF8);
            tlvs.WriteString(0x6e, ui.Lastname, Encoding.UTF8);
            tlvs.WriteString(0x78, ui.Nickname, Encoding.UTF8);

            // Home Address
            tlvs.WriteByteArray(0x96, ProcessDirectoryUpdateRequestUserDetails(0x96, ui));
            // Origin Address
            tlvs.WriteByteArray(0xa0, ProcessDirectoryUpdateRequestUserDetails(0xa0, ui));
            // Phone Numbers
            tlvs.WriteByteArray(0xc8, ProcessDirectoryUpdateRequestUserDetails(0xc8, ui));
            // Emails
            tlvs.WriteByteArray(0x8c, ProcessDirectoryUpdateRequestUserDetails(0x8c, ui));
            // Work
            tlvs.WriteByteArray(0x118, ProcessDirectoryUpdateRequestUserDetails(0x118, ui));
            // Education
            tlvs.WriteByteArray(0x10e, ProcessDirectoryUpdateRequestUserDetails(0x10e, ui));
            // Interests
            tlvs.WriteByteArray(0x122, ProcessDirectoryUpdateRequestUserDetails(0x122, ui));

            // Timezone
            TimeSpan ts = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);

            if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now))
            {
                ts -= TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year).Delta;
            }
            tlvs.WriteSshort(0x17c, (short)(ts.TotalMinutes / -30));

            switch (ui.Gender.ToString().ToUpper())
            {
            case "F": tlvs.WriteByte(0x82, 1); break;

            case "M": tlvs.WriteByte(0x82, 2); break;

            default: tlvs.WriteByte(0x82, 0); break;
            }

            tlvs.WriteString(0xfa, ui.Website, Encoding.ASCII);

            if (ui.Birthday == DateTime.MinValue)
            {
                tlvs.WriteDouble(0x1a4, 0);
            }
            else
            {
                tlvs.WriteDouble(0x1a4, ui.Birthday.ToOADate() - 2);
            }

            tlvs.WriteUshort(0xaa, (ushort)ui.Language1);
            tlvs.WriteUshort(0xb4, (ushort)ui.Language2);
            tlvs.WriteUshort(0xbe, (ushort)ui.Language3);

            tlvs.WriteUshort(0x12c, (ushort)ui.MaritalStatus);
            tlvs.WriteString(0x186, ui.About, Encoding.UTF8);

            tlvs.WriteString(0x226, ui.StatusNote, Encoding.UTF8);
            tlvs.WriteUshort(0x1f9, ui.PrivacyLevel);
            tlvs.WriteUshort(0x19a, ui.Auth);
            tlvs.WriteByte(0x212, ui.WebAware);
            tlvs.WriteByte(0x1ea, ui.AllowSpam);
            tlvs.WriteUshort(0x1c2, (ushort)Encoding.Default.CodePage);     //ui.CodePage

            ByteStream stream = new ByteStream();

            stream.WriteUshort(0x0003);
            stream.WriteUshort((ushort)tlvs.GetByteCount());
            stream.WriteByteArray(tlvs.GetBytes());

            /* * * * * Header * * * * */
            SNACHeader sh = CreateIcqMetaHeader();

            stream = CreateDirectoryHeader(DirectoryRequestType.SetInfoRequest, stream);
            stream = CreateMetaInfoHeader(parent, sh, MetaInfoRequestType.DirectoryUpdateRequest, stream);

            //parent.StoreRequestID(sh.RequestID, DirecotyQueryType.InfoUser);
            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }