Skip to content
Snippets Groups Projects
Commit 72dc99ae authored by Patrick's avatar Patrick
Browse files

Added code to handle duplicate users.

parent 2d459c9f
No related branches found
No related tags found
1 merge request!1Update 1
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<h1>2doku</h1> <h1>2doku</h1>
<div id="error-container"></div>
<div id="player-info-container"> <div id="player-info-container">
<h2 id="score-header">Player Scores</h2> <h2 id="score-header">Player Scores</h2>
</div> </div>
...@@ -23,11 +23,6 @@ ...@@ -23,11 +23,6 @@
.filter(c => c[0] === "token")[0]; .filter(c => c[0] === "token")[0];
return t ? t[1] : null; return t ? t[1] : null;
} }
function hideJoinButton() {
document.querySelector("#join-game").style.display = "none";
}
const socket = io({ const socket = io({
query: { query: {
gameId: window.location.href.split("/").filter(e => e.length > 0).pop(), gameId: window.location.href.split("/").filter(e => e.length > 0).pop(),
...@@ -42,7 +37,7 @@ ...@@ -42,7 +37,7 @@
BOARD1.updateBoard(args.boardDisplay, args.boardLock, args.boardColors); BOARD1.updateBoard(args.boardDisplay, args.boardLock, args.boardColors);
document.querySelector("#join-game").style.display = "none"; document.querySelector("#join-game").style.display = "none";
displayPlayerScores(args.playerScores); displayPlayerScores(args.playerScores);
hideJoinButton(); socket.emit("verify solution", args.boardDisplay);
}); });
socket.on("game stop", () => { socket.on("game stop", () => {
...@@ -50,8 +45,14 @@ ...@@ -50,8 +45,14 @@
}); });
document.querySelector("#join-game").onclick = () => { document.querySelector("#join-game").onclick = () => {
socket.emit("join game"); socket.emit("join game", null, (duplicate) => {
hideJoinButton(); if (duplicate) {
document.querySelector("#error-container").textContent = "Sorry, but you logged in as a duplicate user.";
document.querySelector("#player-info-container").style.display = "none";
document.querySelector("#board-container").style.display = "none";
}
});
document.querySelector("#join-game").style.display = "none";
} }
function updateToServer(x, y, num) { function updateToServer(x, y, num) {
......
...@@ -297,9 +297,11 @@ io.on("connection", (socket) => { ...@@ -297,9 +297,11 @@ io.on("connection", (socket) => {
game.sendBoard(); game.sendBoard();
}); });
socket.on("join game", () => { socket.on("join game", (_, fn) => {
if (!game.playerUsers.includes(user)) { if (!game.playerUsers.includes(user)) {
game.userJoin(socketId, user); game.userJoin(socketId, user);
} else {
fn("duplicate");
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment