/// <summary> /// Processes requested chat room information -- SNAC(0D,09) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(0D,09)</param> public void ProcessChatRoomInformation(DataPacket dp) { ushort maxRooms = 0xFFFF; ReadOnlyCollection <Tlv> exchangeTlvs = null; ChatRoom newRoom = null; // Parse the response using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { maxRooms = tlvs.ReadByte(0x0002); if (tlvs.HasTlv(0x0003)) { exchangeTlvs = tlvs.ReadAllTlvs(0x0003); } if (tlvs.HasTlv(0x0004)) { newRoom = new ChatRoom(new ByteStream(tlvs.ReadByteArray(0x0004))); } } // If this packet was received in response to a chat room creation request, // request a new chat room connection from the BOS connection if (newRoom != null) { RequestChatRoomConnection(newRoom); } }
/// <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; } } }
private void ProcessMetaInformationResponse(DataPacket dp) { using (TlvBlock tlvs = new TlvBlock(dp.Data.ReadByteArrayToEnd())) { if (tlvs.HasTlv(0x0001)) { ByteStream stream = new ByteStream(tlvs.ReadByteArray(0x0001)); ushort cmdLength = stream.ReadUshortLE(); String uin = stream.ReadUintLE().ToString(); ushort command = stream.ReadUshortLE(); ushort requestId = stream.ReadUshortLE(); MetaResponseType responseType = (MetaResponseType)command; switch (responseType) { case MetaResponseType.OfflineMessage: parent.Messages.ReadIcqOfflineMessage(uin, stream); break; case MetaResponseType.EndOfflineMessage: parent.Messages.EndOfflineMessageSequence(uin, true); break; case MetaResponseType.MetaDataReply: this.ProcessMetaDataReply(uin, dp, stream); break; } } } }
public void TestChatRoomCreation() { ByteStream dataStream = new ByteStream(Data.SNAC_0D_09); using (TlvBlock tlvs = new TlvBlock(dataStream.ReadByteArrayToEnd())) { Assert.IsTrue(tlvs.HasTlv(0x0004), "TLV 0x0004 missing from data stream"); ChatRoom chatRoom = new ChatRoom(new ByteStream(tlvs.ReadByteArray(0x0004))); Assert.AreEqual(0x0004, chatRoom.Exchange); Assert.AreEqual("!aol://2719:10-4-chat9614646934270543373", chatRoom.FullName); Assert.AreEqual(0x0000, chatRoom.Instance); Assert.AreEqual("Chat 9614646934270543373", chatRoom.DisplayName); Assert.AreEqual(new DateTime(2007, 8, 5, 20, 9, 21, DateTimeKind.Utc), chatRoom.CreationTime); } }
/// <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 }