There are no multi dimensional arrays in your example. You also haven't explained in the game--does everyone play together at the same time, or are there different games which can each contain their own players, isolated from each other?
Here's an example way to handle this: I haven't used sockets in a while, so I'm using your code and my rough memory of how it's handled--correct any mistakes as necessary.
var games = []
var socketStorage = {};
// ===============================================
// GAME LOGIC
// ===============================================
// socketStorage[socket.id] = {}; // <- this line is unnecessary.
socketStorage[socket.id] = {
username : "username",
socket : socket,
currQuestion : {
answered : false,
answer : false
},
allQuestionsAnswers : []
};
socket.on("setusername", function(msg){
socketStorage[socket.id].username = msg.username;
console.log(socketStorage[socket.id].username);
});
socket.on("newgame", function(msg){
newGameId = games.length;
games.push([]);
games[gameId].push(socketStorage[socket.id]);
socket.emit("newgamecreated", { gameId: newGameId });
});
socket.on("joingame", function(msg){
var gameId = msg.gameNumber;
games[gameId].push(socketStorage[socket.id]);
});
socket.on("getgames", function(msg){
gamesToUsers = {};
games.forEach(function(game, index) {
gamesToUsers[index] = game.map(function(socket) {
return socket.username
});
});
socket.emit("currentgames", gamesToUsers);
});
This is incomplete, and incredibly basic, and likely has several errors, but should give you enough to understand the concept of how to go about this. Whenever someone does something in a game, you'll just want to use a loop to socket.emit the new information to everyone who is in the same game. so,
socket.on("somethinghappenedingame", function(msg){
game = msg.gameNumber;
update = msg.update;
games[game].forEach(function(socketObj){
socketObj.socket.emit("gameUpdate", update);
});
});
Hope that helps.