Пример #1
0
        /// <summary>
        /// Sets the client's extended status -- SNAC(01,1E)
        /// </summary>
        /// <param name="sess">A <see cref="Session"/> object</param>
        /// <param name="availablemessage">The available message to set</param>
        /// <param name="flags">The ICQ flags to set</param>
        /// <param name="status">The ICQ status to set</param>
        /// <remarks>Either the available message or the flags/status can be set in one call to SetExtendedStatus</remarks>
        private static void SetExtendedStatus(Session sess, string availablemessage, ICQFlags flags, ICQStatus status)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.BasicOscarService;
            sh.FamilySubtypeID = (ushort)GenericServiceControls.SetExtendedStatus;
            sh.Flags           = 0x0000;
            sh.RequestID       = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();

            if (availablemessage != null)
            {
                stream.WriteUshort(0x001D);
                stream.WriteUshort((ushort)(availablemessage.Length + 8));
                stream.WriteUshort(0x0002);
                stream.WriteByte(0x04);
                stream.WriteByte((byte)(Encoding.ASCII.GetByteCount(availablemessage) + 4));
                stream.WriteUshort((ushort)Encoding.ASCII.GetByteCount(availablemessage));
                stream.WriteString(availablemessage, Encoding.ASCII);
                stream.WriteUshort(0x0000);
            }
            else
            {
                uint stat = (uint)((ushort)flags << 16);
                stat |= (ushort)status;
                stream.WriteUint(0x00060004);
                stream.WriteUint(stat);
            }

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

            dp.ParentConnection = sess.Connections.BOSConnection;
            SNACFunctions.BuildFLAP(dp);
        }
Пример #2
0
        /// <summary>
        /// Allows the authorization to another client in the future
        /// </summary>
        /// <param name="sess">the session object</param>
        /// <param name="screenname">the destination screenname</param>
        /// <param name="reason">the reason for the future authorization</param>
        public static void SendFutureAuthorizationGrant(Session sess, string screenname, string reason)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.SSIService;
            sh.FamilySubtypeID = (ushort)SSIService.SendFutureAuthorizationGrant;


            ByteStream stream = new ByteStream();

            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenname));
            stream.WriteString(screenname, Encoding.ASCII);

            stream.WriteUshort((ushort)sess.Encoding.GetByteCount(reason));
            stream.WriteString(reason, sess.Encoding);

            stream.WriteUshort(0x0000);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #3
0
        public void TestByteStreamStringWriting()
        {
            ByteStream stream = new ByteStream();
            stream.WriteByte((byte) Encoding.ASCII.GetByteCount("Adrienne"));
            stream.WriteString("Adrienne", Encoding.ASCII);

            Assert.AreEqual(testData.Length, stream.GetByteCount());
            byte[] data = stream.GetBytes();
            for (int i = 0; i < testData.Length; i++)
            {
                Assert.AreEqual(testData[i], data[i]);
            }
        }
Пример #4
0
        /// <summary>
        /// Delete yourself from another client server-side contact list.
        /// </summary>
        /// <param name="sess"></param>
        /// <param name="screenname">The contacts icq-number.</param>
        public static void RemoveMySSIItem(Session sess, string screenname)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.SSIService;
            sh.FamilySubtypeID = (ushort)SSIService.RemoveSelfFromContact;


            ByteStream stream = new ByteStream();

            stream.WriteByte((byte)screenname.Length);
            stream.WriteString(screenname, Encoding.ASCII);
            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #5
0
        /// <summary>
        /// Sends an out-of-the-country text message
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="number">The number to which to send the message</param>
        /// <param name="message">The message to send</param>
        /// <param name="alias">The sender's alias</param>
        /// <remarks><paramref name="message"/> must be in codepage 1252. A delivery receipt
        /// is automatically requested by this method.</remarks>
        public static void SendSMSMessage(ISession sess, string number, string message, string alias)
        {
            string xmlformat = "<icq_sms_message>\n" +
                               "\t<destination>{0}</destination>\n" +
                               "\t<text>{1}</text>\n" +
                               "\t<codepage>1252</codepage>\n" +
                               "\t<senders_UIN>{2}</senders_UIN>\n" +
                               "\t<senders_name>{3}</senders_name>\n" +
                               "\t<delivery_receipt>Yes</delivery_receipt>\n" +
                               "\t<time>{4}</time>\n" +
                               "</icq_sms_message>\n";

            string xml = String.Format(xmlformat,
                                       number,
                                       message,
                                       sess.ScreenName,
                                       alias,
                                       DateTime.Now.ToString("r"));

            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort)ICQExtensionsService.MetaInformationRequest;
            sh.Flags           = 0x0000;
            sh.RequestID       = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();

            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort)sh.RequestID);
            stream.WriteUshort(0x8214);
            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x0016);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUshort(0x0000);
            stream.WriteUshort((ushort)Encoding.ASCII.GetByteCount(xml));
            stream.WriteString(xml, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #6
0
        /// <summary>
        /// Sends a request to find accounts by their associated email address -- SNAC(0A,02)
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="email">The email address to query</param>
        public static void FindUsersByEmail(ISession sess, string email)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort) SNACFamily.UserLookupService;
            sh.FamilySubtypeID = (ushort) UserLookupService.FindUserByEmailRequest;
            sh.Flags = 0x0000;
            sh.RequestID = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();
            stream.WriteString(email, Encoding.ASCII);

            sess.StoreRequestID(sh.RequestID, email);

            DataPacket dp = Marshal.BuildDataPacket(sess, sh, stream);
            SNACFunctions.BuildFLAP(dp);
        }
Пример #7
0
        /// <summary>
        /// Registers the user's screenname with the Location service -- SNAC(02,0B)
        /// </summary>
        /// <param name="sess">A <see cref="Session"/> object</param>
        /// <remarks>
        /// The function of this SNAC is unknown, but the official AIM client (5.9.3861) sends it sometime
        /// after SNAC(01,02) is sent.
        /// </remarks>
        public static void SetSelfLocation(Session sess)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.LocationService;
            sh.FamilySubtypeID = (ushort)0x000B;



            ByteStream stream = new ByteStream();

            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(sess.ScreenName));
            stream.WriteString(sess.ScreenName, Encoding.ASCII);

            // This SNAC expects a response in SNAC(02,0C)
            sess.StoreRequestID(sh.RequestID, null);
            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #8
0
        /// <summary>
        /// Sends a request to find accounts by their associated email address -- SNAC(0A,02)
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="email">The email address to query</param>
        public static void FindUsersByEmail(ISession sess, string email)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.UserLookupService;
            sh.FamilySubtypeID = (ushort)UserLookupService.FindUserByEmailRequest;
            sh.Flags           = 0x0000;
            sh.RequestID       = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();

            stream.WriteString(email, Encoding.ASCII);

            sess.StoreRequestID(sh.RequestID, email);

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

            SNACFunctions.BuildFLAP(dp);
        }
Пример #9
0
            public byte[] GetBytes()
            {
                ByteStream buffer = new ByteStream();

                buffer.WriteUshort((ushort)Encoding.UTF8.GetByteCount(item.Name));
                buffer.WriteString(item.Name, Encoding.UTF8);
                buffer.WriteUshort(item.GroupID);
                buffer.WriteUshort(item.ItemID);
                buffer.WriteUshort(item.ItemType);
                if (item.Tlvs == null)
                {
                    buffer.WriteUshort(0x000);
                }
                else
                {
                    buffer.WriteUshort((ushort)item.Tlvs.GetByteCount());
                    buffer.WriteTlvBlock(item.Tlvs);
                }

                return(buffer.GetBytes());
            }
Пример #10
0
        /// <summary>
        /// Changes the password on an ICQ account
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="newpassword">The new password</param>
        /// <remarks>If the new password is longer than 8 characters, it is automatically
        /// truncated to 8 characters by the server.</remarks>
        public static void ChangeICQPassword(ISession sess, string newpassword)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort) SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort) ICQExtensionsService.MetaInformationRequest;
            sh.Flags = 0x0000;
            sh.RequestID = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();
            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort) sh.RequestID);
            stream.WriteUshort(0x042E);
            stream.WriteUshort((ushort) (newpassword.Length + 1));
            stream.WriteString(newpassword, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #11
0
        /// <summary>
        /// Changes the password on an ICQ account
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="newpassword">The new password</param>
        /// <remarks>If the new password is longer than 8 characters, it is automatically
        /// truncated to 8 characters by the server.</remarks>
        public static void ChangeICQPassword(ISession sess, string newpassword)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort)ICQExtensionsService.MetaInformationRequest;
            sh.Flags           = 0x0000;
            sh.RequestID       = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();

            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort)sh.RequestID);
            stream.WriteUshort(0x042E);
            stream.WriteUshort((ushort)(newpassword.Length + 1));
            stream.WriteString(newpassword, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #12
0
        /// <summary>
        /// Sends an XML string
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="xml">The contents of an XML document</param>
        /// <remarks>I have no idea how to use this.</remarks>
        public static void SendXmlRequest(ISession sess, string xml)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort)ICQExtensionsService.MetaInformationRequest;
            sh.Flags           = 0x0000;
            sh.RequestID       = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();

            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort)sh.RequestID);
            stream.WriteUshort(0x0998);
            stream.WriteUshort((ushort)Encoding.ASCII.GetByteCount(xml));
            stream.WriteString(xml, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #13
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;
        }
Пример #14
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));
        }
Пример #15
0
        /// <summary>
        /// Sends a typing notification
        /// </summary>
        /// <param name="screenName">The screenname to receive the typing notification</param>
        /// <param name="tn">A <see cref="TypingNotification"/> enumeration specifying what
        /// notification to send</param>
        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>
        public void SendTypingNotification(string screenName, TypingNotification tn)
        {
            if (!parent.LoggedIn)
            {
                throw new NotLoggedInException();
            }

            DirectIMConnection conn = parent.Connections.GetDirectIMByScreenname(screenName);
            if (conn != null)
            {
                if (conn.Connected)
                {
                    // TODO:  send DIM typing notifications
                }
            }

            // Construct SNAC(04,14)
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_ICBM_FAMILY;
            sh.FamilySubtypeID = ICBM_TYPING_NOTIFICATION;

            ByteStream stream = new ByteStream();
            stream.WriteByteArray(new byte[] {0, 0, 0, 0, 0, 0, 0, 0});
            stream.WriteUshort(0x0001);
            stream.WriteByte((byte) Encoding.ASCII.GetByteCount(screenName));
            stream.WriteString(screenName, Encoding.ASCII);
            stream.WriteUshort((ushort) tn);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #16
0
        /// <summary>
        /// Delete yourself from another client server-side contact list.
        /// </summary>
        /// <param name="sess"></param>
        /// <param name="screenname">The contacts icq-number.</param>
        public static void RemoveMySSIItem(Session sess, string screenname)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort)SNACFamily.SSIService;
            sh.FamilySubtypeID = (ushort)SSIService.RemoveSelfFromContact;

            ByteStream stream = new ByteStream();
            stream.WriteByte((byte)screenname.Length);
            stream.WriteString(screenname, Encoding.ASCII);
            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #17
0
        /// <summary>
        /// Sets the client's available message -- SNAC(01,1E)
        /// </summary>
        /// <param name="availablemessage">The available message to set</param>
        internal void SetAvailableMessage(string availablemessage)
        {
            SNACHeader sh = new SNACHeader(SNAC_BOS_FAMILY, BOS_SET_EXTENDED_STATUS);

            ByteStream stream = new ByteStream();
            if (String.IsNullOrEmpty(availablemessage))
            {
                availablemessage = String.Empty;
            }

            stream.WriteUshort(0x001D);
            stream.WriteUshort((ushort)(availablemessage.Length + 8));
            stream.WriteUshort(0x0002);
            stream.WriteByte(0x04);
            stream.WriteByte((byte)(Encoding.ASCII.GetByteCount(availablemessage) + 4));
            stream.WriteUshort((ushort)Encoding.ASCII.GetByteCount(availablemessage));
            stream.WriteString(availablemessage, Encoding.ASCII);
            stream.WriteUshort(0x0000);

            DataPacket dp = Marshal.BuildDataPacket(parent, sh, stream);
            dp.ParentConnection = parent.Connections.BOSConnection;
            SNACFunctions.BuildFLAP(dp);
        }
Пример #18
0
        /// <summary>
        /// Requests a single type of user information from the server
        /// </summary>
        /// <param name="screenname">The screenname to get information about</param>
        /// <param name="requesttype">The type of information to retrieve</param>
        /// <remarks>Results are returned by the <see cref="UserInfoReceived"/> event</remarks>
        public void RequestBasicUserInfo(string screenname, BasicUserInfoRequest requesttype)
        {
            // Build SNAC(02,05)
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_LOCATION_FAMILY;
            sh.FamilySubtypeID = LOCATION_REQUEST_BASIC_INFO;

            ByteStream stream = new ByteStream();
            stream.WriteUshort((ushort)requesttype);
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenname));
            stream.WriteString(screenname, Encoding.ASCII);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #19
0
        /// <summary>
        /// Requests all user information from the server
        /// </summary>
        /// <param name="screenname">The screenname to get information about</param>
        /// <remarks>Results are returned by the <see cref="UserInfoReceived"/> event</remarks>
        public void RequestAllUserInfo(string screenname)
        {
            //KSD-SYSTEMS - commented at 24.02.2010 -> I want AllUserInfo, no Redirect
            // If the requested information is an ICQ name, redirect this
            //if (ScreennameVerifier.IsValidICQ(screenname))
            //{
            //    RequestBasicUserInfo(screenname, BasicUserInfoRequest.AwayMessage);
            //    return;
            //}

            // Build SNAC(02,15)
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_LOCATION_FAMILY;
            sh.FamilySubtypeID = LOCATION_REQUEST_ALL_INFO;

            ByteStream stream = new ByteStream();
            stream.WriteUint((uint)(UserInfoRequest.AwayMessage | UserInfoRequest.Capabilities | UserInfoRequest.UserProfile));
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenname));
            stream.WriteString(screenname, Encoding.ASCII);
            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #20
0
        /// <summary>
        /// Sends a warning to a remote client -- SNAC(04,08)
        /// </summary>
        /// <param name="screenname">The screenname of the client to warn</param>
        /// <param name="anonymous">Send the warning as anonymous or as yourself</param>
        public void SendWarning(string screenname, bool anonymous)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_ICBM_FAMILY;
            sh.FamilySubtypeID = ICBM_SEND_WARNING;

            ByteStream stream = new ByteStream();
            stream.WriteUshort((ushort)((anonymous) ? 1 : 0));
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenname));
            stream.WriteString(screenname, Encoding.ASCII);

            // Save the screenname so the handler for the reply SNAC can retrieve it
            parent.StoreRequestID(sh.RequestID, screenname);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #21
0
        /// <summary>
        /// Sends an out-of-the-country text message
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="number">The number to which to send the message</param>
        /// <param name="message">The message to send</param>
        /// <param name="alias">The sender's alias</param>
        /// <remarks><paramref name="message"/> must be in codepage 1252. A delivery receipt
        /// is automatically requested by this method.</remarks>
        public static void SendSMSMessage(ISession sess, string number, string message, string alias)
        {
            string xmlformat = "<icq_sms_message>\n" +
                               "\t<destination>{0}</destination>\n" +
                               "\t<text>{1}</text>\n" +
                               "\t<codepage>1252</codepage>\n" +
                               "\t<senders_UIN>{2}</senders_UIN>\n" +
                               "\t<senders_name>{3}</senders_name>\n" +
                               "\t<delivery_receipt>Yes</delivery_receipt>\n" +
                               "\t<time>{4}</time>\n" +
                               "</icq_sms_message>\n";

            string xml = String.Format(xmlformat,
                                       number,
                                       message,
                                       sess.ScreenName,
                                       alias,
                                       DateTime.Now.ToString("r"));

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort) SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort) ICQExtensionsService.MetaInformationRequest;
            sh.Flags = 0x0000;
            sh.RequestID = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();
            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort) sh.RequestID);
            stream.WriteUshort(0x8214);
            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x0016);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUint(0x00000000);
            stream.WriteUshort(0x0000);
            stream.WriteUshort((ushort) Encoding.ASCII.GetByteCount(xml));
            stream.WriteString(xml, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #22
0
 /// <summary>
 /// Inserts an ICBM header
 /// </summary>
 private static void InsertIcbmHeader(ByteStream stream, Cookie cookie, ushort channel, string screenName)
 {
     stream.WriteByteArray(cookie.ToByteArray());
             stream.WriteUshort(channel);
             stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenName));
             stream.WriteString(screenName, Encoding.ASCII);
 }
Пример #23
0
        /// <summary>
        /// Sends a status report to the OSCAR server -- SNAC(0B,03)
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <remarks>libfaim does not send this report</remarks>
        public static void SendStatusReport(ISession sess)
        {
            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = (ushort)SNACFamily.UsageStatsService;
            sh.FamilySubtypeID = (ushort)UsageStatsService.UsageReport;
            sh.Flags           = 0;
            sh.RequestID       = Session.GetNextRequestID();

            // Get the necessary strings together
            string sn = sess.ScreenName;
            // Here we start lying until I can figure out how to get *all* the values in .NET
            string osversion   = Environment.OSVersion.ToString();
            string osname      = "Windows 98";    //osversion.Substring(0, osversion.LastIndexOf(" ") - 1);
            string osver       = "4.10.67766446"; //osversion.Substring(osversion.LastIndexOf(" ") + 1);
            string procname    = "Intel Pentium";
            string winsockname = "Microsoft Corporation BSD Socket API for Windows";
            string winsockver  = "4.1.1998";

            Encoding enc               = Encoding.ASCII;
            byte     snlength          = (byte)enc.GetByteCount(sn);
            ushort   osversionlength   = (ushort)enc.GetByteCount(osversion);
            ushort   osnamelength      = (ushort)enc.GetByteCount(osname);
            ushort   osverlength       = (ushort)enc.GetByteCount(osver);
            ushort   procnamelength    = (ushort)enc.GetByteCount(procname);
            ushort   winsocknamelength = (ushort)enc.GetByteCount(winsockname);
            ushort   winsockverlength  = (ushort)enc.GetByteCount(winsockver);

            ByteStream mainStream = new ByteStream();

            using (ByteStream stream = new ByteStream())
            {
                TimeSpan t = (DateTime.Now - new DateTime(1970, 1, 1));
                stream.WriteUint((uint)t.Seconds);
                t = (DateTime.UtcNow - new DateTime(1970, 1, 1).ToUniversalTime());
                stream.WriteUint((uint)t.Seconds);
                stream.WriteUint(0x00000000);
                stream.WriteUint(0x00000000);
                stream.WriteUint(0x00000000);
                stream.WriteUint(0x00000000);
                stream.WriteByte(snlength);
                stream.WriteString(sn, Encoding.ASCII);
                stream.WriteUshort(osnamelength);
                stream.WriteString(osname, Encoding.ASCII);
                stream.WriteUshort(osverlength);
                stream.WriteString(osver, Encoding.ASCII);
                stream.WriteUshort(procnamelength);
                stream.WriteString(procname, Encoding.ASCII);
                stream.WriteUshort(winsocknamelength);
                stream.WriteString(winsockname, Encoding.ASCII);
                stream.WriteUshort(winsockverlength);
                stream.WriteString(winsockver, Encoding.ASCII);
                stream.WriteUint(0x00000002);
                stream.WriteUint(0x00010001);
                stream.WriteUint(0x00020002);

                using (TlvBlock tlv = new TlvBlock())
                {
                    tlv.WriteByteArray(0x0009, stream.GetBytes());
                    mainStream.WriteTlvBlock(tlv);
                }
            }

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, mainStream));
        }
Пример #24
0
        /// <summary>
        /// Requests a list of accounts associated with an email address
        /// </summary>
        /// <param name="email">The email address to search for</param>
        /// <remarks>Results are returned by the <see cref="FindByEmailResults"/> event</remarks>
        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>
        public void FindUsersByEmail(string email)
        {
            if (!parent.LoggedIn)
            {
                throw new NotLoggedInException();
            }

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_USERLOOKUP_FAMILY;
            sh.FamilySubtypeID = USERLOOKUP_EMAIL_SEARCH;

            ByteStream stream = new ByteStream();
            stream.WriteString(email, Encoding.ASCII);

            parent.StoreRequestID(sh.RequestID, email);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #25
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;
        }
Пример #26
0
            public byte[] GetBytes()
            {
                ByteStream buffer = new ByteStream();

                buffer.WriteUshort((ushort)Encoding.UTF8.GetByteCount(item.Name));
                buffer.WriteString(item.Name, Encoding.UTF8);
                buffer.WriteUshort(item.GroupID);
                buffer.WriteUshort(item.ItemID);
                buffer.WriteUshort(item.ItemType);
                if (item.Tlvs == null)
                    buffer.WriteUshort(0x000);
                else
                {
                    buffer.WriteUshort((ushort)item.Tlvs.GetByteCount());
                    buffer.WriteTlvBlock(item.Tlvs);
                }

                return buffer.GetBytes();
            }
Пример #27
0
        /// <summary>
        /// Returns an MD5 hash of the client's password, an authorization key, and a constant string
        /// </summary>
        /// <param name="authkey">The authorization key sent by the server</param>
        /// <returns>A 16-byte MD5 hash</returns>
        /// <remarks>
        /// <para>
        /// The hashing process is fairly simple:
        /// <list>
        /// <item>The authorization key is put into a buffer</item>
        /// <item>The password itself is hashed via MD5 and appended to the buffer</item>
        /// <item>The constant string, "AOL Instant Messenger (SM)", is appended to the buffer in plaintext</item>
        /// <item>The entire buffer is MD5 hashed and returned to the caller</item>
        /// </list>
        /// </para>
        /// <para>
        /// This method exists to prevent the password from having to be passed around in a data structure
        /// </para>
        /// </remarks>
        protected internal byte[] HashPassword(byte[] authkey)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            ByteStream stream = new ByteStream();
            stream.WriteByteArray(authkey);
            stream.WriteByteArray(md5.ComputeHash(Encoding.ASCII.GetBytes(_password)));
            stream.WriteString(Constants.AIM_MD5_STRING, Encoding.ASCII);

            return md5.ComputeHash(stream.GetBytes());
        }
Пример #28
0
        /// <summary>
        /// Downloads a buddy icon from the AIM servers
        /// </summary>
        /// <param name="screenName">The screenname to which the icon belongs</param>
        /// <param name="iconId">The ID of the icon stored on the server</param>
        public void DownloadBuddyIcon(string screenName, BartID iconId)
        {
            // Check to make sure the icon ID is valid and actually a buddy icon
            if (iconId == null || iconId.Data == null ||
                !(iconId.Type == BartTypeId.BuddyIcon || iconId.Type == BartTypeId.BigBuddyIcon))
            {
                return;
            }

            // Check to see if the icon's cached, if the cache location is set
            if (!String.IsNullOrEmpty(AutoSaveLocation))
            {
                string saveLocation = Path.Combine(AutoSaveLocation, iconId.ToString());
                if (File.Exists(saveLocation))
                {
                    OnBuddyIconDownloaded(screenName, iconId, saveLocation);
                    return;
                }
            }

            // Check to see if there's already a request in progress for this icon ID
            if (currentlyDownloading.Contains(iconId))
            {
                return;
            }
            currentlyDownloading.Add(iconId);

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_BART_FAMILY;
            sh.FamilySubtypeID = BART_DOWNLOAD;
            sh.Flags = 0;

            ByteStream stream = new ByteStream();
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenName));
            stream.WriteString(screenName, Encoding.ASCII);
            stream.WriteByte(0x01);
            stream.WriteBartID(iconId);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Пример #29
0
        /// <summary>
        /// Allows the authorization to another client in the future
        /// </summary>
        /// <param name="sess">the session object</param>
        /// <param name="screenname">the destination screenname</param>
        /// <param name="reason">the reason for the future authorization</param>
        public static void SendFutureAuthorizationGrant(Session sess, string screenname, string reason)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort) SNACFamily.SSIService;
            sh.FamilySubtypeID = (ushort) SSIService.SendFutureAuthorizationGrant;

            ByteStream stream = new ByteStream();

            stream.WriteByte((byte) Encoding.ASCII.GetByteCount(screenname));
            stream.WriteString(screenname, Encoding.ASCII);

            stream.WriteUshort((ushort) sess.Encoding.GetByteCount(reason));
            stream.WriteString(reason, sess.Encoding);

            stream.WriteUshort(0x0000);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #30
0
        /// <summary>
        /// Sends an XML string
        /// </summary>
        /// <param name="sess">A <see cref="ISession"/> object</param>
        /// <param name="xml">The contents of an XML document</param>
        /// <remarks>I have no idea how to use this.</remarks>
        public static void SendXmlRequest(ISession sess, string xml)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort) SNACFamily.ICQExtensionsService;
            sh.FamilySubtypeID = (ushort) ICQExtensionsService.MetaInformationRequest;
            sh.Flags = 0x0000;
            sh.RequestID = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();
            stream.WriteUshort(0x0001);
            stream.WriteUshort(0x000A);
            stream.WriteUshort(0x0008);
            stream.WriteUint(uint.Parse(sess.ScreenName));
            stream.WriteUshortLE(0x07D0);
            stream.WriteUshortLE((ushort) sh.RequestID);
            stream.WriteUshort(0x0998);
            stream.WriteUshort((ushort) Encoding.ASCII.GetByteCount(xml));
            stream.WriteString(xml, Encoding.ASCII);
            stream.WriteByte(0x00);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(sess, sh, stream));
        }
Пример #31
0
        /// <summary>
        /// Sets the client's extended status -- SNAC(01,1E)
        /// </summary>
        /// <param name="sess">A <see cref="Session"/> object</param>
        /// <param name="availablemessage">The available message to set</param>
        /// <param name="flags">The ICQ flags to set</param>
        /// <param name="status">The ICQ status to set</param>
        /// <remarks>Either the available message or the flags/status can be set in one call to SetExtendedStatus</remarks>
        private static void SetExtendedStatus(Session sess, string availablemessage, ICQFlags flags, ICQStatus status)
        {
            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = (ushort)SNACFamily.BasicOscarService;
            sh.FamilySubtypeID = (ushort)GenericServiceControls.SetExtendedStatus;
            sh.Flags = 0x0000;
            sh.RequestID = Session.GetNextRequestID();

            ByteStream stream = new ByteStream();
            if (availablemessage != null)
            {
                stream.WriteUshort(0x001D);
                stream.WriteUshort((ushort)(availablemessage.Length + 8));
                stream.WriteUshort(0x0002);
                stream.WriteByte(0x04);
                stream.WriteByte((byte)(Encoding.ASCII.GetByteCount(availablemessage) + 4));
                stream.WriteUshort((ushort)Encoding.ASCII.GetByteCount(availablemessage));
                stream.WriteString(availablemessage, Encoding.ASCII);
                stream.WriteUshort(0x0000);
            }
            else
            {
                uint stat = (uint)((ushort)flags << 16);
                stat |= (ushort)status;
                stream.WriteUint(0x00060004);
                stream.WriteUint(stat);
            }

            DataPacket dp = Marshal.BuildDataPacket(sess, sh, stream);
            dp.ParentConnection = sess.Connections.BOSConnection;
            SNACFunctions.BuildFLAP(dp);
        }