|
@@ -22,7 +22,8 @@ class randomFree {
|
|
if(clients.length > 1) {
|
|
if(clients.length > 1) {
|
|
let p1 = nsp.sockets[clients[0]];
|
|
let p1 = nsp.sockets[clients[0]];
|
|
let p2 = nsp.sockets[clients[1]];
|
|
let p2 = nsp.sockets[clients[1]];
|
|
-
|
|
|
|
|
|
+ p1.emit('test');
|
|
|
|
+ p2.emit('test');
|
|
const channel = clients[0] + clients[1];
|
|
const channel = clients[0] + clients[1];
|
|
|
|
|
|
let err = (e) => {
|
|
let err = (e) => {
|
|
@@ -34,19 +35,21 @@ class randomFree {
|
|
p1.join(channel, err);
|
|
p1.join(channel, err);
|
|
p2.leave('queue', err);
|
|
p2.leave('queue', err);
|
|
p2.join(channel, err);
|
|
p2.join(channel, err);
|
|
- // setTimeout(() => {
|
|
|
|
- // console.log("MATCH: " +channel+ " !");
|
|
|
|
- // console.log(Object.keys(nsp.in(channel).sockets));
|
|
|
|
- // console.log("QUEUE!");
|
|
|
|
- // console.log(Object.keys(nsp.in('queue').sockets));
|
|
|
|
- // }, 5000);
|
|
|
|
|
|
+
|
|
nsp.in(channel).clients((err, clients) => {
|
|
nsp.in(channel).clients((err, clients) => {
|
|
console.log('Channel: ' + channel);
|
|
console.log('Channel: ' + channel);
|
|
console.log(clients);
|
|
console.log(clients);
|
|
- let matchInfo = this.joinGame(p1, p2);
|
|
|
|
|
|
+ let matchInfo = this.joinGame(p1.id, p2.id);
|
|
//possible change to 'joinFreeRandomGame' ?
|
|
//possible change to 'joinFreeRandomGame' ?
|
|
|
|
+ console.log("Joining Game");
|
|
p1.emit('joinGame', matchInfo.playerOneState);
|
|
p1.emit('joinGame', matchInfo.playerOneState);
|
|
p2.emit('joinGame', matchInfo.playerTwoState);
|
|
p2.emit('joinGame', matchInfo.playerTwoState);
|
|
|
|
+
|
|
|
|
+ const broadcast = (data) => {
|
|
|
|
+ nsp.in(channel).emit('move', data);
|
|
|
|
+ };
|
|
|
|
+ p1.on('broadcast', broadcast);
|
|
|
|
+ p2.on('broadcast', broadcast);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -68,9 +71,9 @@ class randomFree {
|
|
|
|
|
|
createSetupArray(playerOne, playerTwo, playerOneCards, playerTwoCards){
|
|
createSetupArray(playerOne, playerTwo, playerOneCards, playerTwoCards){
|
|
let id = {
|
|
let id = {
|
|
- playerOne: playerOne,
|
|
|
|
- playerTwo: playerTwo,
|
|
|
|
- };
|
|
|
|
|
|
+ playerOne: playerOne,
|
|
|
|
+ playerTwo: playerTwo,
|
|
|
|
+ };
|
|
let cards = {
|
|
let cards = {
|
|
playerOne: playerOneCards.hashedCardsArray,
|
|
playerOne: playerOneCards.hashedCardsArray,
|
|
playerTwo: playerTwoCards.hashedCardsArray,
|
|
playerTwo: playerTwoCards.hashedCardsArray,
|
|
@@ -91,7 +94,7 @@ class randomFree {
|
|
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);
|
|
|
|
|
|
+ hashedCardsArray.push(hashedCard.toString());
|
|
}
|
|
}
|
|
return {playerCardsArray, saltArray, hashedCardsArray};
|
|
return {playerCardsArray, saltArray, hashedCardsArray};
|
|
}
|
|
}
|