📄 uploadgroupfriendpacket.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.Hashtable;
import java.util.List;
import edu.tsinghua.lumaqq.qq.PacketParseException;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.packets.OutPacket;
/**
* <pre>
* 上传分组中好友列表的消息包,格式为
* 1. 头部
* 2. 好友的QQ号,4字节
* 3. 好友所在的组序号,0表示我的好友组,自己添加的组从1开始
* 4. 如果有更多好友,重复2,3部分
* 5. 尾部
* </pre>
*
* @author 马若劼
*/
public class UploadGroupFriendPacket extends OutPacket {
private Hashtable friends;
/**
* 构造函数
*/
public UploadGroupFriendPacket() {
super(QQ.QQ_CMD_UPLOAD_GROUP_FRIEND, true);
friends = new Hashtable();
}
/**
* @param buf
* @param length
* @throws PacketParseException
*/
public UploadGroupFriendPacket(ByteBuffer buf, int length)
throws PacketParseException {
super(buf, length);
}
/**
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
*/
protected void putBody(ByteBuffer buf) {
// 写入每一个好友的QQ号和组序号
int gSize = friends.size() + 1;
for(int i = 0; i < gSize; i++) {
Integer gKey = new Integer(i);
List gList = (List)friends.get(gKey);
// 等于null说明这是一个空组,不用处理了
if(gList != null) {
int fSize = gList.size();
for(int j = 0; j < fSize; j++) {
buf.putInt(((Integer)gList.get(j)).intValue());
buf.put((byte)i);
}
}
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#parseBody(java.nio.ByteBuffer)
*/
protected void parseBody(ByteBuffer buf) throws PacketParseException {
while(buf.hasRemaining()) {
Integer qq = new Integer(buf.getInt());
Integer gKey = new Integer(buf.get() & 0xFF);
List gList = (List)friends.get(gKey);
if(gList == null) {
gList = new ArrayList();
friends.put(gKey, gList);
}
gList.add(qq);
}
}
/**
* 添加好友信息
* @param gIndex 好友所在的组索引
* @param qqNum 好友的QQ号
*/
public void addFriend(int gIndex, int qqNum) {
Integer gKey = new Integer(gIndex);
List gList = null;
if(friends.containsKey(gKey))
gList = (List)friends.get(gKey);
else {
gList = new ArrayList();
friends.put(gKey, gList);
}
gList.add(new Integer(qqNum));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -