00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "evaaddfriend.h"
00021 #include "evadefines.h"
00022 #include <string.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #ifdef _WIN32
00026 #include <winsock.h>
00027 #else
00028 #include <arpa/inet.h>
00029 #endif
00030
00031 AddFriendPacket::AddFriendPacket( )
00032 : OutPacket(),
00033 qqNum(0)
00034 {
00035 }
00036
00037 AddFriendPacket::AddFriendPacket( const int id )
00038 : OutPacket(QQ_CMD_ADD_FRIEND, true),
00039 qqNum(id)
00040 {
00041 }
00042
00043 AddFriendPacket::AddFriendPacket(const AddFriendPacket &rhs)
00044 : OutPacket(rhs)
00045 {
00046 qqNum = rhs.getAddQQ();
00047 }
00048
00049
00050 AddFriendPacket & AddFriendPacket::operator =( const AddFriendPacket & rhs )
00051 {
00052 *( (OutPacket *)this) = (OutPacket)rhs;
00053 qqNum = rhs.getAddQQ();
00054 return *this;
00055 }
00056
00057 int AddFriendPacket::putBody( unsigned char * buf )
00058 {
00059 if(qqNum==0) return 0;
00060 char strID[20];
00061 sprintf(strID,"%d", qqNum);
00062 int len = strlen(strID);
00063 memcpy(buf, strID, len);
00064 return len;
00065 }
00066
00067
00068
00069 AddFriendReplyPacket::AddFriendReplyPacket(unsigned char* buf, int len)
00070 : InPacket(buf, len)
00071 {
00072 }
00073
00074 AddFriendReplyPacket::AddFriendReplyPacket( const AddFriendReplyPacket &rhs)
00075 : InPacket(rhs)
00076 {
00077 replyCode = rhs.getReplyCode();
00078 myQQ = rhs.getMyQQ();
00079 }
00080
00081 AddFriendReplyPacket &AddFriendReplyPacket::operator=(const AddFriendReplyPacket &rhs)
00082 {
00083 *((InPacket *)this) = (InPacket)rhs;
00084 replyCode = rhs.getReplyCode();
00085 myQQ = rhs.getMyQQ();
00086 return *this;
00087 }
00088
00089 void AddFriendReplyPacket::parseBody()
00090 {
00091 int index=0;
00092 while(decryptedBuf[index++] != 0x1f);
00093 #ifdef WIN32
00094 char* qqstr; qqstr=(char*)_alloca(index+1);
00095 #else
00096 char qqstr[index+1];
00097 #endif
00098 memcpy(qqstr, decryptedBuf, index);
00099 qqstr[index]=0x00;
00100 myQQ = atoi(qqstr);
00101 replyCode = decryptedBuf[index] - 0x30;
00102 }
00103
00104
00105
00106 AddFriendAuthPacket::AddFriendAuthPacket( )
00107 : OutPacket( QQ_CMD_ADD_FRIEND_AUTH, true),
00108 message("")
00109 {
00110 }
00111
00112 AddFriendAuthPacket::AddFriendAuthPacket( const int id , const uint8_t type )
00113 : OutPacket( QQ_CMD_ADD_FRIEND_AUTH, true),
00114 type(type),
00115 buddyQQNum(id),
00116 message("")
00117 {
00118 }
00119
00120 AddFriendAuthPacket::AddFriendAuthPacket( AddFriendAuthPacket & rhs )
00121 : OutPacket(rhs)
00122 {
00123 type = rhs.getType();
00124 buddyQQNum = rhs.getBuddyQQ();
00125 message = rhs.getMessage();
00126 }
00127
00128 AddFriendAuthPacket & AddFriendAuthPacket::operator =( const AddFriendAuthPacket & rhs )
00129 {
00130 *((OutPacket *)this) = (OutPacket)rhs;
00131 type = rhs.getType();
00132 buddyQQNum = rhs.getBuddyQQ();
00133 message = rhs.getMessage();
00134 return *this;
00135 }
00136
00137 int AddFriendAuthPacket::putBody( unsigned char * buf )
00138 {
00139 char qq[20];
00140 sprintf(qq,"%d", buddyQQNum);
00141 int offset = strlen(qq);
00142 memcpy(buf, qq, offset);
00143 buf[offset++] = DIVIDER;
00144 buf[offset++] = type;
00145 buf[offset++] = DIVIDER;
00146 memcpy(buf + offset, message.c_str(), message.length());
00147 return offset + message.length();
00148 }
00149
00150
00151
00152 AddFriendAuthReplyPacket::AddFriendAuthReplyPacket( unsigned char * buf, int len )
00153 : InPacket(buf, len)
00154 {
00155 }
00156
00157 AddFriendAuthReplyPacket::AddFriendAuthReplyPacket( const AddFriendAuthReplyPacket & rhs )
00158 : InPacket(rhs)
00159 {
00160 }
00161
00162 AddFriendAuthReplyPacket & AddFriendAuthReplyPacket::operator =( const AddFriendAuthReplyPacket & rhs )
00163 {
00164 *((InPacket *)this) = (InPacket)rhs;
00165 replyCode = rhs.getReplyCode();
00166 return *this;
00167 }
00168
00169 const bool AddFriendAuthReplyPacket::isSentOK( ) const
00170 {
00171 return replyCode == QQ_ADD_FRIEND_AUTH_REPLY_OK;
00172 }
00173
00174 void AddFriendAuthReplyPacket::parseBody( )
00175 {
00176 replyCode = decryptedBuf[0];
00177 }
00178
00179
00180
00181 DeleteFriendPacket::DeleteFriendPacket( )
00182 : OutPacket(QQ_CMD_DELETE_FRIEND, true),
00183 buddyQQNum(0)
00184 {
00185 }
00186
00187 DeleteFriendPacket::DeleteFriendPacket( const int id )
00188 : OutPacket(QQ_CMD_DELETE_FRIEND, true),
00189 buddyQQNum(id)
00190 {
00191 }
00192
00193 DeleteFriendPacket::DeleteFriendPacket( const DeleteFriendPacket & rhs )
00194 : OutPacket(rhs)
00195 {
00196 buddyQQNum = rhs.getBuddyQQ();
00197 }
00198
00199 DeleteFriendPacket & DeleteFriendPacket::operator =( const DeleteFriendPacket & rhs )
00200 {
00201 *((OutPacket *)this) = (OutPacket)rhs;
00202 buddyQQNum = rhs.getBuddyQQ();
00203 return *this;
00204 }
00205
00206 int DeleteFriendPacket::putBody( unsigned char * buf )
00207 {
00208 if(buddyQQNum==0) return 0;
00209 char qq[20];
00210 sprintf(qq,"%d", buddyQQNum);
00211 memcpy(buf, qq, strlen(qq));
00212 return strlen(qq);
00213 }
00214
00215
00216
00217 DeleteFriendReplyPacket::DeleteFriendReplyPacket( unsigned char * buf, int len )
00218 : InPacket(buf, len)
00219 {
00220 }
00221
00222 DeleteFriendReplyPacket::DeleteFriendReplyPacket( const DeleteFriendReplyPacket & rhs )
00223 : InPacket(rhs)
00224 {
00225 replyCode = rhs.getReplyCode();
00226 }
00227
00228 DeleteFriendReplyPacket & DeleteFriendReplyPacket::operator =( const DeleteFriendReplyPacket & rhs )
00229 {
00230 *((InPacket *)this) = (InPacket)rhs;
00231 replyCode = rhs.getReplyCode();
00232 return *this;
00233 }
00234
00235 const bool DeleteFriendReplyPacket::isDeleted( ) const
00236 {
00237 return replyCode == QQ_DELETE_FRIEND_REPLY_OK;
00238 }
00239
00240 void DeleteFriendReplyPacket::parseBody( )
00241 {
00242 replyCode = decryptedBuf[0];
00243 }
00244
00245
00246
00247
00248 DeleteMePacket::DeleteMePacket( )
00249 : OutPacket(QQ_CMD_DELETE_ME, true),
00250 buddyQQNum(0)
00251 {
00252 }
00253
00254 DeleteMePacket::DeleteMePacket( const int id )
00255 : OutPacket(QQ_CMD_DELETE_ME, true),
00256 buddyQQNum(id)
00257 {
00258 }
00259
00260 DeleteMePacket::DeleteMePacket( const DeleteMePacket & rhs )
00261 : OutPacket(rhs)
00262 {
00263 buddyQQNum = rhs.getBuddyQQ();
00264 }
00265
00266 DeleteMePacket & DeleteMePacket::operator =( const DeleteMePacket & rhs )
00267 {
00268 *((OutPacket *)this) = (OutPacket)rhs;
00269 buddyQQNum = rhs.getBuddyQQ();
00270 return *this;
00271 }
00272
00273 int DeleteMePacket::putBody( unsigned char * buf )
00274 {
00275 if(buddyQQNum==0) return 0;
00276 int qq = htonl(buddyQQNum);
00277 memcpy(buf, &qq, 4);
00278 return 4;
00279 }
00280
00281
00282
00283
00284 DeleteMeReplyPacket::DeleteMeReplyPacket( unsigned char * buf, int len )
00285 : InPacket(buf, len)
00286 {
00287 }
00288
00289 DeleteMeReplyPacket::DeleteMeReplyPacket( const DeleteMeReplyPacket & rhs )
00290 : InPacket(rhs)
00291 {
00292 replyCode = rhs.getReplyCode();
00293 }
00294
00295 DeleteMeReplyPacket & DeleteMeReplyPacket::operator =( const DeleteMeReplyPacket & rhs )
00296 {
00297 *((InPacket *)this) = (InPacket)rhs;
00298 replyCode = rhs.getReplyCode();
00299 return *this;
00300 }
00301
00302 const bool DeleteMeReplyPacket::isDeleted( ) const
00303 {
00304 return replyCode == QQ_DELETE_ME_REPLY_OK;
00305 }
00306
00307 void DeleteMeReplyPacket::parseBody( )
00308 {
00309 replyCode = decryptedBuf[0];
00310 }
00311
00312
00313
00314
00315 SystemNotificationPacket::SystemNotificationPacket( unsigned char * buf, int len )
00316 : InPacket(buf, len)
00317 {
00318 }
00319
00320 SystemNotificationPacket::SystemNotificationPacket( const SystemNotificationPacket & rhs )
00321 : InPacket(rhs)
00322 {
00323 type = rhs.getType();
00324 myQQ = rhs.getMyQQ();
00325 fromQQ = rhs.getFromQQ();
00326 message = rhs.getMessage();
00327 }
00328
00329 SystemNotificationPacket & SystemNotificationPacket::operator =( const SystemNotificationPacket & rhs )
00330 {
00331 *((InPacket *)this) = (InPacket)rhs;
00332 type = rhs.getType();
00333 myQQ = rhs.getMyQQ();
00334 fromQQ = rhs.getFromQQ();
00335 message = rhs.getMessage();
00336 return *this;
00337 }
00338
00339 void SystemNotificationPacket::parseBody( )
00340 {
00341 int start=0 , offset=0;
00342 #ifdef WIN32
00343 char* buf; buf=(char*)_alloca(bodyLength);
00344 #else
00345 char buf[bodyLength];
00346 #endif
00347
00348 while(decryptedBuf[offset]!=DIVIDER) offset++;
00349 memcpy(buf, decryptedBuf + start, offset-start);
00350 buf[offset-start]=0x00;
00351 start = ++offset;
00352 type = (uint8_t)atoi(buf);
00353
00354
00355 while(decryptedBuf[offset]!=DIVIDER) offset++;
00356 memcpy(buf, decryptedBuf +start, offset-start);
00357 buf[offset-start]=0x00;
00358 start = ++offset;
00359 fromQQ = atoi(buf);
00360
00361
00362 while(decryptedBuf[offset]!=DIVIDER) offset++;
00363 memcpy(buf, decryptedBuf+start, offset-start);
00364 buf[offset-start]=0x00;
00365 start = ++offset;
00366 myQQ = atoi(buf);
00367
00368
00369 if(offset < bodyLength ) {
00370 memcpy(buf, decryptedBuf +start, bodyLength-start);
00371 buf[bodyLength - start] = 0x00;
00372 message = buf;
00373 }else
00374 message = "";
00375 }
00376