Fix auto check local server error

This commit is contained in:
2023-08-23 22:39:40 +08:00
parent 90deaa84b4
commit b69b2941b6
4 changed files with 16 additions and 7 deletions

View File

@ -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 />

View File

@ -26,6 +26,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using GrasscutterTools.DispatchServer;
using GrasscutterTools.DispatchServer.Model;
using GrasscutterTools.Game;
using GrasscutterTools.GOOD;
using GrasscutterTools.OpenCommand;
@ -125,7 +126,7 @@ namespace GrasscutterTools.Pages
// 自动尝试查询本地服务端地址,降低使用门槛
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",
@ -133,13 +134,13 @@ namespace GrasscutterTools.Pages
"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)
@ -169,6 +170,14 @@ namespace GrasscutterTools.Pages
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();
}

View File

@ -12,7 +12,7 @@ namespace GrasscutterTools.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -97,7 +97,7 @@ namespace GrasscutterTools.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://127.0.0.1")]
[global::System.Configuration.DefaultSettingValueAttribute("http://127.0.0.1:443")]
public string Host {
get {
return ((string)(this["Host"]));

View File

@ -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)" />