📄 systemnotificationpacket.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.in;
import java.io.UnsupportedEncodingException;
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.packets.InPacket;
/**
* <pre>
* 系统消息包,系统消息和ReceiveIMPacket里面的系统通知有什么区别呢?
* 系统消息是表示你被别人加为好友了之类的消息,所以有源有目的,其他人
* 收不到的,系统通知是系统发给大家的消息。好了,废话这么多,系统消息的
* 格式是:
* 1. 头部,头部说明了系统消息的类型,目前已知的有四种
* 2. 以0x1F相隔的多个字段,对于已知的类型,分别是消息类型,源,目的,消息正文,对于未知的
* 消息类型,前面三个是一样的,后面的就未知了
* 3. 尾部
* </pre>
*
* @author 马若劼
*/
public class SystemNotificationPacket extends InPacket {
// 分隔符
public static final String DIVIDER = Character.toString((char)0x1F);
// 消息类型
public char type;
// 从哪里来,是源的QQ号
public int from;
// 到哪里去,目的的QQ号
public int to;
// 附加的消息,比如如果别人拒绝了你加他为好友,并说了理由,那就在这里了
public String message;
/**
* 构造函数
* @param buf 缓冲区
* @param length 包长度
* @throws PacketParseException 解析错误
*/
public SystemNotificationPacket(ByteBuffer buf, int length) throws PacketParseException {
super(buf, length);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.InPacket#parseBody(java.nio.ByteBuffer)
*/
protected void parseBody(ByteBuffer buf) throws PacketParseException {
byte[] b = buf.array();
String s = null;
try {
s = new String(b, QQ.QQ_CHARSET_DEFAULT);
} catch (UnsupportedEncodingException e) {
s = new String(b);
}
String[] fields = s.split(DIVIDER);
type = Utils.getChar(fields[0], 0);
from = Utils.getInt(fields[1], 0);
to = Utils.getInt(fields[2], 0);
if(fields.length > 3)
message = fields[3];
else
message = "";
if(from == 0 || to == 0)
throw new PacketParseException("系统通知字段解析出错");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -