Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-match
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
MyCard
ygopro-match
Commits
a19ed686
Commit
a19ed686
authored
Apr 27, 2019
by
Peter Xin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clear response
parent
b36d9bc5
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
389 additions
and
8 deletions
+389
-8
main.js
main.js
+38
-8
package-lock.json
package-lock.json
+351
-0
No files found.
main.js
View file @
a19ed686
...
...
@@ -394,12 +394,6 @@ let getTimeResponse = function(parsedUrl, res) {
notFoundResponse
(
res
);
};
let
textResponse
=
function
(
res
,
text
)
{
res
.
statusCode
=
200
;
res
.
contentType
=
'
text/plain
'
;
res
.
end
(
text
);
};
// 结束游戏 (POST /finish)
let
endUserResponse
=
function
(
req
,
res
)
{
let
form
=
''
;
...
...
@@ -418,7 +412,7 @@ let endUserResponse = function(req, res) {
};
// 许可(GET /permit)
let
get
UserPermit
=
function
(
query
,
req
,
res
)
{
let
end
UserPermit
=
function
(
query
,
req
,
res
)
{
let
username
=
query
.
username
;
let
password
=
query
.
password
;
let
arena
=
query
.
arena
;
...
...
@@ -438,6 +432,34 @@ let getUserPermit = function(query, req, res) {
}
else
res
.
end
(
JSON
.
stringify
({
permit
:
false
,
reason
:
'
No record in player pool.
'
}));
};
// 清除待选用户(POST /clear)
let
endClearResponse
=
function
(
query
,
res
)
{
let
ak
=
query
.
ak
;
if
(
ak
!=
config
.
ak
)
return
notAllowedResponse
(
res
);
let
arena
=
query
.
arena
||
"
entertain
"
;
let
user
=
query
.
user
||
"
*
"
;
let
arena_info
=
config
.
servers
[
arena
];
if
(
arena_info
==
null
||
arena_info
==
undefined
)
return
notFoundResponse
(
res
);
let
shadow_pool
=
new
Map
(
playingPlayerPool
)
let
count
=
0
;
for
(
let
[
iterate_user
,
iterate_info
]
of
shadow_pool
.
entries
())
{
if
(
iterate_user
!=
"
*
"
&&
iterate_user
!=
user
)
continue
;
if
(
iterate_info
.
address
==
arena_info
&&
iterate_info
.
port
==
arena_info
.
port
)
{
playingPlayerPool
.
delete
(
iterate_user
);
playingPlayerOpponents
.
delete
(
iterate_user
);
count
+=
1
;
}
}
res
.
end
(
`
${
count
}
user cleared.`
);
};
let
notAllowedResponse
=
function
(
res
)
{
res
.
statusCode
=
405
;
res
.
end
(
"
Check your access key.
"
)
}
let
notFoundResponse
=
function
(
res
)
{
...
...
@@ -445,6 +467,12 @@ let notFoundResponse = function(res) {
res
.
end
();
};
let
textResponse
=
function
(
res
,
text
)
{
res
.
statusCode
=
200
;
res
.
contentType
=
'
text/plain
'
;
res
.
end
(
text
);
};
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
parsedUrl
=
url
.
parse
(
req
.
url
,
true
);
...
...
@@ -455,7 +483,9 @@ const server = http.createServer((req, res) => {
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/finish
'
))
endUserResponse
(
req
,
res
);
else
if
(
req
.
method
==
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/permit
'
))
getUserPermit
(
parsedUrl
.
query
,
req
,
res
);
endUserPermit
(
parsedUrl
.
query
,
req
,
res
);
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/clear
'
))
endClearResponse
(
parsedUrl
.
query
,
res
)
else
notFoundResponse
(
res
);
...
...
package-lock.json
0 → 100644
View file @
a19ed686
This diff is collapsed.
Click to expand it.
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