<commit_before>unit UFRMNodesIp;

{ Copyright (c) 2016 by <NAME>

  Distributed under the MIT software license, see the accompanying file LICENSE
  or visit http://www.opensource.org/licenses/mit-license.php.

  This unit is a part of the PascalCoin Project, an infinitely scalable
  cryptocurrency. Find us here:
  Web: https://pascalcoin.org
  Source: https://github.com/PascalCoin/PascalCoin

  If you like it, consider a donation using Bitcoin:
  16K3HCZRhFUtM8GdWRcfKeaa6KsuyxZaYk

  THIS LICENSE HEADER MUST NOT BE REMOVED.
}

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

uses
{$IFnDEF FPC}
  Windows,
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
  Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, UAppParams;

type
  TFRMNodesIp = class(TForm)
    memoNodesIp: TMemo;
    Label1: TLabel;
    bbOk: TBitBtn;
    bbCancel: TBitBtn;
    cbTryOnlyWithThisServers: TCheckBox;
    procedure bbOkClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cbTryOnlyWithThisServersClick(Sender: TObject);
  private
    FAppParams: TAppParams;
    procedure SetAppParams(const Value: TAppParams);
    { Private declarations }
  public
    { Public declarations }
    Procedure PrepareData;
    Property AppParams : TAppParams read FAppParams write SetAppParams;
  end;

implementation

uses
  UNetProtocol, UNode, UConst, USettings;

{$IFnDEF FPC}
  {$R *.dfm}
{$ELSE}
  {$R *.lfm}
{$ENDIF}

{ TFRMNodesIp }

procedure TFRMNodesIp.bbOkClick(Sender: TObject);
Var nsarr : TNodeServerAddressArray;
  ips : AnsiString;
begin
  TNode.DecodeIpStringToNodeServerAddressArray(memoNodesIp.Lines.Text,nsarr);
  if (length(nsarr)=0) And (cbTryOnlyWithThisServers.Checked) then begin
    raise Exception.Create('No valid IP in list!');
  end;
  // Encode
  ips := TNode.EncodeNodeServerAddressArrayToIpString(nsarr);
  if Assigned(FAppParams) then begin
    FAppParams.ParamByName[CT_PARAM_PeerCache].SetAsString(ips);
    if cbTryOnlyWithThisServers.Checked then Begin
      FAppParams.ParamByName[CT_PARAM_TryToConnectOnlyWithThisFixedServers].SetAsString(ips);
      TNetData.NetData.DiscoverFixedServersOnly(nsarr);
      Application.MessageBox(PChar('Restart application to take effect'),PChar(Application.Title),MB_OK);
    end else begin
      FAppParams.ParamByName[CT_PARAM_TryToConnectOnlyWithThisFixedServers].SetAsString('');
      setlength(nsarr,0);
      TNetData.NetData.DiscoverFixedServersOnly(nsarr);
    end;
  end;
  setlength(nsarr,0);
  ModalResult := MrOk;
end;

procedure TFRMNodesIp.cbTryOnlyWithThisServersClick(Sender: TObject);
begin
  if cbTryOnlyWithThisServers.Checked then begin
    cbTryOnlyWithThisServers.Font.Color := clRed;
    cbTryOnlyWithThisServers.Font.Style := [fsBold];
  end else begin
    cbTryOnlyWithThisServers.ParentFont := true;
  end;
  if cbTryOnlyWithThisServers.Checked then begin
    Application.MessageBox(PChar('ALERT:'+#10+
      'If "'+cbTryOnlyWithThisServers.Caption+'" is checked '+#10+
      'and no valid server found, you will be alone!')
      ,PChar(Application.Title),MB_OK+MB_ICONWARNING);
  end;
end;

procedure TFRMNodesIp.FormCreate(Sender: TObject);<commit_msg>Classic GUI discover IP's bug<commit_after>unit UFRMNodesIp;

{ Copyright (c) 2016 by <NAME>

  Distributed under the MIT software license, see the accompanying file LICENSE
  or visit http://www.opensource.org/licenses/mit-license.php.

  This unit is a part of the PascalCoin Project, an infinitely scalable
  cryptocurrency. Find us here:
  Web: https://pascalcoin.org
  Source: https://github.com/PascalCoin/PascalCoin

  If you like it, consider a donation using Bitcoin:
  16K3HCZRhFUtM8GdWRcfKeaa6KsuyxZaYk

  THIS LICENSE HEADER MUST NOT BE REMOVED.
}

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

uses
{$IFnDEF FPC}
  Windows,
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
  Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, UAppParams;

type
  TFRMNodesIp = class(TForm)
    memoNodesIp: TMemo;
    Label1: TLabel;
    bbOk: TBitBtn;
    bbCancel: TBitBtn;
    cbTryOnlyWithThisServers: TCheckBox;
    procedure bbOkClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cbTryOnlyWithThisServersClick(Sender: TObject);
  private
    FAppParams: TAppParams;
    procedure SetAppParams(const Value: TAppParams);
    { Private declarations }
  public
    { Public declarations }
    Procedure PrepareData;
    Property AppParams : TAppParams read FAppParams write SetAppParams;
  end;

implementation

uses
  UNetProtocol, UNode, UConst, USettings;

{$IFnDEF FPC}
  {$R *.dfm}
{$ELSE}
  {$R *.lfm}
{$ENDIF}

{ TFRMNodesIp }

procedure TFRMNodesIp.bbOkClick(Sender: TObject);
Var nsarr : TNodeServerAddressArray;
  ips : AnsiString;
  i : Integer;
begin
  TNode.DecodeIpStringToNodeServerAddressArray(memoNodesIp.Lines.Text,nsarr);
  if (length(nsarr)=0) And (cbTryOnlyWithThisServers.Checked) then begin
    raise Exception.Create('No valid IP in list!');
  end;
  // Encode
  ips := TNode.EncodeNodeServerAddressArrayToIpString(nsarr);
  if Assigned(FAppParams) then begin
    FAppParams.ParamByName[CT_PARAM_PeerCache].SetAsString(ips);
    if cbTryOnlyWithThisServers.Checked then Begin
      FAppParams.ParamByName[CT_PARAM_TryToConnectOnlyWithThisFixedServers].SetAsString(ips);
      TNetData.NetData.DiscoverFixedServersOnly(nsarr);
      Application.MessageBox(PChar('Restart application to take effect'),PChar(Application.Title),MB_OK);
    end else begin
      FAppParams.ParamByName[CT_PARAM_TryToConnectOnlyWithThisFixedServers].SetAsString('');
      for i:=Low(nsarr) to High(nsarr) do begin
        TNetData.NetData.AddServer(nsarr[i]);
      end;
      setlength(nsarr,0);
      TNetData.NetData.DiscoverFixedServersOnly(nsarr);
    end;
  end;
  setlength(nsarr,0);
  ModalResult := MrOk;
end;

procedure TFRMNodesIp.cbTryOnlyWithThisServersClick(Sender: TObject);
begin
  if cbTryOnlyWithThisServers.Checked then begin
    cbTryOnlyWithThisServers.Font.Color := clRed;
    cbTryOnlyWithThisServers.Font.Style := [fsBold];
  end else begin
    cbTryOnlyWithThisServers.ParentFont := true;
  end;
  if cbTryOnlyWithThisServers.Checked then begin
    Application.MessageBox(PChar('ALERT:'+#10+
      'If "'+cbTryOnlyWithThisServers.Caption+'" is checked '+#10+
      'and no valid server found, you will be alone!')
      ,PChar(Application.Title),MB_OK+MB_ICONWARNING);
  end;
end;

procedure TFRMNodesIp.FormCreate(Sender: TObject);
{'fraction_non_alphanumeric': 0.09562423500611995, 'fraction_numerical': 0.005201958384332925, 'mean_word_length': 4.774734982332156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6792281', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2205, 'n_words': 493}