Ĺadny brzuch
Mo więc mam procegurę i wysyłam z srewera pakiet 'dodajuser' no i powinno być tak jeścli plik istnieje to wysyła do klijęta ze juz jest a jak nie ma to dooaje plik txt i wysyła 'hasło' i 'nick' a jak odbierze pak 'logowanie' to wysyła do klijenta ze jest zalogowany. Noi sklepałem takie coś ale jak wyślę dodajuser to wykonuje wszystkie procedury a powinno tylko odpowiednie a jak wyślę 'logowanie' to nie działa. Co z tym zrobć??
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var P: String;
Str: TStrings;
Sta: String;
i: Integer;
u: TStringList;
tmpClient: TSimpleTCPClient;
begin
P := Socket.ReceiveText;
if DecodeType(P) = 'dodajuser' then begin
Str := TStringList.Create;
Str.Text := RString(P,#2);
if FileExists('users' + Str[0] + '.txt') then
Sta := 'Podany Nick jest już zajęty!';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta)) ;
end
else
logi.Items.Add('Nowy użytkownik: ' + Str[0]) ;
u:=TStringList.create;
u.add(Str[1]);
u.add(Str[2]);
u.SaveToFile('users' + Str[0] + '.txt') ;
Sta := 'Konto ' + Str[0] + ' zostało urworzone. Hasło do konta to: ' + Str[1];
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta));
end;
u.Free;
Str.Free;
begin
P := Socket.ReceiveText;
if DecodeType(P) = 'logowanie' then
showmessage('logowanie');
Sta := 'Zalogowany';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta))
end;
u.Free;
Str.Free;
end;
end;
end;
end.
Wiem ze jest problem tu:
if DecodeType(P) = 'dodajuser' then begin
Str := TStringList.Create;
Str.Text := RString(P,#2);
if FileExists('users' + Str[0] + '.txt') then begin
Sta := 'Podany Nick jest już zajęty!';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta)) ;
end; end
else
logi.Items.Add('Nowy użytkownik: ' + Str[0]) ;
u:=TStringList.create;
u.add(Str[1]);
u.add(Str[2]);
u.SaveToFile('users' + Str[0] + '.txt') ;
Sta := 'Konto ' + Str[0] + ' zostało urworzone. Hasło do konta to: ' + Str[1];
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta));
end;
u.Free;
Str.Free;
u.Free;
Str.Free;
end;
bo nie bieze pod uwage else tylko wykonuje całą procedurę od razu
zanotowane.pl doc.pisz.pl pdf.pisz.pl zsf.htw.pl
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var P: String;
Str: TStrings;
Sta: String;
i: Integer;
u: TStringList;
tmpClient: TSimpleTCPClient;
begin
P := Socket.ReceiveText;
if DecodeType(P) = 'dodajuser' then begin
Str := TStringList.Create;
Str.Text := RString(P,#2);
if FileExists('users' + Str[0] + '.txt') then
Sta := 'Podany Nick jest już zajęty!';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta)) ;
end
else
logi.Items.Add('Nowy użytkownik: ' + Str[0]) ;
u:=TStringList.create;
u.add(Str[1]);
u.add(Str[2]);
u.SaveToFile('users' + Str[0] + '.txt') ;
Sta := 'Konto ' + Str[0] + ' zostało urworzone. Hasło do konta to: ' + Str[1];
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta));
end;
u.Free;
Str.Free;
begin
P := Socket.ReceiveText;
if DecodeType(P) = 'logowanie' then
showmessage('logowanie');
Sta := 'Zalogowany';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta))
end;
u.Free;
Str.Free;
end;
end;
end;
end.
Wiem ze jest problem tu:
if DecodeType(P) = 'dodajuser' then begin
Str := TStringList.Create;
Str.Text := RString(P,#2);
if FileExists('users' + Str[0] + '.txt') then begin
Sta := 'Podany Nick jest już zajęty!';
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta)) ;
end; end
else
logi.Items.Add('Nowy użytkownik: ' + Str[0]) ;
u:=TStringList.create;
u.add(Str[1]);
u.add(Str[2]);
u.SaveToFile('users' + Str[0] + '.txt') ;
Sta := 'Konto ' + Str[0] + ' zostało urworzone. Hasło do konta to: ' + Str[1];
I := Server.Connections.Count;
if I <> 0 then
for I := 0 to I - 1 do
begin
tmpClient := Server.Connections[I];
if kompy.Checked[I] then
Server.Send(tmpClient, PChar(Sta), Length(Sta));
end;
u.Free;
Str.Free;
u.Free;
Str.Free;
end;
bo nie bieze pod uwage else tylko wykonuje całą procedurę od razu