|
@@ -4,7 +4,7 @@ const nsp = io.of('/randomFree');
|
|
const crypto = require('crypto-js');
|
|
const crypto = require('crypto-js');
|
|
const cryptoSHA256= crypto.SHA256;
|
|
const cryptoSHA256= crypto.SHA256;
|
|
|
|
|
|
-
|
|
|
|
|
|
+const gameService= {}; //require
|
|
class randomFree {
|
|
class randomFree {
|
|
|
|
|
|
constructor() {
|
|
constructor() {
|
|
@@ -50,6 +50,24 @@ class randomFree {
|
|
};
|
|
};
|
|
p1.on('broadcast', broadcast);
|
|
p1.on('broadcast', broadcast);
|
|
p2.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++){
|
|
for (let i =0; i<5; i++){
|
|
let playerCard = Math.floor((Math.random()*100 )% 100 );
|
|
let playerCard = Math.floor((Math.random()*100 )% 100 );
|
|
let salt = crypto.lib.WordArray.random(128 / 8).toString();
|
|
let salt = crypto.lib.WordArray.random(128 / 8).toString();
|
|
- let hashedCard = cryptoSHA256(playerCard.toString + salt);
|
|
|
|
|
|
+ let hashedCard = cryptoSHA256(playerCard.toString() + salt);
|
|
playerCardsArray.push(playerCard);
|
|
playerCardsArray.push(playerCard);
|
|
saltArray.push(salt);
|
|
saltArray.push(salt);
|
|
hashedCardsArray.push(hashedCard.toString());
|
|
hashedCardsArray.push(hashedCard.toString());
|