OICQPack.pas
上传用户:hbtcygglw
上传日期:2007-01-07
资源大小:281k
文件大小:5k
- unit OICQPack;
- interface
- uses Windows,SysUtils,classes;
- const
- OICQ_CMD_LOGON=$13;
- OICQ_CMD_LOGOFF=$1;
- OICQ_CMD_GETUSERINFO=$06;
- OICQ_CMD_SENDMSG=$08;
- OICQ_CMD_ADDFRIEND=$09;
- OICQ_CMD_GETFRIENDLIST=$0C;
- OICQ_CMD_REMOVEFRIEND=$0A;
- OICQ_CMD_PING=$02;
- function BuildEmptyPack(var buf:array of char;buflen:Integer;Cmd:Byte;MsgId:Word;uid:string):Integer;
- function BuildPingPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:String):Integer;
- function BuildLogonPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- function ParseLogonReponse(buf:array of char;buflen:Integer;var uid:string;var ip:string;var port:string):Boolean;
- function BuildLogoffPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- function BuildGetFriendListPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- function ParseFriendList(buf:array of char;buflen:Integer;items:TStrings):Integer;
- function BuildGetUserInfoPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:String;FriendId:String):Integer;
- function ParseUserInfo(buf:array of char;buflen:Integer;var uid:string;var name:string):Boolean;
- function BuildDeleteFriend(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;FriendId:string):Integer;
- function ParseDeleteReponse(buf:array of char;buflen:Integer):Boolean;
- implementation
- uses data;
- function BuildEmptyPack(var buf:array of char;buflen:Integer;Cmd:Byte;MsgId:Word;uid:string):Integer;
- var
- id:DWORD;
- begin
- //Version header
- buf[0]:=#2;
- buf[1]:=#1;
- buf[2]:=#7;
- buf[3]:=#0;
- //Cmd
- buf[4]:=Chr(Cmd);
- //MsgId
- buf[5]:=Chr((MsgId and $ff00) shr 8);
- buf[6]:=Chr(MsgId and $00ff);
- //uid
- id:=StrToInt(uid);
- buf[7]:=Chr((id and $ff000000) shr 24);
- buf[8]:=Chr((id and $00ff0000) shr 16);
- buf[9]:=Chr((id and $0000ff00) shr 8);
- buf[10]:=Chr(id and $000000ff);
- Result:=11;
- end;
- function BuildLogonPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_LOGON,MsgId,uid);
- buf[i]:=#$30;
- Inc(i);
- buf[i]:=#$1f;
- Inc(i);
- i:=ArrayStrCopy(buf,buflen,i,password);
- buf[i]:=#03;
- Result:=i+1;
- end;
- function ParseLogonReponse(buf:array of char;buflen:Integer;var uid:string;var ip:string;var port:string):Boolean;
- var
- i:Integer;
- begin
- if(buf[4]=#$13)then
- begin
- Result:=True;
- i:=ParseStrFromBuf(buf,buflen,7,$1f,uid);
- i:=ParseStrFromBuf(buf,buflen,i+1,$1f,ip);
- ParseStrFromBuf(buf,buflen,i+1,$1f,port);
- end
- else Result:=False;
- end;
- function BuildLogoffPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_LOGOFF,MsgId,uid);
- i:=ArrayStrCopy(buf,buflen,i,password);
- buf[i]:=#03;
- Result:=i+1;
- end;
- function BuildGetFriendListPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;password:string):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_GETFRIENDLIST,MsgId,uid);
- i:=ArrayStrCopy(buf,buflen,i,password);
- buf[i]:=#03;
- Result:=i+1;
- end;
- function ParseFriendList(buf:array of char;buflen:Integer;items:TStrings):Integer;
- var
- i:integer;
- str:string;
- begin
- Result:=0;
- if(buf[4]=Chr(OICQ_CMD_GETFRIENDLIST))then
- begin
- i:=ParseStrFromBuf(buf,buflen,7,$1f,str);
- while((i<buflen) and (i<>7))do
- begin
- items.add(str);
- i:=ParseStrFromBuf(buf,buflen,i+1,$1f,str);
- Inc(Result);
- end;
- end
- else Result:=-1;
- end;
- function BuildGetUserInfoPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:String;FriendId:String):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_GETUSERINFO,MsgId,uid);
- i:=ArrayStrCopy(buf,buflen,i,FriendId);
- buf[i]:=#03;
- Result:=i+1;
- end;
- function ParseUserInfo(buf:array of char;buflen:Integer;var uid:string;var name:string):Boolean;
- var
- i:Integer;
- begin
- if(buf[4]=Chr(OICQ_CMD_GETUSERINFO))then
- begin
- Result:=True;
- i:=ParseStrFromBuf(buf,buflen,7,$1e,uid);
- ParseStrFromBuf(buf,buflen,i+1,$1e,name);
- end
- else Result:=False;
- end;
- function BuildDeleteFriend(var buf:array of char;buflen:Integer;MsgId:Word;uid:string;FriendId:string):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_REMOVEFRIEND,MsgId,uid);
- i:=ArrayStrCopy(buf,buflen,i,FriendId);
- buf[i]:=#03;
- Result:=i+1;
- end;
- function ParseDeleteReponse(buf:array of char;buflen:Integer):Boolean;
- begin
- Result:=(buf[4]=Chr(OICQ_CMD_REMOVEFRIEND));
- end;
- function BuildPingPack(var buf:array of char;buflen:Integer;MsgId:Word;uid:String):Integer;
- var
- i:Integer;
- begin
- i:=BuildEmptyPack(buf,buflen,OICQ_CMD_PING,MsgId,uid);
- i:=ArrayStrCopy(buf,buflen,i+1,uid);
- buf[i]:=#3;
- Result:=i+1;
- end;
- end.