/// <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 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 }