|
@@ -4,12 +4,14 @@ const nsp = io.of('/randomFree');
|
|
|
const crypto = require('crypto-js');
|
|
|
const cryptoSHA256= crypto.SHA256;
|
|
|
|
|
|
+let Users = require('../../database').Repositories.Users;
|
|
|
+
|
|
|
const gameService= {}; //require
|
|
|
class randomFree {
|
|
|
|
|
|
constructor() {
|
|
|
nsp.on('connection', (socket) => {
|
|
|
- console.log('someone connected');
|
|
|
+ console.log('Someone connected');
|
|
|
socket.join('queue');
|
|
|
this.match();
|
|
|
});
|
|
@@ -22,9 +24,12 @@ class randomFree {
|
|
|
if(clients.length > 1) {
|
|
|
let p1 = nsp.sockets[clients[0]];
|
|
|
let p2 = nsp.sockets[clients[1]];
|
|
|
+
|
|
|
p1.emit('test');
|
|
|
p2.emit('test');
|
|
|
+
|
|
|
const channel = clients[0] + clients[1];
|
|
|
+ console.log(channel);
|
|
|
|
|
|
let err = (e) => {
|
|
|
if(e)throw e;
|
|
@@ -36,10 +41,14 @@ class randomFree {
|
|
|
p2.leave('queue', err);
|
|
|
p2.join(channel, err);
|
|
|
|
|
|
+ let token1 = p1.request._query['token'];
|
|
|
+ let token2 = p2.request._query['token'];
|
|
|
+ // maybe i need to change to username
|
|
|
+
|
|
|
nsp.in(channel).clients((err, clients) => {
|
|
|
console.log('Channel: ' + channel);
|
|
|
console.log(clients);
|
|
|
- let matchInfo = this.joinGame(p1.id, p2.id);
|
|
|
+ let matchInfo = this.joinGame(token1, token2);
|
|
|
//possible change to 'joinFreeRandomGame' ?
|
|
|
console.log("Joining Game");
|
|
|
p1.emit('joinGame', matchInfo.playerOneState);
|
|
@@ -88,14 +97,14 @@ class randomFree {
|
|
|
}
|
|
|
|
|
|
createSetupArray(playerOne, playerTwo, playerOneCards, playerTwoCards){
|
|
|
- let id = {
|
|
|
- playerOne: playerOne,
|
|
|
- playerTwo: playerTwo,
|
|
|
- };
|
|
|
- let cards = {
|
|
|
- playerOne: playerOneCards.hashedCardsArray,
|
|
|
- playerTwo: playerTwoCards.hashedCardsArray,
|
|
|
- };
|
|
|
+ let id = [
|
|
|
+ playerOne,
|
|
|
+ playerTwo
|
|
|
+ ];
|
|
|
+ let cards = [
|
|
|
+ playerOneCards.hashedCardsArray,
|
|
|
+ playerTwoCards.hashedCardsArray
|
|
|
+ ];
|
|
|
|
|
|
let setup = {id, cards };
|
|
|
return setup;
|
|
@@ -114,7 +123,7 @@ class randomFree {
|
|
|
saltArray.push(salt);
|
|
|
hashedCardsArray.push(hashedCard.toString());
|
|
|
}
|
|
|
- return {playerCardsArray, saltArray, hashedCardsArray};
|
|
|
+ return {playerCardsArray, saltArray, hashedCardsArray};
|
|
|
}
|
|
|
|
|
|
}
|