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
c5da27ff
Commit
c5da27ff
authored
Feb 20, 2017
by
Peter Xin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Time API
parent
3a3433ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
6 deletions
+39
-6
main.js
main.js
+39
-6
No files found.
main.js
View file @
c5da27ff
...
@@ -10,7 +10,7 @@ const config = JSON.parse(fs.readFileSync("./config.json"));
...
@@ -10,7 +10,7 @@ const config = JSON.parse(fs.readFileSync("./config.json"));
let
athleticUserPool
=
[];
let
athleticUserPool
=
[];
let
entertainUserPool
=
[];
let
entertainUserPool
=
[];
let
deadUserPool
=
[];
let
deadUserPool
=
[];
let
predictedEntertainTime
=
180
,
predictedAthleticTime
=
18
0
;
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
60
0
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
let
localLog
=
function
(
content
)
{
let
localLog
=
function
(
content
)
{
...
@@ -265,24 +265,23 @@ let closedUser = function (res, pool) {
...
@@ -265,24 +265,23 @@ let closedUser = function (res, pool) {
// 计算预期时间
// 计算预期时间
let
calculatePredictedTime
=
function
()
{
let
calculatePredictedTime
=
function
()
{
if
(
entertainRequestCountInTime
==
0
)
if
(
entertainRequestCountInTime
==
0
)
predictedEntertainTime
=
18
0
;
predictedEntertainTime
=
60
0
;
else
{
else
{
predictedEntertainTime
=
600
/
entertainRequestCountInTime
;
predictedEntertainTime
=
600
/
entertainRequestCountInTime
;
entertainRequestCountInTime
=
0
;
entertainRequestCountInTime
=
0
;
}
}
localLog
(
"
entertain adjust predicted time to
"
+
predictedEntertainTime
+
"
s.
"
);
localLog
(
"
entertain adjust predicted time to
"
+
predictedEntertainTime
+
"
s.
"
);
if
(
athleticRequestCountInTime
==
0
)
if
(
athleticRequestCountInTime
==
0
)
predictedAthleticTime
=
18
0
;
predictedAthleticTime
=
60
0
;
else
{
else
{
predictedAthleticTime
=
600
/
athleticRequestCountInTime
;
predictedAthleticTime
=
600
/
athleticRequestCountInTime
;
athleticRequestCountInTime
=
0
;
athleticRequestCountInTime
=
0
;
}
}
localLog
(
"
athletic adjust predicted time to
"
+
predictedAthleticTime
+
"
s.
"
);
localLog
(
"
athletic adjust predicted time to
"
+
predictedAthleticTime
+
"
s.
"
);
};
};
setInterval
(
calculatePredictedTime
,
600000
);
//
创建服务器
//
匹配(POST /)
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
matchResponse
=
function
(
req
,
res
)
{
try
{
try
{
// 读取数据
// 读取数据
let
credentials
=
new
Buffer
(
req
.
headers
[
'
authorization
'
].
split
(
'
'
)[
1
],
'
base64
'
).
toString
().
split
(
'
:
'
);
let
credentials
=
new
Buffer
(
req
.
headers
[
'
authorization
'
].
split
(
'
'
)[
1
],
'
base64
'
).
toString
().
split
(
'
:
'
);
...
@@ -321,9 +320,43 @@ const server = http.createServer((req, res) => {
...
@@ -321,9 +320,43 @@ const server = http.createServer((req, res) => {
res
.
end
();
res
.
end
();
return
;
return
;
}
}
}
// 时间(GET /stats)
let
getTimeResponse
=
function
(
parsedUrl
,
res
)
{
if
(
parsedUrl
.
pathname
===
'
/stats/entertain
'
)
textResponse
(
res
,
predictedEntertainTime
.
toString
());
else
if
(
parsedUrl
.
pathname
===
'
/stats/athletic
'
)
textResponse
(
res
,
predictedAthleticTime
.
toString
());
else
notFoundResponse
(
res
);
}
let
textResponse
=
function
(
res
,
text
)
{
res
.
statusCode
=
200
;
res
.
contentType
=
'
text/plain
'
;
res
.
end
(
text
);
}
let
notFoundResponse
=
function
(
res
)
{
res
.
statusCode
=
404
;
res
.
end
();
}
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
parsedUrl
=
url
.
parse
(
req
.
url
);
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
===
'
/
'
)
matchResponse
(
req
,
res
);
else
if
(
req
.
method
===
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/stats
'
))
getTimeResponse
(
parsedUrl
,
res
);
else
notFoundResponse
(
res
);
})
})
server
.
timeout
=
0
server
.
timeout
=
0
server
.
listen
(
1025
);
server
.
listen
(
1025
);
setInterval
(
update
,
config
.
match
.
timeInterval
);
setInterval
(
update
,
config
.
match
.
timeInterval
);
setInterval
(
calculatePredictedTime
,
600000
);
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