📄 evaqun.cpp
字号:
int QunReplyPacket::parseJoinAuthReply(unsigned char *buf, int ){ int pos = 0; if(replyCode == QQ_QUN_CMD_REPLY_OK){ int tmp4; memcpy(&tmp4, buf + pos, 4); qunID = ntohl(tmp4); pos+=4; } return pos;}// useful variable: qunIDint QunReplyPacket::parseModifyInfoReply(unsigned char *buf, int ){ int pos = 0; //if(replyCode == QQ_QUN_CMD_REPLY_OK){ int tmp4; memcpy(&tmp4, buf + pos, 4); qunID = ntohl(tmp4); pos+=4; //} return pos;}// useful variables: searchType and qunInfoListint QunReplyPacket::parseSearchReply(unsigned char *buf, int len){ printf("QunReplyPacket::parseSearchReply\n"); for(int i=0; i<len; i++){ if(!(i%8)) printf("\n%d: ",i); char t = buf[i]; printf("%2x ", (uint8_t)t); } printf("\n"); int pos=0; if(replyCode == QQ_QUN_CMD_REPLY_OK) { searchType = buf[pos++]; // actually, In new QQ, all types except QQ_SEARCH_QUN_BY_ID are searched by Web Explorer while(pos < len ) { QunInfo info; pos+=info.readQunInfoFromSearchReply(buf+pos); qunInfoList.push_back(info); } } printf("QunReplyPacket:: parseSearchReply ----- finished\n"); return pos;}/* for this part, the useful variables are: type, qunID, parentID and info, qunQQNumberList (actually these two contain all information)*/int QunReplyPacket::parseGetTempQunInfoReply(unsigned char *buf, int len){ int pos=0; if(replyCode == QQ_QUN_CMD_REPLY_OK) { pos = info.readTempQunInfo(buf); type = info.getType(); qunID = info.getQunID(); parentQunID = info.getExtID(); int tmp4; while(pos < len ) { memcpy(&tmp4, buf+pos, 4); qunQQNumberList.push_back(ntohl(tmp4)); pos+=5; // note that we ignore one unknow byte, maybe just the seperator byte } } return pos;}int QunReplyPacket::parseExitTempQunReply(unsigned char *buf, int ){ int pos = 0; if(replyCode == QQ_QUN_CMD_REPLY_OK) { type = buf[pos++]; int tmp4; memcpy(&tmp4, buf + pos, 4); parentQunID = ntohl(tmp4); pos+=4; memcpy(&tmp4, buf + pos, 4); qunID = ntohl(tmp4); pos+=4; } return pos;}// useful variables: type, parentQunID, qunID and qunQQNumberListint QunReplyPacket::parseGetTempQunMembers(unsigned char *buf, int len){ int pos=0; if(replyCode == QQ_QUN_CMD_REPLY_OK) { type = buf[pos++]; int tmp4; memcpy(&tmp4, buf+pos, 4); parentQunID = ntohl(tmp4); pos+=4; memcpy(&tmp4, buf + pos, 4); qunID = ntohl(tmp4); pos+=4; while(pos < len ) { memcpy(&tmp4, buf+pos, 4); qunQQNumberList.push_back(ntohl(tmp4)); pos+=4; } } return pos;}// useful variables: qunID, targetQQint QunReplyPacket::parseModifyQunCard(unsigned char *buf, int len){ int pos=0; //if(replyCode == QQ_QUN_CMD_REPLY_OK) { int tmp4; memcpy(&tmp4, buf+pos, 4); qunID = ntohl(tmp4); pos+=4; memcpy(&tmp4, buf + pos, 4); targetQQ = ntohl(tmp4); pos+=4; //} return pos;}int QunReplyPacket::parseRequestAllRealNames(unsigned char *buf, int len){ if(replyCode != QQ_QUN_CMD_REPLY_OK) { printf("Qun real name reply code is NOT ok.\n"); return 0; } int pos = 0; qunID = EvaUtil::read32( buf + pos); pos+=4; m_CardVersion = EvaUtil::read32( buf + pos); pos+=4; m_NextStart = EvaUtil::read32( buf + pos); pos+=4; m_RealNameList.clear(); int tmpId; char strName[257]; unsigned char nameLen = 0; while(pos<len){ tmpId = EvaUtil::read32( buf + pos); pos+=4; nameLen = buf[pos++]; memcpy(strName, buf + pos, nameLen); pos+=nameLen; strName[nameLen] = 0x0; std::string name; name.assign(strName); m_RealNameList[tmpId] = name; } return pos;}// useful variables: qunID, targetQQint QunReplyPacket::parseRequestQunCard(unsigned char *buf, int len){ int pos = 0; int tmp4; memcpy(&tmp4, buf + pos, 4); pos+=4; qunID = ntohl(tmp4); memcpy(&tmp4, buf + pos, 4); targetQQ = ntohl(tmp4); pos+=4; if(replyCode == QQ_QUN_CMD_REPLY_OK) { unsigned char strLen; char *str; strLen = buf[pos++]; str = new char[strLen + 1]; memcpy(str, buf+pos, strLen); pos+=strLen; str[strLen] = 0x00; realName.assign(str); delete str; gender = buf[pos++]; strLen = buf[pos++]; str = new char[strLen + 1]; memcpy(str, buf+pos, strLen); pos+=strLen; str[strLen] = 0x00; phone.assign(str); delete str; strLen = buf[pos++]; str = new char[strLen + 1]; memcpy(str, buf+pos, strLen); pos+=strLen; str[strLen] = 0x00; email.assign(str); delete str; strLen = buf[pos++]; str = new char[strLen + 1]; memcpy(str, buf+pos, strLen); pos+=strLen; str[strLen] = 0x00; memo.assign(str); delete str; }else pos++; return pos;}int QunReplyPacket::parseQunAdminOperation(unsigned char *buf, int len){ int pos=0; int tmp4; memcpy(&tmp4, buf+pos, 4); qunID = ntohl(tmp4); pos+=4; if(replyCode == QQ_QUN_CMD_REPLY_OK) { memcpy(&tmp4, buf + pos, 4); versionID = ntohl(tmp4); pos+=4; memcpy(&tmp4, buf + pos, 4); targetQQ = ntohl(tmp4); pos+=4; opCode = buf[pos++]; } return pos;}int QunReplyPacket::parseQunTransfer(unsigned char *buf, int len){ int pos=0; int tmp4; memcpy(&tmp4, buf+pos, 4); qunID = ntohl(tmp4); pos+=4; memcpy(&tmp4, buf + pos, 4); targetQQ = ntohl(tmp4); pos+=4; if(replyCode == QQ_QUN_CMD_REPLY_OK) { memcpy(&tmp4, buf + pos, 4); versionID = ntohl(tmp4); pos+=4; } return pos;}/***************************************************************************************************************/ QunGetInfoPacket::QunGetInfoPacket(const int id) : QunPacket(QQ_QUN_CMD_GET_QUN_INFO, id){}QunGetInfoPacket::QunGetInfoPacket(const QunGetInfoPacket &rhs) : QunPacket(rhs){}QunGetInfoPacket::~QunGetInfoPacket(){}int QunGetInfoPacket::putBody(unsigned char *buf){ buf[0] = qunCommand; int tmp4 = htonl(qunID); memcpy(buf + 1, &tmp4, 4); return 5;}/***************************************************************************************************************/ QunGetMemberInfoPacket::QunGetMemberInfoPacket(const int id) : QunPacket(QQ_QUN_CMD_GET_MEMBER_INFO, id){}QunGetMemberInfoPacket::QunGetMemberInfoPacket( const QunGetMemberInfoPacket & rhs ) : QunPacket(rhs){ memberList = rhs.getMemberList();}QunGetMemberInfoPacket::~ QunGetMemberInfoPacket( ){}QunGetMemberInfoPacket & QunGetMemberInfoPacket::operator =( const QunGetMemberInfoPacket & rhs ){ *(QunPacket*)this = (QunPacket)rhs; memberList = rhs.getMemberList(); return *this;}void QunGetMemberInfoPacket::addMember( const unsigned int id ){ memberList.push_back(id);}int QunGetMemberInfoPacket::putBody( unsigned char * buf ){ int pos=0; buf[pos++] = qunCommand; int tmp4 = htonl(qunID); memcpy(buf + pos, &tmp4, 4); pos+=4; std::list<unsigned int>::iterator itr; for(itr=memberList.begin(); itr!= memberList.end(); ++itr){ tmp4 = htonl(*itr); memcpy(buf + pos, &tmp4, 4); pos+=4; } return pos;}/***************************************************************************************************************/ QunGetOnlineMemberPacket::QunGetOnlineMemberPacket(const unsigned int id) : QunPacket(QQ_QUN_CMD_GET_ONLINE_MEMBER, id){}QunGetOnlineMemberPacket::QunGetOnlineMemberPacket(const QunGetOnlineMemberPacket &rhs) : QunPacket(rhs){}QunGetOnlineMemberPacket::~QunGetOnlineMemberPacket(){}int QunGetOnlineMemberPacket::putBody(unsigned char *buf){ buf[0] = qunCommand; int tmp4 = htonl(qunID); memcpy(buf + 1, &tmp4, 4); return 5;}/***************************************************************************************************************/ QunActivatePacket::QunActivatePacket(const unsigned int id) : QunPacket(QQ_QUN_CMD_ACTIVATE_QUN, id){}QunActivatePacket::QunActivatePacket(const QunActivatePacket &rhs) : QunPacket(rhs){}QunActivatePacket::~QunActivatePacket(){}int QunActivatePacket::putBody(unsigned char *buf){ buf[0] = qunCommand; int tmp4 = htonl(qunID); memcpy(buf + 1, &tmp4, 4); return 5;}/***************************************************************************************************************/QunAuthPacket::QunAuthPacket() : QunPacket(), type(QQ_QUN_AUTH_REQUEST), receiver(0), m_Code(0), m_CodeLen(0), message(""){}QunAuthPacket::QunAuthPacket( const unsigned int id, unsigned char authType ) : QunPacket(QQ_QUN_CMD_JOIN_QUN_AUTH, id), type(authType), receiver(0), m_Code(0), m_CodeLen(0), message(""){}QunAuthPacket::QunAuthPacket( const QunAuthPacket & rhs ) : QunPacket(rhs){ *this = rhs;}QunAuthPacket::~ QunAuthPacket( ){ if(m_Code) delete []m_Code;}QunAuthPacket & QunAuthPacket::operator =( const QunAuthPacket & rhs ){ *(QunPacket *)this = (QunPacket)rhs; type = rhs.getAuthType(); receiver = rhs.getReceiver(); message = rhs.getMessage(); setCode(rhs.getCode(), rhs.getCodeLength()); return *this;}void QunAuthPacket::setCode(const unsigned char *code, const unsigned short len){ if(len && code){ m_CodeLen = len; if(m_Code) delete []m_Code; m_Code = new unsigned char[m_CodeLen]; memcpy(m_Code, code, m_CodeLen); }}void QunAuthPacket::setToken(const unsigned char *code, const unsigned short len){ // so far, code and token never appear in the same sub-command of // this packet. so, we just use one pair of variabls setCode(code, len);}int QunAuthPacket::putBody( unsigned char * buf ){ int pos=0; buf[pos++] = qunCommand; int tmp4 = htonl(qunID); memcpy(buf + pos, &tmp4, 4); pos+=4; buf[pos++]=type; if(type == QQ_QUN_AUTH_REQUEST){ WRITE16(buf+pos, m_CodeLen); pos+=2; memcpy(buf+pos, m_Code, m_CodeLen); pos += m_CodeLen; } tmp4 = htonl(receiver); memcpy(buf + pos, &tmp4, 4); pos+=4; int len = message.length(); buf[pos++] = (char)(len & 0xFF); memcpy(buf+pos, message.c_str(), len); pos+=len; if(type == QQ_QUN_AUTH_APPROVE || type == QQ_QUN_AUTH_REJECT){ WRITE16(buf+pos, m_CodeLen); pos+=2; memcpy(buf+pos, m_Code, m_CodeLen); pos += m_CodeLen; } printf("QunAuthPacket\n"); for(int i=0; i<pos; i++){ if(!(i%8)) printf("\n%d: ", i); printf("%2x ", (uint8_t)buf[i]); } printf("\n\n"); return pos;}/***************************************************************************************************************/QunSendIMPacket::QunSendIMPacket( const unsigned int id ) : QunPacket(QQ_QUN_CMD_SEND_IM, id), encoding(QQ_IM_ENCODING_GB), red(0),green(0),blue(0), bold(false),italic(false),underline(false), fontSize(0x09), fontFlag(0x09), message("Hello, I am using Eva."){ char *fname = (char *)malloc(5); fname[0] = 0xcb; fname[1] = 0xce; fname[2] = 0xcc; fname[3] = 0xe5; fname[4] = 0x00; fontName = fname; // just set font name to "Song Ti" in Chinese free(fname);}QunSendIMPacket::QunSendIMPacket( const QunSendIMPacket & rhs ) : QunPacket(rhs){ encoding = rhs.getEncoding(); fontName = rhs.getFontName(); red = rhs.getRed(); green = rhs.getGreen(); blue = rhs.getBlue(); fontFlag = 0x00; bold = rhs.isBold(); fontFlag |= bold ? 0x20 : 0x00; italic = rhs.isItalic(); fontFlag |= italic ? 0x40 : 0x00; underline = rhs.isUnderline(); fontFlag |= underline ? 0x80 : 0x00; fontSize = rhs.getFontSize(); fontFlag |= fontSize; message = rhs.getMessage();}QunSendIMPacket::~ QunSendIMPacket( ){}QunSendIMPacket & QunSendIMPacket::operator =( const QunSendIMPacket & rhs ){ *((QunPacket *)this) = (QunPacket)rhs; encoding = rhs.getEncoding(); fontName = rhs.getFontName(); red = rhs.getRed(); green = rhs.getGreen(); blue = rhs.getBlue(); fontFlag = 0x00; bold = rhs.isBold(); fontFlag |= bold ? 0x20 : 0x00; italic = rhs.isItalic(); fontFlag |= italic ? 0x40 : 0x00; underline = rhs.isUnderline(); fontFlag |= underline ? 0x80 : 0x00; fontSize = rhs.getFontSize(); fontFlag |= fontSize; message = rhs.getMessage(); return *this;}void QunSendIMPacket::setFontSize( char fontSize ){ this->fontSize = fontSize; fontSize &= 0x1F; fontFlag &= 0xE0; fontFlag |= fontSize;}void QunSendIMPacket::setUnderline( bool underline ){ this->underline = underline; fontFlag &= 0x7F; fontFlag |= underline ? 0x80 : 0x00;}void QunSendIMPacket::setItalic( bool italic ){ this->italic = italic; fontFlag &= 0xBF; fontFlag |= italic ? 0x40 : 0x00;}void QunSendIMPacket::setBold( bool bold ){ this->bold = bold; fontFlag &= 0xDF; fontFlag |= bold ? 0x20 : 0x00;}int QunSendIMPacket::putBody( unsigned char * buf ){ int pos=0; buf[pos++] = qunCommand; // qun command int tmp4 = htonl(qunID); memcpy(buf+pos, &tmp4, 4); // qun internal ID pos+=4; int lenPos = pos; // we record the index of the length of following contents, it takes 2 bytes pos+=2; std::string str2send = EvaUtil::convertToSend(message); memcpy(buf+pos, str2send.c_str(), str2send.length()); pos += str2send.length(); //now we can set the length of message and font name; short tmp2 = htons((short)(str2send.length() + fontName.length() + 10)); memcpy(buf + lenPos, &tmp2, 2); buf[pos++] = 0x20; // a space buf[pos++] = 0x00; // C style string terminator buf[pos++] = fontFlag; buf[pos++] = red; buf[pos++] = green; buf[pos++] = blue; buf[pos++] = 0; short tmpEncoding = htons(encoding); // encoding for text memcpy(buf+pos,&tmpEncoding, 2); pos+=2; int len = fontName.length(); // font name memcpy(buf+pos, fontName.c_str(), len); pos+=len; buf[pos++] = 0x0D; // an Enter return pos;}/***************************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -