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
d8bd1d7a
Commit
d8bd1d7a
authored
Mar 30, 2019
by
IamI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
permit
parent
b88680fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
main.js
main.js
+22
-6
No files found.
main.js
View file @
d8bd1d7a
...
@@ -163,7 +163,6 @@ let updateEntertainMatch = function () {
...
@@ -163,7 +163,6 @@ let updateEntertainMatch = function () {
entertainUserPool
.
sort
((
a
,
b
)
=>
b
.
data
.
exp
-
a
.
data
.
exp
);
entertainUserPool
.
sort
((
a
,
b
)
=>
b
.
data
.
exp
-
a
.
data
.
exp
);
// 从高到低进行贪心配对
// 从高到低进行贪心配对
let
newPool
=
[];
let
newPool
=
[];
// TODO: 加入时间分界
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
let
userA
=
entertainUserPool
[
i
];
let
userA
=
entertainUserPool
[
i
];
let
userB
=
entertainUserPool
[
i
+
1
];
let
userB
=
entertainUserPool
[
i
+
1
];
...
@@ -215,15 +214,15 @@ let pair = function (userARes, userBRes, serverName) {
...
@@ -215,15 +214,15 @@ let pair = function (userARes, userBRes, serverName) {
buffer
.
writeUInt16LE
(
options_buffer
.
readUInt16LE
(
i
)
^
secret
,
i
)
buffer
.
writeUInt16LE
(
options_buffer
.
readUInt16LE
(
i
)
^
secret
,
i
)
}
}
let
password
=
buffer
.
toString
(
'
base64
'
)
+
room_id
;
let
password
=
buffer
.
toString
(
'
base64
'
)
+
room_id
;
let
result
=
JSON
.
stringify
(
{
let
result
=
{
"
address
"
:
server
.
address
,
"
address
"
:
server
.
address
,
"
port
"
:
server
.
port
,
"
port
"
:
server
.
port
,
"
password
"
:
password
,
"
password
"
:
password
,
}
)
;
};
playingPlayerPool
.
set
(
client
.
username
,
result
);
playingPlayerPool
.
set
(
client
.
username
,
result
);
playingPlayerTimeout
.
set
(
client
.
username
,
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
client
.
username
));
playingPlayerTimeout
.
set
(
client
.
username
,
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
client
.
username
));
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
end
(
result
);
client
.
end
(
JSON
.
stringify
(
result
)
);
}
}
};
};
...
@@ -345,7 +344,7 @@ let matchResponse = function(req, res) {
...
@@ -345,7 +344,7 @@ let matchResponse = function(req, res) {
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
let
message
=
playingPlayerPool
.
get
(
username
);
let
message
=
playingPlayerPool
.
get
(
username
);
localLog
(
username
+
"
is relining to:
"
+
message
);
localLog
(
username
+
"
is relining to:
"
+
message
);
res
.
end
(
message
);
res
.
end
(
JSON
.
stringify
(
message
)
);
return
;
return
;
case
"
drop
"
:
case
"
drop
"
:
rejectUser
(
res
);
rejectUser
(
res
);
...
@@ -418,6 +417,21 @@ let endUserResponse = function(req, res) {
...
@@ -418,6 +417,21 @@ let endUserResponse = function(req, res) {
})
})
};
};
// 许可(GET /permit)
let
getUserPermit
=
function
(
query
,
req
,
res
)
{
let
username
=
query
.
username
;
let
password
=
query
.
password
;
if
(
playingPlayerPool
.
has
(
username
))
{
let
info
=
playingPlayerPool
.
get
(
username
);
if
(
password
==
info
.
password
)
res
.
json
({
permit
:
true
,
reason
:
null
});
else
res
.
json
({
permit
:
true
,
reason
:
'
Wrong roomname.
'
});
}
else
res
.
json
({
permit
:
false
,
reason
:
'
No record in player pool.
'
})
}
let
notFoundResponse
=
function
(
res
)
{
let
notFoundResponse
=
function
(
res
)
{
res
.
statusCode
=
404
;
res
.
statusCode
=
404
;
res
.
end
();
res
.
end
();
...
@@ -425,13 +439,15 @@ let notFoundResponse = function(res) {
...
@@ -425,13 +439,15 @@ let notFoundResponse = function(res) {
// 创建服务器
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
parsedUrl
=
url
.
parse
(
req
.
url
);
let
parsedUrl
=
url
.
parse
(
req
.
url
,
true
);
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
===
'
/
'
)
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
===
'
/
'
)
matchResponse
(
req
,
res
);
matchResponse
(
req
,
res
);
else
if
(
req
.
method
===
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/stats
'
))
else
if
(
req
.
method
===
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/stats
'
))
getTimeResponse
(
parsedUrl
,
res
);
getTimeResponse
(
parsedUrl
,
res
);
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/finish
'
))
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/finish
'
))
endUserResponse
(
req
,
res
);
endUserResponse
(
req
,
res
);
else
if
(
req
.
method
==
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/permit
'
))
getUserPermit
(
parsedUrl
.
query
,
req
,
res
);
else
else
notFoundResponse
(
res
);
notFoundResponse
(
res
);
...
...
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