diff --git a/Plain Craft Launcher 2/Modules/Base/ModNet.vb b/Plain Craft Launcher 2/Modules/Base/ModNet.vb index c908343d..020f79fd 100644 --- a/Plain Craft Launcher 2/Modules/Base/ModNet.vb +++ b/Plain Craft Launcher 2/Modules/Base/ModNet.vb @@ -3,28 +3,6 @@ Public Module ModNet Public Const NetDownloadEnd As String = ".PCLDownloading" - Public Class NetResponse - Private _StatusCode As Object - Private _ResponseHeader As String - Private _Response As Object - - Public Sub New(StatusCode As Integer, ResponseHeader As String, Response As Object) - _StatusCode = StatusCode - _ResponseHeader = ResponseHeader - _Response = Response - End Sub - - Public Function GetResponseData() As String - Return _Response - End Function - - Public Function GetResponseHeader() As String - Return _ResponseHeader - End Function - Public Function GetStatusCode() As Integer - Return _StatusCode - End Function - End Class ''' ''' 测试 Ping。失败则返回 -1。 @@ -435,12 +413,7 @@ RequestFinished: Using Reader As New StreamReader(DataStream) Res = Reader.ReadToEnd() End Using - If ReturnAllResponse Then - Dim StatusCode As Integer = CType(Resp, HttpWebResponse).StatusCode - Return New NetResponse(StatusCode, Resp.Headers.ToString, Res) - Else - Return Res - End If + Return Res Catch ex As ThreadInterruptedException Throw Catch ex As WebException @@ -461,14 +434,6 @@ RequestFinished: If Res = "" Then ex = New WebException($"网络请求失败({ex.Status},{ex.Message},{Url})", ex) Throw ex - ElseIf ReturnAllResponse Then - Try - Dim HeaderData = ex.Response.Headers.ToString - Dim StatusCode = ex.Status - Return New NetResponse(StatusCode, HeaderData, Res) - Catch exc As Exception - Return Res - End Try Else ex = New ResponsedWebException($"服务器返回错误({ex.Status},{ex.Message},{Url}){vbCrLf}{Res}", Res, ex) End If diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb index ce920978..9753ddb4 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb @@ -705,7 +705,6 @@ LoginFinish: Dim AccessToken As String Dim RefreshToken As String Dim IDToken As String - Dim LittleSkinToken As NetResponse Dim LoginJson As JObject 'AccessToken 和 RefreshToken 都要有,不然没法刷新 If Not LittleSkinAccess = "" AndAlso Not LittleSkinRefresh = "" Then @@ -713,14 +712,12 @@ LoginFinish: RefreshData.Add(New JProperty("refresh_token", LittleSkinRefresh)) RefreshData.Add(New JProperty("access_token", LittleSkinAccess)) RefreshData.Add(New JProperty("client_id", LittleSkinClientId)) - LittleSkinToken = NetRequestOnce( + LoginJson = GetJson(NetRequestOnce( Url:="https://open.littleskin.cn/oauth/token", Method:="POST", Data:=RefreshData, Headers:=New Dictionary(Of String, String) From {{"Accept-Language", "zh_CN"}}, - ContentType:="application/json; charset=utf-8", - ReturnAllResponse:=True) - LoginJson = GetJson(LittleSkinToken.GetResponseData()) + ContentType:="application/json; charset=utf-8")) AccessToken = LoginJson("access_token").ToString(0) RefreshToken = LoginJson("refresh_token").ToString(0) IDToken = LoginJson("id_token").ToString(0) @@ -783,7 +780,6 @@ LoginFinish: Dim LoginJson Dim AccessToken As String Dim RefreshToken As String - Dim LittleSkinJson As NetResponse 'LittleSkin OAuth 登录检查 If Data.Input.BaseUrl.ToLower.Contains("littleskin.cn") And Not LittleSkinClientId = "" Then @@ -803,14 +799,12 @@ LoginFinish: ' LittleSkin OAuth 登录步骤 1: 获取授权代码 If LittleSkinOAuth Then McLaunchLog("开始 LittleSkin OAuth 登录步骤 1/3(原始登录)") - LittleSkinJson = NetRequestOnce( + LoginJson = GetJson(NetRequestOnce( Url:="https://open.littleskin.cn/oauth/device_code", Method:="POST", Data:=RequestData.ToString(0), Headers:=New Dictionary(Of String, String) From {{"Accept-Language", "zh_CN"}}, - ContentType:="application/json; charset=utf-8", - ReturnAllResponse:=True) - LoginJson = GetJson(LittleSkinJson.GetResponseData()) + ContentType:="application/json; charset=utf-8")) Else LoginJson = GetJson(NetRequestRetry( Url:=Data.Input.BaseUrl & "/authenticate", @@ -853,15 +847,15 @@ LoginFinish: Dim RequestInfo = New JObject() RequestInfo.Add(New JProperty("uuid", UUID)) '需要 Yggdrasil.MinecraftToken.Create - Dim Token As NetResponse = NetRequestOnce(Url:=Data.Input.BaseUrl & "/oauth", + Result = GetJson(NetRequestOnce(Url:=Data.Input.BaseUrl & "/oauth", Method:="POST", Data:=RequestInfo.ToString(0), Headers:=New Dictionary(Of String, String) From {{"Authorization", "Bearer " & AccessToken}}, ContentType:="application/json; charset=utf-8", ReturnAllResponse:=True - ) + )) + - Result = GetJson(Token.GetResponseData()) Dim ClientToken = Result("clientToken").ToString Dim MCAccessToken = Result("accessToken").ToString diff --git a/Plain Craft Launcher 2/Modules/ModSecret.vb b/Plain Craft Launcher 2/Modules/ModSecret.vb index 119a76fb..a4e633fe 100644 --- a/Plain Craft Launcher 2/Modules/ModSecret.vb +++ b/Plain Craft Launcher 2/Modules/ModSecret.vb @@ -15,7 +15,7 @@ Friend Module ModSecret 'CurseForge API Key Public Const CurseForgeAPIKey As String = "" ' LittleSkin OAuth ClientId - Public Const LittleSkinClientId = "" + Public Const LittleSkinClientId = "868" Friend Sub SecretOnApplicationStart() '提升 UI 线程优先级 diff --git a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb index c45e0f06..313db37c 100644 --- a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb @@ -137,7 +137,7 @@ Finished(ResultJson) Return Catch ex As Exception - If ex.Message.Contains("authorization_declined") Then + If ex.Message.Contains("authorization_declined") Or ex.Message.Contains("access_denied") Then Finished(New Exception("$你拒绝了 PCL 申请的权限……")) Return ElseIf ex.Message.Contains("expired_token") Then