public void SendClusterIM(int clusterId, string message, int totalFragments, int fragmentSequence, FontStyle fontStyle) { ClusterSendIMExPacket packet = new ClusterSendIMExPacket(QQClient); packet.ClusterId = clusterId; packet.Message = message; packet.TotalFragments = totalFragments; packet.FragmentSequence = fragmentSequence; packet.FontStyle = fontStyle; QQClient.PacketManager.SendPacket(packet, QQPort.Main.Name); }
/// <summary> /// 发送普通信息 /// </summary> /// <param name="receiver">The receiver.</param> /// <param name="message">The message.</param> /// <param name="totalFragments">The total fragments.总分块数</param> /// <param name="fragementSequence">The fragement sequence.当前当块序号</param> /// <param name="fontSytle">The font sytle.</param> public void SendIM(int receiver, byte[] message, int totalFragments, int fragementSequence, FontStyle fontSytle) { SendIMPacket packet = new SendIMPacket(QQClient); packet.Receiver = receiver; packet.Message = message; packet.TotalFragments = totalFragments; packet.FragmentSequence = fragementSequence; packet.FontStyle = fontSytle; QQClient.PacketManager.SendPacket(packet, QQPort.Main.Name); }
/// <summary> /// 发送临时信息 /// <remark>abu 2008-03-11 </remark> /// </summary> /// <param name="receiver">The receiver.</param> /// <param name="message">The message.</param> /// <param name="myNick">My nick.你的昵称</param> /// <param name="fontSytle">The font sytle.</param> public void SendTempIM(int receiver, string message, string myNick, FontStyle fontSytle) { TempSessionOpPacket packet = new TempSessionOpPacket(QQClient); packet.SubCommand = TempSessionSubCmd.SendIM; packet.Receiver = receiver; packet.Message = message; packet.Nick = myNick; packet.FontStyle = fontSytle; QQClient.PacketManager.SendPacket(packet, QQPort.Main.Name); }
public SendIMPacket(QQClient client) : base(QQCommand.Send_IM,true,client) { FontStyle = new FontStyle(); Message = null; MessageType = NormalIMType.TEXT; ReplyType = ReplyType.NORMAL; TransferType = TransferType.FILE; FakeIp = false; TotalFragments = 1; FragmentSequence = 0; }
/// <summary> /// 发送普通信息 /// <remark>abu 2008-03-11 </remark> /// </summary> /// <param name="receiver">The receiver.</param> /// <param name="message">The message.</param> /// <param name="fontSytle">The font sytle.</param> public void SendIM(int receiver, string message, FontStyle fontSytle) { int MaxByte = QQGlobal.QQ_MAX_SEND_IM;//取最长长度 // //发送长信息的功能由 @蓝色的风之精灵 补充,http://www.cnblogs.com/lersh/archive/2008/04/22/1165451.html // if (Encoding.GetEncoding(QQGlobal.QQ_CHARSET_DEFAULT).GetBytes(message).Length > MaxByte)//判断是不是要分段发送 { List<byte> messageBytes = new List<byte>(); messageBytes.AddRange(Utils.Util.GetBytes(message)); messageBytes.Add(0x20);//补一个空格,不补似乎也会出问题 int messageSize = messageBytes.Count; int totalFragments = ((messageSize % MaxByte) > 0) ? (messageSize / MaxByte + 1) : (messageSize / MaxByte);//计算分片数 for (int fragementSequence = 0; fragementSequence < totalFragments; fragementSequence++) { int index = fragementSequence * MaxByte; int BytesSize = ((messageSize - index) > MaxByte) ? MaxByte : (messageSize - index);//不能每次都申请最大长度的byte数组,不然字体会出问题 byte[] messageFragementBytes = new byte[BytesSize]; messageBytes.CopyTo(index, messageFragementBytes, 0, BytesSize); SendIM(receiver, messageFragementBytes, totalFragments, fragementSequence, fontSytle); } } else { SendIM(receiver, Utils.Util.GetBytes(message), 1, 0, fontSytle); } }
/// <summary> /// 分析09的流 /// </summary> /// <param name="buf"></param> public void Read09(ByteBuffer buf) { FontStyle = new FontStyle(); // 是否有字体属性 HasFontAttribute = buf.GetInt() != 0; // 分片数 TotalFragments = (int)buf.Get(); // 分片序号 FragmentSequence = (int)buf.Get(); // 消息id 两个字节 MessageId = (int)buf.GetUShort(); // 消息类型,这里的类型表示是正常回复还是自动回复之类的信息 ReplyType = (ReplyType)buf.Get(); // 消息正文 #region 字体属性开始 未处理 buf.Position += 8;//'M' 'S' 'G' 00 00 00 00 00 buf.GetInt();//send time buf.Position += 12;//5D 69 71 DE 00 80 80 00 0A 00 86 00 参见sendim int len = buf.GetUShort(); buf.GetByteArray(len);//字体 E5 AE 8B E4 BD 93 =宋体 #endregion buf.GetUShort();//00 00 IsNormalIM09 = true;//标注09的信息 MessageBytes = buf.GetByteArray(buf.Remaining()); //_Message = ""; //while (buf.HasRemaining()) //{ // byte type = buf.Get(); // len = buf.GetUShort(); // switch (type) // { // case 0x01://pure text // //len_str = buf.GetUShort(); // _Message +=new NormalIMText(QQClient,buf.GetByteArray(len)).ToString(); // break; // case 0x02://face // _Message += new NormalIMFace(QQClient, buf.GetByteArray(len)).ToString(); // break; // case 0x06://image // _Message += new NormalIMImage(QQClient, buf.GetByteArray(len)).ToString(); // break; // default: // QQClient.LogManager.Log(ToString() + " Class Parse Unknown Type=0x" + type.ToString("X") + " Data=" + Utils.Util.ToHex(buf.GetByteArray(len))); // break; // } //} }
/// <summary>给定一个输入流,解析NormalIM结构 /// </summary> /// <param name="buf">The buf.</param> public void Read(ByteBuffer buf) { FontStyle = new FontStyle(); // 是否有字体属性 HasFontAttribute = buf.GetInt() != 0; // 分片数 TotalFragments = (int)buf.Get(); // 分片序号 FragmentSequence = (int)buf.Get(); // 消息id 两个字节 MessageId = (int)buf.GetUShort(); // 消息类型,这里的类型表示是正常回复还是自动回复之类的信息 ReplyType = (ReplyType)buf.Get(); // 消息正文,长度=剩余字节数 - 包尾字体属性长度 int remain = buf.Remaining(); int fontAttributeLength = HasFontAttribute ? (buf.Get(buf.Position + remain - 1) & 0xFF) : 0; MessageBytes = buf.GetByteArray(remain - fontAttributeLength); // 这后面都是字体属性,这个和SendIMPacket里面的是一样的 if (HasFontAttribute) { if (buf.HasRemaining()) FontStyle.Read(buf); else HasFontAttribute = false; } }
public TempSessionOpPacket(QQClient client) : base(QQCommand.Temp_Session_OP_05,true,client) { Site = Nick = Message = string.Empty; FontStyle = new FontStyle(); }
/// <summary> /// Initializes a new instance of the <see cref="ClusterSendIMExPacket"/> class. /// </summary> /// <param name="user">The user.</param> public ClusterSendIMExPacket(QQClient client) : base(client) { SubCommand = ClusterCommand.SEND_IM_EX09; TotalFragments = 1; FragmentSequence = 0; MessageId = (ushort)Utils.Util.Random.Next(); FontStyle = new FontStyle(); Message = string.Empty; }
/// <summary> /// </summary> /// <param name="buf">The buf.</param> public void Read(ByteBuffer buf) { // 发送者 Sender = buf.GetInt(); // 未知的4字节 buf.GetInt(); // 昵称 int len = buf.Get() & 0xFF; Nick = Utils.Util.GetString(buf, len); // 群名称 len = buf.Get() & 0xFF; Site = Utils.Util.GetString(buf, len); // 未知的1字节 buf.Get(); // 时间 Time = (long)buf.GetInt() * 1000L; // 后面的内容长度 len = buf.GetUShort(); // 得到字体属性长度,然后得到消息内容 int fontStyleLength = buf.Get(buf.Position + len - 1) & 0xFF; Message = Utils.Util.GetString(buf, len - fontStyleLength); // 字体属性 FontStyle = new FontStyle(); FontStyle.Read(buf); }