1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
Public Function Login(ByVal Username As String, ByVal Password As String, ByVal proxy As String)
Try
Dim proxyer As New WebProxy(proxy)
Dim WR As WebRequest = WebRequest.Create("https://authserver.mojang.com/authenticate")
WR.Method = "POST"
WR.Proxy = proxyer
WR.Timeout = 8000
Dim PostData As String = "{""agent"": {""name"": ""Minecraft"",""version"": 1},""username"": """ & Username & """,""password"": """ & Password & """,""requestUser"":true}"
WR.ContentType = "application/json"
Dim ByteArray As Byte() = Encoding.UTF8.GetBytes(PostData)
WR.ContentLength = ByteArray.Length
Dim DataStream As Stream = WR.GetRequestStream
DataStream.Write(ByteArray, 0, ByteArray.Length)
DataStream.Close()
Dim JsonResponse As WebResponse = WR.GetResponse
DataStream = JsonResponse.GetResponseStream
Dim SR As New StreamReader(DataStream)
Dim Response As String = SR.ReadToEnd
Dim DecodedJson As New JObject
DecodedJson = JsonConvert.DeserializeObject(Response)
Player = DecodedJson.Item("selectedProfile").Item("name").ToString
Uuid = DecodedJson.Item("selectedProfile").Item("id").ToString
AccessToken = DecodedJson.Item("accessToken").ToString
ClientToken = DecodedJson.Item("clientToken").ToString
Catch ex As WebException
Dim SR As New StreamReader(ex.Response.GetResponseStream)
Dim DecodedJson As New JObject
DecodedJson = JsonConvert.DeserializeObject(SR.ReadToEnd)
LoggedIn = False
Return False
Exit Function
End Try
LoggedIn = True
Return True
End Function |
Partager