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

📄 friendremarkoppacket.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;
import edu.tsinghua.lumaqq.qq.beans.FriendRemark;
import edu.tsinghua.lumaqq.qq.packets.OutPacket;

/**
 * <pre>
 * 上传下载好友备注的消息包,格式为
 * 1. 头部
 * 2. 包类型,表明是上传还是下载,1字节
 * 3. 一个未知字节0x0
 * 4. 操作对象的QQ号,4字节
 * 5. 一个未知字节0x0
 * 6. 以下为备注信息,一共7个域,域的顺序依次次是
 *    姓名、手机、电话、地址、邮箱、邮编、备注
 *    每个域都有一个前导字节,这个字节表示了这个域的字节长度
 * 7. 尾部
 * 
 * 说明:如果是上传备注,所有的部分都需要,如果是下载备注,仅保留1,2,4,7部分
 * </pre>
 * 
 * @author 马若劼
 */
public class FriendRemarkOpPacket extends OutPacket {
	// 操作类型,上传还是下载
	private byte type;
	// 操作的对象的QQ号
	private int qq;
	// 好友备注对象
	private FriendRemark remark;
	
    /**
     * 构造函数
     */
    public FriendRemarkOpPacket() {
        super(QQ.QQ_CMD_FRIEND_REMARK_OP, true);
		type = QQ.QQ_UPLOAD_FRIEND_REMARK;
		remark = new FriendRemark();
    }
    
    /**
     * @param buf
     * @param length
     * @throws PacketParseException
     */
    public FriendRemarkOpPacket(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(type);
		// 未知字节0x0,仅在上传时
		if(type == QQ.QQ_UPLOAD_FRIEND_REMARK)
			buf.put((byte)0);
		// 操作对象的QQ号
		buf.putInt(qq);
		// 后面的内容为一个未知字节0和备注信息,仅在上传时
		if(type == QQ.QQ_UPLOAD_FRIEND_REMARK) {
			buf.put((byte)0);
			// 备注信息
			// 姓名
			if(remark.name == null || remark.name.equals(""))
				buf.put((byte)0);
			else {
				byte[] b = Utils.getBytes(remark.name, QQ.QQ_CHARSET_DEFAULT);
				buf.put((byte)b.length);
				buf.put(b);					
			}
			// 手机
			if(remark.mobile == null || remark.mobile.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = remark.mobile.getBytes();
				buf.put((byte)b.length);
				buf.put(b);					
			}
			// 电话
			if(remark.telephone == null || remark.telephone.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = remark.telephone.getBytes();
				buf.put((byte)b.length);
				buf.put(b);				
			}
			// 地址
			if(remark.address == null || remark.address.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = remark.address.getBytes();
				buf.put((byte)b.length);
				buf.put(b);					
			}
			// 邮箱
			if(remark.email == null || remark.email.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = remark.email.getBytes();
				buf.put((byte)b.length);
				buf.put(b);					
			}
			// 邮编
			if(remark.zipcode == null || remark.zipcode.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = remark.zipcode.getBytes();
				buf.put((byte)b.length);
				buf.put(b);						
			}
			// 备注
			if(remark.note == null || remark.note.equals(""))
			    buf.put((byte)0);
			else  {
				byte[] b = Utils.getBytes(remark.note, QQ.QQ_CHARSET_DEFAULT);
				buf.put((byte)b.length);
				buf.put(b);					
			}
		}
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.OutPacket#parseBody(java.nio.ByteBuffer)
     */
    protected void parseBody(ByteBuffer buf) throws PacketParseException {
        type = buf.get();
        if(type == QQ.QQ_UPLOAD_FRIEND_REMARK)
            buf.get();
        qq = buf.getInt();
        if(type == QQ.QQ_UPLOAD_FRIEND_REMARK) {
            buf.get();
            remark.name = Utils.getString(buf, buf.get() & 0xFF);
            remark.mobile = Utils.getString(buf, buf.get() & 0xFF);
            remark.telephone = Utils.getString(buf, buf.get() & 0xFF);
            remark.address = Utils.getString(buf, buf.get() & 0xFF);
            remark.email = Utils.getString(buf, buf.get() & 0xFF);
            remark.zipcode = Utils.getString(buf, buf.get() & 0xFF);
            remark.note = Utils.getString(buf, buf.get() & 0xFF);
        }
    }
    
	/**
	 * @return Returns the address.
	 */
	public String getAddress() {
		return remark.address;
	}
	
	/**
	 * @param address The address to set.
	 */
	public void setAddress(String address) {
		remark.address = address;
	}
	
	/**
	 * @return Returns the email.
	 */
	public String getEmail() {
		return remark.email;
	}
	
	/**
	 * @param email The email to set.
	 */
	public void setEmail(String email) {
		remark.email = email;
	}
	
	/**
	 * @return Returns the mobile.
	 */
	public String getMobile() {
		return remark.mobile;
	}
	
	/**
	 * @param mobile The mobile to set.
	 */
	public void setMobile(String mobile) {
		remark.mobile = mobile;
	}
	
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return remark.name;
	}
	
	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		remark.name = name;
	}
	
	/**
	 * @return Returns the note.
	 */
	public String getNote() {
		return remark.note;
	}
	
	/**
	 * @param note The note to set.
	 */
	public void setNote(String note) {
		remark.note = note;
	}
	
	/**
	 * @return Returns the telephone.
	 */
	public String getTelephone() {
		return remark.telephone;
	}
	
	/**
	 * @param telephone The telephone to set.
	 */
	public void setTelephone(String telephone) {
		remark.telephone = telephone;
	}
	
	/**
	 * @return Returns the zipcode.
	 */
	public String getZipcode() {
		return remark.zipcode;
	}
	
	/**
	 * @param zipcode The zipcode to set.
	 */
	public void setZipcode(String zipcode) {
		remark.zipcode = zipcode;
	}
	
	/**
	 * @return Returns the qq.
	 */
	public int getQQ() {
		return qq;
	}
	
	/**
	 * @param qq The qq to set.
	 */
	public void setQQ(int qqNum) {
		this.qq = qqNum;
	}
	
	/**
	 * @return Returns the remark.
	 */
	public FriendRemark getRemark() {
		return remark;
	}
	
	/**
	 * @param remark The remark to set.
	 */
	public void setRemark(FriendRemark remark) {
		this.remark = remark;
	}
	
	/**
	 * @return Returns the type.
	 */
	public byte getType() {
		return type;
	}
	
	/**
	 * @param type The type to set.
	 */
	public void setType(byte type) {
		this.type = type;
	}
}

⌨️ 快捷键说明

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