00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "evafriend.h"
00021 #include "evadefines.h"
00022 #include <string.h>
00023 #ifdef _WIN32
00024 #include <winsock.h>
00025 #else
00026 #include <arpa/inet.h>
00027 #endif
00028
00029 FriendItem::FriendItem()
00030 :qqNum(0), mIsOnline(false)
00031 {
00032 qunGroupIndex = 0;
00033 qunAdminValue = 0;
00034 }
00035
00036 FriendItem::FriendItem(const unsigned char *buf, int *len)
00037 : mIsOnline(false)
00038 {
00039 parseData(buf, len);
00040 }
00041
00042 FriendItem::FriendItem(const FriendItem &rhs)
00043 {
00044 *this = rhs;
00045 }
00046
00047 FriendItem &FriendItem::operator=(const FriendItem &rhs)
00048 {
00049 qqNum = rhs.getQQ();
00050 face = rhs.getFace() ;
00051 age = rhs.getAge();
00052 gender = rhs.getGender();
00053 nick = rhs.getNick();
00054 extFlag = rhs.getExtFlag();
00055 commonFlag = rhs.getCommonFlag();
00056 loginTime = rhs.getLoginTime();
00057 idleTime = rhs.getIdleTime();
00058 lastRefreshTime = rhs.getLastRefreshTime();
00059 mIsOnline = rhs.isOnline();
00060 qunGroupIndex = rhs.getQunGroupIndex();
00061 qunAdminValue = rhs.getQunAdminValue();
00062 m_QunRealName = rhs.getQunRealName();
00063 return *this;
00064 }
00065
00066 void FriendItem::parseData(const unsigned char *buf, int *len)
00067 {
00068 int qqtemp;
00069 memcpy(&qqtemp, buf, 4);
00070 qqNum = ntohl(qqtemp);
00071 short tmp2;
00072 memcpy(&tmp2, buf+4, 2);
00073 face = ntohs(tmp2);
00074 age = buf[6];
00075 gender = buf[7];
00076 int nickLen = (int)(buf[8]);
00077 char *b = (char *)malloc( (nickLen+1)*sizeof(char));
00078 memcpy(b, buf+9, nickLen);
00079 b[nickLen]=0x00;
00080 nick.assign(b);
00081 free(b);
00082
00083 extFlag = buf[9+nickLen+2];
00084 commonFlag = buf[9+nickLen+3];
00085 *len = 9+nickLen+4;
00086 }
00087
00088
00089
00090 GetFriendListPacket::GetFriendListPacket()
00091 : OutPacket(QQ_CMD_GET_FRIEND_LIST, true),
00092 startPosition(QQ_FRIEND_LIST_POSITION_START)
00093 {
00094 }
00095
00096 GetFriendListPacket::GetFriendListPacket(const short startPosition)
00097 : OutPacket(QQ_CMD_GET_FRIEND_LIST, true),
00098 startPosition(startPosition)
00099 {
00100 }
00101
00102 GetFriendListPacket::GetFriendListPacket(const GetFriendListPacket &rhs)
00103 : OutPacket(rhs)
00104 {
00105 startPosition = rhs.getStartPosition();
00106 }
00107
00108 GetFriendListPacket &GetFriendListPacket::operator=( const GetFriendListPacket &rhs)
00109 {
00110 *((OutPacket*)this) = (OutPacket)rhs;
00111 startPosition = rhs.getStartPosition();
00112 return *this;
00113 }
00114
00115 int GetFriendListPacket::putBody(unsigned char *buf)
00116 {
00117 short pos = htons(startPosition);
00118 memcpy(buf, &pos, 2);
00119
00120 buf[2] = QQ_FRIEND_LIST_SORTED;
00121 buf[3] = 0x00;
00122 buf[4] = 0x01;
00123 return 5;
00124 }
00125
00126
00127
00128 GetFriendListReplyPacket::GetFriendListReplyPacket(unsigned char *buf, int len)
00129 : InPacket(buf, len)
00130 {
00131 }
00132
00133 GetFriendListReplyPacket::GetFriendListReplyPacket(const GetFriendListReplyPacket &rhs)
00134 :InPacket(rhs)
00135 {
00136 position = rhs.getPosition();
00137 friends = rhs.getFriendList();
00138 }
00139
00140 GetFriendListReplyPacket &GetFriendListReplyPacket::operator=( const GetFriendListReplyPacket &rhs)
00141 {
00142 *((InPacket *)this) = (InPacket)rhs;
00143 position = rhs.getPosition();
00144 friends = rhs.getFriendList();
00145 return *this;
00146 }
00147
00148 void GetFriendListReplyPacket::parseBody()
00149 {
00150 short pos;
00151 memcpy(&pos, decryptedBuf, 2);
00152 position = ntohs(pos);
00153 int offset = 2;
00154 while(bodyLength > offset) {
00155 int tmp=0;
00156 friends.push_back(FriendItem(decryptedBuf+offset, &tmp));
00157 offset+=tmp;
00158 }
00159 }
00160
00161
00162