?? groupnameoppacket.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 java.util.ArrayList;
import java.util.List;
import edu.tsinghua.lumaqq.qq.PacketParseException;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.qq.packets.OutPacket;
/**
* <pre>
* 上傳下載分組名字的消息包,格式為
* 1. 頭部
* 2. 操作方式字節,如果為0x2,為上傳組名,如果為0x1,為請求下載組名
* 如果為0x2,后面的部分為
* i. 組序號,qq缺省的組,比如我的好友,序號是0,其他我們自己添加的組,從1開始,一個字節。
* 但是要注意的是,這里不包括我的好友組,因為我的好友組是QQ的缺省組,無需上傳名稱
* ii. 16個字節的組名,如果組名長度少于16個字節,后面的填0。之所以是16個,是因為QQ的組名長度最多8個漢字
* iii. 如果有更多組,重復i,ii部分
* 如果為0x1,后面的部分為
* i. 未知字節0x2
* ii. 4個未知字節,全0
* 3. 尾部
* </pre>
*
* @author 馬若劼
*/
public class GroupNameOpPacket extends OutPacket {
private List groups;
private byte type;
/**
* 構造函數
*/
public GroupNameOpPacket() {
super(QQ.QQ_CMD_GROUP_NAME_OP, true);
type = QQ.QQ_UPLOAD_GROUP_NAME;
groups = new ArrayList();
}
/**
* @param buf
* @param length
* @throws PacketParseException
*/
public GroupNameOpPacket(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);
if(type == QQ.QQ_UPLOAD_GROUP_NAME) {
// 循環寫入各個組
int size = groups.size();
for(int i = 0; i < size; i++) {
String name = (String)groups.get(i);
// 組序號
buf.put((byte)(i + 1));
// 組名稱
byte[] nameBytes = Utils.getBytes(name, QQ.QQ_CHARSET_DEFAULT);
// 超過最大長度的,截短;小于最大長度的,補0
if(nameBytes.length > QQ.QQ_MAX_GROUP_NAME_BYTE)
buf.put(nameBytes, 0, QQ.QQ_MAX_GROUP_NAME_BYTE);
else {
buf.put(nameBytes);
int j = QQ.QQ_MAX_GROUP_NAME_BYTE - nameBytes.length;
while(j-- > 0)
buf.put((byte)0);
}
}
} else {
// 未知字節0x2
buf.put((byte)0x2);
// 未知4字節,全0
buf.putInt(0);
}
}
/* (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_GROUP_NAME) {
while(buf.hasRemaining()) {
buf.get();
groups.add(Utils.getString(buf, (byte)0x00, QQ.QQ_MAX_GROUP_NAME_BYTE));
}
}
}
/**
* 添加組名,這個方法沒有限制添加的組名叫什么,也沒有明確規定第一個組必須是
* 我的好友組,這些規范需要在上層程序中實現。當然也可以不一定非要第一個組是
* 我的好友組,這些客戶端的trick隨便你怎么搞
* @param name
*/
public void addGroup(String name) {
groups.add(name);
}
/**
* @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 + -