msn budbringer i delphi

, hvordan arbejdet med msn budbringer protokol i delphi,,,,,, at denne artikel er svær forældet og vil blive ajourført, snart,,,,,. dette er en gennemførelse af msn budbringer protokol i delphi, det er ikke komplet, og for at bygge det, du skal bruge wsocket pakke, er de fleste af hvad er forelagt her, er en del af varespecifikationen (stadig ikke nok til at gøre en fuldstændig rippet msn budbringer klon).det, du ser her, er de alle sammen (mest på grund af den kendsgerning, at jeg ganske enkelt ny muffer programmering), i denne artikel er baseret på værker af venkydude msn artikel og en gammel udgave af kmerlin (en opensource msn budbringer klon til linux).det er den anden artikel, jeg skrev til instant messaging (den første om yahoo protokol, noget, som jeg ikke har været i stand til at gennemføre på grund af tidnød (masse) jeg planlægning i en ajourføring af denne artikel, så hurtigt som muligt, < --------------------------------- kode ---------------------------------------- >,,,,, {globale todo: at gennemføre lokale todo, rengøring, udvide},,,, enhed, msnmessenger,,,,,,,,, bruger grænseflade,,,,,,, wsocket, md 5, klasser, sysutils,,,,,,,,,,,, tuserstate = (usonline, //du er online,,,, usbusy, //faktisk travlt,,,, usbrb, //tilbage,,,,, usaway, //væk,,,, usonphone, //pr. telefon,,,,,,, uslunch, //frokost,,,, ushidden,,, /skjult,,,, usoffline ,,//Offline,, ,,);,,, TMSNMessenger = ,class,(TComponent),, ,private,, ,FConnected: Boolean;,, FUserName: ,String,;,, FPassword: ,String,;,, FFriendlyUserName: ,String,;,, FLog: TStrings;,, FFriendlyNameChange: TNotifyEvent;,, FState: TUserState;,, ,function ,GetHost: ,String,;,, ,procedure ,SetHost(,const ,Value: ,String,);,, ,function ,GetPort: ,String,;,, ,procedure ,SetPort(,const ,Value: ,String,);,, ,procedure ,SetUserName(,const ,Value: ,String,);,, ,procedure ,SetPassWord(,const ,Value: ,String,);,, ,function ,GetFriendlyUserName: ,String,;,, ,procedure ,SetFriendlyUserName(,const ,Value: ,String,);,, ,procedure ,SetState(,const ,Value: TUserState);,, ,protected,,, fsocket: twsocket;,, ftrialid: heltal,,,,,,,, sendver; proceduren, receivesyn,,,,,, socketwrite (, konstant, astring:, snor,),,, procedure, logwrite (, denne data:, snor,).,,, procedure, processcommand (, konstant, planøkonomi:, snor,),,, procedure, socketdisconnect (afsender: tobject; fejl: ord;,,, procedure, socketdataavailable (afsender: tobject; fejl: ord;,,, procedure, socketconnect (afsender: tobject; fejl: ord),,,,,, triggerfriendlynamechange;, dynamisk,,,,,,, konstruktøren, skabe (aowner: tcomponent), tilsidesættes,,,,,,,, destructor, ødelægge og tilsidesætte,,,,,,,,,, login procedure, logoff;,,, der er offentliggjort, og ejendom, -, -læs, gethost, skrive, sethost;,,, ejendom, havn: streng læser, getport, skrive, setport;,,, ejendom, brugernavn: streng læser, fusername, skrive, setusername;,,, ejendom, kodeord: streng læser, fpassword, skrive, setpassword;,,, ejendom, friendlyusername: streng læser, getfriendlyusername, skrive, setfriendlyusername;,,, ejendom, forbundet: boolean, læse, fconnected;,,, ejendom, log: tstrings, læse, skrive, piske, piske,,,, ejendom, friendlynamechange: tnotifyevent, læse, skrive, ffriendlynamechange ffriendlynamechange,,,,, ejendom, status: tuserstate, læse, skrive, setstate fstate,,,,,,,,,,,, gennemførelse, anvendelse, vinduer,,,,,,, konstant, realstate:, system, [tuserstate], snor, =,,,'chg% d nln ",'chg% d BSY',,'CHG %d BRB',,'CHG %d AWY',,'CHG %d PHN',,'CHG %d LUN',,,, ,'CHG %d HDN',,'CHG %d FLN' ,);,,,type,, ,CharSet = ,Set of ,char;,,,function ,UTF8ToAnsi(x: ,string,): ansistring;,, ,,{ Function that recieves UTF8 string and converts,, to ansi string },,,,var,, ,i: integer;,, b1, b2: byte;,,begin,, ,Result := x;,, i := ,1,;,, ,while ,i <= Length(Result) ,do begin,, if ,(ord(Result[i]) ,and ,,$80,) <> ,0 ,,then begin,, ,b1 := ord(Result[i]);,, b2 := ord(Result[i + ,1,]);,, ,if ,(b1 ,and ,,$F0,) <> ,$C0 ,,then,, ,Result[i] := ,#128,, ,,else begin,, ,Result[i] := Chr((b1 ,shl ,,6,) ,or ,(b2 ,and ,,$3F,));,, Delete(Result, i + ,1,,1,);,, ,end,;,, ,end,;,, inc(i);,, ,end,;,,end,;,,,function ,AnsiToUtf8(x: ansistring): ,string,;,, ,,{ Function that recieves ansi string and converts,, to UTF8 string },,,,var,, ,i: integer;,, b1, b2: byte;,,begin,, ,Result := x;,, ,for ,i := Length(Result) ,downto ,,1 ,,do,, if ,Result[i] >= ,#127 ,,then begin,, ,b1 := ,$C0 ,,or ,(ord(Result[i]) ,shr ,,6,);,, b2 := ,$80 ,,or ,(ord(Result[i]) ,and ,,$3F,);,, Result[i] := chr(b1);,, Insert(chr(b2), Result, i + ,1,);,, ,end,;,,end,;,,,Function ,ExtractWord(N:Integer;S:,String,;WordDelims:CharSet):,String,;,,Var,, ,I,J:Word;,, Count:Integer;,, SLen:Integer;,,Begin,, ,Count := ,0,;,, I := ,1,;,, Result := ,'',;,, SLen := Length(S);,, ,While ,I <= SLen ,Do Begin,, ,,,{preskoc oddelovace},, ,,,While ,(I <= SLen) ,And ,(S[I] ,In ,WordDelims) ,Do ,Inc(I);,, ,,{neni-li na konci retezce, bude nalezen zacatek slova},, ,,,If ,I <= SLen ,Then ,Inc(Count);,, J := I;,, ,,{a zde je konec slova},, ,,,While ,(J <= SLen) ,And Not,(S[J] ,In ,WordDelims) ,Do ,Inc(J);,, ,,{je-li toto n-te slovo, vloz ho na vystup},, ,,,If ,Count = N ,Then Begin,, ,Result := Copy(S,I,J-I);,, Exit,, ,End,;,, I := J;,, ,End,; ,,{while},,,,End,;,,,,function ,WordAt(,const ,Text : ,string,; Position : Integer) : ,string,;,,begin,, ,Result := ExtractWord(Position, Text, [,' ',]);,,end,;,,,,{ TMSNMessenger },,,,,constructor ,TMSNMessenger.Create(AOwner: TComponent);,,begin,, inherited ,Create(AOwner);,, FSocket := TWSocket.Create(Self);,, FSocket.Addr := ,'messenger.hotmail.com',;,, FSocket.Port := ,'1863',;,, FSocket.Proto:= ,'tcp',;,,, FSocket.OnSessionConnected := SocketConnect;,, FSocket.OnSessionClosed := SocketDisconnect;,, FSocket.OnDataAvailable := SocketDataAvailable;,, FConnected := False;,,end,;,,,destructor ,TMSNMessenger.Destroy;,,begin,, ,FSocket.Free;,, FSocket := ,nil,;,, ,inherited ,Destroy;,,end,;,, , , ,function ,TMSNMessenger.GetFriendlyUserName: ,String,;,,begin,, if not ,FConnected ,then,, ,Result := FFriendlyUserName;,,end,;,,,function ,TMSNMessenger.GetHost: ,String,;,,begin,, ,Result := FSocket.Addr;,,end,;,,,function ,TMSNMessenger.GetPort: ,String,;,,begin,, ,Result := FSocket.Port;,,end,;,,,procedure ,TMSNMessenger.Login;,,begin,, ,FSocket.Connect;,,end,;,,,procedure ,TMSNMessenger.Logoff;,,begin,, end,;,,,procedure ,TMSNMessenger.LogWrite(,const ,Data: ,String,);,,begin,, if ,Assigned( FLog ) ,then,, ,FLog.Add(Data);,,end,;,,,,{Processcommand here is akin to a windowproc,, here we process all kind of info sent from the server,, as of now it is IFFull (full of if's) perhaps if i have,, some spare time will turn this into a case,,, TODO: Clean this procedure mess up,, TODO: Add more commands},,,,,procedure ,TMSNMessenger.ProcessCommand;,,var,, ,Tmp: ,String,;,, Hash: ,String,;,,begin,, ,Tmp := WordAt(ACommand,1,);,,, ,if ,Tmp = ,'VER' ,,then,, ,SocketWrite(,'INF %d',);,,, ,if ,Tmp = ,'INF' ,,then,, ,SocketWrite(,'USR %d MD5 I ',+ FUserName);,,, ,if ,Tmp = ,'USR' ,,then,, begin,, if ,WordAt(ACommand,4,) = ,'S' ,,then,, begin,, ,Hash := WordAt(ACommand,5,);,, Delete(Hash, pos(,#13#10,, Hash), Length(Hash));,, Hash := StrMD5(Hash + PassWord);,, SocketWrite(,'USR %d MD5 S ' ,+ Lowercase(Hash));,, ,end else,, begin,, ,FFriendlyUserName := WordAt(ACommand,5,);,, SocketWrite(,'SYN %d 1',);,, ReceiveSYN;,, ,end,;,, ,end,;,,,{When you receive an XFR and you are not connected,, to the msn server it means redirect to another server},, ,,,if ,(TMP = ,'XFR',) ,and not ,Connected ,then,, begin,, ,TMP := WordAt(ACommand,4,);,, FSocket.Close;,, Delete(Tmp, pos(,':',, Tmp), Length(Tmp));,, FSocket.Addr := Tmp;,, TMP := WordAt(ACommand,4,);,, Delete(Tmp,1,, pos(,':',, Tmp));,, FSocket.Port := Tmp;,, FSocket.Connect;,, Exit;,, ,end,;,,,{Rename Friendly name},, ,,,if ,(TMP = ,'REA',) ,then,, begin,, ,FFriendlyUserName := WordAt(ACommand,5,);,, FFriendlyUserName := StringReplace(FFriendlyUserName,' ',,' ',, [rfReplaceall]);,, TriggerFriendlyNameChange;,, ,end,;,,,{The out command is received before the server,, disconnects us, if it's because we've logged in another machine,, we receive the message OUT OTH (OTHER MACHINE),, TODO write sda begivenhed eller noget at hente denne meddelelse},,,,,, hvis (tmp =,'out "), så begynder, hvis også (,'oth", planøkonomi) > 1,,,,, logwrite (,'logged ud i en computer ved at afbryde.);,,,,,,,,,,,,,,,,, (syn er uden tvivl det mest informationfull msn budbringer kommando, syn informerer os om:,,, der er til rådighed, e - mail, ven liste, block liste, ændre listen (personer, der har de i deres lister), telefonnumre (hjem, mobile osv.), msn budbringer indstillinger, osv.,,,,,, men det kommer med en pris, for der er så mange oplysninger, wsocket ikke kan få alle oplysninger korrekt (en kvalitet af ikke - blokerende muffer), og dermed for at få det vi vil fryse denne tråd i 5 sekunder,, (dvs. your forms will not receive any message and,, seem unresponsive for a while), I,, know there must be a better way around if somebody knows email me.,,, TODO : Parse the received content,, TODO : look for a way wich does not have to freeze the thread,, },,,,,procedure ,TMSNMessenger.ReceiveSYN;,,var,, ,Tmp: ,String,;,,begin,, ,FSocket.OnDataAvailable := ,nil,;,,, Sleep(,5000,);,, Tmp := FSocket.ReceiveStr;,,, FSocket.OnDataAvailable := SocketDataAvailable;,, Tmp := UTF8ToAnsi(Tmp);,, LogWrite(,'RECV : ' ,+ Tmp);,, SocketWrite(,'CHG %d NLN',);,,end,;,,,procedure ,TMSNMessenger.SendVER;,,begin,, ,SocketWrite(,'VER %d CVR0 MSNP5 MSNP6 MSNP7',),,end,;,,,procedure ,TMSNMessenger.SetFriendlyUserName(,const ,Value: ,String,);,,var,, ,tmp: ,String,;,,begin,, if ,FConnected ,and ,(FUserName <> Value) ,then,, begin,, ,tmp := StringReplace(Value,' ',,' ',, [rfReplaceAll]);,, tmp := AnsiToUtf8(Tmp);,, SocketWrite(,'REA %d ' ,+ FUsername + ,' ',+ tmp);,, ,end,;,,end,;,,,procedure ,TMSNMessenger.SetHost(,const ,Value: ,String,);,,begin,, if not ,Connected ,then,, if ,FSocket.Addr <> Value ,then,, ,FSocket.Addr := Value;,,end,;,,,procedure ,TMSNMessenger.SetPassWord(,const ,Value: ,String,);,,begin,, if not ,Connected ,then,, if ,(FPassword <> Value) ,then,, ,FPassword := Value;,,end,;,,,procedure ,TMSNMessenger.SetPort(,const ,Value: ,String,);,,begin,, if not ,Connected ,then,, if ,FSocket.Port <> Value ,then,, ,FSocket.Port := Value;,,end,;,,,procedure ,TMSNMessenger.SetState(,const ,Value: TUserState);,,begin,, if ,FConnected ,then,, if ,(FState <> Value) ,then,, ,SocketWrite( RealState[Value] );,,end,;,,,procedure ,TMSNMessenger.SetUserName(,const ,Value: ,String,);,,begin,, if not ,FConnected ,then,, if ,FUsername <> Value ,then,, ,FUserName := Value;,,end,;,,,procedure ,TMSNMessenger.SocketConnect(Sender: TObject; Error: Word);,,begin,, ,FTrialID := ,1,;,, SendVER;,,end,;,,,procedure ,TMSNMessenger.SocketDataAvailable(Sender: TObject; Error: Word);,,var,, ,Tmp: ,String,;,,begin,, ,Tmp := FSocket.ReceiveStr;,, Tmp := UTF8ToAnsi(Tmp);,, LogWrite(,'RECV : ' ,+ Tmp);,, ProcessCommand(Tmp);,,end,;,,,procedure ,TMSNMessenger.SocketDisconnect(Sender: TObject; Error: Word);,,begin,, ,FConnected := False;,, LogWrite(,'Disconnected',);,,end,;,,,procedure ,TMSNMessenger.SocketWrite(,const ,AString: ,String,);,,begin,, ,FSocket.SendStr(Format(AString, [FTrialID]) + ,#13,+,#10,);,, LogWrite(,'SENT : ' ,+ Format(AString, [FTrialID]));,, Inc(FTrialID);,,end,;,,,procedure ,TMSNMessenger.TriggerFriendlyNameChange;,,begin,, if ,Assigned(FFriendlyNameChange) ,then,, ,FFriendlyNameChange(Self);,,end,;,,,end,.,,<---------------------------------/CODE---------------------------------------> a sample would be: AMSN := TMSNMessenger.Create(Self); //AMSN is a variable of type TMSNMessenger AMSN.UserName: = "; //angiver brugernavn, der bør altid være i form * @hotmail.com amsn.password: ="; //angiver kodeordet amsn. log: = memo1. linjer; //log viser en bestemmelse til at dumpe sendt og modtaget oplysninger, jeg bruger den til at indhente oplysninger og den slags, men protokollen det er ikke obligatorisk at bruge det amsn. login //procedure, der indikerer, at vi burde starte login proces,



Previous:
Next Page: