Skip to content

Commit

Permalink
Fix auto check local server error
Browse files Browse the repository at this point in the history
  • Loading branch information
jie65535 committed Aug 23, 2023
1 parent 90deaa8 commit b69b294
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<value>10001</value>
</setting>
<setting name="Host" serializeAs="String">
<value>https://127.0.0.1</value>
<value>http://127.0.0.1:443</value>
</setting>
<setting name="CheckedLastVersion" serializeAs="String">
<value />
Expand Down
15 changes: 12 additions & 3 deletions Source/GrasscutterTools/Pages/PageOpenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Windows.Forms;

using GrasscutterTools.DispatchServer;
using GrasscutterTools.DispatchServer.Model;
using GrasscutterTools.Game;
using GrasscutterTools.GOOD;
using GrasscutterTools.OpenCommand;
Expand Down Expand Up @@ -125,21 +126,21 @@ public override void OnEnter()
// 自动尝试查询本地服务端地址,降低使用门槛
Task.Run(async () =>
{
var localhosts = new string[] {
var localhostList = new[] {
"http://127.0.0.1:443",
"https://127.0.0.1",
"http://127.0.0.1",
"https://127.0.0.1:80",
"http://127.0.0.1:8080",
"https://127.0.0.1:8080",
};
foreach (var host in localhosts)
foreach (var host in localhostList)
{
try
{
await UpdateServerStatus(host);
// 自动填写本地服务端地址
TxtHost.Text = host;
BeginInvoke(new Action(() => TxtHost.Text = host));
break;
}
catch (Exception)
Expand Down Expand Up @@ -169,6 +170,14 @@ public override void OnClosed()
private async Task UpdateServerStatus(string host)
{
var status = await DispatchServerAPI.QueryServerStatus(host);
if (InvokeRequired)
BeginInvoke(new Action<ServerStatus>(ShowServerStatus), status);
else
ShowServerStatus(status);
}

private void ShowServerStatus(ServerStatus status)
{
LblServerVersion.Text = status.Version;
LblPlayerCount.Text = status.MaxPlayer > 0 ? $"{status.PlayerCount}/{status.MaxPlayer}" : status.PlayerCount.ToString();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/GrasscutterTools/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Value Profile="(Default)">10001</Value>
</Setting>
<Setting Name="Host" Type="System.String" Scope="User">
<Value Profile="(Default)">https://127.0.0.1</Value>
<Value Profile="(Default)">http://127.0.0.1:443</Value>
</Setting>
<Setting Name="CheckedLastVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
Expand Down

0 comments on commit b69b294

Please sign in to comment.