/// <summary> /// Processes a message received from a chat room -- SNAC(0E,06) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(0E,06)</param> internal void ProcessIncomingMessage(DataPacket dp) { UserInfo sender = new UserInfo(); byte[] message; Encoding encoding = Encoding.ASCII; string language = ""; byte[] cookie = dp.Data.ReadByteArray(8); ushort channel = dp.Data.ReadUshort(); using (TlvBlock outerTlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { using (ByteStream userStream = new ByteStream(outerTlvs.ReadByteArray(0x0003))) { sender = userStream.ReadUserInfo(); } using (TlvBlock innerTlvs = new TlvBlock(outerTlvs.ReadByteArray(0x0005))) { message = innerTlvs.ReadByteArray(0x0001); encoding = Marshal.AolMimeToEncoding(innerTlvs.ReadString(0x0002, Encoding.ASCII)); language = innerTlvs.ReadString(0x0003, Encoding.ASCII); } } if (MessageReceived != null) { IM msg = new IM(sender); msg.Message = Encoding.Unicode.GetString(Encoding.Convert(encoding, Encoding.Unicode, message)); msg.Cookie = Cookie.GetReceivedCookie(cookie); MessageReceived(this, new MessageReceivedEventArgs(msg)); } }
/// <summary> /// Processes user information sent by the server -- SNAC(02,06) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(02,06)</param> private void ProcessUserInfo(DataPacket dp) { if (dp.SNAC.Flags != 0) { Logging.DumpFLAP(dp.Data.GetBytes(), "You've got to be s******g me"); } // Apparently, the userinfo block will always be first, // and then possibly TLVs 0x0001 - 0x0005, depending on the request byte[] awaymessage = null; Encoding awaymessageencoding = Encoding.ASCII; byte[] profile = null; Encoding profileencoding = Encoding.ASCII; Capabilities caps = Capabilities.None; UserInfo ui = dp.Data.ReadUserInfo(); using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { profileencoding = Marshal.AolMimeToEncoding(tlvs.ReadString(LOCATION_PROFILE_ENCODING, Encoding.ASCII)); profile = tlvs.ReadByteArray(LOCATION_PROFILE); awaymessageencoding = Marshal.AolMimeToEncoding(tlvs.ReadString(LOCATION_AWAYMESSAGE_ENCODING, Encoding.ASCII)); awaymessage = tlvs.ReadByteArray(LOCATION_AWAYMESSAGE); caps = CapabilityProcessor.ProcessCLSIDList(tlvs.ReadByteArray(LOCATION_CAPABILITIES)); } UserInfoResponse uir = new UserInfoResponse(); uir.Info = ui; if (profile != null) { uir.Profile = profileencoding.GetString(profile, 0, profile.Length); uir.ProfileEncoding = profileencoding; } if (awaymessage != null) { uir.AwayMessage = awaymessageencoding.GetString(awaymessage, 0, awaymessage.Length); uir.AwayMessageEncoding = awaymessageencoding; } uir.ClientCapabilities = caps; if (UserInfoReceived != null) { UserInfoReceived(this, uir); } }
private ChatExchangeInfo ParseChatExchangeInfo(ByteStream stream, int tlvLength) { ChatExchangeInfo retval = new ChatExchangeInfo(); retval.Exchange = stream.ReadUshort(); using (TlvBlock tlvs = new TlvBlock(stream.ReadByteArray(tlvLength))) { retval.ClassPermissions = tlvs.ReadUshort(0x0002); retval.Flags = tlvs.ReadUshort(0x00C9); retval.Name = tlvs.ReadString(0x00D3, Encoding.ASCII); retval.CreationPermissions = tlvs.ReadByte(0x00D5); retval.CharSet1 = tlvs.ReadString(0x00D6, Encoding.ASCII); retval.Language1 = tlvs.ReadString(0x00D7, Encoding.ASCII); retval.CharSet2 = tlvs.ReadString(0x00D8, Encoding.ASCII); retval.Language2 = tlvs.ReadString(0x00D9, Encoding.ASCII); } return(retval); }
/// <summary> /// Creates a new <see cref="ChatRoom"/> from a received <see cref="ByteStream"/> /// </summary> public ChatRoom(ByteStream stream) { exchangeNumber = stream.ReadUshort(); fullName = stream.ReadString(stream.ReadByte(), Encoding.ASCII); instance = stream.ReadUshort(); // A small chat room info block will only contain the bare essentials: // exchange number, chat room name, and instance number. // The chat room class really wants a display name, so parse one here. if (stream.HasMoreData) { detailLevel = stream.ReadByte(); unknownCode = stream.ReadUshort(); // No idea what this is using (TlvBlock block = new TlvBlock(stream.ReadByteArrayToEnd())) { flags = block.ReadUshort(CHATROOM_FLAGS); if (block.HasTlv(CHATROOM_CREATION_TIME)) { creationTime = block.ReadDateTime(CHATROOM_CREATION_TIME); } maxMessageLength = block.ReadUshort(CHATROOM_MESSAGE_LENGTH); maxOccupants = block.ReadUshort(CHATROOM_MAX_OCCUPANTS); displayName = block.ReadString(CHATROOM_DISPLAYNAME, Encoding.ASCII); creationPermissions = block.ReadByte(CHATROOM_PERMISSIONS); string charset = block.ReadString(CHATROOM_CHARSET1, Encoding.ASCII); if (!String.IsNullOrEmpty(charset)) { charSet1 = Encoding.GetEncoding(charset); } language1 = block.ReadString(CHATROOM_LANGUAGE1, Encoding.ASCII); charset = block.ReadString(CHATROOM_CHARSET2, Encoding.ASCII); if (!String.IsNullOrEmpty(charset)) { charSet2 = Encoding.GetEncoding(charset); } language2 = block.ReadString(CHATROOM_LANGUAGE2, Encoding.ASCII); contentType = block.ReadString(CHATROOM_CONTENTTYPE, Encoding.ASCII); } } // Make sure there's a display name to show if (String.IsNullOrEmpty(displayName)) { Match match = AolUriParser.Match(fullName); if (match.Success) { //displayName = UtilityMethods.DeHexUri(match.Groups["roomname"].Value); int lastDashBeforeName = fullName.IndexOf('-', 16); displayName = fullName.Substring(lastDashBeforeName + 1); } else { displayName = fullName; } } }
/// <summary> /// Processes the server response to a new family request -- SNAC(01,05) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(01,05)</param> private void ProcessNewServiceResponse(DataPacket dp) { int startIndex = 0; byte[] SNACData = dp.Data.ReadByteArrayToEnd(); if (SNACData[0] == 0x00 && SNACData[1] == 0x06) { startIndex += 2; // What the heck is this...0x0006, some families, some of the time? } using (TlvBlock tlvs = new TlvBlock(SNACData, startIndex)) { ushort family = tlvs.ReadUshort(NEW_SERVICE_FAMILY); string BOSaddress = tlvs.ReadString(NEW_SERVICE_ADDRESS, Encoding.ASCII); byte[] cookie = tlvs.ReadByteArray(NEW_SERVICE_COOKIE); Connection newconn = null; object store = dp.ParentSession.RetrieveRequestID(dp.SNAC.RequestID); if (family != 0x000E) { newconn = dp.ParentSession.Connections.CreateNewConnection(family); } else { ChatRoom roominfo = (ChatRoom)store; newconn = dp.ParentSession.Connections.CreateNewChatConnection(roominfo); } string[] bosinfo = BOSaddress.Split(':'); int port = 0; if (bosinfo.Length == 2) { port = Int32.Parse(bosinfo[1]); } else { port = dp.ParentSession.ServerSettings.LoginPort; } newconn.ServerConnectionCompleted += delegate { newconn.ReadHeader(); }; newconn.Server = bosinfo[0]; newconn.Port = port; newconn.Cookie = new Cookie(cookie); newconn.ConnectToServer(); } // The connection process continues when the server sends SNAC(01,03) }
/// <summary> /// Processes a login response -- SNAC(17,03) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(17,03)</param> internal void ProcessLoginResponse(DataPacket dp) { // Pull apart SNAC(17,03) Cookie cookie; string BOSaddress; using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { if (tlvs.HasTlv(0x0008)) { ushort errorcode = tlvs.ReadUshort(0x0008); parent.OnLoginFailed((LoginErrorCode)errorcode); return; } BOSaddress = tlvs.ReadString(0x0005, Encoding.ASCII); cookie = Cookie.GetReceivedCookie(tlvs.ReadByteArray(0x0006)); } // Shut down the authorization connection // Socket shutdown is initiated by the server parent.OnLoginStatusUpdate("Authorized", 0.33); dp.ParentConnection.DisconnectFromServer(false); // Create a new connection to the BOS server Connection newconn = parent.Connections.CreateNewConnection(0x0001); string[] bosinfo = BOSaddress.Split(':'); newconn.ServerConnectionCompleted += delegate(Connection conn) { conn.ReadyForData = true; conn.ReadHeader(); }; newconn.Server = bosinfo[0]; if (bosinfo.Length == 2) { newconn.Port = Int32.Parse(bosinfo[1]); } else { newconn.Port = dp.ParentConnection.Port; } Logging.WriteString("Connect to Server after auth. Address from dp: {0} - Address to connect: {1}:{2}", BOSaddress, newconn.Server, newconn.Port); newconn.Cookie = cookie; newconn.ConnectToServer(); // The login process continues when the server sends SNAC(01,03) on the new connection }
/// <summary> /// Processes an update to the chat room information -- SNAC(0E,02) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(0E,02)</param> internal void ProcessRoomUpdate(DataPacket dp) { exchangeNumber = dp.Data.ReadUshort(); fullName = dp.Data.ReadString(dp.Data.ReadByte(), Encoding.ASCII); instance = dp.Data.ReadUshort(); detailLevel = dp.Data.ReadByte(); ushort tlvcount = dp.Data.ReadUshort(); using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { displayName = tlvs.ReadString(CHATROOM_DISPLAYNAME, Encoding.ASCII); flags = tlvs.ReadUshort(CHATROOM_FLAGS); creationTime = tlvs.ReadDateTime(CHATROOM_CREATION_TIME); maxMessageLength = tlvs.ReadUshort(CHATROOM_MESSAGE_LENGTH); string charset = tlvs.ReadString(CHATROOM_CHARSET1, Encoding.ASCII); if (!String.IsNullOrEmpty(charset)) { charSet1 = Encoding.GetEncoding(charset); } language1 = tlvs.ReadString(CHATROOM_LANGUAGE1, Encoding.ASCII); charset = tlvs.ReadString(CHATROOM_CHARSET2, Encoding.ASCII); if (!String.IsNullOrEmpty(charset)) { charSet2 = Encoding.GetEncoding(charset); } language2 = tlvs.ReadString(CHATROOM_LANGUAGE2, Encoding.ASCII); contentType = tlvs.ReadString(CHATROOM_CONTENTTYPE, Encoding.ASCII); ushort maxvisiblemessagelength = tlvs.ReadUshort(0x00DA); string description = tlvs.ReadString(0x00D3, Encoding.ASCII); } }
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); } }