I cant seem to find a socket.io method that would do this.
I'm trying to create a "finding a game" system that would grab player from an array then put them in a room that's open.
index.js:
// Put user in find a game queue.
socket.on('bsb2v2find', function(data){
bsb2v2finding.push(data);
userdata = data;
});
// Server gets an update that there's an open server.
socket.on('bsb2v2opnrm', function(room){
if(bsb2v2finding.length >= 4 && bsb2v2finding.filter(function(player){ return player.username === userdata.name}).length){
var players = [];
repeatLoop(4, function(){
players.push(bsb2v2finding.shift());
});
repeatLoop(4, function(i){
// This is where all player connect to a room on the game port.
players.socket.join(room);
});
}
});
function repeatLoop(num, callback){
for(var i = 0;i !== num;i++){
callback(i);
}
}
via Korbin Deary
No comments:
Post a Comment