Commit 2f0b067b authored by nanahira's avatar nanahira

improve MyCard match

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