Some fixes. TODO: game.mode must be analyze when score is not '*' ==> simplify Board...
[vchess.git] / server / sockets.js
index f3d1928..d92778c 100644 (file)
@@ -31,6 +31,7 @@ module.exports = function(wss) {
   wss.on("connection", (socket, req) => {
     const query = getJsonFromUrl(req.url);
     const sid = query["sid"];
+    // TODO: later, allow duplicate connections (shouldn't be much more complicated)
     // Ignore duplicate connections (on the same live game that we play):
     if (!!clients[sid])
       return socket.send(JSON.stringify({code:"duplicate"}));
@@ -83,6 +84,10 @@ module.exports = function(wss) {
           clients[obj.target].send(
             JSON.stringify({code:"refusechallenge", cid:obj.cid, from:sid}));
           break;
+        case "deletechallenge":
+          clients[obj.target].send(
+            JSON.stringify({code:"deletechallenge", cid:obj.cid, from:sid}));
+          break;
         case "newgame":
           clients[obj.target].send(JSON.stringify(
             {code:"newgame", gameInfo:obj.gameInfo, cid:obj.cid}));
@@ -107,13 +112,12 @@ module.exports = function(wss) {
           obj.oppid = sid; //I'm the opponent of my opponent(s)
           clients[oppId].send(JSON.stringify(obj));
           break;
-        // TODO: moreover, here, game info should be sent (through challenge; not stored here)
-        // TODO: also other challenge events
         case "resign":
           clients[obj.target].send(JSON.stringify({code:"resign"}));
           break;
-        // TODO: case "challenge" (get ID) --> send to all, "acceptchallenge" (with ID) --> send to all, "cancelchallenge" --> send to all
-        // also, "sendgame" (give current game info, if any) --> to new connections, "sendchallenges" (same for challenges) --> to new connections
+        case "abort":
+          clients[obj.target].send(JSON.stringify({code:"abort",msg:obj.msg}));
+          break;
       }
     });
     socket.on("close", () => {