?? _03inpacket.java
字號(hào):
/*
* 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;
import java.nio.ByteBuffer;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.annotation.BasePacket;
import edu.tsinghua.lumaqq.qq.annotation.DocumentalPacket;
import edu.tsinghua.lumaqq.qq.beans.QQUser;
/**
* <pre>
* 03協(xié)議族輸入包基類(其實(shí)和輸出包一樣),這個(gè)協(xié)議族的格式為
* 1. 協(xié)議族包頭,1字節(jié),0x03
* 2. 命令,1字節(jié)
* 3. 包序號(hào),2字節(jié)
* 4. 未知的4字節(jié)
* 5. 未知的4字節(jié)
* 6. 未知的4字節(jié)
* 7. 未知的4字節(jié)
* 8. 未知的4字節(jié)
* 9. 未知的4字節(jié)
* 10. 未知的4字節(jié)
* 11. 未知的4字節(jié)
* 12. 未知的4字節(jié)
* 13. 分片數(shù),1字節(jié)
* Note: 對(duì)于一個(gè)收到的包來(lái)說(shuō),13部分可能大于1
* 14. 當(dāng)前分片,1字節(jié),從0開(kāi)始
* 15. 未知1字節(jié)
* 16. 發(fā)送者版本號(hào),2字節(jié)
* 17. 未知1字節(jié)
* 18. 包體
*
* Note: 此協(xié)議族無(wú)加密,無(wú)包尾
* </pre>
*
* @author luma
*/
@DocumentalPacket
@BasePacket(name="03協(xié)議族輸入包", klass=_03InPacket.class)
public abstract class _03InPacket extends InPacket {
public byte totalFragment;
public byte currentFragment;
public int serialNumber;
public _03InPacket(char command, QQUser user) {
super(QQ.QQ_HEADER_03_FAMILY, (char)0, command, user);
}
public _03InPacket(ByteBuffer buf, int length, QQUser user) throws PacketParseException {
super(buf, length, user);
}
@Override
protected int getLength(int bodyLength) {
return QQ.QQ_LENGTH_FTP_FAMILY_HEADER + bodyLength;
}
@Override
protected int getHeadLength() {
return QQ.QQ_LENGTH_FTP_FAMILY_HEADER;
}
@Override
protected int getTailLength() {
return 0;
}
@Override
protected void putHead(ByteBuffer buf) {
buf.put(QQ.QQ_HEADER_03_FAMILY);
buf.put((byte)command);
buf.putChar(sequence);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.putInt(0);
buf.put((byte)0x01);
buf.put((byte)0x0);
buf.put((byte)0x0);
buf.putChar(source);
buf.put((byte)0x0);
}
@Override
protected byte[] getBodyBytes(ByteBuffer buf, int length) {
// 得到包體長(zhǎng)度
int bodyLen = length - QQ.QQ_LENGTH_FTP_FAMILY_HEADER;
// 得到包體內(nèi)容
byte[] body = new byte[bodyLen];
buf.get(body);
return body;
}
@Override
protected void putTail(ByteBuffer buf) {
}
@Override
protected void putBody(ByteBuffer buf) {
}
@Override
protected byte[] encryptBody(byte[] b, int offset, int length) {
byte[] ret = new byte[length];
System.arraycopy(b, offset, ret, 0, length);
return ret;
}
@Override
protected byte[] decryptBody(byte[] body, int offset, int length) {
byte[] ret = new byte[length];
System.arraycopy(body, offset, ret, 0, length);
return ret;
}
@Override
protected int getCryptographStart() {
return -1;
}
@Override
protected void parseHeader(ByteBuffer buf) throws PacketParseException {
header = buf.get();
command = (char)buf.get();
sequence = buf.getChar();
serialNumber = buf.getInt();
buf.position(buf.position() + 32);
totalFragment = buf.get();
currentFragment = buf.get();
buf.get();
source = buf.getChar();
buf.get();
}
@Override
protected void parseTail(ByteBuffer buf) throws PacketParseException {
}
@Override
public boolean equals(Object obj) {
if(obj instanceof _03InPacket) {
_03InPacket in = (_03InPacket)obj;
return command == in.command &&
serialNumber == in.serialNumber;
} else if(obj instanceof _03OutPacket) {
_03OutPacket out = (_03OutPacket)obj;
return command == out.command &&
serialNumber == out.serialNumber;
} else
return false;
}
@Override
public String toString() {
return "包類型: " + Util.getFTPCommandString(command) + " 序號(hào): " + (int)sequence;
}
@Override
public int getFamily() {
return QQ.QQ_PROTOCOL_FAMILY_03;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -