예제 #1
0
파일: SNAC02.cs 프로젝트: saroj82/OscarLib
        /// <summary>
        /// Sets the user's directory information -- SNAC(02,09)
        /// </summary>
        /// <param name="sess">A <see cref="Session"/> object</param>
        /// <param name="allow"><c>true</c> if other users may search this information, <c>false</c> if not</param>
        /// <param name="firstname">A first name</param>
        /// <param name="middlename">A middle name</param>
        /// <param name="lastname">A last name</param>
        /// <param name="maidenname">A maiden name</param>
        /// <param name="nickname">A nickname</param>
        /// <param name="city">A city</param>
        /// <param name="state">A state</param>
        /// <param name="country">A country (two-letter code)</param>
        /// <param name="zip">A ZIP code</param>
        /// <param name="address">An address</param>
        public static void SetDirectoryInformation(
            Session sess, bool allow,
            string firstname, string middlename, string lastname, string maidenname, string nickname,
            string city, string state, string country, string zip, string address)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.LocationService;
            sh.FamilySubtypeID = (ushort)LocationServices.UpdateDirectoryInfoRequest;



            ByteStream stream = new ByteStream();

            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteUshort(0x001A, (ushort)((allow) ? 0x0001 : 0x0000));
                tlvs.WriteString(DIRECTORY_FIRSTNAME, firstname, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_MIDDLENAME, middlename, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_LASTNAME, lastname, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_MAIDENNAME, maidenname, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_COUNTRY, country, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_STATE, state, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_CITY, city, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_NICKNAME, nickname, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_ZIPCODE, zip, Encoding.ASCII);
                tlvs.WriteString(DIRECTORY_ADDRESS, address, Encoding.ASCII);
                stream.WriteByteArray(tlvs.GetBytes());
            }

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
예제 #2
0
파일: SNAC02.cs 프로젝트: saroj82/OscarLib
        /// <summary>
        /// Sets the user's interests list -- SNAC(02,0F)
        /// </summary>
        /// <param name="sess">A <see cref="Session"/> object</param>
        /// <param name="allow"><c>true</c> if other users may search this information, <c>false</c> if not</param>
        /// <param name="interests">An array of interest names</param>
        /// <remarks>
        /// OSCAR allows a user to set up to five interests. If <paramref name="interests"/> contains
        /// more than five items, only the first five are used.
        /// </remarks>
        public static void SetInterestsInformation(Session sess, bool allow, string[] interests)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.LocationService;
            sh.FamilySubtypeID = (ushort)LocationServices.UpdateInterestsRequest;



            ByteStream stream = new ByteStream();

            using (TlvBlock tlvs = new TlvBlock())
            {
                tlvs.WriteUshort(INTERESTS_ALLOWSEARCH, (ushort)((allow) ? 0x0001 : 0x0000));
                for (int i = 0; i < interests.Length && i < 5; i++)
                {
                    tlvs.WriteString(INTERESTS_INTEREST, interests[i], Encoding.ASCII);
                }
                stream.WriteByteArray(tlvs.GetBytes());
            }

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
예제 #3
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));
        }
예제 #4
0
        /// <summary>
        /// Sends a direct connection request
        /// </summary>
        /// <param name="conn">A <see cref="DirectConnection"/> object that will handle the request</param>
        public void RequestDirectConnectionInvite(DirectConnection conn)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_ICBM_FAMILY;
            sh.FamilySubtypeID = ICBM_OUTGOING_MESSAGE;

            ByteStream stream = new ByteStream();
            InsertIcbmHeader(stream, conn.Cookie, 0x0002, conn.Other.ScreenName);
            using (ByteStream tlv05 = new ByteStream())
            {
                tlv05.WriteUshort(RendezvousData.UshortFromType(RendezvousType.Invite));
                tlv05.WriteByteArray(conn.Cookie.ToByteArray());
                tlv05.WriteByteArray(CapabilityProcessor.GetCapabilityArray(conn.Capability));

                using (TlvBlock tlvs = new TlvBlock())
                {
                    tlvs.WriteUshort(DC_SEQUENCE_NUMBER, RendezvousData.UshortFromSequence(conn.Sequence));
                    if (conn.Sequence == RendezvousSequence.DirectOrStage1)
                    {
                        tlvs.WriteEmpty(0x000F);
                    }
                    if (!String.IsNullOrEmpty(conn.Message))
                    {
                        tlvs.WriteString(DC_MESSAGE, conn.Message, Encoding.ASCII);
                    }

                    uint ipaddress = 0;
                    if (conn.Method == DirectConnectionMethod.Proxied)
                    {
                        ipaddress = ConvertIPAddress(conn.AOLProxyIP);
                    }
                    else
                    {
                        ipaddress = ConvertIPAddress(conn.ClientIP);
                    }

                    tlvs.WriteUint(DC_PROXY_IP_ADDRESS, ipaddress);
                    tlvs.WriteUint(DC_PROXY_IP_ADDRESS_COMPLIMENT, ~ipaddress);

                    if (conn.Sequence == RendezvousSequence.DirectOrStage1)
                    {
                        tlvs.WriteUint(DC_CLIENT_IP_ADDRESS, ConvertIPAddress(conn.ClientIP));
                    }

                    if (conn.Sequence != RendezvousSequence.Stage3)
                    {
                        tlvs.WriteUshort(DC_PORT, (ushort)conn.Port);
                        tlvs.WriteUshort(DC_PORT_COMPLIMENT, (ushort)(~conn.Port));
                    }

                    if (conn.Method == DirectConnectionMethod.Proxied)
                    {
                        tlvs.WriteEmpty(DC_USE_PROXY_FLAG);
                    }

                    if (conn is FileTransferConnection && conn.Sequence == RendezvousSequence.DirectOrStage1)
                    {
                        FileTransferConnection ftc = conn as FileTransferConnection;
                        using (ByteStream tlv2711 = new ByteStream())
                        {
                            tlv2711.WriteUshort((ushort)((ftc.TotalFiles > 1) ? 0x0002 : 0x0001));
                            tlv2711.WriteUshort((ushort)ftc.TotalFiles);
                            tlv2711.WriteUint(ftc.TotalFileSize);
                            tlv2711.WriteString(ftc.FileHeader.Name, Encoding.ASCII);
                            tlv2711.WriteByte(0x00);
                            tlvs.WriteByteArray(0x2711, tlv2711.GetBytes());
                        }
                        tlvs.WriteString(0x2712, ftc.LocalFileNameEncoding.WebName, Encoding.ASCII);
                    }

                    tlv05.WriteByteArray(tlvs.GetBytes());
                }

                stream.WriteUshort(0x0005);
                stream.WriteUshort((ushort)tlv05.GetByteCount());
                stream.WriteByteArray(tlv05.GetBytes());
            }

            // Acknowledgement request
            stream.WriteUint(0x00030000);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
예제 #5
0
        /// <summary>
        /// Invites an AIM user to an AOL chatroom
        /// </summary>
        /// <param name="chatroom">The <see cref="ChatRoom"/> describing the chatroom</param>
        /// <param name="screenName">The screenname of the user to invite</param>
        /// <param name="message">A message to send along with the invitation</param>
        public Cookie InviteToChatRoom(ChatRoom chatroom, string screenName, string message)
        {
            if (!parent.LoggedIn)
            {
                throw new NotLoggedInException();
            }

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_ICBM_FAMILY;
            sh.FamilySubtypeID = ICBM_OUTGOING_MESSAGE;

            Cookie cookie = Cookie.CreateCookieForSending();

            Encoding enc = Encoding.ASCII;
            byte destlength = (byte) enc.GetByteCount(screenName);
            ushort messagelength = (ushort) enc.GetByteCount(message);
            byte roomnamelength = (byte) enc.GetByteCount(chatroom.FullName);

            ByteStream stream = new ByteStream();
            InsertIcbmHeader(stream, cookie, 0x0002, screenName);

            ByteStream header = new ByteStream();
            header.WriteUshort(0x0000);
            header.WriteByteArray(cookie.ToByteArray());
            header.WriteUint(0x748F2420);
            header.WriteUint(0x628711D1);
            header.WriteUint(0x82224445);
            header.WriteUint(0x53540000);

            using (TlvBlock tlv05 = new TlvBlock())
            {
                tlv05.WriteUshort(0x000A, 0x0001);
                tlv05.WriteEmpty(0x000F);
                tlv05.WriteString(0x000C, message, enc);

                ByteStream tlv2711 = new ByteStream();
                tlv2711.WriteUshort(chatroom.Exchange);
                tlv2711.WriteByte(roomnamelength);
                tlv2711.WriteString(chatroom.FullName, enc);
                tlv2711.WriteUshort(chatroom.Instance);

                tlv05.WriteByteArray(0x2711, tlv2711.GetBytes());

                header.WriteByteArray(tlv05.GetBytes());
            }

            stream.WriteUshort(0x0005);
            stream.WriteUshort((ushort) header.GetByteCount());
            stream.WriteByteArray(header.GetBytes());

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

            return cookie;
        }
예제 #6
0
        /// <summary>
        /// Sends an ICBM on channel 1 -- SNAC(04,06)
        /// </summary>
        /// <param name="destination">The screenname to receive the IM</param>
        /// <param name="message">The message to send</param>
        /// <param name="flags">A <see cref="OutgoingMessageFlags"/> enumeration specifying what
        /// additional information should be sent with the message</param>
        private Cookie SendMessageThroughServer(string destination, string message, OutgoingMessageFlags flags)
        {
            SNACHeader sh = new SNACHeader();
                    sh.FamilyServiceID = SNAC_ICBM_FAMILY;
                    sh.FamilySubtypeID = ICBM_OUTGOING_MESSAGE;

                    byte[] default_features = new byte[] { 0x01, 0x01, 0x01, 0x02 };
                    Cookie cookie = Cookie.CreateCookieForSending();
                    Encoding encoding = UtilityMethods.FindBestOscarEncoding(message);

                    ByteStream stream = new ByteStream();

                    InsertIcbmHeader(stream, cookie, 0x0001, destination);
                    using (TlvBlock tlvs = new TlvBlock())
                    {
                        // Write in TLV 0x0002: a text message
                        using (TlvBlock tlv02 = new TlvBlock())
                        {
                            tlv02.WriteByteArray(0x0501, default_features);
                            ByteStream feature0101 = new ByteStream();
                            feature0101.WriteUshort(Marshal.EncodingToCharset(encoding));
                            feature0101.WriteUshort(0x0000);
                            feature0101.WriteString(message, encoding);
                            tlv02.WriteByteArray(0x0101, feature0101.GetBytes());
                            tlvs.WriteByteArray(0x0002, tlv02.GetBytes());
                        }

                        // Pack in optional TLVs
                        if ((flags & OutgoingMessageFlags.AutoResponse) != 0)
                        {
                            tlvs.WriteEmpty(0x0004);
                        }
                        else
                        {
                            // Request a notification of delivery - note that this can't happen
                            // with an AutoResponse flag set, otherwise the message is bounced
                            tlvs.WriteEmpty(0x0003);
                        }

                        if ((flags & OutgoingMessageFlags.DeliverOffline) != 0
                            && (flags & OutgoingMessageFlags.AutoResponse) == 0)
                        {
                            // Try to store if the user is offline
                            tlvs.WriteEmpty(0x0006);
                        }

                        // Add the TLVs to the byte stream
                        stream.WriteByteArray(tlvs.GetBytes());
                    }

                    // Cache the message for delivery updates
                    messageStatuses.Add(sh.RequestID, new MessageStatusEventArgs(cookie, destination));

                    // Send that sucker off
                    SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
                    return cookie;
        }
예제 #7
0
 public byte[] GetBytes()
 {
     return(value.GetBytes());
 }