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
5c89cddb
Commit
5c89cddb
authored
Jan 01, 2026
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add player-joined
parent
0b5522ac
Pipeline
#42301
failed with stages
in 1 minute and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
10 deletions
+51
-10
main.js
main.js
+51
-10
No files found.
main.js
View file @
5c89cddb
...
...
@@ -46,7 +46,7 @@ class Pool {
handleTimeout
(
user
)
{
if
(
clearUserPools
(
user
))
localLog
(
this
.
config
.
timeoutL
ogPrefix
+
user
);
localLog
(
this
.
config
.
l
ogPrefix
+
user
);
}
transferToPool
(
targetPool
,
user
,
logPrefix
)
{
...
...
@@ -60,9 +60,10 @@ class Pool {
}
}
let
playingPool
=
new
Pool
({
timeoutLogPrefix
:
"
With timeout, user is seen as had left the game:
"
,
timeoutMs
:
config
.
match
.
longestMatchTime
});
let
pendingPool
=
new
Pool
({
timeoutLogPrefix
:
"
Pending room expired for user:
"
,
timeoutMs
:
600000
});
const
allPools
=
[
playingPool
,
pendingPool
];
let
pendingPool
=
new
Pool
({
logPrefix
:
"
Pending room expired for user:
"
,
timeoutMs
:
600000
});
let
joinedPool
=
new
Pool
({
logPrefix
:
"
Joined room expired for user:
"
,
timeoutMs
:
600000
});
let
playingPool
=
new
Pool
({
logPrefix
:
"
With timeout, user is seen as had left the game:
"
,
timeoutMs
:
config
.
match
.
longestMatchTime
});
const
allPools
=
[
playingPool
,
joinedPool
,
pendingPool
];
let
playerOpponents
=
new
Map
();
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
...
...
@@ -378,6 +379,7 @@ let closedUser = function (res, pool) {
// 当 srvpro 通知本服务器游戏已正常结束时
let
finishUser
=
function
(
json
)
{
localLog
(
"
room-finish:
"
+
JSON
.
stringify
(
json
));
let
userA
=
json
.
usernameA
;
let
userB
=
json
.
usernameB
;
if
(
!
userA
&&
!
userB
)
return
;
...
...
@@ -391,6 +393,15 @@ let finishUser = function (json) {
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
finished the game.
"
);
};
// 当 srvpro 通知本服务器玩家已进入房间时
let
joinUser
=
function
(
query
)
{
localLog
(
"
room-joined:
"
+
JSON
.
stringify
(
query
));
let
user
=
query
.
username
;
if
(
!
user
)
return
;
pendingPool
.
transferToPool
(
joinedPool
,
user
,
"
Unknown pending player joined the room:
"
);
localLog
(
"
Player
"
+
user
+
"
joined the room.
"
);
};
// 当 srvpro 通知本服务器游戏已开始时
let
startUser
=
function
(
query
)
{
localLog
(
"
room-start:
"
+
JSON
.
stringify
(
query
));
...
...
@@ -399,7 +410,9 @@ let startUser = function (query) {
if
(
!
userA
&&
!
userB
)
return
;
for
(
let
user
of
[
userA
,
userB
])
{
if
(
!
user
)
continue
;
pendingPool
.
transferToPool
(
playingPool
,
user
,
"
Unknown pending player started the game:
"
);
let
roomInfo
=
joinedPool
.
transferToPool
(
playingPool
,
user
,
null
);
if
(
!
roomInfo
)
pendingPool
.
transferToPool
(
playingPool
,
user
,
"
Unknown pending player started the game:
"
);
}
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
started the game.
"
);
};
...
...
@@ -450,9 +463,24 @@ let matchResponse = function(req, res) {
localLog
(
username
+
"
is droped due to try relining.
"
);
return
;
default
:
break
;
// 什么都不做,继续加入匹配池。
clearUserPools
(
username
);
break
;
// 继续加入匹配池。
}
}
if
(
joinedPool
.
has
(
username
))
{
switch
(
config
.
match
.
reconnect
)
{
case
"
reconnect
"
:
case
"
drop
"
:
rejectUser
(
res
);
localLog
(
username
+
"
is rejected due to joined room.
"
);
return
;
default
:
clearUserPools
(
username
);
break
;
}
}
if
(
pendingPool
.
has
(
username
))
clearUserPools
(
username
);
// let arg = url.parse(req.url, true).query;
let
arg
=
parseRequestUrl
(
req
).
query
;
if
(
!
arg
.
arena
)
arg
.
arena
=
'
entertain
'
;
...
...
@@ -524,10 +552,11 @@ let endUserPermit = function(query, res) {
let
password
=
query
.
password
;
let
arena
=
query
.
arena
;
let
info
=
null
;
if
(
pendingPool
.
has
(
username
))
{
info
=
pendingPool
.
get
(
username
);
}
else
if
(
playingPool
.
has
(
username
))
{
info
=
playingPool
.
get
(
username
);
for
(
let
pool
of
allPools
)
{
if
(
pool
.
has
(
username
))
{
info
=
pool
.
get
(
username
);
break
;
}
}
if
(
info
)
{
if
(
password
==
info
.
password
)
{
...
...
@@ -583,6 +612,16 @@ let startUserResponse = function(query, res) {
res
.
end
(
'
ok
'
);
};
// 玩家进入房间 (POST /player-joined)
let
playerJoinedResponse
=
function
(
query
,
res
)
{
let
ak
=
query
.
ak
;
if
(
ak
!=
config
.
ak
)
return
notAllowedResponse
(
res
);
let
result
=
joinUser
(
query
);
res
.
statusCode
=
200
;
res
.
end
(
'
ok
'
);
};
let
notAllowedResponse
=
function
(
res
)
{
res
.
statusCode
=
405
;
res
.
end
(
"
Check your access key.
"
)
...
...
@@ -627,6 +666,8 @@ const server = http.createServer((req, res) => {
endUserResponse
(
req
,
res
)
}
else
if
(
req
.
method
===
'
POST
'
&&
pathname
.
startsWith
(
'
/room-start
'
))
{
startUserResponse
(
query
,
res
)
}
else
if
(
req
.
method
===
'
POST
'
&&
pathname
.
startsWith
(
'
/player-joined
'
))
{
playerJoinedResponse
(
query
,
res
)
}
else
if
(
req
.
method
===
'
GET
'
&&
pathname
.
startsWith
(
'
/permit
'
))
{
endUserPermit
(
query
,
res
)
}
else
if
(
req
.
method
===
'
POST
'
&&
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