Ver código fonte

Random free event emitters

Dim Dim 6 anos atrás
pai
commit
ce32fcc973
1 arquivos alterados com 20 adições e 2 exclusões
  1. 20 2
      services/matchmaking/randomFree.js

+ 20 - 2
services/matchmaking/randomFree.js

@@ -4,7 +4,7 @@ const nsp = io.of('/randomFree');
 const crypto = require('crypto-js');
 const cryptoSHA256= crypto.SHA256;
 
-
+const gameService= {}; //require
 class randomFree {
 
 	constructor() {
@@ -50,6 +50,24 @@ class randomFree {
                     };
                     p1.on('broadcast', broadcast);
                     p2.on('broadcast', broadcast);
+
+                    const gameOver = (data) => {
+                        let result;
+                        // result = gameService.lastMove(data);
+                        nsp.in(channel).emit('result', result);
+                    };
+                    p1.once('gameOver', gameOver);
+                    p2.once('gameOver', gameOver);
+
+                    const dispute = (data) => {
+                        let result;
+                        // result. gameService.dispute(data);
+
+                        //may change to 'disputeResult'
+                        nsp.in(channel).emit('result', result);
+                    };
+                    p1.on('dispute', dispute);
+                    p2.on('dispute', dispute);
 				});
 			}
 
@@ -91,7 +109,7 @@ class randomFree {
 		for (let i =0; i<5; i++){
 		    let playerCard = Math.floor((Math.random()*100 )% 100 );
 			let salt = crypto.lib.WordArray.random(128 / 8).toString();
-            let hashedCard = cryptoSHA256(playerCard.toString + salt);
+            let hashedCard = cryptoSHA256(playerCard.toString() + salt);
 		    playerCardsArray.push(playerCard);
 			saltArray.push(salt);
 			hashedCardsArray.push(hashedCard.toString());