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
54fb539f
Commit
54fb539f
authored
Dec 30, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add /room-start
parent
61186136
Pipeline
#42232
passed with stages
in 2 minutes and 6 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
4 deletions
+53
-4
main.js
main.js
+53
-4
No files found.
main.js
View file @
54fb539f
...
@@ -14,6 +14,8 @@ let deadUserPool = [];
...
@@ -14,6 +14,8 @@ let deadUserPool = [];
let
playingPlayerPool
=
new
Map
();
let
playingPlayerPool
=
new
Map
();
let
playingPlayerOpponents
=
new
Map
();
let
playingPlayerOpponents
=
new
Map
();
let
playingPlayerTimeout
=
new
Map
();
let
playingPlayerTimeout
=
new
Map
();
let
pendingPlayerPool
=
new
Map
();
let
pendingPlayerTimeout
=
new
Map
();
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
...
@@ -206,8 +208,6 @@ let pair = function (userARes, userBRes, serverName) {
...
@@ -206,8 +208,6 @@ let pair = function (userARes, userBRes, serverName) {
}
}
options_buffer
.
writeUInt8
(
checksum
&
0xFF
,
0
);
options_buffer
.
writeUInt8
(
checksum
&
0xFF
,
0
);
localLog
(
userARes
.
username
+
"
and
"
+
userBRes
.
username
+
"
matched on room
"
+
room_id
);
localLog
(
userARes
.
username
+
"
and
"
+
userBRes
.
username
+
"
matched on room
"
+
room_id
);
playingPlayerOpponents
.
set
(
userARes
.
username
,
userBRes
.
username
);
playingPlayerOpponents
.
set
(
userBRes
.
username
,
userARes
.
username
);
for
(
let
client
of
[
userARes
,
userBRes
])
{
for
(
let
client
of
[
userARes
,
userBRes
])
{
let
buffer
=
new
Buffer
(
6
);
let
buffer
=
new
Buffer
(
6
);
let
secret
=
parseInt
(
client
.
password
)
%
65535
+
1
;
let
secret
=
parseInt
(
client
.
password
)
%
65535
+
1
;
...
@@ -220,8 +220,10 @@ let pair = function (userARes, userBRes, serverName) {
...
@@ -220,8 +220,10 @@ let pair = function (userARes, userBRes, serverName) {
"
port
"
:
server
.
port
,
"
port
"
:
server
.
port
,
"
password
"
:
password
,
"
password
"
:
password
,
};
};
playingPlayerPool
.
set
(
client
.
username
,
result
);
pendingPlayerPool
.
set
(
client
.
username
,
result
);
playingPlayerTimeout
.
set
(
client
.
username
,
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
client
.
username
));
if
(
pendingPlayerTimeout
.
has
(
client
.
username
))
clearTimeout
(
pendingPlayerTimeout
.
get
(
client
.
username
));
pendingPlayerTimeout
.
set
(
client
.
username
,
setTimeout
(
timeoutPendingUser
,
600000
,
client
.
username
));
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
lookup
(
result
).
then
(
r
=>
lookup
(
result
).
then
(
r
=>
client
.
end
(
JSON
.
stringify
(
r
))
client
.
end
(
JSON
.
stringify
(
r
))
...
@@ -302,6 +304,34 @@ let finishUser = function (json) {
...
@@ -302,6 +304,34 @@ let finishUser = function (json) {
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
finished the game.
"
);
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
finished the game.
"
);
};
};
// 当 srvpro 通知本服务器游戏已开始时
let
startUser
=
function
(
query
)
{
localLog
(
"
room-start:
"
+
JSON
.
stringify
(
query
));
let
userA
=
query
.
usernameA
;
let
userB
=
query
.
usernameB
;
if
(
!
userA
&&
!
userB
)
return
;
if
(
userA
&&
userB
)
{
playingPlayerOpponents
.
set
(
userA
,
userB
);
playingPlayerOpponents
.
set
(
userB
,
userA
);
}
for
(
let
user
of
[
userA
,
userB
])
{
if
(
!
user
)
continue
;
let
roomInfo
=
pendingPlayerPool
.
get
(
user
);
if
(
!
roomInfo
)
{
localLog
(
"
Unknown pending player started the game:
"
+
user
);
continue
;
}
pendingPlayerPool
.
delete
(
user
);
clearTimeout
(
pendingPlayerTimeout
.
get
(
user
));
pendingPlayerTimeout
.
delete
(
user
);
playingPlayerPool
.
set
(
user
,
roomInfo
);
if
(
playingPlayerTimeout
.
has
(
user
))
clearTimeout
(
playingPlayerTimeout
.
get
(
user
));
playingPlayerTimeout
.
set
(
user
,
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
user
));
}
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
started the game.
"
);
};
// 当超过时间,而 srvpro 从未通知基本服务器游戏已结束时
// 当超过时间,而 srvpro 从未通知基本服务器游戏已结束时
let
timeoutUser
=
function
(
user
)
{
let
timeoutUser
=
function
(
user
)
{
if
(
playingPlayerPool
.
delete
(
user
))
if
(
playingPlayerPool
.
delete
(
user
))
...
@@ -310,6 +340,13 @@ let timeoutUser = function(user) {
...
@@ -310,6 +340,13 @@ let timeoutUser = function(user) {
playingPlayerTimeout
.
delete
(
user
);
playingPlayerTimeout
.
delete
(
user
);
};
};
// 当房间未开始而超时
let
timeoutPendingUser
=
function
(
user
)
{
if
(
pendingPlayerPool
.
delete
(
user
))
localLog
(
"
Pending room expired for user:
"
+
user
);
pendingPlayerTimeout
.
delete
(
user
);
};
// 计算预期时间
// 计算预期时间
let
calculatePredictedTime
=
function
()
{
let
calculatePredictedTime
=
function
()
{
if
(
entertainRequestCountInTime
===
0
)
if
(
entertainRequestCountInTime
===
0
)
...
@@ -469,6 +506,16 @@ let endClearResponse = function(query, res) {
...
@@ -469,6 +506,16 @@ let endClearResponse = function(query, res) {
res
.
end
(
`
${
count
}
user cleared.`
);
res
.
end
(
`
${
count
}
user cleared.`
);
};
};
// 开始游戏 (POST /room-start)
let
startUserResponse
=
function
(
query
,
res
)
{
let
ak
=
query
.
ak
;
if
(
ak
!=
config
.
ak
)
return
notAllowedResponse
(
res
);
let
result
=
startUser
(
query
);
res
.
statusCode
=
200
;
res
.
end
(
'
ok
'
);
};
let
notAllowedResponse
=
function
(
res
)
{
let
notAllowedResponse
=
function
(
res
)
{
res
.
statusCode
=
405
;
res
.
statusCode
=
405
;
res
.
end
(
"
Check your access key.
"
)
res
.
end
(
"
Check your access key.
"
)
...
@@ -507,6 +554,8 @@ const server = http.createServer((req, res) => {
...
@@ -507,6 +554,8 @@ const server = http.createServer((req, res) => {
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
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/room-start
'
))
startUserResponse
(
parsedUrl
.
query
,
res
);
else
if
(
req
.
method
==
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/permit
'
))
else
if
(
req
.
method
==
'
GET
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/permit
'
))
endUserPermit
(
parsedUrl
.
query
,
req
,
res
);
endUserPermit
(
parsedUrl
.
query
,
req
,
res
);
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/clear
'
))
else
if
(
req
.
method
===
'
POST
'
&&
parsedUrl
.
pathname
.
startsWith
(
'
/clear
'
))
...
...
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