?? 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>
* 系統(tǒng)消息包,系統(tǒng)消息和ReceiveIMPacket里面的系統(tǒng)通知有什么區(qū)別呢?
* 系統(tǒng)消息是表示你被別人加為好友了之類的消息,所以有源有目的,其他人
* 收不到的,系統(tǒng)通知是系統(tǒng)發(fā)給大家的消息。好了,廢話這么多,系統(tǒng)消息的
* 格式是:
* 1. 頭部,頭部說明了系統(tǒng)消息的類型,目前已知的有四種
* 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;
/**
* 構(gòu)造函數(shù)
* @param buf 緩沖區(qū)
* @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("系統(tǒng)通知字段解析出錯");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -