?? searchuserpacket.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.out;
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.OutPacket;
/**
* <pre>
* 搜索在線用戶的包,格式為
* 1. 頭部
* 2. 1個字節,表示搜索類型,比如搜索全部在線用戶是0x31,自定義搜索是0x30
* 3. 1字節分隔符: 0x1F
* 4. 搜索參數
* i. 對于搜索全部在線用戶的請求,是一個頁號,用字符串表示,從0開始
* ii. 對于自定義搜索類型,是3個域,用0x1F分隔,依次是
* a. 要搜索的用戶的QQ號的字符串形式
* b. 要搜索的用戶的昵稱
* c. 要搜索的用戶的email
* 另外QQ還有一個匹配整個字符串的選項,如果這個選擇被選中,那就是如上所說的格式,如果
* 沒有被選中,那就會在b和c之后各加一個'%'字符,也就是0x25。在abc之后,還跟一個分隔符,
* 然后是頁號的字符串形式,以0結束。另外,如果用戶沒有提供某個參數,則用0x2D替代,也就是
* '-'字符
* 5. 尾部
* </pre>
*
* @author 馬若劼
*/
public class SearchUserPacket extends OutPacket {
private byte searchType;
private String page;
private String qqStr;
private String nick;
private String email;
private boolean matchEntireString;
/** 分隔符 */
private static final byte DELIMIT = 0x1F;
/** 如果字段為空,用0x2D替代,即'-'字符 */
private static final byte NULL = 0x2D;
/** 通配府,即'%'字符 */
private static final byte PERCENT = 0x25;
/**
* 構造函數
*/
public SearchUserPacket() {
super(QQ.QQ_CMD_SEARCH_USER, true);
page = "0";
searchType = QQ.QQ_SEARCH_ALL;
qqStr = nick = email = "";
matchEntireString = false;
}
/**
* @param buf
* @param length
* @throws PacketParseException
*/
public SearchUserPacket(ByteBuffer buf, int length)
throws PacketParseException {
super(buf, length);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
*/
protected void putBody(ByteBuffer buf) {
// 開始組裝內容
if(searchType == QQ.QQ_SEARCH_ALL) {
buf.put(searchType);
buf.put(DELIMIT);
buf.put(page.getBytes());
} else if(searchType == QQ.QQ_SEARCH_CUSTOM) {
buf.put(searchType);
buf.put(DELIMIT);
// QQ號
if(qqStr == null || qqStr.equals("")) buf.put(NULL);
else buf.put(qqStr.getBytes());
buf.put(DELIMIT);
// 昵稱
if(nick == null || nick.equals("")) buf.put(NULL);
else {
buf.put(Utils.getBytes(nick, QQ.QQ_CHARSET_DEFAULT));
if(!matchEntireString)
buf.put(PERCENT);
}
buf.put(DELIMIT);
// email
if(email == null || email.equals("")) buf.put(NULL);
else {
buf.put(email.getBytes());
if(!matchEntireString)
buf.put(PERCENT);
}
buf.put(DELIMIT);
// 結尾
buf.put(page.getBytes());
buf.put((byte)0x0);
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#parseBody(java.nio.ByteBuffer)
*/
protected void parseBody(ByteBuffer buf) throws PacketParseException {
searchType = buf.get();
if(searchType == QQ.QQ_SEARCH_ALL) {
buf.get();
page = Utils.getString(buf);
} else if(searchType == QQ.QQ_SEARCH_CUSTOM) {
buf.get();
matchEntireString = false;
qqStr = Utils.getString(buf, DELIMIT);
nick = Utils.getString(buf, DELIMIT);
if(nick.charAt(nick.length()) == PERCENT) {
nick = nick.substring(0, nick.length() - 1);
matchEntireString = true;
}
email = Utils.getString(buf, DELIMIT);
if(email.charAt(email.length()) == PERCENT) {
email = email.substring(0, email.length() - 1);
matchEntireString = true;
}
page = Utils.getString(buf, 0);
}
}
/**
* @param page The page to set.
*/
public void setPage(int page) {
this.page = String.valueOf(page);
}
/**
* @param searchType The searchType to set.
*/
public void setSearchType(byte searchType) {
this.searchType = searchType;
}
/**
* @param matchEntireString The matchEntireString to set.
*/
public void setMatchEntireString(boolean matchEntireString) {
this.matchEntireString = matchEntireString;
}
/**
* @param nick The nick to set.
*/
public void setNick(String nick) {
this.nick = nick;
}
/**
* @param qqNum The qqNum to set.
*/
public void setQQStr(int qqNum) {
this.qqStr = String.valueOf(qqNum);
}
/**
* @param qqStr
*/
public void setQQStr(String qqStr) {
this.qqStr = qqStr;
}
/**
* @param email The email to set.
*/
public void setEmail(String email) {
this.email = email;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -