Ejemplo n.º 1
0
        private byte[] ProcessDirectoryUpdateRequestUserDetails(int typecode, FullUserInfo ui)
        {
            List <TlvBlock> tlvlist = new List <TlvBlock>();
            ByteStream      bstream = null;

            switch (typecode)
            {
            case 0x96:      // Home Address
                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomeAddress, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.HomeCity, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.HomeState, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x82, ui.HomeZip, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteUint(0x8c, (uint)ui.HomeCountry);
                break;

            case 0xa0:      // Origin Address
                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.OriginCity, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.OriginState, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteUint(0x8c, (uint)ui.OriginCountry);
                break;

            case 0xc8:      // Phone Numbers
                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 1);
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomePhone, Encoding.ASCII);

                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 2);
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkPhone, Encoding.ASCII);

                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 3);
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.MobilePhone, Encoding.ASCII);

                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 4);
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomeFax, Encoding.ASCII);

                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 5);
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkFax, Encoding.ASCII);
                break;

            case 0x8c:      // Emails
                if (ui.EmailAddresses != null)
                {
                    foreach (string email in ui.EmailAddresses)
                    {
                        tlvlist.Add(new TlvBlock());
                        tlvlist[tlvlist.Count - 1].WriteUshort(0x78, 0);
                        tlvlist[tlvlist.Count - 1].WriteString(0x64, email, Encoding.ASCII);
                    }
                }
                break;

            case 0x118:     // Work
                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkPosition, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.WorkCompany, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x7d, ui.WorkDepartment, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.WorkWebsite, Encoding.ASCII);
                tlvlist[tlvlist.Count - 1].WriteUshort(0x82, (ushort)ui.WorkIndustry);

                tlvlist[tlvlist.Count - 1].WriteString(0xaa, ui.WorkAddress, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0xb4, ui.WorkCity, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0xbe, ui.WorkState, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0xc8, ui.WorkZip, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteUint(0xd2, (uint)ui.WorkCountry);
                break;

            case 0x10e:     // Education
                tlvlist.Add(new TlvBlock());
                tlvlist[tlvlist.Count - 1].WriteUshort(0x64, (ushort)ui.StudyLevel);
                tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.StudyInstitute, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.StudyDegree, Encoding.UTF8);
                tlvlist[tlvlist.Count - 1].WriteUshort(0x8c, (ushort)ui.StudyYear);
                break;

            case 0x122:     // Interests
                if (ui.InterestInfos != null)
                {
                    foreach (FullUserInfo.InterestInfo info in ui.InterestInfos)
                    {
                        tlvlist.Add(new TlvBlock());
                        tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, (ushort)info.Category);
                        tlvlist[tlvlist.Count - 1].WriteString(0x64, info.Info, Encoding.UTF8);
                    }
                }
                break;
            }

            switch (typecode)
            {
            case 0x96:      // Home Address
                bstream = writeTlvList(tlvlist, 1);
                break;

            case 0xa0:      // Origin Address
                bstream = writeTlvList(tlvlist, 1);
                break;

            case 0xc8:      // Phone Numbers
                bstream = writeTlvList(tlvlist, 5);
                break;

            case 0x8c:      // Emails
                bstream = writeTlvList(tlvlist, 4);
                break;

            case 0x118:     // Work
                bstream = writeTlvList(tlvlist, 1);
                break;

            case 0x10e:     // Education
                bstream = writeTlvList(tlvlist, 1);
                break;

            case 0x122:     // Interests
                bstream = writeTlvList(tlvlist, 4);
                break;
            }

            return(bstream.GetBytes());
        }
Ejemplo n.º 2
0
        private void ProcessDirectoryQueryResponseUserDetails(Tlv t, ref FullUserInfo ui)
        {
            List <TlvBlock> tlvlist = null;
            ByteStream      bstream = new ByteStream(t.Data);

            switch (t.TypeNumber)
            {
            case 0x96:      // Home Address
                tlvlist = readTlvList(bstream, 1);
                break;

            case 0xa0:      // Origin Address
                tlvlist = readTlvList(bstream, 1);
                break;

            case 0xc8:      // Phone Numbers
                tlvlist = readTlvList(bstream, 5);
                break;

            case 0x8c:      // Emails
                tlvlist = readTlvList(bstream, 4);
                break;

            case 0x118:     // Work
                tlvlist = readTlvList(bstream, 1);
                break;

            case 0x10e:     // Education
                tlvlist = readTlvList(bstream, 1);
                break;

            case 0x122:     // Interests
                tlvlist = readTlvList(bstream, 4);
                break;
            }

            if (tlvlist != null)
            {
                ushort count = 0;
                foreach (TlvBlock block in tlvlist)
                {
                    count++;
                    switch (t.TypeNumber)
                    {
                    case 0x96:      // Home Address
                        ui.HomeAddress = block.ReadString(0x64, Encoding.UTF8);
                        ui.HomeCity    = block.ReadString(0x6e, Encoding.UTF8);
                        ui.HomeState   = block.ReadString(0x78, Encoding.UTF8);
                        ui.HomeZip     = block.ReadString(0x82, Encoding.UTF8);
                        ui.HomeCountry = (CountryList)block.ReadUint(0x8c, 0);
                        break;

                    case 0xa0:      // Origin Address
                        ui.OriginCity    = block.ReadString(0x6e, Encoding.UTF8);
                        ui.OriginState   = block.ReadString(0x78, Encoding.UTF8);
                        ui.OriginCountry = (CountryList)block.ReadUint(0x8c, 0);
                        break;

                    case 0xc8:      // Phone Numbers
                        switch (count)
                        {
                        case 1: ui.HomePhone = block.ReadString(0x64, Encoding.ASCII); break;

                        case 2: ui.HomeFax = block.ReadString(0x64, Encoding.ASCII); break;

                        case 3: ui.MobilePhone = block.ReadString(0x64, Encoding.ASCII); break;

                        case 4: ui.WorkPhone = block.ReadString(0x64, Encoding.ASCII); break;

                        case 5: ui.WorkFax = block.ReadString(0x64, Encoding.ASCII); break;

                        default: return;
                        }
                        break;

                    case 0x8c:      // Emails
                        string email = block.ReadString(0x64, Encoding.ASCII);
                        if (!string.IsNullOrEmpty(email))
                        {
                            if (ui.EmailAddresses == null)
                            {
                                ui.EmailAddresses = new string[0];
                            }

                            Array.Resize <string>(ref ui.EmailAddresses, ui.EmailAddresses.Length + 1);
                            ui.EmailAddresses[ui.EmailAddresses.Length - 1] = email;
                        }
                        break;

                    case 0x118:     // Work
                        ui.WorkPosition   = block.ReadString(0x64, Encoding.UTF8);
                        ui.WorkCompany    = block.ReadString(0x6e, Encoding.UTF8);
                        ui.WorkDepartment = block.ReadString(0x7d, Encoding.UTF8);
                        ui.WorkWebsite    = block.ReadString(0x78, Encoding.ASCII);
                        ui.WorkIndustry   = (IndustryList)block.ReadUshort(0x82, 0);

                        ui.WorkAddress = block.ReadString(0xaa, Encoding.UTF8);
                        ui.WorkCity    = block.ReadString(0xb4, Encoding.UTF8);
                        ui.WorkState   = block.ReadString(0xbe, Encoding.UTF8);
                        ui.WorkZip     = block.ReadString(0xc8, Encoding.UTF8);
                        ui.WorkCountry = (CountryList)block.ReadUint(0xd2, 0);
                        break;

                    case 0x10e:     // Education
                        ui.StudyLevel     = (StudyLevelList)block.ReadUshort(0x64, 0);
                        ui.StudyInstitute = block.ReadString(0x6e, Encoding.UTF8);
                        ui.StudyDegree    = block.ReadString(0x78, Encoding.UTF8);
                        ui.StudyYear      = block.ReadUshort(0x8c, 0);
                        break;

                    case 0x122:     // Interests
                        string info = block.ReadString(0x64, Encoding.UTF8);
                        ushort cat  = block.ReadUshort(0x6e, 0);
                        if (!string.IsNullOrEmpty(info) || cat > 0)
                        {
                            if (ui.InterestInfos == null)
                            {
                                ui.InterestInfos = new FullUserInfo.InterestInfo[0];
                            }

                            Array.Resize <FullUserInfo.InterestInfo>(ref ui.InterestInfos, ui.InterestInfos.Length + 1);

                            ui.InterestInfos[ui.InterestInfos.Length - 1].Info     = info;
                            ui.InterestInfos[ui.InterestInfos.Length - 1].Category = (InterestList)cat;
                        }
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        private void ProcessDirectoryQueryResponseUserDetails(TlvBlock tlvs)
        {
            FullUserInfo ui = new FullUserInfo();

            // Email
            ui.Email = tlvs.ReadString(0x50, Encoding.ASCII);       // Verified e-mail
            if (string.IsNullOrEmpty(ui.Email))
            {
                ui.Email = tlvs.ReadString(0x55, Encoding.ASCII);   // Pending e-mail
            }
            // Names
            ui.Screenname = tlvs.ReadString(0x32, Encoding.ASCII);
            ui.Firstname  = tlvs.ReadString(0x64, Encoding.UTF8);
            ui.Lastname   = tlvs.ReadString(0x6e, Encoding.UTF8);
            ui.Nickname   = tlvs.ReadString(0x78, Encoding.UTF8);

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

            ui.Timezone = tlvs.ReadSshort(0x17c, 0);

            switch (tlvs.ReadByte(0x82))
            {
            case 1: ui.Gender = 'F'; break;

            case 2: ui.Gender = 'M'; break;

            default: ui.Gender = '\0'; break;
            }

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

            double birthday = tlvs.ReadDouble(0x1A4, 0);

            if (birthday != 0)
            {
                ui.Birthday = DateTime.FromOADate(birthday + 2);
                ui.Age      = (byte)(DateTime.Now.Year - ui.Birthday.Year);
                if (ui.Birthday.DayOfYear > DateTime.Now.DayOfYear)
                {
                    ui.Age--;
                }
            }

            ui.Language1 = (LanguageList)tlvs.ReadUshort(0xaa, 0);
            ui.Language2 = (LanguageList)tlvs.ReadUshort(0xb4, 0);
            ui.Language3 = (LanguageList)tlvs.ReadUshort(0xbe, 0);

            ui.MaritalStatus = (MartialList)tlvs.ReadUshort(0x12c, 0);
            ui.About         = tlvs.ReadString(0x186, Encoding.UTF8);

            ui.StatusNote   = tlvs.ReadString(0x226, Encoding.UTF8);
            ui.PrivacyLevel = tlvs.ReadUshort(0x1f9, 0);
            ui.Auth         = tlvs.ReadUshort(0x19a, 0);
            ui.WebAware     = tlvs.ReadByte(0x212, 0);
            ui.AllowSpam    = tlvs.ReadByte(0x1ea, 0);
            ui.CodePage     = tlvs.ReadUshort(0x1c2, 0);

            if (FullUserInfoReceived != null)
            {
                FullUserInfoReceived(this, ui);
            }
        }