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
8c41d407
Commit
8c41d407
authored
Oct 20, 2018
by
IamI
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'drop-reline' of github.com:moecube/ygopro-match into drop-reline
parents
bea09dcc
c461c49c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
main.js
main.js
+19
-6
No files found.
main.js
View file @
8c41d407
...
...
@@ -11,6 +11,8 @@ let athleticUserPool = [];
let
entertainUserPool
=
[];
let
deadUserPool
=
[];
let
playingPlayerPool
=
new
Map
();
let
playingPlayerOpponents
=
new
Map
();
let
playingPlayerTimeout
=
new
Map
();
let
predictedEntertainTime
=
600
,
predictedAthleticTime
=
600
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
...
...
@@ -204,6 +206,8 @@ let pair = function (userARes, userBRes, serverName) {
}
options_buffer
.
writeUInt8
(
checksum
&
0xFF
,
0
);
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
])
{
let
buffer
=
new
Buffer
(
6
);
let
secret
=
parseInt
(
client
.
password
)
%
65535
+
1
;
...
...
@@ -214,10 +218,10 @@ let pair = function (userARes, userBRes, serverName) {
let
result
=
JSON
.
stringify
({
"
address
"
:
server
.
address
,
"
port
"
:
server
.
port
,
"
password
"
:
password
"
password
"
:
password
,
});
playingPlayerPool
.
set
(
client
.
username
,
result
);
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
client
.
username
);
playingPlayerTimeout
.
set
(
client
.
username
,
setTimeout
(
timeoutUser
,
config
.
match
.
longestMatchTime
,
client
.
username
)
);
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
end
(
result
);
}
...
...
@@ -281,18 +285,27 @@ let closedUser = function (res, pool) {
// 当 srvpro 通知本服务器游戏已正常结束时
let
finishUser
=
function
(
json
)
{
let
userA
=
decodeURIComponent
(
json
.
usernameA
);
let
userB
=
decodeURIComponent
(
json
.
usernameB
);
let
userA
=
json
.
usernameA
?
decodeURIComponent
(
json
.
usernameA
)
:
undefiend
;
let
userB
=
json
.
usernameB
?
decodeURIComponent
(
json
.
usernameB
)
:
undefined
;
if
(
!
userA
&&
!
userB
)
return
;
if
(
!
userA
&&
playingPlayerOpponents
.
has
(
userB
))
userA
=
playingPlayerOpponents
.
get
(
userB
);
if
(
!
userB
&&
playingPlayerOpponents
.
has
(
userA
))
userB
=
playingPlayerOpponents
.
get
(
userA
);
for
(
let
user
of
[
userA
,
userB
])
{
if
(
!
user
)
continue
;
if
(
!
playingPlayerPool
.
delete
(
user
))
localLog
(
"
Unknown player left the game:
"
+
user
);
clearTimeout
(
playingPlayerTimeout
.
get
(
user
));
playingPlayerTimeout
.
delete
(
user
);
}
localLog
(
"
Player
"
+
userA
+
"
and
"
+
userB
+
"
finished the game.
"
);
};
// 当超过时间,而 srvpro 从未通知基本服务器游戏已结束时
let
timeoutUser
=
function
(
user
)
{
if
(
playingPlayerPool
.
delete
(
user
))
localLog
(
"
With timeout, user is seen as had left the game:
"
+
user
);
playingPlayerOpponents
.
delete
(
user
);
playingPlayerTimeout
.
delete
(
user
);
};
// 计算预期时间
...
...
@@ -323,6 +336,8 @@ let matchResponse = function(req, res) {
if
(
!
username
||
!
password
)
{
throw
'
auth
'
;
}
res
.
username
=
username
;
res
.
password
=
password
;
// 检定是否掉线重连
if
(
playingPlayerPool
.
has
(
username
))
{
switch
(
config
.
match
.
reconnect
)
{
...
...
@@ -340,8 +355,6 @@ let matchResponse = function(req, res) {
let
arg
=
url
.
parse
(
req
.
url
,
true
).
query
;
if
(
!
arg
.
arena
)
arg
.
arena
=
'
entertain
'
;
localLog
(
username
+
'
apply for a
'
+
arg
.
arena
+
'
match.
'
);
res
.
username
=
username
;
res
.
password
=
password
;
// 选择匹配池
let
pool
=
null
;
if
(
arg
.
arena
==
'
athletic
'
)
...
...
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