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
1b2c5a05
Commit
1b2c5a05
authored
Dec 30, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refa using parseRequestUrl
parent
54fb539f
Pipeline
#42233
passed with stages
in 26 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
20 deletions
+46
-20
main.js
main.js
+46
-20
No files found.
main.js
View file @
1b2c5a05
...
@@ -4,8 +4,8 @@ const request = require('request');
...
@@ -4,8 +4,8 @@ const request = require('request');
const
http
=
require
(
'
http
'
);
const
http
=
require
(
'
http
'
);
const
crypto
=
require
(
'
crypto
'
);
const
crypto
=
require
(
'
crypto
'
);
const
fs
=
require
(
'
fs
'
);
const
fs
=
require
(
'
fs
'
);
const
url
=
require
(
'
url
'
);
//
const url = require('url');
const
dns
=
require
(
"
dns
"
);
//
const dns = require("dns");
const
config
=
JSON
.
parse
(
fs
.
readFileSync
(
"
./config.json
"
));
const
config
=
JSON
.
parse
(
fs
.
readFileSync
(
"
./config.json
"
));
let
athleticUserPool
=
[];
let
athleticUserPool
=
[];
...
@@ -23,6 +23,26 @@ let localLog = function (content) {
...
@@ -23,6 +23,26 @@ let localLog = function (content) {
console
.
log
(
"
[
"
+
new
Date
().
toLocaleString
()
+
"
]
"
+
content
)
console
.
log
(
"
[
"
+
new
Date
().
toLocaleString
()
+
"
]
"
+
content
)
};
};
function
parseRequestUrl
(
req
)
{
const
host
=
req
.
headers
&&
req
.
headers
.
host
?
req
.
headers
.
host
:
'
localhost
'
const
urlObj
=
new
URL
(
req
.
url
,
'
http://
'
+
host
)
const
query
=
Object
.
create
(
null
)
const
keys
=
new
Set
()
// 先收集 key(Node 12 的 iterator OK)
for
(
const
k
of
urlObj
.
searchParams
.
keys
())
keys
.
add
(
k
)
// 再聚合成 object(对齐 url.parse(..., true) 的“多值数组”语义)
for
(
const
k
of
keys
)
{
const
all
=
urlObj
.
searchParams
.
getAll
(
k
)
if
(
all
.
length
<=
1
)
query
[
k
]
=
all
.
length
===
1
?
all
[
0
]
:
''
else
query
[
k
]
=
all
}
return
{
urlObj
,
query
}
}
let
getUserConfig
=
function
(
user
,
callback
)
{
let
getUserConfig
=
function
(
user
,
callback
)
{
// HTTP GET 抓取数据。
// HTTP GET 抓取数据。
// 原 HTTP POST 抓取数据保留
// 原 HTTP POST 抓取数据保留
...
@@ -396,7 +416,8 @@ let matchResponse = function(req, res) {
...
@@ -396,7 +416,8 @@ let matchResponse = function(req, res) {
break
;
// 什么都不做,继续加入匹配池。
break
;
// 什么都不做,继续加入匹配池。
}
}
}
}
let
arg
=
url
.
parse
(
req
.
url
,
true
).
query
;
// let arg = url.parse(req.url, true).query;
let
arg
=
parseRequestUrl
(
req
).
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.
'
);
// 选择匹配池
// 选择匹配池
...
@@ -461,7 +482,7 @@ let endUserResponse = function(req, res) {
...
@@ -461,7 +482,7 @@ let endUserResponse = function(req, res) {
};
};
// 许可(GET /permit)
// 许可(GET /permit)
let
endUserPermit
=
function
(
query
,
re
q
,
re
s
)
{
let
endUserPermit
=
function
(
query
,
res
)
{
let
username
=
query
.
username
;
let
username
=
query
.
username
;
let
password
=
query
.
password
;
let
password
=
query
.
password
;
let
arena
=
query
.
arena
;
let
arena
=
query
.
arena
;
...
@@ -547,23 +568,28 @@ function lookup(result) {
...
@@ -547,23 +568,28 @@ function lookup(result) {
// 创建服务器
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
parsedUrl
=
url
.
parse
(
req
.
url
,
true
);
const
parsed
=
parseRequestUrl
(
req
)
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
===
'
/
'
)
const
urlObj
=
parsed
.
urlObj
matchResponse
(
req
,
res
);
const
query
=
parsed
.
query
else
if
(
req
.
method
===
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/stats
'
))
const
pathname
=
urlObj
.
pathname
getTimeResponse
(
parsedUrl
,
res
);
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/finish
'
))
if
(
req
.
method
===
'
POST
'
&&
pathname
===
'
/
'
)
{
endUserResponse
(
req
,
res
);
matchResponse
(
req
,
res
)
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/room-start
'
))
}
else
if
(
req
.
method
===
'
GET
'
&&
pathname
.
startsWith
(
'
/stats
'
))
{
startUserResponse
(
parsedUrl
.
query
,
res
);
getTimeResponse
(
urlObj
,
res
)
else
if
(
req
.
method
==
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/permit
'
))
}
else
if
(
req
.
method
===
'
POST
'
&&
pathname
.
startsWith
(
'
/finish
'
))
{
endUserPermit
(
parsedUrl
.
query
,
req
,
res
);
endUserResponse
(
req
,
res
)
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/clear
'
))
}
else
if
(
req
.
method
===
'
POST
'
&&
pathname
.
startsWith
(
'
/room-start
'
))
{
endClearResponse
(
parsedUrl
.
query
,
res
)
startUserResponse
(
query
,
res
)
else
}
else
if
(
req
.
method
===
'
GET
'
&&
pathname
.
startsWith
(
'
/permit
'
))
{
notFoundResponse
(
res
);
endUserPermit
(
query
,
res
)
}
else
if
(
req
.
method
===
'
POST
'
&&
pathname
.
startsWith
(
'
/clear
'
))
{
endClearResponse
(
query
,
res
)
}
else
{
notFoundResponse
(
res
)
}
});
});
server
.
timeout
=
0
;
server
.
timeout
=
0
;
server
.
listen
(
1025
);
server
.
listen
(
1025
);
...
...
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