Commit 2f440016 authored by 神楽坂玲奈's avatar 神楽坂玲奈

resolve by server

parent a19ed686
...@@ -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);
...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment