⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _05parser.java

📁 MilyQQ是一个使用控制台的QQ客户端,基于LumaQQ的核心JQL包开发,只有一个可执行的jar包(MilyQQ.jar),携带方便,由于是Java程序,因此理论上应该可以运行于所有平台,不过基于
💻 JAVA
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 notXX
*                    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.beans.QQUser;
import edu.tsinghua.lumaqq.qq.packets.in._05.RequestAgentReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in._05.RequestBeginReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in._05.RequestFaceReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in._05.TransferReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in._05.Unknown05InPacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.RequestAgentPacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.RequestBeginPacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.TransferPacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.Unknown05OutPacket;
*/

/**
 * 05系列包的解析器
 *
 * @author luma
 */
public class _05Parser implements IParser {
	private char command, sequence;
	private int offset;
	private int length;

	public _05Parser() {}

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#accept(java.nio.ByteBuffer)
     */
    public boolean accept(ByteBuffer buf) {
        offset = buf.position();
        int bufferLength = buf.limit() - offset;
        if(bufferLength <= 0)
            return false;

        // 检查包头
        if(buf.get(offset) != QQ.QQ_HEADER_05_FAMILY)
            return false;

        // 如果长度小于5,则没有长度标志
        if(bufferLength < 5)
            return false;

        // 检查包长是否大于可用长度
        length = buf.getChar(offset + 3);
        if(length > bufferLength)
            return false;

        // 检查包尾
        if(buf.get(offset + length - 1) != QQ.QQ_TAIL_05_FAMILY)
            return false;

        getCommand(buf);
        return true;
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#getLength()
     */
    public int getLength() {
        return length;
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#parseIncoming(java.nio.ByteBuffer, int, edu.tsinghua.lumaqq.qq.beans.QQUser)
     */
    public InPacket parseIncoming(ByteBuffer buf, int len, QQUser user)
            throws PacketParseException {
        switch(command) {
            case QQ.QQ_05_CMD_REQUEST_AGENT:
                return new RequestAgentReplyPacket(buf, len, user);
            case QQ.QQ_05_CMD_REQUEST_FACE:
                return new RequestFaceReplyPacket(buf, len, user);
            case QQ.QQ_05_CMD_REQUEST_BEGIN:
                return new RequestBeginReplyPacket(buf, len, user);
            case QQ.QQ_05_CMD_TRANSFER:
                return new TransferReplyPacket(buf, len, user);
            default:
                return new Unknown05InPacket(buf, len, user);
        }
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#parseOutcoming(java.nio.ByteBuffer, int, edu.tsinghua.lumaqq.qq.beans.QQUser)
     */
    public OutPacket parseOutcoming(ByteBuffer buf, int len, QQUser user)
            throws PacketParseException {
        switch(command) {
            case QQ.QQ_05_CMD_REQUEST_AGENT:
                return new RequestAgentPacket(buf, len, user);
            case QQ.QQ_05_CMD_REQUEST_BEGIN:
                return new RequestBeginPacket(buf, len, user);
            case QQ.QQ_05_CMD_TRANSFER:
                return new TransferPacket(buf, len, user);
            default:
                return new Unknown05OutPacket(buf, len, user);
        }
    }

    /**
     * 得到包的命令和序号
     *
     * @param buf
     */
    private void getCommand(ByteBuffer buf) {
        command = buf.getChar(offset + 5);
        sequence = buf.getChar(offset + 7);
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#getHash(java.nio.ByteBuffer)
     */
    public int getHash(ByteBuffer buf) {
	    return command | (sequence << 16);
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#isIncoming(java.nio.ByteBuffer)
     */
    public boolean isIncoming(ByteBuffer buf) {
        return false;
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#isUdp(java.nio.ByteBuffer)
     */
    public boolean isUdp(ByteBuffer buf) {
        return false;
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#isDuplicated(java.nio.ByteBuffer)
     */
    public boolean isDuplicated(ByteBuffer buf) {
//		int hash = getHash(buf);
//	    boolean duplicated = PacketMonitor.getInstance().check(new Integer(hash), true);
//	    if(duplicated)
//	        log.debug("包" + Util.get05CommandString(command) + " 序号 " + (int)sequence + "重复到达,忽略");
//	    return duplicated;
        return false;
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.packets.IParser#isDuplicatedNeedReply()
     */
    public boolean isDuplicatedNeedReply() {
        return false;
    }

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.qq.packets.IParser#relocate(java.nio.ByteBuffer)
	 */
	public int relocate(ByteBuffer buf) {
		int offset = buf.position();
    	if(buf.remaining() < 5)
    		return offset;
		int len = buf.getChar(offset + 3);
		if(len == 0 || offset + len > buf.limit())
			return offset;
		else
			return offset + len;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -