Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xu Chenxi
ygopro2
Commits
d6c25c1f
Commit
d6c25c1f
authored
May 13, 2019
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test mycard
parent
2dd80e7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
190 additions
and
17 deletions
+190
-17
Assets/SibylSystem/selectServer/MyCardHelper.cs
Assets/SibylSystem/selectServer/MyCardHelper.cs
+118
-0
Assets/SibylSystem/selectServer/SelectServer.cs
Assets/SibylSystem/selectServer/SelectServer.cs
+72
-17
No files found.
Assets/SibylSystem/selectServer/MyCardHelper.cs
0 → 100644
View file @
d6c25c1f
using
UnityEngine
;
using
UnityEngine.Networking
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
public
class
JSONObject
{
public
string
Stringify
()
{
return
JsonUtility
.
ToJson
(
this
);
}
}
public
class
LoginUserObject
:
JSONObject
{
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
;
}
public
class
LoginObject
:
JSONObject
{
public
LoginUserObject
user
;
public
string
token
;
public
string
message
;
}
public
class
LoginRequest
:
JSONObject
{
public
string
account
;
public
string
password
;
public
LoginRequest
(
string
user
,
string
pass
)
{
this
.
account
=
user
;
this
.
password
=
pass
;
}
}
public
class
MatchObject
:
JSONObject
{
public
string
address
;
public
int
port
;
public
string
password
;
}
public
class
MyCardHelper
{
string
username
;
int
userid
=
0
;
public
bool
login
(
string
name
,
string
password
,
out
string
fail_reason
)
{
try
{
LoginRequest
data
=
new
LoginRequest
(
name
,
password
);
string
data_str
=
data
.
Stringify
();
UnityWebRequest
www
=
UnityWebRequest
.
Post
(
"https://api.moecube.com/accounts/signin"
,
data_str
);
www
.
SetRequestHeader
(
"Content-Type"
,
"application/json"
);
yield
return
www
.
SendWebRequest
();
if
(
www
.
isNetworkError
||
www
.
isHttpError
)
{
fail_reason
=
www
.
error
;
return
false
;
}
else
if
(
www
.
responseCode
>=
400
)
{
fail_reason
=
"Login failed"
;
return
false
;
}
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
)
{
fail_reason
=
e
.
Message
;
return
false
;
}
return
true
;
}
public
string
requestMatch
(
string
match_type
,
out
string
fail_reason
)
{
string
ret
;
if
(!
username
||
!
userid
)
{
fail_reason
=
"Not logged in"
;
return
null
;
}
try
{
string
auth_str
=
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
());
www
.
SetRequestHeader
(
"Authorization"
,
"Basic "
+
auth_str
);
yield
return
www
.
SendWebRequest
();
if
(
www
.
isNetworkError
||
www
.
isHttpError
)
{
fail_reason
=
www
.
error
;
return
null
;
}
else
if
(
www
.
responseCode
>=
400
)
{
fail_reason
=
"Match failed"
;
return
null
;
}
else
{
string
result
=
www
.
downloadHandler
.
text
;
MatchObject
result_object
=
JsonUtility
.
FromJson
<
MatchObject
>(
result
);
ret
=
result_object
.
password
;
}
}
catch
(
Exception
e
)
{
fail_reason
=
e
.
Message
;
return
null
;
}
return
ret
;
}
}
Assets/SibylSystem/selectServer/SelectServer.cs
View file @
d6c25c1f
...
...
@@ -55,6 +55,8 @@ public class SelectServer : WindowServantSP
serversList
.
items
.
Add
(
"[AI]Doom Bots of Doom"
);
//serversList.items.Add("[OCG&TCG]한국서버");
//serversList.items.Add("[OCG&TCG]YGOhollow (JP)");
serversList
.
items
.
Add
(
"[MyCard]Athletic"
);
serversList
.
items
.
Add
(
"[MyCard]Entertain"
);
if
(
Application
.
systemLanguage
==
SystemLanguage
.
Chinese
||
Application
.
systemLanguage
==
SystemLanguage
.
ChineseSimplified
||
Application
.
systemLanguage
==
SystemLanguage
.
ChineseTraditional
)
{
serversList
.
items
.
Add
(
"[自定义]"
);
...
...
@@ -126,6 +128,26 @@ public class SelectServer : WindowServantSP
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"port_"
).
value
=
"573"
;
Config
.
Set
(
"serversPicker"
,
"[AI]Doom Bots of Doom"
);
inputIP_
.
enabled
=
false
;
inputPort_
.
enabled
=
false
;
break
;
}
case
"[MyCard]Athletic"
:
{
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"ip_"
).
value
=
"tiramisu.mycard.moe"
;
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"port_"
).
value
=
"8911"
;
Config
.
Set
(
"serversPicker"
,
"[MyCard]Athletic"
);
inputIP_
.
enabled
=
false
;
inputPort_
.
enabled
=
false
;
break
;
}
case
"[MyCard]Entertain"
:
{
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"ip_"
).
value
=
"tiramisu.mycard.moe"
;
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"port_"
).
value
=
"7911"
;
Config
.
Set
(
"serversPicker"
,
"[MyCard]Entertain"
);
inputIP_
.
enabled
=
false
;
inputPort_
.
enabled
=
false
;
break
;
...
...
@@ -290,6 +312,33 @@ public class SelectServer : WindowServantSP
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"version_"
).
value
=
str
;
}
bool
isMyCard
()
{
string
server
=
serversList
.
value
;
return
server
==
"[MyCard]Athletic"
||
server
==
"[MyCard]Entertain"
;
}
void
startMyCard
(
string
name
,
string
password
,
string
match_type
=
"entertain"
)
{
mycard
=
new
MyCardHelper
();
Program
.
PrintToChat
(
InterString
.
Get
(
"正在登录至MyCard。"
));
string
fail_reason
;
bool
res
=
mycard
.
login
(
name
,
password
,
out
fail_reason
);
if
(!
res
)
{
Program
.
PrintToChat
(
InterString
.
Get
(
"MyCard登录失败。原因: "
)
+
fail_reason
);
return
;
}
Program
.
PrintToChat
(
InterString
.
Get
(
"正在请求匹配。匹配类型: "
)
+
match_type
);
string
pswString
=
mycard
.
requestMatch
(
match_type
,
out
fail_reason
);
if
(!
pswString
)
{
Program
.
PrintToChat
(
InterString
.
Get
(
"匹配请求失败。原因: "
)
+
fail_reason
);
return
;
}
string
ipString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"ip_"
).
value
;
string
portString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"port_"
).
value
;
string
versionString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"version_"
).
value
;
Program
.
PrintToChat
(
InterString
.
Get
(
"匹配成功。正在进入房间。"
));
KF_onlineGame
(
name
,
ipString
,
portString
,
versionString
,
pswString
);
}
void
onClickJoin
()
{
if
(!
isShowed
)
...
...
@@ -301,12 +350,16 @@ public class SelectServer : WindowServantSP
string
portString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"port_"
).
value
;
string
pswString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"psw_"
).
value
;
string
versionString
=
UIHelper
.
getByName
<
UIInput
>(
gameObject
,
"version_"
).
value
;
if
(
isMyCard
())
{
startMyCard
(
Name
,
pswString
,
portString
==
"8911"
?
"athletic"
:
"entertain"
);
}
else
{
KF_onlineGame
(
Name
,
ipString
,
portString
,
versionString
,
pswString
);
}
}
public
void
onClickRoomList
()
{
if
(!
isShowed
)
if
(!
isShowed
||
isMyCard
()
)
{
return
;
}
...
...
@@ -335,6 +388,7 @@ public class SelectServer : WindowServantSP
{
if
(
name
!=
""
)
{
if
(!
isMyCard
())
{
//string fantasty = "(" + versionString + ")" + ipString + ":" + portString + " " + pswString;
string
fantasty
=
"psw: "
+
pswString
;
list
.
items
.
Remove
(
fantasty
);
...
...
@@ -351,6 +405,7 @@ public class SelectServer : WindowServantSP
}
File
.
WriteAllText
(
"config/passwords.conf"
,
all
);
printFile
(
false
);
}
(
new
Thread
(()
=>
{
TcpHelper
.
join
(
ipString
,
name
,
portString
,
pswString
,
versionString
);
})).
Start
();
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment