mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-06-08 23:19:14 +08:00
Update auto find local server address
This commit is contained in:
parent
cfb94e70b7
commit
f393b372ec
@ -1387,6 +1387,36 @@ namespace GrasscutterTools.Forms
|
|||||||
BeginInvoke(new Action(() => ShowTip(Resources.TokenRestoredFromCache, BtnInvokeOpenCommand)));
|
BeginInvoke(new Action(() => ShowTip(Resources.TokenRestoredFromCache, BtnInvokeOpenCommand)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 自动尝试查询本地服务端地址,降低门槛
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(5000);
|
||||||
|
var localhosts = new string[] {
|
||||||
|
"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)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await UpdateServerStatus(host);
|
||||||
|
// 自动填写本地服务端地址
|
||||||
|
TxtHost.Text = host;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveOpenCommand()
|
private void SaveOpenCommand()
|
||||||
@ -1396,6 +1426,16 @@ namespace GrasscutterTools.Forms
|
|||||||
Settings.Default.TokenCache = OC?.Token;
|
Settings.Default.TokenCache = OC?.Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task UpdateServerStatus(string host)
|
||||||
|
{
|
||||||
|
var status = await DispatchServerAPI.QueryServerStatus(host);
|
||||||
|
LblServerVersion.Text = status.Version;
|
||||||
|
if (status.MaxPlayer >= 0)
|
||||||
|
LblPlayerCount.Text = $"{status.PlayerCount}/{status.MaxPlayer}";
|
||||||
|
else
|
||||||
|
LblPlayerCount.Text = status.PlayerCount.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
private async void BtnQueryServerStatus_Click(object sender, EventArgs e)
|
private async void BtnQueryServerStatus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var btn = sender as Button;
|
var btn = sender as Button;
|
||||||
@ -1405,16 +1445,12 @@ namespace GrasscutterTools.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var status = await DispatchServerAPI.QueryServerStatus(TxtHost.Text);
|
await UpdateServerStatus(TxtHost.Text);
|
||||||
LblServerVersion.Text = status.Version;
|
|
||||||
if (status.MaxPlayer >= 0)
|
|
||||||
LblPlayerCount.Text = $"{status.PlayerCount}/{status.MaxPlayer}";
|
|
||||||
else
|
|
||||||
LblPlayerCount.Text = status.PlayerCount.ToString();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(Resources.QueryServerStatusFailed + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(Resources.QueryServerStatusFailed + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OC = new OpenCommandAPI(TxtHost.Text);
|
OC = new OpenCommandAPI(TxtHost.Text);
|
||||||
|
Loading…
Reference in New Issue
Block a user