Einzelnen Beitrag anzeigen

RedShakal
(Gast)

n/a Beiträge
 
#13

Re: Connection Closed Gracefully.

  Alt 21. Dez 2009, 18:33
Ich habe leider keine Ahnung von Threadsaving aber mein aktueller Code sieht so aus:

Delphi-Quellcode:
procedure TServer.IdTCPServer1Execute(AThread: TIdContext);
var
  Data : String;
  StrArr : TDynStringArray;
  ini : TIniFile;
   f : TextFile;
   Files : string;
   y,m,d : Word;
begin
 with AThread.Connection do
   begin
     DecodeDate(Now,d,m,y);
     Files := Format('log\%.2d-%.2d-%.2d.txt',[y,m,d]);

     AssignFile(f, Files);

     if FileExists(Files) then Append(f) else Rewrite(f);

     Data := String(Socket.ReadLn);
     Data := Trim(Data);

     if Length(Data) > 0 then
       begin
         StrArr := Explode('|', Data);
         if StrArr[0] = 'loginthen
           begin
               if StrArr[3] = Clientver then
                 begin
                   if FileExists('accounts\'+StrArr[1]+'.ini') then
                     begin
                       ini := TIniFile.Create('accounts\'+StrArr[1]+'.ini');
                       try
                         if StrArr[2] = ini.ReadString('Login','Passwort','') then
                           begin
                             Socket.WriteLn('login');
                             WriteLn('['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' hat sich eingeloggt.');
                             WriteLn(f, '['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' hat sich eingeloggt.');
                           end
                         else
                           begin
                             Socket.WriteLn('invalid');
                             WriteLn('['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' falsches Passwort.');
                             WriteLn(f, '['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' falsches Passwort.');
                           end;
                       finally
                         ini.free;
                       end;
                     end
                   else
                     begin
                       Socket.WriteLn('na');
                       WriteLn('['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' existiert nicht.');
                       WriteLn(f, '['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' existiert nicht.');
                     end;
                 end
                   else
                     begin
                       Socket.WriteLn('version');
                     end;
           end;

         if StrArr[0] = 'registerthen
           begin
             if FileExists('accounts\'+StrArr[1]+'.ini') then
               begin
                 Socket.WriteLn('vorhanden');
                 WriteLn('['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' existiert bereits.');
                 WriteLn(f, '['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' existiert bereits.');
               end
             else
               begin
                 try
                   ini := TIniFile.Create('accounts\'+StrArr[1]+'.ini');
                   ini.WriteString('Login','Passwort',StrArr[2]);
                   ini.WriteString('Login','E-Mail',StrArr[3]);
                 finally
                   Socket.WriteLn('erfolg');
                   ini.free;
                   WriteLn('['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' wurde registriert.');
                   WriteLn(f, '['+TimeToStr(Time)+']'+' Account: '+StrArr[1]+' wurde registriert.');
                 end;
               end;
           end;
       end;
   end;
    CloseFile(f);
end;
  Mit Zitat antworten Zitat