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> /// Performs TLV 0x2711 processing for direct connect (sendfiles, DirectIM) negotiation /// </summary> private void ProcessDirectConnectionRequest(DirectConnection conn, ByteStream stream) { if (conn.Type == RendezvousType.Accept) { // They're accepting, which means we're going to get a connection on the // listener socket set up in FileTransferManager. Do nothing here } else if (conn.Type == RendezvousType.Cancel) { DirectConnection cancelled = parent.Connections.GetDirectConnectionByCookie(conn.Cookie); if (cancelled != null) { if (cancelled is FileTransferConnection) { (cancelled as FileTransferConnection).CancelFileTransfer( "Remote user cancelled direct connection"); } else if (cancelled is DirectIMConnection) { parent.OnDirectIMSessionCancelled(cancelled, "Remote user cancelled direct connection"); } } return; } else if (conn.Type == RendezvousType.Invite) { // AIM sends a type 0x0000 when accepting...huh. if (conn.Sequence == RendezvousSequence.DirectOrStage1) { if (stream.HasMoreData && conn is FileTransferConnection) { FileTransferConnection ftconn = conn as FileTransferConnection; ftconn.SubType = stream.ReadUshort(); ftconn.TotalFiles = stream.ReadUshort(); ftconn.TotalFileSize = stream.ReadUint(); int strlen = 0; byte[] servicedata = stream.ReadByteArrayToEnd(); // The filename in an RD invite is null-terminated ASCII while (servicedata[strlen++] != 0x00) ; ftconn.FileHeader.Name = Encoding.ASCII.GetString(servicedata, 0, strlen - 1); } parent.OnDirectConnectionRequestReceived(conn.Cookie); } else if (conn.Sequence == RendezvousSequence.Stage2) { // The receipient of a previous invite wants a stage 2 proxy redirection // Shut down the server socket, we won't be getting a connection on it conn.StopListeningSocket(); SendDirectConnectionAccept(conn); conn.StartSendThroughStage2AolProxy(); } else if (conn.Sequence == RendezvousSequence.Stage3) { // Direct connection and proxy 2 failed, the sender's trying to proxy it now conn.Method = DirectConnectionMethod.Proxied; conn.ConnectToServer(); } } }
/// <summary> /// Processes an incoming ICBM message on channel 1 -- SNAC(04,07) /// </summary> /// <param name="stream">A received <see cref="ByteStream"/></param> /// <param name="ui">The UserInfo block that came with this message</param> private void ProcessChannelOneMessage(ByteStream stream, UserInfo ui) { IM message = new IM(ui); using (TlvBlock tlvs = new TlvBlock(stream.ReadByteArrayToEnd())) { message.IsAutoResponse = tlvs.HasTlv(0x0004); // If this message was received offline, cast it to an OfflineIM if (tlvs.HasTlv(0x0006)) { message = new OfflineIM(message); if (tlvs.HasTlv(0x0016)) { ((OfflineIM)message).ReceivedOn = tlvs.ReadDateTime(0x0016); } } GetChannelOneMessage(new ByteStream(tlvs.ReadByteArray(0x0002)), ref message); } // Figure out what to do with it if (message is OfflineIM) { OfflineIM offlineMessage = message as OfflineIM; if (isRetrievingOfflineMessages) { // Queue it for delivery AcceptIcbmOIM(offlineMessage); } else { // A single offline message? Okay then if (OfflineMessagesReceived != null) { List<OfflineIM> tmpList = new List<OfflineIM>(1); tmpList.Add(offlineMessage); OfflineMessagesReceived(this, new OfflineMessagesReceivedEventArgs(parent.ScreenName, new Collection<OfflineIM>(tmpList))); } } // Offline messages don't get delivered via OnMessageReceived - if the offline messages event // isn't hooked up, tough stuff. return; } else { OnMessageReceived(message); } }
/// <summary> /// Process a ICBM that was sent over channel two - rich text messages, chat/filetransfer invites, buddy icons /// </summary> private void ProcessChannelTwoMessage(ByteStream stream, UserInfo ui, DataPacket dp) { TlvBlock tlvs = new TlvBlock(stream.ReadByteArrayToEnd()); //KSD-SYSTEMS - commented at 02.12.2009 -> Hangs up at errorCode reading //ushort errorCode = tlvs.ReadUshort(0x000B); DirectConnection conn = ProcessChannel2Tlv05(new ByteStream(tlvs.ReadByteArray(0x0005)), ui, dp); }
/// <summary> /// Processes the inner TLV list in TLV 0x0005 and returns a new DirectConnection /// </summary> private DirectConnection ProcessChannel2Tlv05(ByteStream stream, UserInfo ui, DataPacket dp) { byte[] invitemessage; Encoding encoding = Encoding.ASCII; string language = "en"; DirectConnection directconn = null; // Pull the type, cookie, and capability array RendezvousType rtype = RendezvousData.TypeFromUshort(stream.ReadUshort()); Cookie cookie = Cookie.GetReceivedCookie(stream.ReadByteArray(8)); byte[] capabilitiesArray = stream.ReadByteArray(16); Capabilities capabilities = CapabilityProcessor.ProcessCLSIDList(capabilitiesArray); // Create the correct type of connection based on the capability if (capabilities == Capabilities.SendFiles) { if ((directconn = parent.Connections.GetDirectConnectionByCookie(cookie)) == null) { directconn = parent.Connections.CreateNewFileTransferConnection( DirectConnectionMethod.Direct, DirectConnectRole.Receiver); } } else if (capabilities == Capabilities.DirectIM) { if ((directconn = parent.Connections.GetDirectConnectionByCookie(cookie)) == null) { directconn = parent.Connections.CreateNewDirectIMConnection( DirectConnectionMethod.Direct, DirectConnectRole.Receiver); } } else if (capabilities == Capabilities.Chat) { directconn = parent.Connections.CreateNewChatInvitationConnection(DirectConnectRole.Receiver); } else { // Currently unsupported parent.OnWarning(ServerErrorCode.UnknownRendezvousChannel, dp); return null; } directconn.Other = ui; directconn.Cookie = cookie; directconn.Type = rtype; ByteStream serviceData = null; Encoding serviceDataEncoding = Encoding.ASCII; // Process the inner TLV list using (TlvBlock tlvs = new TlvBlock(stream.ReadByteArrayToEnd())) { directconn.AOLProxyIP = tlvs.ReadIPAddress(DC_PROXY_IP_ADDRESS); // proxy ip directconn.ClientIP = tlvs.ReadIPAddress(DC_CLIENT_IP_ADDRESS); // internal ip directconn.VerifiedIP = tlvs.ReadIPAddress(0x0004); // external ip directconn.Port = tlvs.ReadUshort(DC_PORT); directconn.Sequence = RendezvousData.SequenceFromUshort(tlvs.ReadUshort(DC_SEQUENCE_NUMBER)); invitemessage = tlvs.ReadByteArray(DC_MESSAGE); if (tlvs.HasTlv(0x000D)) { encoding = Encoding.GetEncoding(tlvs.ReadString(0x000D, Encoding.ASCII)); } language = tlvs.ReadString(0x000E, Encoding.ASCII); directconn.Method = (tlvs.HasTlv(DC_USE_PROXY_FLAG)) ? DirectConnectionMethod.Proxied : DirectConnectionMethod.Direct; serviceData = new ByteStream(tlvs.ReadByteArray(0x2711)); if (tlvs.HasTlv(0x2712)) { serviceDataEncoding = Encoding.GetEncoding(tlvs.ReadString(0x2712, Encoding.ASCII)); } } if (invitemessage != null) { directconn.Message = encoding.GetString(invitemessage, 0, invitemessage.Length); } // Process the extra data, if necessary if (directconn is FileTransferConnection || directconn is DirectIMConnection) { ProcessDirectConnectionRequest(directconn, serviceData); } else if (directconn is ChatInvitationConnection) { ChatInvitationConnection cic = directconn as ChatInvitationConnection; cic.ChatInvite = new ChatInvitation(); cic.ChatInvite.Message = directconn.Message; cic.ChatInvite.Encoding = encoding; cic.ChatInvite.Language = language; ProcessChatInvitationRequest(cic, serviceData); } return directconn; }