📄 facereceiver.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.ui.experimental;
import java.io.IOException;
import java.net.InetSocketAddress;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.QQClient;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.beans.ClusterIM;
import edu.tsinghua.lumaqq.qq.events.IQQListener;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.net.IPort;
import edu.tsinghua.lumaqq.qq.packets.out._05.RequestBeginPacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.RequestFacePacket;
import edu.tsinghua.lumaqq.qq.packets.out._05.TransferPacket;
/**
* 测试自定义表情接收功能用
*
* @author luma
*/
public class FaceReceiver implements IQQListener {
public byte[] key;
public int sessionId;
public InetSocketAddress agentAddress;
public byte[] md5;
public IPort port;
public QQClient client;
public int clusterId;
private static final String CUSTOM_FACE_PORT = "receive face";
/**
* @param im
*/
public FaceReceiver(ClusterIM im) {
int i = im.message.indexOf(QQ.QQ_CUSTOM_FACE_TAG);
sessionId = Util.getInt(im.message.substring(i + 9, i + 17).trim(), 16, 0);
byte[] ip = Util.convertHexStringToByteNoSpace(im.message.substring(i + 17, i + 25));
byte temp = ip[0];
ip[0] = ip[3];
ip[3] = temp;
temp = ip[1];
ip[1] = ip[2];
ip[2] = temp;
agentAddress = new InetSocketAddress(Util.convertIpToString(ip), 443);
key = im.message.substring(i + 33, i + 49).getBytes();
}
public void start() {
createPort();
client.addQQListener(this);
RequestFacePacket packet = new RequestFacePacket(client.getUser());
packet.setClusterId(clusterId);
packet.setKey(key);
packet.setFileAgentToken(client.getUser().getFileAgentToken());
packet.setSessionId(sessionId);
client.sendPacket(packet, CUSTOM_FACE_PORT);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.events.IQQListener#qqEvent(edu.tsinghua.lumaqq.qq.events.QQEvent)
*/
public void qqEvent(QQEvent e) {
switch(e.type) {
case QQEvent.QQ_REQUEST_FACE_SUCCESS:
processRequestFaceSuccess(e);
break;
case QQEvent.QQ_RECEIVE_FACE_INFO:
processReceiveFaceInfo(e);
break;
case QQEvent.QQ_REQUEST_BEGIN_SUCCESS:
processRequestBeginSuccess(e);
break;
}
}
/**
* @param e
*/
private void processRequestBeginSuccess(QQEvent e) {
TransferPacket packet = new TransferPacket(client.getUser());
client.sendPacket(packet, CUSTOM_FACE_PORT);
}
/**
* @param e
*/
private void processReceiveFaceInfo(QQEvent e) {
RequestBeginPacket packet = new RequestBeginPacket(client.getUser());
packet.setSessionId(sessionId);
packet.setRequestSend(false);
packet.setKey(key);
client.sendPacket(packet, CUSTOM_FACE_PORT);
}
/**
* @param e
*/
private void processRequestFaceSuccess(QQEvent e) {
// RequestBeginPacket packet = new RequestBeginPacket(client.getUser());
// packet.setKey(key);
// packet.setSessionId(sessionId);
// client.sendPacket(packet, CUSTOM_FACE_PORT);
}
/**
* 创建一个到中转服务器的连接
*/
private void createPort() {
try {
port = client.installTCPPort(CUSTOM_FACE_PORT, agentAddress, true);
} catch (IOException e) {
// 失败,结束发送
port = null;
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -