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
2f440016
Commit
2f440016
authored
Dec 21, 2020
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve by server
parent
a19ed686
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
main.js
main.js
+21
-4
No files found.
main.js
View file @
2f440016
...
@@ -5,6 +5,7 @@ const http = require('http');
...
@@ -5,6 +5,7 @@ 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
config
=
JSON
.
parse
(
fs
.
readFileSync
(
"
./config.json
"
));
const
config
=
JSON
.
parse
(
fs
.
readFileSync
(
"
./config.json
"
));
let
athleticUserPool
=
[];
let
athleticUserPool
=
[];
...
@@ -222,7 +223,9 @@ let pair = function (userARes, userBRes, serverName) {
...
@@ -222,7 +223,9 @@ let pair = function (userARes, userBRes, serverName) {
playingPlayerPool
.
set
(
client
.
username
,
result
);
playingPlayerPool
.
set
(
client
.
username
,
result
);
playingPlayerTimeout
.
set
(
client
.
username
,
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
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
end
(
JSON
.
stringify
(
result
));
resolve
(
result
).
then
(
r
=>
client
.
end
(
JSON
.
stringify
(
r
))
);
}
}
};
};
...
@@ -344,7 +347,9 @@ let matchResponse = function(req, res) {
...
@@ -344,7 +347,9 @@ let matchResponse = function(req, res) {
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
let
message
=
playingPlayerPool
.
get
(
username
);
let
message
=
playingPlayerPool
.
get
(
username
);
localLog
(
username
+
"
is relining to:
"
+
message
);
localLog
(
username
+
"
is relining to:
"
+
message
);
res
.
end
(
JSON
.
stringify
(
message
));
resolve
(
username
).
then
(
r
=>
res
.
end
(
JSON
.
stringify
(
r
))
);
return
;
return
;
case
"
drop
"
:
case
"
drop
"
:
rejectUser
(
res
);
rejectUser
(
res
);
...
@@ -419,7 +424,7 @@ let endUserPermit = function(query, req, res) {
...
@@ -419,7 +424,7 @@ let endUserPermit = function(query, req, res) {
if
(
playingPlayerPool
.
has
(
username
))
{
if
(
playingPlayerPool
.
has
(
username
))
{
let
info
=
playingPlayerPool
.
get
(
username
);
let
info
=
playingPlayerPool
.
get
(
username
);
if
(
password
==
info
.
password
)
{
if
(
password
==
info
.
password
)
{
// There is a bug. Should check if server is an array.
// There is a bug. Should check if server is an array.
// But since now we have only one server for each arena..
// But since now we have only one server for each arena..
let
isCorrectArena
=
(
!
arena
||
(
info
.
address
===
config
.
servers
[
arena
].
address
&&
info
.
port
===
config
.
servers
[
arena
].
port
));
let
isCorrectArena
=
(
!
arena
||
(
info
.
address
===
config
.
servers
[
arena
].
address
&&
info
.
port
===
config
.
servers
[
arena
].
port
));
if
(
isCorrectArena
)
if
(
isCorrectArena
)
...
@@ -429,7 +434,7 @@ let endUserPermit = function(query, req, res) {
...
@@ -429,7 +434,7 @@ let endUserPermit = function(query, req, res) {
}
}
else
else
res
.
end
(
JSON
.
stringify
({
permit
:
false
,
reason
:
'
Wrong roomname.
'
}));
res
.
end
(
JSON
.
stringify
({
permit
:
false
,
reason
:
'
Wrong roomname.
'
}));
}
}
else
else
res
.
end
(
JSON
.
stringify
({
permit
:
false
,
reason
:
'
No record in player pool.
'
}));
res
.
end
(
JSON
.
stringify
({
permit
:
false
,
reason
:
'
No record in player pool.
'
}));
};
};
...
@@ -473,6 +478,18 @@ let textResponse = function (res, text) {
...
@@ -473,6 +478,18 @@ let textResponse = function (res, text) {
res
.
end
(
text
);
res
.
end
(
text
);
};
};
function
resolve
(
result
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
dns
.
lookup
(
result
.
address
,
{
family
:
4
},(
err
,
address
,
family
)
=>
{
if
(
err
)
{
resolve
(
result
);
}
else
{
resolve
({...
result
,
address
});
}
})
})
}
// 创建服务器
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
let
parsedUrl
=
url
.
parse
(
req
.
url
,
true
);
let
parsedUrl
=
url
.
parse
(
req
.
url
,
true
);
...
...
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