Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
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
nanahira
srvpro
Commits
7e52d6d0
Commit
7e52d6d0
authored
Jul 05, 2018
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add upload player list to challonge
parent
d66fa8db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
ygopro-tournament.js
ygopro-tournament.js
+64
-0
No files found.
ygopro-tournament.js
View file @
7e52d6d0
...
@@ -18,6 +18,14 @@ var loadJSON = require('load-json-file').sync;
...
@@ -18,6 +18,14 @@ var loadJSON = require('load-json-file').sync;
var
settings
=
loadJSON
(
'
./config/config.json
'
);
var
settings
=
loadJSON
(
'
./config/config.json
'
);
config
=
settings
.
modules
.
tournament_mode
;
config
=
settings
.
modules
.
tournament_mode
;
challonge_config
=
settings
.
modules
.
challonge
;
var
challonge
;
if
(
challonge_config
.
enabled
)
{
challonge
=
require
(
'
challonge
'
).
createClient
({
apiKey
:
challonge_config
.
api_key
});
}
//http长连接
//http长连接
var
responder
;
var
responder
;
...
@@ -122,6 +130,57 @@ var clearDecks = function() {
...
@@ -122,6 +130,57 @@ var clearDecks = function() {
}
}
}
}
var
UploadToChallonge
=
function
()
{
if
(
!
challonge
)
{
sendResponse
(
"
未开启Challonge模式。
"
);
return
false
;
}
sendResponse
(
"
开始读取玩家列表。
"
);
var
decks_list
=
fs
.
readdirSync
(
config
.
deck_path
);
var
player_list
=
[];
for
(
var
k
in
decks_list
)
{
var
deck_name
=
decks_list
[
k
];
if
(
_
.
endsWith
(
deck_name
,
"
.ydk
"
))
{
player_list
.
push
(
deck_name
.
slice
(
0
,
deck_name
.
length
-
4
));
}
}
if
(
!
player_list
.
length
)
{
sendResponse
(
"
玩家列表为空。
"
);
return
false
;
}
sendResponse
(
"
读取玩家列表完毕,共有
"
+
player_list
.
length
+
"
名玩家。
"
);
sendResponse
(
"
开始上传玩家列表至Challonge。
"
);
var
success_count
=
[
0
];
for
(
var
k
in
player_list
)
{
var
player_name
=
player_list
[
k
];
sendResponse
(
"
正在上传玩家
"
+
player_name
+
"
至Challonge。
"
);
challonge
.
participants
.
create
({
id
:
challonge_config
.
tournament_id
,
participant
:
{
name
:
player_name
},
callback
:
(
function
(
player_name
,
success_count
)
{
return
function
(
err
,
data
)
{
if
(
err
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传失败:
"
+
err
.
text
);
}
else
{
if
(
data
.
participant
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕,其Challonge ID是
"
+
data
.
participant
.
id
+
"
。
"
);
}
else
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕。
"
);
}
++
success_count
[
0
];
if
(
success_count
[
0
]
>=
player_list
.
length
)
{
sendResponse
(
"
玩家列表上传完成。
"
);
}
}
};
})(
player_name
,
success_count
)
});
}
return
true
;
}
var
receiveDecks
=
function
(
files
)
{
var
receiveDecks
=
function
(
files
)
{
var
result
=
[];
var
result
=
[];
for
(
var
i
in
files
)
{
for
(
var
i
in
files
)
{
...
@@ -209,6 +268,11 @@ http.createServer(function (req, res) {
...
@@ -209,6 +268,11 @@ http.createServer(function (req, res) {
clearDecks
();
clearDecks
();
res
.
end
(
u
.
query
.
callback
+
'
("已删除全部卡组。");
'
);
res
.
end
(
u
.
query
.
callback
+
'
("已删除全部卡组。");
'
);
}
}
else
if
(
u
.
pathname
===
'
/api/upload_to_challonge
'
)
{
res
.
writeHead
(
200
);
var
result
=
UploadToChallonge
();
res
.
end
(
u
.
query
.
callback
+
'
("操作完成。");
'
);
}
else
{
else
{
res
.
writeHead
(
400
);
res
.
writeHead
(
400
);
res
.
end
(
"
400
"
);
res
.
end
(
"
400
"
);
...
...
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