⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clustercreatepacket.java

📁 很多人都在开发的QQ代码
💻 JAVA
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.qq.packets.out;

import java.nio.ByteBuffer;

import edu.tsinghua.lumaqq.qq.PacketParseException;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Utils;

/**
 * <pre>
 * 创建群请求包,格式为:
 * 1. 头部
 * 2. 群命令类型,1字节,创建是0x01
 * 3. 群的类型,固定还是临时,1字节
 * 4. 是否需要认证,1字节
 * 5. 未知的2字节,0x0000
 * 6. 群的分类,2字节。2003中有提供了四个分类,比如同学,朋友,这个字段就是分类的序号,
 *    估计自己随便搞个分类也没有问题
 * 7. 群名称长度,1字节
 * 8. 群名称
 * 9. 未知的2字节,0x0000
 * 10. 群声明长度,1字节
 * 11. 群声明
 * 12. 群描述长度,1字节
 * 13. 群描述
 * 14. 群现有成员的QQ号列表,每个QQ号4字节
 * 15. 尾部 
 * </pre>
 * 
 * @author 马若劼
 */
public class ClusterCreatePacket extends ClusterCommandPacket {
	private byte type;
	private byte authType;
	private char category;
	private String name;
	private String notice;
	private String description;
	private int[] members;
	
    /**
     * 构造函数
     */
    public ClusterCreatePacket() {
        super();
		this.subCommand = QQ.QQ_CLUSTER_CMD_CREATE_CLUSTER;
		this.type = QQ.QQ_CLUSTER_TYPE_PERMANENT;
		this.authType = QQ.QQ_CLUSTER_NEED_AUTH;		
    }

    /**
     * @param buf
     * @param length
     * @throws PacketParseException
     */
    public ClusterCreatePacket(ByteBuffer buf, int length)
            throws PacketParseException {
        super(buf, length);
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
     */
    protected void putBody(ByteBuffer buf) {
		// 群命令类型
		buf.put(subCommand);
		// 群类型
		buf.put(type);
		// 认证类型
		buf.put(authType);
		// 未知的2字节
		buf.putChar((char)0);
		// 群的分类
		buf.putChar(category);
		// 群名称长度和群名称
		byte[] b = name.getBytes();
		buf.put((byte)(b.length & 0xFF));
		buf.put(b);
		// 未知的2字节
		buf.putChar((char)0);
		// 群声明长度和群声明
		b = notice.getBytes();
		buf.put((byte)(b.length & 0xFF));
		buf.put(b);
		// 群描述长度和群描述
		b = description.getBytes();
		buf.put((byte)(b.length & 0xFF));
		buf.put(b);
		// 群中的好友
		for(int i = 0; i < members.length; i++)
			buf.putInt(members[i]);
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.OutPacket#parseBody(java.nio.ByteBuffer)
     */
    protected void parseBody(ByteBuffer buf) throws PacketParseException {
        subCommand = buf.get();
        type = buf.get();
        authType = buf.get();
        buf.getChar();
        category = buf.getChar();            
        name = Utils.getString(buf, buf.get() & 0xFF);
        buf.getChar();
        notice = Utils.getString(buf, buf.get() & 0xFF);
        description = Utils.getString(buf, buf.get() & 0xFF);
        
        int m = buf.remaining() / 4;
        members = new int[m];
        for(int i = 0; i < m; i++)
            members[i] = buf.getInt();
    }
	
	/**
	 * @return Returns the authType.
	 */
	public byte getAuthType() {
		return authType;
	}
	
	/**
	 * @param authType The authType to set.
	 */
	public void setAuthType(byte authType) {
		this.authType = authType;
	}
	
	/**
	 * @return Returns the description.
	 */
	public String getDescription() {
		return description;
	}
	
	/**
	 * @param description The description to set.
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	
	/**
	 * @return Returns the members.
	 */
	public int[] getMembers() {
		return members;
	}
	
	/**
	 * @param members The members to set.
	 */
	public void setMembers(int[] members) {
		this.members = members;
	}
	
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * @return Returns the notice.
	 */
	public String getNotice() {
		return notice;
	}
	
	/**
	 * @param notice The notice to set.
	 */
	public void setNotice(String notice) {
		this.notice = notice;
	}
	
	/**
	 * @return Returns the type.
	 */
	public byte getType() {
		return type;
	}
	
	/**
	 * @param type The type to set.
	 */
	public void setType(byte type) {
		this.type = type;
	}
	
	/**
	 * @return Returns the category.
	 */
	public char getCategory() {
		return category;
	}
	
	/**
	 * @param category The category to set.
	 */
	public void setCategory(char category) {
		this.category = category;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -