Skip to content

Commit 230ff12

Browse files
committed
feat: 可以一键根据 Yggdrasil API 返回的信息来填写注册地址、服务器名称
1 parent 73bdc53 commit 230ff12

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSetup.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@
189189
</Grid.ColumnDefinitions>
190190
<local:MyButton x:Name="BtnServerNideWeb" Grid.Column="0" MinWidth="140" Text="服主后台" Padding="13,0" Margin="0,0,20,0" HorizontalAlignment="Left" ColorType="Highlight" />
191191
</Grid>
192-
<local:MyButton x:Name="BtnServerAuthLittle" Height="35" MinWidth="150" Margin="0,12,0,0" Text="设置为 LittleSkin" HorizontalAlignment="Left" ColorType="Highlight" />
192+
<StackPanel x:Name="PanServerAuth" Orientation="Horizontal">
193+
<local:MyButton x:Name="BtnServerAuthDetect" Height="35" MinWidth="150" Margin="0,12,20,0" Text="设置为服务器默认" HorizontalAlignment="Left" ColorType="Highlight" ToolTip="请求验证服务器,以此获取并自动填写信息。"/>
194+
<local:MyButton x:Name="BtnServerAuthLittle" Height="35" MinWidth="150" Margin="0,12,0,0" Text="设置为 LittleSkin" HorizontalAlignment="Left" ColorType="Highlight" />
195+
</StackPanel>
193196
</StackPanel>
194197
</local:MyCard>
195198
<local:MyCard x:Name="CardAdvance" Margin="0,0,0,15" Title="高级选项" IsSwapped="True" CanSwap="True">

Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSetup.xaml.vb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ PreFin:
391391
TextServerAuthRegister.Visibility = If(Type = 4, Visibility.Visible, Visibility.Collapsed)
392392
LabServerAuthServer.Visibility = If(Type = 4, Visibility.Visible, Visibility.Collapsed)
393393
TextServerAuthServer.Visibility = If(Type = 4, Visibility.Visible, Visibility.Collapsed)
394-
BtnServerAuthLittle.Visibility = If(Type = 4, Visibility.Visible, Visibility.Collapsed)
394+
PanServerAuth.Visibility = If(Type = 4, Visibility.Visible, Visibility.Collapsed)
395395
CardServer.TriggerForceResize()
396396
End Sub
397397

@@ -400,6 +400,37 @@ PreFin:
400400
OpenWebsite("https://login.mc-user.com:233/server/intro")
401401
End Sub
402402

403+
'自动填写信息
404+
Private Sub BtnServerAuthDetect_Click(sender As Object, e As EventArgs) Handles BtnServerAuthDetect.Click
405+
If MyMsgBox("即将把第三方登录设置覆盖为认证服务器提供的信息。" & vbCrLf & "请务必确保认证服务器地址正确。" & vbCrLf & vbCrLf & "是否确实要覆盖当前设置?", "设置覆盖确认", "继续", "取消") = 2 Then Return
406+
RunInNewThread(Function()
407+
Try
408+
Dim AuthServer As String = Dispatcher.Invoke(Function()
409+
TextServerAuthName.IsEnabled = False
410+
TextServerAuthRegister.IsEnabled = False
411+
Return TextServerAuthServer.Text
412+
End Function)
413+
Dim Result = NetRequestByClientRetry(
414+
AuthServer & "?lang=zh_CN", HttpMethod.Get,
415+
ContentType:="application/json",
416+
RequireJson:=True)
417+
'获取结果
418+
Dim ResultJson As JObject = GetJson(Result)
419+
RunInUi(Function()
420+
TextServerAuthName.Text = ResultJson("meta")("serverName").ToString & " 登录"
421+
TextServerAuthRegister.Text = ResultJson("meta")("links")("register").ToString
422+
End Function)
423+
Hint("信息获取成功!", HintType.Green)
424+
Catch ex As Exception
425+
Hint("信息获取失败,还是手动输入吧......", HintType.Red)
426+
Finally
427+
RunInUi(Function()
428+
TextServerAuthName.IsEnabled = True
429+
TextServerAuthRegister.IsEnabled = True
430+
End Function)
431+
End Try
432+
End Function)
433+
End Sub
403434
'LittleSkin
404435
Private Sub BtnServerAuthLittle_Click(sender As Object, e As EventArgs) Handles BtnServerAuthLittle.Click
405436
If TextServerAuthServer.Text <> "" AndAlso TextServerAuthServer.Text <> "https://littleskin.cn/api/yggdrasil" AndAlso

0 commit comments

Comments
 (0)