/// <summary> /// Sends authorization request -- SNAC(17,02) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(17,07)</param> public static 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 = (ushort)SNACFamily.AuthorizationRegistrationService; header.FamilySubtypeID = (ushort)AuthorizationRegistrationService.LoginRequest; header.Flags = 0; header.RequestID = Session.GetNextRequestID(); OSCARIdentification id = dp.ParentSession.ClientIdentification; ByteStream stream = new ByteStream(); using (TlvBlock tlvs = new TlvBlock()) { tlvs.WriteString(0x0001, dp.ParentSession.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, dp.ParentSession.HashPassword(key)); tlvs.WriteByte(0x004A, 0x01); tlvs.WriteEmpty(0x004C); stream.WriteTlvBlock(tlvs); } DataPacket newPacket = Marshal.BuildDataPacket(dp.ParentSession, header, stream); newPacket.ParentConnection = dp.ParentConnection; SNACFunctions.BuildFLAP(newPacket); }
/// <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); }
/// <summary> /// Sends authorization request -- SNAC(17,02) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(17,07)</param> public static 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 = (ushort) SNACFamily.AuthorizationRegistrationService; header.FamilySubtypeID = (ushort) AuthorizationRegistrationService.LoginRequest; header.Flags = 0; header.RequestID = Session.GetNextRequestID(); OSCARIdentification id = dp.ParentSession.ClientIdentification; ByteStream stream = new ByteStream(); using (TlvBlock tlvs = new TlvBlock()) { tlvs.WriteString(0x0001, dp.ParentSession.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, dp.ParentSession.HashPassword(key)); tlvs.WriteByte(0x004A, 0x01); tlvs.WriteEmpty(0x004C); stream.WriteTlvBlock(tlvs); } DataPacket newPacket = Marshal.BuildDataPacket(dp.ParentSession, header, stream); newPacket.ParentConnection = dp.ParentConnection; SNACFunctions.BuildFLAP(newPacket); }
/// <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)); }
/// <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)); }
/// <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; }
/// <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; }