From 662bd5694f973d052ef854bbfee73e80b5e331cc Mon Sep 17 00:00:00 2001 From: ksh Date: Wed, 11 Aug 2021 13:45:06 +0900 Subject: [PATCH] Ping tab: add current connection (#29) --- Data/DcLang-Japanese.txt | 1 + Data/DcLang-Korean(Actoz).txt | 1 + Data/DcLang-Korean(Test).txt | 1 + Resources/mesg.txt | 1 + Tab/PingForm.Designer.cs | 30 +++++++++++++++++++++++++- Tab/PingForm.cs | 40 ++++++++++++++++++++++++++++++++++- 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Data/DcLang-Japanese.txt b/Data/DcLang-Japanese.txt index be24bfb..4a3f3da 100644 --- a/Data/DcLang-Japanese.txt +++ b/Data/DcLang-Japanese.txt @@ -98,6 +98,7 @@ LANG=日本語 340=テスト&& お知らせ保存 341=TTS使用 342=正しいDiscordのウェブフックURLを入力してください +343=現在アドレス 10001="{0}" 発生! 10002=待機: {0} diff --git a/Data/DcLang-Korean(Actoz).txt b/Data/DcLang-Korean(Actoz).txt index aceab75..1e40384 100644 --- a/Data/DcLang-Korean(Actoz).txt +++ b/Data/DcLang-Korean(Actoz).txt @@ -98,6 +98,7 @@ LANG=한국어(액토즈) 340=테스트 && 알림설정 저장 341=말하기 사용 342=올바른 디스코드 웹훅 주소를 입력해주세요. +343=연결된 IP주소 10001="{0}" 발생했어요! 10002=찾습니다: {0} diff --git a/Data/DcLang-Korean(Test).txt b/Data/DcLang-Korean(Test).txt index af54fc9..9846286 100644 --- a/Data/DcLang-Korean(Test).txt +++ b/Data/DcLang-Korean(Test).txt @@ -98,6 +98,7 @@ LANG=한국어 340=테스트 && 알림설정 저장 341=TTS 사용 342=올바른 디스코드 Webhook을 입력해주세요. +343=현재 연결 IP 10001="{0}" 떠스요! 10002=찾아요: {0} diff --git a/Resources/mesg.txt b/Resources/mesg.txt index 4ec1555..acd29ea 100644 --- a/Resources/mesg.txt +++ b/Resources/mesg.txt @@ -99,6 +99,7 @@ LANG=English 340=Test && Save Notifies 341=Use TTS 342=Invalid discord webhook URL +343=Address 10001="{0}" spawned! 10002=Entry: {0} diff --git a/Tab/PingForm.Designer.cs b/Tab/PingForm.Designer.cs index 54c43b7..c6dc6f3 100644 --- a/Tab/PingForm.Designer.cs +++ b/Tab/PingForm.Designer.cs @@ -46,6 +46,8 @@ namespace DutyContent.Tab this.lblPingColors = new System.Windows.Forms.Label(); this.chkUsePing = new System.Windows.Forms.CheckBox(); this.panelDock = new System.Windows.Forms.Panel(); + this.lblPingAddress = new System.Windows.Forms.Label(); + this.lstPingAddress = new System.Windows.Forms.ListBox(); this.panel6.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbxPingGraph)).BeginInit(); this.tlpnPingColors.SuspendLayout(); @@ -58,6 +60,8 @@ namespace DutyContent.Tab | System.Windows.Forms.AnchorStyles.Right))); this.panel6.AutoScroll = true; this.panel6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel6.Controls.Add(this.lstPingAddress); + this.panel6.Controls.Add(this.lblPingAddress); this.panel6.Controls.Add(this.cboPingDefAddr); this.panel6.Controls.Add(this.lblPingDefAddr); this.panel6.Controls.Add(this.pbxPingGraph); @@ -67,7 +71,7 @@ namespace DutyContent.Tab this.panel6.Controls.Add(this.chkUsePing); this.panel6.Location = new System.Drawing.Point(12, 12); this.panel6.Name = "panel6"; - this.panel6.Size = new System.Drawing.Size(776, 304); + this.panel6.Size = new System.Drawing.Size(776, 399); this.panel6.TabIndex = 2; // // cboPingDefAddr @@ -256,6 +260,28 @@ namespace DutyContent.Tab this.panelDock.Size = new System.Drawing.Size(800, 450); this.panelDock.TabIndex = 3; // + // lblPingAddress + // + this.lblPingAddress.AutoSize = true; + this.lblPingAddress.Location = new System.Drawing.Point(23, 315); + this.lblPingAddress.Name = "lblPingAddress"; + this.lblPingAddress.Size = new System.Drawing.Size(25, 13); + this.lblPingAddress.TabIndex = 16; + this.lblPingAddress.Text = "343"; + // + // lstPingAddress + // + this.lstPingAddress.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lstPingAddress.FormattingEnabled = true; + this.lstPingAddress.Location = new System.Drawing.Point(129, 309); + this.lstPingAddress.Name = "lstPingAddress"; + this.lstPingAddress.ScrollAlwaysVisible = true; + this.lstPingAddress.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; + this.lstPingAddress.Size = new System.Drawing.Size(642, 82); + this.lstPingAddress.TabIndex = 17; + // // PingForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -294,5 +320,7 @@ namespace DutyContent.Tab private System.Windows.Forms.Label lblPingColors; private System.Windows.Forms.CheckBox chkUsePing; private System.Windows.Forms.Panel panelDock; + private System.Windows.Forms.Label lblPingAddress; + private System.Windows.Forms.ListBox lstPingAddress; } } \ No newline at end of file diff --git a/Tab/PingForm.cs b/Tab/PingForm.cs index 33c732a..6792b93 100644 --- a/Tab/PingForm.cs +++ b/Tab/PingForm.cs @@ -90,7 +90,7 @@ namespace DutyContent.Tab public void RefreshLocale() { - + } public void UpdateUiLocale() @@ -103,6 +103,7 @@ namespace DutyContent.Tab lblPingStat4.Text = MesgLog.Text(333); chkPingGraph.Text = MesgLog.Text(334); lblPingDefAddr.Text = MesgLog.Text(335); + lblPingAddress.Text = MesgLog.Text(343); } private void SaveConfig(int interval = 5000) @@ -220,10 +221,14 @@ namespace DutyContent.Tab long rtt = 0; double loss = 0; + List addrs = new List(); + if (conns.Length > 0) { foreach (var row in conns) { + addrs.Add(row.RemoteAddress.ToString()); + var (r, l) = CalcPing(row.RemoteAddress); if (rtt < r) @@ -241,6 +246,8 @@ namespace DutyContent.Tab return; } + addrs.Add(DcConfig.Duty.PingDefAddr); + var defip = ThirdParty.Converter.ToIPAddressFromIPV4(DcConfig.Duty.PingDefAddr); if (defip == IPAddress.None || defip == IPAddress.IPv6None) @@ -289,6 +296,37 @@ namespace DutyContent.Tab _grpr.DrawValues(_kepts); WorkerAct.Invoker(() => _grpr.Leave()); } + + // + if (addrs.Count == 0) + { + if (lstPingAddress.Items.Count != 0) + lstPingAddress.Items.Clear(); + } + else + { + bool havetoupdate = false; + + if (lstPingAddress.Items.Count == 0) + havetoupdate = true; + else + { + var i = lstPingAddress.Items[0] as string; + havetoupdate = !addrs.Contains(i); + } + + if (havetoupdate) + { + WorkerAct.Invoker(() => + { + lstPingAddress.BeginUpdate(); + lstPingAddress.Items.Clear(); + foreach (var i in addrs) + lstPingAddress.Items.Add(i); + lstPingAddress.EndUpdate(); + }); + } + } } // http://forum.codecall.net/topic/37643-c-packet-lossping-program/