protected override void PutBody(ByteBuffer buf)
        {
            // 命令类型
            buf.Put((byte)SubCommand);
            // 群内部ID
            buf.PutInt(ClusterId);
            // 后面数据的长度,这个长度需要根据后面的长度计算才能知道,
            // 所以先占个位置
            int pos = buf.Position;

            buf.PutChar((char)0);
            // 未知的2字节
            buf.PutChar((char)1);
            // 分片数
            buf.Put((byte)TotalFragments);
            // 分片序号
            buf.Put((byte)FragmentSequence);
            // 消息id
            buf.PutUShort(MessageId);
            // 未知4字节
            buf.PutInt(0);
            // 以0结束的消息,首先我们要根据用户设置的message,解析出一个网络可发送的格式
            // 这一步比较麻烦,暂时想不到好的办法
            byte[] msgBytes = null;
            int    j, i = 0;

            while ((j = Message.IndexOf((char)FaceType.DEFAULT, i)) != -1)
            {
                string sub = Message.Substring(i, j);
                if (!sub.Equals(""))
                {
                    msgBytes = Utils.Util.GetBytes(sub);
                    buf.Put(msgBytes);
                }
                buf.Put((byte)FaceType.DEFAULT);
                buf.Put((byte)(Message[j + 1] & 0xFF));
                i = j + 2;
            }
            if (i < Message.Length)
            {
                string sub = Message.Substring(i);
                msgBytes = Utils.Util.GetBytes(sub);
                buf.Put(msgBytes);
            }

            // 只有最后一个分片有空格和字体属性
            if (FragmentSequence == TotalFragments - 1)
            {
                buf.Put((byte)0x20);
                FontStyle.Write(buf);
            }
            // 写入长度
            int cur = buf.Position;

            buf.Position = pos;
            buf.PutChar((char)(cur - pos - 2));
            buf.Position = cur;
        }
示例#2
0
 /// <summary> 初始化普通消息包的其余部分
 ///     <remark>abu 2008-02-29 </remark>
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitTextContent(ByteBuffer buf)
 {
     // 消息方式,是发送的,还是自动回复的,1字节
     buf.Put((byte)ReplyType);
     // 写入消息正文字节数组
     if (Message != null)
     {
         buf.Put(Message);
     }
     // 最后一个分片时追加空格
     if (FragmentSequence == TotalFragments - 1)
     {
         buf.Put((byte)0x20);
     }
     // 消息尾部,字体修饰属性
     FontStyle.Write(buf);
 }