You need to sign in or sign up before continuing.
Commit c461c49c authored by 不如归去's avatar 不如归去 Committed by GitHub

Fix

parent 3f31b006
...@@ -12,6 +12,7 @@ let entertainUserPool = []; ...@@ -12,6 +12,7 @@ let entertainUserPool = [];
let deadUserPool = []; let deadUserPool = [];
let playingPlayerPool = new Map(); let playingPlayerPool = new Map();
let playingPlayerOpponents = new Map(); let playingPlayerOpponents = new Map();
let playingPlayerTimeout = new Map();
let predictedEntertainTime = 600, predictedAthleticTime = 600; let predictedEntertainTime = 600, predictedAthleticTime = 600;
let entertainRequestCountInTime = 0, athleticRequestCountInTime = 0; let entertainRequestCountInTime = 0, athleticRequestCountInTime = 0;
...@@ -220,7 +221,7 @@ let pair = function (userARes, userBRes, serverName) { ...@@ -220,7 +221,7 @@ let pair = function (userARes, userBRes, serverName) {
"password": password, "password": password,
}); });
playingPlayerPool.set(client.username, result); 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.writeHead(200, {'Content-Type': 'application/json', 'Cache-Control': 'no-cache'});
client.end(result); client.end(result);
} }
...@@ -293,6 +294,8 @@ let finishUser = function (json) { ...@@ -293,6 +294,8 @@ let finishUser = function (json) {
if (!user) continue; if (!user) continue;
if (!playingPlayerPool.delete(user)) if (!playingPlayerPool.delete(user))
localLog("Unknown player left the game: " + user); localLog("Unknown player left the game: " + user);
clearTimeout(playingPlayerTimeout.get(user));
playingPlayerTimeout.delete(user);
} }
localLog("Player " + userA + " and " + userB + " finished the game."); localLog("Player " + userA + " and " + userB + " finished the game.");
}; };
...@@ -302,6 +305,7 @@ let timeoutUser = function(user) { ...@@ -302,6 +305,7 @@ let timeoutUser = function(user) {
if (playingPlayerPool.delete(user)) if (playingPlayerPool.delete(user))
localLog("With timeout, user is seen as had left the game: " + user); localLog("With timeout, user is seen as had left the game: " + user);
playingPlayerOpponents.delete(user); playingPlayerOpponents.delete(user);
playingPlayerTimeout.delete(user);
}; };
// 计算预期时间 // 计算预期时间
......
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