Show waiting players during practice
This commit is contained in:
16
server.js
16
server.js
@@ -76,6 +76,15 @@ const server = http.createServer((request, response) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestUrl.pathname === "/lobby") {
|
||||
response.writeHead(200, {
|
||||
"Cache-Control": "no-store",
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
});
|
||||
response.end(request.method === "HEAD" ? undefined : JSON.stringify(lobbyStatus()));
|
||||
return;
|
||||
}
|
||||
|
||||
const staticName = staticFiles.get(requestUrl.pathname);
|
||||
if (!staticName) {
|
||||
response.writeHead(404);
|
||||
@@ -257,6 +266,13 @@ function pairClients(xClient, oClient) {
|
||||
send(oClient, { type: "paired", player: "O", roomId });
|
||||
}
|
||||
|
||||
function lobbyStatus() {
|
||||
return {
|
||||
activeGames: rooms.size,
|
||||
waitingPlayers: waitingClientId && clients.has(waitingClientId) ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
function handleSocketData(client, buffer) {
|
||||
if (!clients.has(client.id)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user