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

📄 loginreplypacket.java

📁 很多人都在开发的QQ代码
💻 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.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>
 * QQ登陆应答包
 * 000 字节是应答码,0表示登陆成功,1表示登陆重定向,2表示密码错误,3表示其他错误
 * 001-016字节是session key
 * 017-020字节是用户QQ号
 * 021-024字节是服务器探测到的用户IP
 * 025-026字节是服务器探测到的用户端口
 * 027-030字节是服务器自己的IP
 * 031-032字节是服务器的端口
 * 033-036字节是本次登陆时间,为什么要乘1000?因为这个时间乘以1000才对,-_-!...
 * 037-062是未知的26字节
 * 063-066字节是一个未知服务器1的ip
 * 067-068字节是一个未知服务器1的端口
 * 069-072是一个未知服务器2的ip
 * 073-074是一个未知服务器2的端口
 * 075-076是两个未知字节
 * 077-078是两个未知字节
 * 079-110是32个未知字节
 * 111-122是12个未知字节
 * 123-126是上次登陆的ip
 * 127-130是上次登陆的时间
 * 131-138是8个未知字节
 * </pre>
 *
 * @author 马若劼
 */
public class LoginReplyPacket extends InPacket {
	public byte[] sessionKey;
	public byte[] ip;
	public byte[] serverIp;
	public byte[] lastLoginIp;
	public byte[] redirectIp;
	public int port;
	public int serverPort;
	public int redirectPort;
	public long loginTime;
	public long lastLoginTime;
	public byte replyCode;
	public String replyMessage;
	
    /**
     * 构造函数
     * @param buf 缓冲区
     * @param length 包长度
     * @throws PacketParseException 解析错误
     */
    public LoginReplyPacket(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 {
        replyCode = buf.get();
        switch(replyCode) {
            case QQ.QQ_LOGIN_REPLY_OK:
                // 001-016字节是session key
            	sessionKey = new byte[QQ.QQ_KEY_LENGTH];
                buf.get(sessionKey);
                // 017-020字节是用户QQ号
                buf.getInt();
                // 021-024字节是服务器探测到的用户IP
                ip = new byte[4];
                buf.get(ip);
                // 025-026字节是服务器探测到的用户端口
                port = buf.getChar();
                // 027-030字节是服务器自己的IP
                serverIp = new byte[4];                    
                buf.get(serverIp);
                // 031-032字节是服务器的端口
                serverPort = buf.getChar();
                // 033-036字节是本次登陆时间,为什么要乘1000?因为这个时间乘以1000才对,-_-!...
                loginTime = (long)buf.getInt() * 1000L;
                // 037-062是未知的26字节
                // 063-066字节是一个未知服务器1的ip
                // 067-068字节是一个未知服务器1的端口
                // 069-072是一个未知服务器2的ip
                // 073-074是一个未知服务器2的端口
                // 075-076是两个未知字节
                // 077-078是两个未知字节
                // 079-110是32个未知字节
                // 111-122是12个未知字节
                buf.position(buf.position() + 86);
                // 123-126是上次登陆的ip
                lastLoginIp = new byte[4];
                buf.get(lastLoginIp);
                // 127-130是上次登陆的时间
                lastLoginTime = (long)buf.getInt() * 1000L;
                // 131-138是8个未知字节
                // TODO do nothing
                break;
            case QQ.QQ_LOGIN_REPLY_PWD_ERROR:
				// 密码错误,我们得到服务器发回来的消息
                byte[] b = buf.array();
			    replyMessage = Utils.getString(b, 1, b.length - 1, QQ.QQ_CHARSET_DEFAULT);
                break;
            case QQ.QQ_LOGIN_REPLY_REDIRECT:
				// 登陆重定向,可能是为了负载平衡
				// 001-004字节是用户QQ号
				buf.getInt();
				// 005-008字节是重定向到的服务器IP
				redirectIp = new byte[4];
				buf.get(redirectIp);
				// 009-010字节是重定向到的服务器的端口
				redirectPort = buf.getChar();
                break;
			default:
				replyCode = QQ.QQ_LOGIN_REPLY_MISC_ERROR;
				break;
        }
    }
}

⌨️ 快捷键说明

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