unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, ExtCtrls, Buttons, ComCtrls, ScktComp, AppEvnts,
  dWinsock, buffsock ;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    connbtn: TBitBtn;
    discbtn: TBitBtn;
    Comandobox: TComboBox;
    comandobox2: TComboBox;
    commbtn: TBitBtn;
    linea: TBevel;
    hostrem: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    portarem: TEdit;
    portaloc: TEdit;
    Memo1: TMemo;
    Edit5: TEdit;
    StatusBar1: TStatusBar;
    ApplicationEvents1: TApplicationEvents;
    Button1: TButton;
    Client: TTextClient;
    procedure ComandoboxChange(Sender: TObject);
    procedure connbtnClick(Sender: TObject);
    procedure discbtnClick(Sender: TObject);
    procedure commbtnClick(Sender: TObject);
    procedure ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure Esci1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ApplicationEvents1Hint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ClientLineReceived(socket: TLineSocketBase;
      const line: String; complete: Boolean);
    procedure ClientDisconnect(Sender: TObject; Socket: TSocketBase);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.ComandoboxChange(Sender: TObject);
begin

if comandobox.ItemIndex = 0 then
  begin
    comandobox2.Enabled:=True;
    portaloc.enabled:=True;
    portarem.enabled:=True;
    hostrem.Enabled:=True;
  end;
if comandobox.ItemIndex = 1 then
  begin
    comandobox2.Enabled:=True;
    portaloc.enabled:=True;
     hostrem.Enabled:=True;
    portarem.enabled:=True;
    portarem.Text:='21';
  end;
if comandobox.ItemIndex = 2 then
  begin
    comandobox2.Enabled:=False;
    portaloc.enabled:=False;
    portarem.enabled:=False;
    hostrem.Enabled:=False;

  end;
  if comandobox.ItemIndex = 3 then
  begin
    comandobox2.Enabled:=False;
    portaloc.enabled:=False;
    portarem.enabled:=False;
    hostrem.Enabled:=False;

  end;
  if comandobox.ItemIndex = 4 then
  begin
    comandobox2.Enabled:=False;
    portaloc.enabled:=False;
    portarem.enabled:=false;
    hostrem.Enabled:=true;

  end;


end;         

procedure TForm1.connbtnClick(Sender: TObject);
begin
if not Client.Connected then
begin
if edit1.Text <> '' then
begin
Client.Address:= edit1.Text;
Client.Port:= edit5.Text;
Statusbar1.Panels[1].Text:='Connected';
Client.Open(TLinesocket);
commbtn.Enabled:=True;
end
else messagedlg('Enter ip adress!',mtWarning,[mbok],0);
end
else messagedlg ('Already connected',mtWarning,[mbok],0);
end;



procedure TForm1.discbtnClick(Sender: TObject);
begin
if Client.Connected then
 begin
  Client.Close;
  commbtn.Enabled:= False;
  Statusbar1.Panels[1].Text:='Disconnected';
 end
else messagedlg ('Already Disconnected',mtWarning,[mbok],0);
end;

procedure TForm1.commbtnClick(Sender: TObject);
begin
if comandobox.ItemIndex= 0 then
    begin
      if  comandobox2.ItemIndex= 0 then  (Client.Conn as TLineSocket).WriteLine('/TCPD CONN '+hostrem.Text+' '+portarem.Text+'['+portaloc.Text+']')
      else  (Client.Conn as TLineSocket).WriteLine('/TCPD DISC');
    end
else if comandobox.ItemIndex= 1 then
    begin
      if  comandobox2.ItemIndex= 0 then  (Client.Conn as TLineSocket).WriteLine('/FTPD CONN '+hostrem.Text+' '+portarem.Text+'['+portaloc.Text+']')
      else  (Client.Conn as TLineSocket).WriteLine('/FTPD DISC');
    end
else if comandobox.ItemIndex = 2 then  (Client.Conn as TLineSocket).WriteLine('/NETS')
else if comandobox.ItemIndex = 3 then  (Client.Conn as TLineSocket).WriteLine('/STAT')
else if messagedlg('You are sure?'+#13#10+'The search take some minuts and make to discover you!', mtWarning, [mbYes,mbNo],0) = mrYes then
 (Client.Conn as TLineSocket).WriteLine('/LOGD '+hostrem.Text);
end;

procedure TForm1.ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
memo1.lines.Add('Connected'); 
end;

procedure TForm1.Esci1Click(Sender: TObject);
begin
Form1.Close;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Client.Connected then Client.Close;
end;



procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
Statusbar1.panels[0].Text:= Application.Hint;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
end;


procedure TForm1.ClientLineReceived(socket: TLineSocketBase;
  const line: String; complete: Boolean);
begin
memo1.Lines.add(line);
end;

procedure TForm1.ClientDisconnect(Sender: TObject; Socket: TSocketBase);
begin
commbtn.Enabled:= False;
memo1.Lines.add ('Disconnected');
Statusbar1.Panels[1].Text:='Disconnected';
end;

end.
