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
524bec53
Commit
524bec53
authored
Jun 18, 2018
by
IamI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add drop-reline support.
parent
350315b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
8 deletions
+38
-8
main.js
main.js
+38
-8
No files found.
main.js
View file @
524bec53
...
@@ -10,6 +10,7 @@ const config = JSON.parse(fs.readFileSync("./config.json"));
...
@@ -10,6 +10,7 @@ const config = JSON.parse(fs.readFileSync("./config.json"));
let
athleticUserPool
=
[];
let
athleticUserPool
=
[];
let
entertainUserPool
=
[];
let
entertainUserPool
=
[];
let
deadUserPool
=
[];
let
deadUserPool
=
[];
let
playingPlayerPool
=
new
Map
();
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
...
@@ -215,6 +216,7 @@ let pair = function (userARes, userBRes, serverName) {
...
@@ -215,6 +216,7 @@ let pair = function (userARes, userBRes, serverName) {
"
port
"
:
server
.
port
,
"
port
"
:
server
.
port
,
"
password
"
:
password
"
password
"
:
password
});
});
playingPlayerPool
.
set
(
client
.
username
,
result
);
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
(
result
);
}
}
...
@@ -257,7 +259,7 @@ let errorUser = function (res) {
...
@@ -257,7 +259,7 @@ let errorUser = function (res) {
localLog
(
res
.
username
+
"
errored for get user information.
"
);
localLog
(
res
.
username
+
"
errored for get user information.
"
);
res
.
statusCode
=
400
;
res
.
statusCode
=
400
;
res
.
end
();
res
.
end
();
}
}
;
// 当用户断开连接时
// 当用户断开连接时
let
closedUser
=
function
(
res
,
pool
)
{
let
closedUser
=
function
(
res
,
pool
)
{
...
@@ -274,7 +276,17 @@ let closedUser = function (res, pool) {
...
@@ -274,7 +276,17 @@ let closedUser = function (res, pool) {
// 若用户未在匹配池中,挂黑名单
// 若用户未在匹配池中,挂黑名单
else
else
deadUserPool
.
push
(
res
);
deadUserPool
.
push
(
res
);
}
};
// 当 srvpro 通知本服务器游戏已正常结束时
let
finishUser
=
function
(
json
)
{
let
userA
=
json
.
usernameA
;
let
userB
=
json
.
usernameB
;
for
(
let
user
in
[
userA
,
userB
])
{
if
(
!
playingPlayerPool
.
delete
(
user
))
localLog
(
"
Unknown player left the game:
"
+
user
);
}
};
// 计算预期时间
// 计算预期时间
let
calculatePredictedTime
=
function
()
{
let
calculatePredictedTime
=
function
()
{
...
@@ -304,6 +316,11 @@ let matchResponse = function(req, res) {
...
@@ -304,6 +316,11 @@ let matchResponse = function(req, res) {
if
(
!
username
||
!
password
)
{
if
(
!
username
||
!
password
)
{
throw
'
auth
'
;
throw
'
auth
'
;
}
}
// 检定是否掉线重连
if
(
playingPlayerPool
.
has
(
username
))
{
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
res
.
end
(
result
);
}
let
arg
=
url
.
parse
(
req
.
url
,
true
).
query
;
let
arg
=
url
.
parse
(
req
.
url
,
true
).
query
;
if
(
!
arg
.
arena
)
arg
.
arena
=
'
entertain
'
;
if
(
!
arg
.
arena
)
arg
.
arena
=
'
entertain
'
;
localLog
(
username
+
'
apply for a
'
+
arg
.
arena
+
'
match.
'
);
localLog
(
username
+
'
apply for a
'
+
arg
.
arena
+
'
match.
'
);
...
@@ -334,7 +351,7 @@ let matchResponse = function(req, res) {
...
@@ -334,7 +351,7 @@ let matchResponse = function(req, res) {
res
.
end
();
res
.
end
();
return
;
return
;
}
}
}
}
;
// 时间(GET /stats)
// 时间(GET /stats)
let
getTimeResponse
=
function
(
parsedUrl
,
res
)
{
let
getTimeResponse
=
function
(
parsedUrl
,
res
)
{
...
@@ -344,18 +361,29 @@ let getTimeResponse = function(parsedUrl, res) {
...
@@ -344,18 +361,29 @@ let getTimeResponse = function(parsedUrl, res) {
textResponse
(
res
,
predictedAthleticTime
.
toString
());
textResponse
(
res
,
predictedAthleticTime
.
toString
());
else
else
notFoundResponse
(
res
);
notFoundResponse
(
res
);
}
}
;
let
textResponse
=
function
(
res
,
text
)
{
let
textResponse
=
function
(
res
,
text
)
{
res
.
statusCode
=
200
;
res
.
statusCode
=
200
;
res
.
contentType
=
'
text/plain
'
;
res
.
contentType
=
'
text/plain
'
;
res
.
end
(
text
);
res
.
end
(
text
);
}
};
// 结束游戏 (POST /finish)
let
endUserResponse
=
function
(
req
,
res
)
{
let
json
=
''
;
req
.
on
(
'
data
'
,
(
data
)
=>
json
+=
data
);
req
.
on
(
'
end
'
,
function
()
{
let
result
=
finishUser
(
json
);
res
.
statusCode
=
200
;
res
.
end
(
'
ok
'
);
})
};
let
notFoundResponse
=
function
(
res
)
{
let
notFoundResponse
=
function
(
res
)
{
res
.
statusCode
=
404
;
res
.
statusCode
=
404
;
res
.
end
();
res
.
end
();
}
}
;
// 创建服务器
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
...
@@ -364,11 +392,13 @@ const server = http.createServer((req, res) => {
...
@@ -364,11 +392,13 @@ const server = http.createServer((req, res) => {
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
'
))
endUserResponse
(
req
,
res
);
else
else
notFoundResponse
(
res
);
notFoundResponse
(
res
);
})
})
;
server
.
timeout
=
0
server
.
timeout
=
0
;
server
.
listen
(
1025
);
server
.
listen
(
1025
);
setInterval
(
update
,
config
.
match
.
timeInterval
);
setInterval
(
update
,
config
.
match
.
timeInterval
);
...
...
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