Commit 2f0b067b authored by nanahira's avatar nanahira

improve MyCard match

parent 3d535df2
...@@ -8,11 +8,11 @@ public class MyCard : WindowServantSP ...@@ -8,11 +8,11 @@ public class MyCard : WindowServantSP
{ {
public bool isMatching = false; public bool isMatching = false;
public bool isRequesting = false; public bool isRequesting = false;
const string mycard_ip = "tiramisu.mycard.moe"; const string mycardTiramisuAddress = "tiramisu.mycard.moe";
const string athletic_port = "8911"; const string mycardTiramisuAthleticPort = "8911";
const string entertain_port = "7911"; const string mycardTiramisuEntertainPort = "7911";
Thread requestThread = null; Thread requestThread = null;
MyCardHelper helper; MyCardHelper mycardHelper;
UIInput inputUsername; UIInput inputUsername;
UIInput inputPsw; UIInput inputPsw;
...@@ -26,7 +26,7 @@ public class MyCard : WindowServantSP ...@@ -26,7 +26,7 @@ public class MyCard : WindowServantSP
UIHelper.registEvent(gameObject, "community_", onClickCommunity); UIHelper.registEvent(gameObject, "community_", onClickCommunity);
inputUsername = UIHelper.getByName<UIInput>(gameObject, "name_"); inputUsername = UIHelper.getByName<UIInput>(gameObject, "name_");
inputPsw = UIHelper.getByName<UIInput>(gameObject, "psw_"); inputPsw = UIHelper.getByName<UIInput>(gameObject, "psw_");
helper = new MyCardHelper(); mycardHelper = new MyCardHelper();
loadUser(); loadUser();
SetActiveFalse(); SetActiveFalse();
} }
...@@ -74,27 +74,27 @@ public class MyCard : WindowServantSP ...@@ -74,27 +74,27 @@ public class MyCard : WindowServantSP
Application.OpenURL("https://ygobbs.com/"); Application.OpenURL("https://ygobbs.com/");
} }
void matchThread(string username, string password, string match_type) { void matchThread(string username, string password, string matchType) {
try { try {
Program.PrintToChat(InterString.Get("正在登录至MyCard。")); Program.PrintToChat(InterString.Get("正在登录至MyCard。"));
string fail_reason = ""; string failReason = "";
bool res = helper.login(username, password, out fail_reason); bool res = mycardHelper.login(username, password, out failReason);
if (!res) { if (!res) {
Program.PrintToChat(InterString.Get("MyCard登录失败。原因: ") + fail_reason); Program.PrintToChat(InterString.Get("MyCard登录失败。原因: ") + failReason);
isRequesting = false; isRequesting = false;
return; return;
} }
Program.PrintToChat(InterString.Get("正在请求匹配。匹配类型: ") + match_type); Program.PrintToChat(InterString.Get("正在请求匹配。匹配类型: ") + matchType);
string pswString = helper.requestMatch(match_type, out fail_reason); MatchResultObject matchResultObject = mycardHelper.requestMatch(matchType, out failReason);
if (pswString == null) { if (matchResultObject == null) {
Program.PrintToChat(InterString.Get("匹配请求失败。原因: ") + fail_reason); Program.PrintToChat(InterString.Get("匹配请求失败。原因: ") + failReason);
isRequesting = false; isRequesting = false;
return; return;
} }
Program.PrintToChat(InterString.Get("匹配成功。正在进入房间。")); Program.PrintToChat(InterString.Get("匹配成功。正在进入房间。"));
Program.I().mycard.isMatching = true; Program.I().mycard.isMatching = true;
(new Thread(() => { TcpHelper.join(mycard_ip, username, match_type == "athletic" ? athletic_port : entertain_port, pswString, "0x" + String.Format("{0:X}", Config.ClientVersion)); })).Start(); (new Thread(() => { TcpHelper.join(matchResultObject.address, mycardHelper.username, matchResultObject.port, matchResultObject.password, "0x" + String.Format("{0:X}", Config.ClientVersion)); })).Start();
isRequesting = false; isRequesting = false;
} catch (Exception e) { } catch (Exception e) {
if (e.GetType() != typeof(ThreadAbortException)) { if (e.GetType() != typeof(ThreadAbortException)) {
...@@ -106,7 +106,7 @@ public class MyCard : WindowServantSP ...@@ -106,7 +106,7 @@ public class MyCard : WindowServantSP
} }
} }
void startMatch(string match_type) { void startMatch(string matchType) {
string username = inputUsername.value; string username = inputUsername.value;
string password = inputPsw.value; string password = inputPsw.value;
if (username == "" || password == "") if (username == "" || password == "")
...@@ -123,7 +123,7 @@ public class MyCard : WindowServantSP ...@@ -123,7 +123,7 @@ public class MyCard : WindowServantSP
Program.PrintToChat(InterString.Get("已开始匹配。")); Program.PrintToChat(InterString.Get("已开始匹配。"));
requestThread = new Thread(() => requestThread = new Thread(() =>
{ {
matchThread(username, password, match_type); matchThread(username, password, matchType);
}); });
requestThread.Start(); requestThread.Start();
} }
......
...@@ -49,16 +49,16 @@ public class LoginRequest { ...@@ -49,16 +49,16 @@ public class LoginRequest {
} }
[Serializable] [Serializable]
public class MatchObject { public class MatchResultObject {
public string address; public string address;
public int port; public int port;
public string password; public string password;
} }
public class MyCardHelper { public class MyCardHelper {
string username = null; public string username = null;
int userid = -1; int userid = -1;
public bool login(string name, string password, out string fail_reason) { public bool login(string name, string password, out string failReason) {
try { try {
LoginRequest data = new LoginRequest(); LoginRequest data = new LoginRequest();
data.account = name; data.account = name;
...@@ -71,7 +71,7 @@ public class MyCardHelper { ...@@ -71,7 +71,7 @@ public class MyCardHelper {
while (!www.isDone) { while (!www.isDone) {
if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error)) if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{ {
fail_reason = www.error; failReason = www.error;
return false; return false;
} }
} }
...@@ -80,17 +80,17 @@ public class MyCardHelper { ...@@ -80,17 +80,17 @@ public class MyCardHelper {
username = result_object.user.username; username = result_object.user.username;
userid = result_object.user.id; userid = result_object.user.id;
} catch (Exception e) { } catch (Exception e) {
fail_reason = e.Message; failReason = e.Message;
return false; return false;
} }
fail_reason = null; failReason = null;
return true; return true;
} }
public string requestMatch(string match_type, out string fail_reason) { public MatchResultObject requestMatch(string matchType, out string failReason) {
string ret; MatchResultObject matchResultObject;
if (username == null || userid < 0) { if (username == null || userid < 0) {
fail_reason = "Not logged in"; failReason = "Not logged in";
return null; return null;
} }
try { try {
...@@ -99,22 +99,22 @@ public class MyCardHelper { ...@@ -99,22 +99,22 @@ public class MyCardHelper {
header_list.Add("Authorization", auth_str); header_list.Add("Authorization", auth_str);
header_list.Add("Content-Type", "application/x-www-form-urlencoded"); header_list.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] meta = new byte[1]; byte[] meta = new byte[1];
WWW www = new WWW("https://api.mycard.moe/ygopro/match?locale=zh-CN&arena=" + match_type, meta, header_list); WWW www = new WWW("https://api.moecube.com/ygopro/match?locale=zh-CN&arena=" + matchType, meta, header_list);
while (!www.isDone) { while (!www.isDone) {
if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error)) if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{ {
fail_reason = www.error; failReason = www.error;
return null; return null;
} }
} }
string result = www.text; string result = www.text;
MatchObject result_object = JsonUtility.FromJson<MatchObject>(result); matchResultObject = JsonUtility.FromJson<MatchResultObject>(result);
ret = result_object.password; ret = result_object.password;
} catch (Exception e) { } catch (Exception e) {
fail_reason = e.Message; failReason = e.Message;
return null; return null;
} }
fail_reason = null; failReason = null;
return ret; return ret;
} }
......
...@@ -1116,7 +1116,7 @@ public class Program : MonoBehaviour ...@@ -1116,7 +1116,7 @@ public class Program : MonoBehaviour
string FPS = m_FPS.ToString(); string FPS = m_FPS.ToString();
try { FPS = FPS.Substring(0, 5); } catch{} try { FPS = FPS.Substring(0, 5); } catch{}
GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.035.2-Nekoyuki] " + "FPS: " + FPS); GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.035.2-Nekoyukiw] " + "FPS: " + FPS);
} }
void Update() void Update()
......
...@@ -1417,7 +1417,7 @@ MonoBehaviour: ...@@ -1417,7 +1417,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1 keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3} mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3}
mFont: {fileID: 0} mFont: {fileID: 0}
mText: KoishiPro2 iOS 1.035.2-Nekoyuki mText: KoishiPro2 iOS 1.035.2-Nekoyukiw
mFontSize: 18 mFontSize: 18
mFontStyle: 0 mFontStyle: 0
mAlignment: 1 mAlignment: 1
......
...@@ -123,7 +123,7 @@ PlayerSettings: ...@@ -123,7 +123,7 @@ PlayerSettings:
16:10: 1 16:10: 1
16:9: 1 16:9: 1
Others: 1 Others: 1
bundleVersion: 1.035.2-Nekoyuki bundleVersion: 1.035.2-Nekoyukiw
preloadedAssets: [] preloadedAssets: []
metroInputSource: 0 metroInputSource: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1
......
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