Nikatlas vor 6 Jahren
Ursprung
Commit
406dc7afd4
1 geänderte Dateien mit 15 neuen und 12 gelöschten Zeilen
  1. 15 12
      services/matchmaking/randomFree.js

+ 15 - 12
services/matchmaking/randomFree.js

@@ -22,7 +22,8 @@ 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];
 
 				let err = (e) => {
@@ -34,19 +35,21 @@ class randomFree {
 				p1.join(channel, err);
 				p2.leave('queue', 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) => {
 					console.log('Channel: ' + channel);
 					console.log(clients);
-                    let matchInfo = this.joinGame(p1, p2);
+                    let matchInfo = this.joinGame(p1.id, p2.id);
 					//possible change to 'joinFreeRandomGame' ?
+					console.log("Joining Game");
 					p1.emit('joinGame', matchInfo.playerOneState);
                     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){
         let id = {
-	            playerOne: playerOne,
-                playerTwo: playerTwo,
-            };
+            playerOne: playerOne,
+            playerTwo: playerTwo,
+        };
 	    let cards = {
 	        playerOne: playerOneCards.hashedCardsArray,
             playerTwo: playerTwoCards.hashedCardsArray,
@@ -91,7 +94,7 @@ class randomFree {
             let hashedCard = cryptoSHA256(playerCard.toString + salt);
 		    playerCardsArray.push(playerCard);
 			saltArray.push(salt);
-			hashedCardsArray.push(hashedCard);
+			hashedCardsArray.push(hashedCard.toString());
 		}
     return {playerCardsArray, saltArray, hashedCardsArray};
     }