Browse Source

Correct ownership on cards

Nikatlas 6 years ago
parent
commit
d3d7fef4fc
3 changed files with 236 additions and 226 deletions
  1. 214 214
      package-lock.json
  2. 2 1
      routes/matchmaking/randomFree.js
  3. 20 11
      services/matchmaking/randomFree.js

File diff suppressed because it is too large
+ 214 - 214
package-lock.json


+ 2 - 1
routes/matchmaking/randomFree.js

@@ -9,6 +9,7 @@ router.get('/join', function(req, res, next) {
     randomFreeService.join(req.user).
     then((data) => {
         console.log(data);
+        console.log("Join Request!");
         res.send(data);
     }).
     catch((err) => {
@@ -17,4 +18,4 @@ router.get('/join', function(req, res, next) {
     });
 });
 
-module.exports = router;
+module.exports = router;

+ 20 - 11
services/matchmaking/randomFree.js

@@ -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};
     }
 
 }

Some files were not shown because too many files changed in this diff