Skip to content

Commit

Permalink
移除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wuliaodexiaoluo committed Dec 21, 2024
1 parent e097916 commit 5557b23
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 51 deletions.
37 changes: 1 addition & 36 deletions Plain Craft Launcher 2/Modules/Base/ModNet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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

''' <summary>
''' 测试 Ping。失败则返回 -1。
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 7 additions & 13 deletions Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb
Original file line number Diff line number Diff line change
Expand Up @@ -705,22 +705,19 @@ 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
RefreshData.Add(New JProperty("grant_type", "refresh_token"))
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)
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Modules/ModSecret.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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 线程优先级
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5557b23

Please sign in to comment.