|
|
|
|
@ -10,12 +10,12 @@ const maxRooms = 3;
|
|
|
|
|
const maxPlayersPerRoom = 1;
|
|
|
|
|
const maxSpectatorsPerRoom = 0;
|
|
|
|
|
|
|
|
|
|
function requestRooms(socket, io, filter){
|
|
|
|
|
function requestRooms(socket, filter){
|
|
|
|
|
console.log('+ requestRooms recieved');
|
|
|
|
|
console.log('- filter: '+filter);
|
|
|
|
|
|
|
|
|
|
let response = getRooms(filter, dump = true);
|
|
|
|
|
io.to(socket.id).emit('returnRooms', response);
|
|
|
|
|
global.io.to(socket.id).emit('returnRooms', response);
|
|
|
|
|
|
|
|
|
|
console.log('');
|
|
|
|
|
}
|
|
|
|
|
@ -35,16 +35,16 @@ function getRooms(filter = 'all', dump = false){
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestCreateRoom(socket, io, playerName){
|
|
|
|
|
function requestCreateRoom(socket, playerName){
|
|
|
|
|
console.log('+ createRoom recieved');
|
|
|
|
|
console.log('- requested by: '+playerName);
|
|
|
|
|
|
|
|
|
|
response = createRoom(roomId = false, dump = true);
|
|
|
|
|
io.to(socket.id).emit('returnCreateRoom', response);
|
|
|
|
|
global.io.to(socket.id).emit('returnCreateRoom', response);
|
|
|
|
|
|
|
|
|
|
if(response.success){
|
|
|
|
|
let response = getRooms(filter = 'all', dump = true);
|
|
|
|
|
io.to(socket.id).emit('returnRooms', response);
|
|
|
|
|
global.io.to(socket.id).emit('returnRooms', response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('');
|
|
|
|
|
@ -102,7 +102,7 @@ function createRoom(roomId = false, dump = true){
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestJoinRoom(socket, io, playerName, roomId){
|
|
|
|
|
function requestJoinRoom(socket, playerName, roomId){
|
|
|
|
|
|
|
|
|
|
console.log('+ requestJoinRoom recieved');
|
|
|
|
|
|
|
|
|
|
@ -140,12 +140,12 @@ function requestJoinRoom(socket, io, playerName, roomId){
|
|
|
|
|
' connected on ' + roomName + ' (' + (people) + '/' + maxPlayersPerRoom + ')');
|
|
|
|
|
|
|
|
|
|
// Joined room (emit to the player that just joined)
|
|
|
|
|
io.to(socket.id).emit('responseRoom', response);
|
|
|
|
|
global.io.to(socket.id).emit('responseRoom', response);
|
|
|
|
|
|
|
|
|
|
if (people >= maxPlayersPerRoom) {
|
|
|
|
|
console.log('- starting game');
|
|
|
|
|
// startGame for room
|
|
|
|
|
startGame(roomId, io);
|
|
|
|
|
startGame(roomId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -161,7 +161,7 @@ function isUserInRoom(playerName, roomId){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startGame(roomId, io){
|
|
|
|
|
function startGame(roomId){
|
|
|
|
|
|
|
|
|
|
console.log('>> Room: ' + roomId + ': Requesting game...');
|
|
|
|
|
let people = roomData[roomId].players;
|
|
|
|
|
@ -187,21 +187,21 @@ function startGame(roomId, io){
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/25028953
|
|
|
|
|
//console.log(util.inspect(io.sockets.adapter.rooms.get(roomId), true, 4, true))
|
|
|
|
|
let clients = io.sockets.adapter.rooms.get(roomId);
|
|
|
|
|
let clients = global.io.sockets.adapter.rooms.get(roomId);
|
|
|
|
|
|
|
|
|
|
// This should return the deck data, etc. for each client
|
|
|
|
|
// ideally only returning the items that the user can/should
|
|
|
|
|
// see i.e. shouldn't give them the inDeck card list just a counter
|
|
|
|
|
// shouldn't have opponent card data/their hand shouldn't be flipped
|
|
|
|
|
roomMod.roomGeneration().then(data => {
|
|
|
|
|
roomMod.roomGeneration(roomId).then(data => {
|
|
|
|
|
response.success = true;
|
|
|
|
|
response.message = data;
|
|
|
|
|
// Each player then gets the roomGeneration stuff
|
|
|
|
|
for (const clientId of clients) {
|
|
|
|
|
const clientSocket = io.sockets.sockets.get(clientId);
|
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
|
console.log('>> responseStartGame: '+clientSocket.playerId);
|
|
|
|
|
// Emit to client socket
|
|
|
|
|
io.to(clientSocket.id).emit('responseStartGame', response);
|
|
|
|
|
global.io.to(clientSocket.id).emit('responseStartGame', response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
@ -209,9 +209,9 @@ function startGame(roomId, io){
|
|
|
|
|
response.message = err;
|
|
|
|
|
// Each player then gets the error message
|
|
|
|
|
for (const clientId of clients) {
|
|
|
|
|
const clientSocket = io.sockets.sockets.get(clientId);
|
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
|
// Emit to client socket
|
|
|
|
|
io.to(clientSocket.id).emit('responseStartGame', err);
|
|
|
|
|
global.io.to(clientSocket.id).emit('responseStartGame', err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|