/// <summary> /// Sends a request for a new chat room connection -- SNAC(01,04) /// </summary> /// <param name="chatRoom">A <see cref="ChatRoom"/> object</param> internal void RequestChatRoomConnection(ChatRoom chatRoom) { SNACHeader sh = new SNACHeader(); sh.FamilyServiceID = 0x0001; sh.FamilySubtypeID = 0x0004; ByteStream chatStream = new ByteStream(); chatStream.WriteUshort(chatRoom.Exchange); chatStream.WriteByte((byte)Encoding.ASCII.GetByteCount(chatRoom.FullName)); chatStream.WriteString(chatRoom.FullName, Encoding.ASCII); chatStream.WriteUshort(chatRoom.Instance); TlvBlock tlv = new TlvBlock(); tlv.WriteByteArray(0x0001, chatStream.GetBytes()); ByteStream mainStream = new ByteStream(); mainStream.WriteUshort(0x000E); mainStream.WriteTlvBlock(tlv); parent.StoreRequestID(sh.RequestID, chatRoom); DataPacket dp = Marshal.BuildDataPacket(parent, sh, mainStream); // This one is always sent on BOS dp.ParentConnection = parent.Connections.BOSConnection; SNACFunctions.BuildFLAP(dp); }
/// <summary> /// Send a message to this chatroom using a specific character set and language /// </summary> /// <param name="message">The message to send</param> /// <param name="charset">The character set in which to encode the message</param> /// <param name="language">The two-letter code of the language of the message</param> private void SendMessage(string message, Encoding charset, string language) { if (!Connection.Connected) { // TODO: The semantics here aren't right throw new NotLoggedInException(); } SNACHeader sh = new SNACHeader(); sh.FamilyServiceID = 0x000E; sh.FamilySubtypeID = (ushort)ChatService.MessageFromClient; byte[] cookie = new byte[8]; Random r = new Random(); r.NextBytes(cookie); ByteStream stream = new ByteStream(); stream.WriteByteArray(cookie); stream.WriteUshort(0x0003); TlvBlock tlvs = new TlvBlock(); using (TlvBlock messageBlock = new TlvBlock()) { Encoding messageEncoding = UtilityMethods.FindBestOscarEncoding(message); messageBlock.WriteString(CHATMESSAGE_MESSAGE, message, messageEncoding); messageBlock.WriteString(CHATMESSAGE_CHARSET, UtilityMethods.OscarEncodingToString(messageEncoding), Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_LANGUAGE, language, Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_CONTENTTYPE, "text/x-aolrtf", Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_ENCODING, "binary", Encoding.ASCII); tlvs.WriteByteArray(0x0005, messageBlock.GetBytes()); } tlvs.WriteEmpty(0x0001); stream.WriteTlvBlock(tlvs); DataPacket dp = Marshal.BuildDataPacket(Connection.ParentSession, sh, stream); dp.ParentConnection = Connection; SNACFunctions.BuildFLAP(dp); }
/// <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> /// Send a message to this chatroom using a specific character set and language /// </summary> /// <param name="message">The message to send</param> /// <param name="charset">The character set in which to encode the message</param> /// <param name="language">The two-letter code of the language of the message</param> private void SendMessage(string message, Encoding charset, string language) { if (!Connection.Connected) { // TODO: The semantics here aren't right throw new NotLoggedInException(); } SNACHeader sh = new SNACHeader(); sh.FamilyServiceID = 0x000E; sh.FamilySubtypeID = (ushort) ChatService.MessageFromClient; byte[] cookie = new byte[8]; Random r = new Random(); r.NextBytes(cookie); ByteStream stream = new ByteStream(); stream.WriteByteArray(cookie); stream.WriteUshort(0x0003); TlvBlock tlvs = new TlvBlock(); using (TlvBlock messageBlock = new TlvBlock()) { Encoding messageEncoding = UtilityMethods.FindBestOscarEncoding(message); messageBlock.WriteString(CHATMESSAGE_MESSAGE, message, messageEncoding); messageBlock.WriteString(CHATMESSAGE_CHARSET, UtilityMethods.OscarEncodingToString(messageEncoding), Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_LANGUAGE, language, Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_CONTENTTYPE, "text/x-aolrtf", Encoding.ASCII); messageBlock.WriteString(CHATMESSAGE_ENCODING, "binary", Encoding.ASCII); tlvs.WriteByteArray(0x0005, messageBlock.GetBytes()); } tlvs.WriteEmpty(0x0001); stream.WriteTlvBlock(tlvs); DataPacket dp = Marshal.BuildDataPacket(Connection.ParentSession, sh, stream); dp.ParentConnection = Connection; SNACFunctions.BuildFLAP(dp); }
/// <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)); }