Commit acf17130 authored by nanahira's avatar nanahira

add MyCard

parent 2dd80e7c
......@@ -17,6 +17,7 @@ public class Menu : WindowServantSP
UIHelper.registEvent(gameObject, "setting_", onClickSetting);
UIHelper.registEvent(gameObject, "deck_", onClickSelectDeck);
UIHelper.registEvent(gameObject, "online_", onClickOnline);
UIHelper.registEvent(gameObject, "myCard_", onClickMyCard);
UIHelper.registEvent(gameObject, "replay_", onClickReplay);
UIHelper.registEvent(gameObject, "single_", onClickPizzle);
//UIHelper.registEvent(gameObject, "ai_", onClickAI);
......@@ -107,6 +108,11 @@ public class Menu : WindowServantSP
Program.I().shiftToServant(Program.I().selectServer);
}
void onClickMyCard()
{
Program.I().shiftToServant(Program.I().mycard);
}
void onClickAI()
{
Program.I().shiftToServant(Program.I().aiRoom);
......@@ -199,6 +205,10 @@ public class Menu : WindowServantSP
{
return;
}
if (Program.I().mycard == null)
{
return;
}
try
{
if (File.Exists("commamd.shell") == false)
......
......@@ -191,7 +191,7 @@ public static class TcpHelper
if (onDisConnected == true)
{
onDisConnected = false;
Program.I().ocgcore.returnServant = Program.I().selectServer;
Program.I().ocgcore.setDefaultReturnServant();
if (TcpHelper.tcpClient != null)
{
if (TcpHelper.tcpClient.Connected)
......@@ -206,7 +206,11 @@ public static class TcpHelper
{
if (Program.I().menu.isShowed == false)
{
Program.I().shiftToServant(Program.I().selectServer);
if (Program.I().mycard.isMatching) {
Program.I().shiftToServant(Program.I().mycard);
} else {
Program.I().shiftToServant(Program.I().selectServer);
}
}
if (!roomListChecking)
{
......
fileFormatVersion: 2
guid: bbd1f321059ac4f1393708fc8edbebcc
folderAsset: yes
timeCreated: 1557922807
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
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";
Thread requestThread = null;
MyCardHelper helper;
UIInput inputUsername;
UIInput inputPsw;
public override void initialize()
{
createWindow(Program.I().new_ui_mycard);
UIHelper.registEvent(gameObject, "exit_", onClickExit);
UIHelper.registEvent(gameObject, "joinAthletic_", onClickJoinAthletic);
UIHelper.registEvent(gameObject, "joinEntertain_", onClickJoinEntertain);
UIHelper.registEvent(gameObject, "database_", onClickDatabase);
UIHelper.registEvent(gameObject, "community_", onClickCommunity);
inputUsername = UIHelper.getByName<UIInput>(gameObject, "name_");
inputPsw = UIHelper.getByName<UIInput>(gameObject, "psw_");
helper = new MyCardHelper();
loadUser();
SetActiveFalse();
}
void saveUser() {
Config.Set("mycard_username", inputUsername.value);
Config.Set("mycard_password", inputPsw.value);
Program.I().selectServer.name = inputUsername.value;
}
void loadUser() {
inputUsername.value = Config.Get("mycard_username", "MyCard");
inputPsw.value = Config.Get("mycard_password", "");
}
public void terminateThread()
{
if (!isRequesting && requestThread == null)
{
return;
}
requestThread.Abort();
requestThread = null;
}
void onClickExit()
{
Program.I().shiftToServant(Program.I().menu);
if (TcpHelper.tcpClient != null)
{
if (isRequesting) {
terminateThread();
}
if (TcpHelper.tcpClient.Connected)
{
TcpHelper.tcpClient.Close();
}
}
}
void onClickDatabase() {
Application.OpenURL("https://mycard.moe/ygopro/arena/");
}
void onClickCommunity() {
Application.OpenURL("https://ygobbs.com/");
}
void matchThread(string username, string password, string match_type) {
try {
Program.PrintToChat(InterString.Get("正在登录至MyCard。"));
string fail_reason = "";
bool res = helper.login(username, password, out fail_reason);
if (!res) {
Program.PrintToChat(InterString.Get("MyCard登录失败。原因: ") + fail_reason);
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);
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();
isRequesting = false;
} catch (Exception e) {
if (e.GetType() != typeof(ThreadAbortException)) {
Program.PrintToChat(InterString.Get("未知错误: ") + e.Message);
} else {
Program.PrintToChat(InterString.Get("匹配已中断。"));
}
isRequesting = false;
}
}
void startMatch(string match_type) {
string username = inputUsername.value;
string password = inputPsw.value;
if (username == "" || password == "")
{
RMSshow_onlyYes("", InterString.Get("用户名或密码为空。"), null);
return;
}
if (isRequesting)
{
terminateThread();
}
saveUser();
isRequesting = true;
Program.PrintToChat(InterString.Get("已开始匹配。"));
requestThread = new Thread(() =>
{
matchThread(username, password, match_type);
});
requestThread.Start();
}
void onClickJoinAthletic() {
startMatch("athletic");
}
void onClickJoinEntertain() {
startMatch("entertain");
}
}
fileFormatVersion: 2
guid: 15aee34bcc5534aba92a4d450adc451f
timeCreated: 1557922807
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System;
using System.Text;
using System.Collections.Generic;
using System.IO;
[Serializable]
public class LoginUserObject {
public int id;
public string username;
public string name;
public string email;
public string password_hash;
public bool active;
public bool admin;
public string avatar;
public string locale;
public string registration_ip_address;
public string ip_address;
public string created_at;
public string updated_at;
public string token;
}
[Serializable]
public class LoginObject {
public LoginUserObject user;
public string token;
}
[Serializable]
public class LoginRequest {
public string account;
public string password;
}
[Serializable]
public class MatchObject {
public string address;
public int port;
public string password;
}
public class MyCardHelper {
string username = null;
int userid = -1;
public bool login(string name, string password, out string fail_reason) {
try {
LoginRequest data = new LoginRequest();
data.account = name;
data.password = password;
string data_str = JsonUtility.ToJson(data);
Dictionary<String, String> header_list = new Dictionary<String, String>();
header_list.Add("Content-Type", "application/json");
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) {
if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{
fail_reason = www.error;
return false;
}
}
string result = www.text;
LoginObject result_object = JsonUtility.FromJson<LoginObject>(result);
username = result_object.user.username;
userid = result_object.user.id;
} catch (Exception e) {
fail_reason = e.Message;
return false;
}
fail_reason = null;
return true;
}
public string requestMatch(string match_type, out string fail_reason) {
string ret;
if (username == null || userid < 0) {
fail_reason = "Not logged in";
return null;
}
try {
string auth_str = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + userid));
Dictionary<String, String> header_list = new Dictionary<String, String>();
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);
while (!www.isDone) {
if (Application.internetReachability == NetworkReachability.NotReachable || !string.IsNullOrEmpty(www.error))
{
fail_reason = www.error;
return null;
}
}
string result = www.text;
MatchObject result_object = JsonUtility.FromJson<MatchObject>(result);
ret = result_object.password;
} catch (Exception e) {
fail_reason = e.Message;
return null;
}
fail_reason = null;
return ret;
}
}
fileFormatVersion: 2
guid: 0fdc02eca02bf4eaa89dded37a5bce1b
timeCreated: 1557922807
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -755,13 +755,21 @@ public class Ocgcore : ServantWithCardDescription
}
}
public void onExit()
public void setDefaultReturnServant() {
if (Program.I().mycard.isMatching) {
returnServant = Program.I().mycard;
} else {
returnServant = Program.I().selectServer;
}
}
public void onExit()
{
if (TcpHelper.tcpClient != null)
{
if (TcpHelper.tcpClient.Connected)
{
Program.I().ocgcore.returnServant = Program.I().selectServer;
setDefaultReturnServant();
TcpHelper.tcpClient.Client.Shutdown(0);
TcpHelper.tcpClient.Close();
}
......@@ -776,7 +784,7 @@ public class Ocgcore : ServantWithCardDescription
{
/*if (TcpHelper.tcpClient.Connected)
{
Program.I().ocgcore.returnServant = Program.I().selectServer;
setDefaultReturnServant();
TcpHelper.tcpClient.Client.Shutdown(0);
TcpHelper.tcpClient.Close();
} */
......
......@@ -88,6 +88,7 @@ public class Program : MonoBehaviour
public GameObject new_ui_setting;
public GameObject new_ui_book;
public GameObject new_ui_selectServer;
public GameObject new_ui_mycard;
public GameObject new_ui_RoomList;
public GameObject new_ui_gameInfo;
public GameObject new_ui_cardDescription;
......@@ -952,7 +953,8 @@ public class Program : MonoBehaviour
public DeckManager deckManager;
public Ocgcore ocgcore;
public SelectServer selectServer;
public RoomList roomList;
public MyCard mycard;
public RoomList roomList;
public Book book;
public puzzleMode puzzleMode;
public AIRoom aiRoom;
......@@ -974,6 +976,8 @@ public class Program : MonoBehaviour
servants.Add(ocgcore);
selectServer = new SelectServer();
servants.Add(selectServer);
mycard = new MyCard();
servants.Add(mycard);
roomList = new RoomList();
servants.Add(roomList);
book = new Book();
......@@ -1020,6 +1024,10 @@ public class Program : MonoBehaviour
{
selectServer.hide();
}
if (to != mycard && mycard.isShowed)
{
mycard.hide();
}
if (to != selectReplay && selectReplay.isShowed)
{
selectReplay.hide();
......@@ -1045,6 +1053,7 @@ public class Program : MonoBehaviour
if (to == deckManager && deckManager.isShowed == false) deckManager.show();
if (to == ocgcore && ocgcore.isShowed == false) ocgcore.show();
if (to == selectServer && selectServer.isShowed == false) selectServer.show();
if (to == mycard && mycard.isShowed == false) mycard.show();
if (to == selectReplay && selectReplay.isShowed == false) selectReplay.show();
if (to == puzzleMode && puzzleMode.isShowed == false) puzzleMode.show();
if (to == aiRoom && aiRoom.isShowed == false) aiRoom.show();
......@@ -1106,7 +1115,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.034.9-A] " + "FPS: " + FPS);
GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.034.9-B] " + "FPS: " + FPS);
}
void Update()
......
......@@ -87,7 +87,7 @@ public class Room : WindowServantSP
Menu.deleteShell();
}
base.show();
Program.I().ocgcore.returnServant = Program.I().selectServer;
Program.I().ocgcore.setDefaultReturnServant();
Program.I().ocgcore.handler = handler;
UIHelper.registEvent(toolBar, "input_", onChat);
Program.charge();
......@@ -495,7 +495,7 @@ public class Room : WindowServantSP
public void StocMessage_DuelStart(BinaryReader r)
{
Program.I().ocgcore.returnServant = Program.I().selectServer;
Program.I().ocgcore.setDefaultReturnServant();
needSide = false;
joinWithReconnect = true;
if (Program.I().deckManager.isShowed)
......
......@@ -351,7 +351,8 @@ public class SelectServer : WindowServantSP
}
File.WriteAllText("config/passwords.conf", all);
printFile(false);
(new Thread(() => { TcpHelper.join(ipString, name, portString, pswString, versionString); })).Start();
Program.I().mycard.isMatching = false;
(new Thread(() => { TcpHelper.join(ipString, name, portString, pswString, versionString); })).Start();
}
else
{
......
......@@ -435,6 +435,11 @@ Prefab:
propertyPath: new_ui_selectServer
value:
objectReference: {fileID: 115020, guid: aeecebc57be069842a18f05155794f6c, type: 2}
- target: {fileID: 11419100, guid: 995e2fa1a1156d248955c5fb98502585, type: 2}
propertyPath: new_ui_mycard
value:
objectReference: {fileID: 1227114789899134, guid: 1e21549c701d371459f1cd723da1a709,
type: 2}
- target: {fileID: 11419100, guid: 995e2fa1a1156d248955c5fb98502585, type: 2}
propertyPath: new_ui_faceShower
value:
......@@ -767,6 +772,225 @@ Prefab:
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 995e2fa1a1156d248955c5fb98502585, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1290697414
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1290697418}
- component: {fileID: 1290697417}
- component: {fileID: 1290697416}
- component: {fileID: 1290697415}
m_Layer: 18
m_Name: UI Root
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!54 &1290697415
Rigidbody:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290697414}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 0
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &1290697416
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290697414}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ae942c9068183dc40a9d01f648273726, type: 3}
m_Name:
m_EditorClassIdentifier:
leftAnchor:
target: {fileID: 0}
relative: 0
absolute: 0
rightAnchor:
target: {fileID: 0}
relative: 1
absolute: 0
bottomAnchor:
target: {fileID: 0}
relative: 0
absolute: 0
topAnchor:
target: {fileID: 0}
relative: 1
absolute: 0
updateAnchors: 1
showInPanelTool: 1
generateNormals: 0
widgetsAreStatic: 0
cullWhileDragging: 1
alwaysOnScreen: 0
anchorOffset: 0
softBorderPadding: 1
renderQueue: 0
startingRenderQueue: 3000
mClipTexture: {fileID: 0}
mAlpha: 1
mClipping: 0
mClipRange: {x: 0, y: 0, z: 300, w: 200}
mClipSoftness: {x: 4, y: 4}
mDepth: 0
mSortingOrder: 0
mClipOffset: {x: 0, y: 0}
--- !u!114 &1290697417
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290697414}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2c5ecb5660b11414fb042fb826e03b73, type: 3}
m_Name:
m_EditorClassIdentifier:
scalingStyle: 0
manualWidth: 1280
manualHeight: 720
minimumHeight: 320
maximumHeight: 1536
fitWidth: 0
fitHeight: 1
adjustByDPI: 0
shrinkPortraitUI: 0
--- !u!4 &1290697418
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290697414}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.002, y: 0.002, z: 0.002}
m_Children:
- {fileID: 1341633899}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1341633898
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1341633899}
- component: {fileID: 1341633901}
- component: {fileID: 1341633900}
m_Layer: 18
m_Name: Camera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1341633899
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1341633898}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1290697418}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1341633900
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1341633898}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2a92b5d748695fd44aac9feef17ba415, type: 3}
m_Name:
m_EditorClassIdentifier:
eventType: 1
eventsGoToColliders: 0
eventReceiverMask:
serializedVersion: 2
m_Bits: 4294967295
debug: 0
useMouse: 1
useTouch: 1
allowMultiTouch: 1
useKeyboard: 1
useController: 0
stickyTooltip: 1
tooltipDelay: 1
longPressTooltip: 0
mouseDragThreshold: 4
mouseClickThreshold: 10
touchDragThreshold: 40
touchClickThreshold: 40
rangeDistance: -1
horizontalAxisName: Horizontal
verticalAxisName: Vertical
horizontalPanAxisName:
verticalPanAxisName:
scrollAxisName: Mouse ScrollWheel
commandClick: 1
submitKey0: 13
submitKey1: 330
cancelKey0: 27
cancelKey1: 331
autoHideCursor: 1
--- !u!20 &1341633901
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1341633898}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 3
m_BackGroundColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: -10
far clip plane: 10
field of view: 60
orthographic: 1
orthographic size: 1
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 262144
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!1 &1534402465
GameObject:
m_ObjectHideFlags: 0
......
......@@ -157,6 +157,7 @@ MonoBehaviour:
new_ui_setting: {fileID: 0}
new_ui_book: {fileID: 0}
new_ui_selectServer: {fileID: 0}
new_ui_mycard: {fileID: 0}
new_ui_gameInfo: {fileID: 0}
new_ui_cardDescription: {fileID: 0}
new_ui_search: {fileID: 0}
......
This diff is collapsed.
This diff is collapsed.
fileFormatVersion: 2
guid: 1e21549c701d371459f1cd723da1a709
timeCreated: 1557910548
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
......@@ -123,7 +123,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.034.9-A
bundleVersion: 1.034.9-B
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