On the road to problems to complete website :)
[vchess.git] / sockets.js
index 452cb6e..675a80e 100644 (file)
@@ -25,6 +25,12 @@ module.exports = function(wss) {
                const params = new URL("http://localhost" + req.url).searchParams;
                const sid = params.get("sid");
                const page = params.get("page");
+               // Ignore duplicate connections:
+               if (!!clients[page][sid])
+               {
+                       socket.send(JSON.stringify({code:"duplicate"}));
+                       return;
+               }
                clients[page][sid] = socket;
                if (page == "index")
                {
@@ -88,6 +94,9 @@ module.exports = function(wss) {
                                                else
                                                        games[page] = {id:sid, fen:obj.fen}; //wait for opponent
                                                break;
+                                       case "cancelnewgame": //if a user cancel his seek
+                                               delete games[page];
+                                               break;
                                        case "resign":
                                                if (!!clients[page][obj.oppid])
                                                        clients[page][obj.oppid].send(JSON.stringify({code:"resign"}), noop);