Skip to content

Commit

Permalink
add Quiet parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dfdragon committed Oct 22, 2017
1 parent a4d5f52 commit 187dfa3
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 204 deletions.
35 changes: 35 additions & 0 deletions Class_ClientNode.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TClientNode = class
FisDSCP: Integer; FDSCP: string;
FisAutoExpire: Integer; FAutoExpire: string;
FisScavengeTTL: Integer; FScavengeTTL: string;
FisQuiet: Integer;

FisMode: Integer; FMode: string;
FisNoDelay: Integer;
Expand Down Expand Up @@ -110,6 +111,8 @@ TClientNode = class
procedure SetisScavengeTTL(const Value: Integer);
procedure SetScavengeTTL(const Value: string);

procedure SetisQuiet(const Value: Integer);

procedure SetisMode(const Value: Integer);
procedure SetMode(const Value: string);

Expand Down Expand Up @@ -192,6 +195,8 @@ TClientNode = class
property isScavengeTTL: Integer read FisScavengeTTL write SetisScavengeTTL;
property ScavengeTTL: string read FScavengeTTL write SetScavengeTTL;

property isQuiet: Integer read FisQuiet write SetisQuiet;

//传输模式
property isMode: Integer read FisMode write SetisMode;
property Mode: string read FMode write SetMode;
Expand Down Expand Up @@ -266,6 +271,7 @@ procedure TClientNode.initPara;
FisDSCP:= 0; FDSCP:= '';
FisAutoExpire:= 0; FAutoExpire:= '';
FisScavengeTTL:= 0; FScavengeTTL:= '';
FisQuiet:= 0;

FisMode:= 0; FMode:= '';
FisNoDelay:= 0;
Expand Down Expand Up @@ -636,6 +642,16 @@ procedure TClientNode.SetScavengeTTL(const Value: string);
FScavengeTTL:= Value;
end;

procedure TClientNode.SetisQuiet(const Value: Integer);
begin
if FCanModifyXML then
begin
FXMLNode.ChildNodes.FindNode('quiet').Attributes['enable']:= Value;
FXMLDocument_Para.SaveToFile;
end;
FisQuiet:= Value;
end;

procedure TClientNode.SetisMode(const Value: Integer);
begin
if FCanModifyXML then
Expand Down Expand Up @@ -832,6 +848,9 @@ function TClientNode.ReadFromXMLNode(XMLClientNode: IXMLNode): Integer;
FisScavengeTTL:= StrToInt(VarToStr(DealNode.Attributes['enable']).Trim);
FScavengeTTL:= VarToStr(DealNode.NodeValue).Trim;

DealNode:= XMLClientNode.ChildNodes.FindNode('quiet');
FisQuiet:= StrToInt(VarToStr(DealNode.Attributes['enable']).Trim);

DealNode:= XMLClientNode.ChildNodes.FindNode('mode');
FisMode:= StrToInt(VarToStr(DealNode.Attributes['enable']).Trim);
FMode:= VarToStr(DealNode.NodeValue).Trim;
Expand Down Expand Up @@ -934,6 +953,9 @@ function TClientNode.WriteToXMLNode(XMLClientNode: IXMLNode): Integer;
DealNode.Attributes['enable']:= FisScavengeTTL;
DealNode.NodeValue:= FScavengeTTL;

DealNode:= XMLClientNode.AddChild('quiet');
DealNode.Attributes['enable']:= FisQuiet;

DealNode:= XMLClientNode.AddChild('mode');
DealNode.Attributes['enable']:= FisMode;
DealNode.NodeValue:= FMode;
Expand Down Expand Up @@ -1043,6 +1065,8 @@ function TClientNode.CreateCMDLine(ClientEXEPathName: string): string;
CMDLine:= CMDLine + ' -autoexpire ' + FAutoExpire;
if (FisScavengeTTL <> 0) and (FScavengeTTL.Trim <> '') then
CMDLine:= CMDLine + ' -scavengettl ' + FScavengeTTL;
if (FisQuiet <> 0) then
CMDLine:= CMDLine + ' -quiet';

//隐藏参数
if (FisACKNoDelay <> 0) then
Expand Down Expand Up @@ -1121,6 +1145,11 @@ function TClientNode.CreateJSONConfig(): string;
if (FisScavengeTTL <> 0) and (FScavengeTTL.Trim <> '') then
JSONObject.AddPair(TJSONPair.Create('scavengettl', TJSONNumber.Create(FScavengeTTL.Trim)));

if (FisQuiet <> 0) then
JSONObject.AddPair(TJSONPair.Create('quiet', TJSONTrue.Create))
else
JSONObject.AddPair(TJSONPair.Create('quiet', TJSONFalse.Create));

if (FisMode <> 0) and (FMode.Trim <> '') then
JSONObject.AddPair(TJSONPair.Create('mode', FMode.Trim));
JSONObject.AddPair(TJSONPair.Create('nodelay', TJSONNumber.Create(FisNoDelay)));
Expand Down Expand Up @@ -1239,6 +1268,10 @@ function TClientNode.ReadFromJSONConfig(JSONStr: string): Integer;
isScavengeTTL:= 1;
ScavengeTTL:= IntegerValue.ToString;
end;
if JSONObject.TryGetValue<Boolean>('quiet', BooleanValue) then
begin
isQuiet:= Integer(BooleanValue);
end;

if JSONObject.TryGetValue<string>('mode', StringValue) then
begin
Expand Down Expand Up @@ -1339,6 +1372,8 @@ function TClientNode.CreateQRCodeData(): string;
if FisScavengeTTL <> 0 then ValueStr:= FScavengeTTL.Trim;
QRData:= QRData + 'scavengettl=' + ValueStr + ';';

QRData:= QRData + 'quiet=' + LowerCase(BoolToStr(Boolean(FisQuiet), True)) + ';';

ValueStr:= '';
if FisMode <> 0 then ValueStr:= FMode.Trim;
QRData:= QRData + 'mode=' + ValueStr + ';';
Expand Down
6 changes: 6 additions & 0 deletions Interface_op.pas
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ procedure Enable_DisableAllCheckbox(State: Boolean);
CheckBox_DSCP.Enabled:= State;
CheckBox_AutoExpire.Enabled:= State;
CheckBox_ScavengeTTL.Enabled:= State;
CheckBox_Quiet.Enabled:= State;

CheckBox_Mode.Enabled:= State;
CheckBox_NoDelay.Enabled:= State;
Expand Down Expand Up @@ -128,6 +129,7 @@ procedure Enable_DisableSelectPara(State: Boolean);
CheckBox_DSCP.Enabled:= State; CheckBox_DSCPClick(FMain);
CheckBox_AutoExpire.Enabled:= State; CheckBox_AutoExpireClick(FMain);
CheckBox_ScavengeTTL.Enabled:= State; CheckBox_ScavengeTTLClick(FMain);
CheckBox_Quiet.Enabled:= State; CheckBox_QuietClick(FMain);
end;
end;

Expand Down Expand Up @@ -170,6 +172,7 @@ procedure DisableAllInterfaceExceptJSON;
Label_DSCP.Enabled:= False; Edit_DSCP.Enabled:= False; Edit_DSCP.Color:= clBtnFace;
Label_AutoExpire.Enabled:= False; Edit_AutoExpire.Enabled:= False; Edit_AutoExpire.Color:= clBtnFace;
Label_ScavengeTTL.Enabled:= False; Edit_ScavengeTTL.Enabled:= False; Edit_ScavengeTTL.Color:= clBtnFace;
Label_Quiet.Enabled:= False;

Label_Mode.Enabled:= False; ComboBox_Mode.Enabled:= False;
Label_NoDelay.Enabled:= False;
Expand Down Expand Up @@ -268,6 +271,9 @@ procedure ShowClientInfoToInterface(ClientNode: TClientNode);
Edit_ScavengeTTL.Text:= ClientNode.ScavengeTTL;
CheckBox_ScavengeTTL.OnClick(FMain);

CheckBox_Quiet.Checked:= Boolean(ClientNode.isQuiet);
CheckBox_Quiet.OnClick(FMain);

//-------------------------------------------------------------------------------------
ComboBox_Mode.ItemIndex:= ComboBox_Mode.Items.IndexOf(ClientNode.Mode);

Expand Down
20 changes: 18 additions & 2 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ object FMain: TFMain
end
item
Alignment = taCenter
Text = 'KCPTun '#23458#25143#31471#31243#24207#35831#20351#29992' 20170218 '#25110#26356#39640#29256#26412
Text = 'KCPTun '#23458#25143#31471#31243#24207#35831#20351#29992' 20171021 '#25110#26356#39640#29256#26412
Width = 50
end>
OnMouseDown = StatusBar_StatusMouseDown
Expand Down Expand Up @@ -477,6 +477,13 @@ object FMain: TFMain
ParentShowHint = False
ShowHint = True
end
object Label_Quiet: TLabel
Left = 340
Top = 181
Width = 72
Height = 12
Caption = #21551#29992#38745#40664#27169#24335
end
object CheckBox_Key: TCheckBox
Left = 10
Top = 24
Expand Down Expand Up @@ -534,6 +541,7 @@ object FMain: TFMain
'tea'
'xtea'
'xor'
'sm4'
'none')
end
object CheckBox_Conn: TCheckBox
Expand Down Expand Up @@ -761,6 +769,14 @@ object FMain: TFMain
OnChange = Edit_ScavengeTTLChange
OnKeyPress = Edit_ScavengeTTLKeyPress
end
object CheckBox_Quiet: TCheckBox
Left = 315
Top = 180
Width = 17
Height = 17
TabOrder = 23
OnClick = CheckBox_QuietClick
end
end
object GroupBox_Mode: TGroupBox
Left = 480
Expand Down Expand Up @@ -1244,7 +1260,7 @@ object FMain: TFMain
Left = 209
Top = 174
Bitmap = {
494C010104001800500110001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C010104001800540110001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000002000000001002000000000000020
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Expand Down
14 changes: 14 additions & 0 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ TFMain = class(TForm)
CheckBox_ScavengeTTL: TCheckBox;
Label_ScavengeTTL: TLabel;
Edit_ScavengeTTL: TEdit;
CheckBox_Quiet: TCheckBox;
Label_Quiet: TLabel;
procedure Btn_AddNodeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Btn_FindClientEXEClick(Sender: TObject);
Expand Down Expand Up @@ -213,6 +215,7 @@ TFMain = class(TForm)
procedure StatusBar_StatusMouseLeave(Sender: TObject);
procedure StatusBar_StatusMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure CheckBox_QuietClick(Sender: TObject);
private
{ Private declarations }
function CreateQRCodeBitmap(QRData: string): TMemoryStream;
Expand Down Expand Up @@ -898,6 +901,17 @@ procedure TFMain.CheckBox_ParityShardClick(Sender: TObject);
LoadQRCodeImage(TClientNode(ListView_Node.Selected.Data));
end;

procedure TFMain.CheckBox_QuietClick(Sender: TObject);
begin
Label_Quiet.Enabled:= CheckBox_Quiet.Checked;
if ListView_Node.Selected = nil then
Exit;
TClientNode(ListView_Node.Selected.Data).isQuiet:= Integer(CheckBox_Quiet.Checked);

if PublicVar.CanModifyXML then
LoadQRCodeImage(TClientNode(ListView_Node.Selected.Data));
end;

procedure TFMain.CheckBox_RcvWndClick(Sender: TObject);
begin
Label_RcvWnd.Enabled:= CheckBox_RcvWnd.Checked;
Expand Down
12 changes: 10 additions & 2 deletions PublicFun.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ procedure CreateBlankParaXML(ParaXMLPathName: string);
end;
end;

//实现-c参数,Node中加入json节点;加入自动重连节点;加入ScavengeTTL节点
//实现-c参数,Node中加入json节点;加入自动重连节点;加入ScavengeTTL节点;加入Quiet节点
procedure RepairParaXML(ParaXMLPathName: string);
var
isModify: Boolean;
XMLDocument_BlankPara: TXMLDocument;
ParasNode, ProgramParaNode, ClientNode, Node, LocalPortNode, JsonNode, AutoConnNode, ScavengeTTLNode: IXMLNode;
ParasNode, ProgramParaNode, ClientNode, Node, LocalPortNode, JsonNode, AutoConnNode, ScavengeTTLNode, QuietNode: IXMLNode;
i: Integer;
begin
isModify:= False;
Expand Down Expand Up @@ -102,6 +102,14 @@ procedure RepairParaXML(ParaXMLPathName: string);
ScavengeTTLNode:= Node.AddChild('scavengettl');
ScavengeTTLNode.Attributes['enable']:= 0;
end;

QuietNode:= Node.ChildNodes.FindNode('quiet');
if QuietNode = nil then
begin
isModify:= True;
QuietNode:= Node.AddChild('quiet');
QuietNode.Attributes['enable']:= 0;
end;
end;
if isModify then
XMLDocument_BlankPara.SaveToFile(ParaXMLPathName);
Expand Down
Loading

0 comments on commit 187dfa3

Please sign in to comment.