Commit c97a4a8d authored by nanahira's avatar nanahira

rewind back to www

parent a44eaa69
using UnityEngine; using UnityEngine;
using UnityEngine.Networking;
using System; using System;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -56,28 +55,21 @@ public class MyCardHelper : MonoBehaviour { ...@@ -56,28 +55,21 @@ public class MyCardHelper : MonoBehaviour {
try { try {
LoginRequest data = new LoginRequest(name, password); LoginRequest data = new LoginRequest(name, password);
string data_str = data.Stringify(); string data_str = data.Stringify();
UnityWebRequest www = UnityWebRequest.Post("https://api.moecube.com/accounts/signin", data_str); Dictionary<String, String> header_list = new Dictionary<String, String>();
www.SetRequestHeader("Content-Type", "application/json"); header_list.Add("Content-Type", "application/json");
www.SendWebRequest(); byte[] data_bytes = Encoding.UTF8.GetBytes(data_str);
WWW www = new WWW("https://api.moecube.com/accounts/signin", data_bytes, header_list);
while (!www.isDone) { while (!www.isDone) {
if (www.isNetworkError || www.isHttpError) if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{ {
fail_reason = www.error; fail_reason = www.error;
return false; return false;
} }
} }
if (www.responseCode >= 400) string result = www.text;
{ LoginObject result_object = JsonUtility.FromJson<LoginObject>(result);
fail_reason = "Login failed"; username = result_object.user.username;
return false; userid = result_object.user.id;
}
else
{
string result = www.downloadHandler.text;
LoginObject result_object = JsonUtility.FromJson<LoginObject>(result);
username = result_object.user.username;
userid = result_object.user.id;
}
} catch (Exception e) { } catch (Exception e) {
fail_reason = e.Message; fail_reason = e.Message;
return false; return false;
...@@ -93,27 +85,19 @@ public class MyCardHelper : MonoBehaviour { ...@@ -93,27 +85,19 @@ public class MyCardHelper : MonoBehaviour {
} }
try { try {
string auth_str = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + userid)); string auth_str = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + userid));
UnityWebRequest www = UnityWebRequest.Post("https://api.mycard.moe/ygopro/match?locale=zh-CN&arena=" + match_type, new WWWForm()); Dictionary<String, String> header_list = new Dictionary<String, String>();
www.SetRequestHeader("Authorization", auth_str); header_list.Add("Authorization", auth_str);
www.SendWebRequest(); WWW www = new WWW("https://api.mycard.moe/ygopro/match?locale=zh-CN&arena=" + match_type, new WWWForm(), header_list);
while (!www.isDone) { while (!www.isDone) {
if (www.isNetworkError || www.isHttpError) if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{ {
fail_reason = www.error; fail_reason = www.error;
return null; return null;
} }
} }
if (www.responseCode >= 400) string result = www.text;
{ MatchObject result_object = JsonUtility.FromJson<MatchObject>(result);
fail_reason = "Match failed"; ret = result_object.password;
return null;
}
else
{
string result = www.downloadHandler.text;
MatchObject result_object = JsonUtility.FromJson<MatchObject>(result);
ret = result_object.password;
}
} catch (Exception e) { } catch (Exception e) {
fail_reason = e.Message; fail_reason = e.Message;
return null; return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment