info.pas
上传用户:hbtcygglw
上传日期:2007-01-07
资源大小:281k
文件大小:4k
- unit info;
- interface
- uses Windows,SysUtils,dialogs,WinSock;
- type
- TFriendInfo=class
- public
- Id,Name:String;
- strIp:String;
- nIp:DWORD;
- nPort:WORD;
- nFaceNo:WORD;
- end;
- //function GetFaceFileName(nFaceNo:WORD):string;
- function GetOICQUserName(Id:string):string;{overload;
- function GetOICQUserName(id:WORD):String;overload;}
- function MakeDirectMsgBuf(var buf:array of char;MsgId:WORD;SrcId:string;FaceNo:Integer;dte,Tme:TDateTime;Msg:String):integer;
- procedure SetSysParam;
- function GetLocalIP:String;
- var
- MyId:String;
- implementation
- uses SysCfg;
- function GetLocalIP : string;
- type
- TaPInAddr = array [0..10] of PInAddr;
- PaPInAddr = ^TaPInAddr;
- var
- phe : PHostEnt;
- pptr : PaPInAddr;
- Buffer : array [0..63] of char;
- I : Integer;
- GInitData : TWSADATA;
- begin
- WSAStartup($101, GInitData);
- Result := '';
- GetHostName(Buffer, SizeOf(Buffer));
- phe :=GetHostByName(buffer);
- if phe = nil then Exit;
- pptr := PaPInAddr(Phe^.h_addr_list);
- I := 0;
- while pptr^[I] <> nil do begin
- result:=StrPas(inet_ntoa(pptr^[I]^));
- Inc(I);
- end;
- WSACleanup;
- end;
- procedure SetSysParam;
- var
- dwVersion:DWORD;
- begin
- dwVersion:=GetVersion;
- if(dwVersion<$80000000)then
- begin
- TimeAMString:='';
- TimePMString:='';
- end;
- CurrencyString:='元';
- CurrencyFormat:=1;
- CurrencyDecimals:=2;
- NegCurrFormat:=5;
- ShortDateFormat:='yyyy-mm-dd';
- ShortTimeFormat:='HH:MM';
- LongTimeFormat:='HH:MM:SS';
- DateSeparator:='-';
- DecimalSeparator:='.';
- //LongDateFormat:='yyyy年mm月dd日';
- TimeSeparator:=':';
- end;
- function MakeDirectMsgBuf(var buf:array of char;MsgId:WORD;SrcId:string;FaceNo:Integer;dte,Tme:TDateTime;Msg:String):integer;
- var
- p,I,l:Integer;
- s:string;
- begin
- //header
- buf[0]:=chr(2);
- buf[1]:=chr(1);
- buf[2]:=chr(7);
- buf[3]:=chr(0);
- //cmd
- buf[4]:=chr($78);
- //Message Id
- buf[5]:=chr((MsgId and $ff00 )shr 8);
- buf[6]:=chr(MsgId and $00ff);
- p:=6;
- //Source Id
- l:=Length(SrcId);
- for i:=0 to l-1 do
- begin
- buf[7+i]:=SrcId[1+i];
- p:=i+7;
- end;
- Inc(p);
- buf[p]:=chr($1f);
- Inc(p);
- buf[p]:='0';
- Inc(p);
- buf[p]:=chr($1f);
- Inc(p);
- //Face no
- s:=IntTOStr(faceno);
- l:=length(s);
- for i:=0 to l-1 do
- begin
- buf[p]:=s[i+1];
- Inc(p);
- end;
- buf[p]:=chr($1f);
- Inc(p);
- //Date time
- s:=DateToStr(dte);
- l:=length(s);
- for i:=0 to l-1 do
- begin
- buf[p]:=s[i+1];
- Inc(p);
- end;
- buf[p]:=chr($1f);
- Inc(p);
- s:=TimeToStr(tme);
- l:=length(s);
- for i:=0 to l-1 do
- begin
- buf[p]:=s[i+1];
- Inc(p);
- end;
- buf[p]:=chr($1f);
- Inc(p);
- //msg
- l:=Length(msg);
- for i:=0 to l-1 do
- begin
- buf[p]:=msg[i+1];
- Inc(p);
- end;
- buf[p]:=chr(3);
- Result:=p+1;
- end;
- function GetCurrentUserId:String;
- begin
- //Result:='1934815';
- Result:=MyId;
- end;
- {function GetFaceFileName(nFaceNo:WORD):String;
- var
- f:TextFile;
- i:Integer;
- s:String;
- begin
- AssignFile(f,GetOICQPath+'faceface.ini');
- Reset(f);
- for i:=0 to nFaceNo do ReadLn(f,s);
- CloseFile(f);
- Result:=s;
- end;}
- function FindStrInBuffer(buffer:PChar;len:DWORD;str:String):DWORD;
- var
- l,p,o:DWORD;
- begin
- p:=0;
- o:=1;
- l:=length(str);
- Result:=$FFFFFFFF;
- while p<=len do
- begin
- if(buffer[p]<>str[o])then
- begin
- Inc(p);
- o:=1;
- end
- else
- begin
- if(o>=l)then
- begin
- Result:=p-l;
- break;
- end;
- Inc(p);
- Inc(o);
- end;
- end;
- end;
- function GetOICQUserName(Id:string):string;
- var
- hFile,nFileLen:Integer;
- nOffset:DWORD;
- buffer:PChar;
- begin
- Result:='';
- hFile:=FileOpen(GOICQPath+''+GetCurrentUserId+'friends.v30',fmOpenRead);
- if(hFile>0)then
- begin
- nFileLen:=FileSeek(hFile,0,2);
- FileSeek(hFile,0,0);
- Buffer := PChar(AllocMem(nFileLen+ 1));
- FileRead(hFile,Buffer^,nFileLen);
- FileClose(hFile);
- nOffset:=FindStrInBuffer(buffer,nFileLen,id);
- if(nOffset<>$FFFFFFFF)then
- begin
- nOffset:=nOffset-61;
- while (buffer[nOffset]<>chr(0))do
- begin
- Result:=Result+buffer[noffset];
- Inc(nOffset);
- end;
- end
- else Result:='Unknow';
- end;
- end;
- {function GetOICQUserName(id:WORD):String;
- begin
- end;}
- end.