|
-
Right, here's the original code i wrote (it's unfinished as yet) but hopefully gives you a rough idea of where I'm at. I think I'm following a similar thinking to you re the rooms array.
I think this code is useless to me though because it's all client side, so causes that delay between joining the lobby then reconnecting meaning two uses can both "think" they're the tenth user and join the same room.
So, it really is this server side business of changing rooms that need to be able to do.
I suppose I could use this method by default, but if 11 people do end up in the same room i could just kick out the last person who joined and get them to go through the whole client side routine again. As this would be a fairly rare occurence it may be ok, although far from perfect.
/* first we connect to "lobby" to see which other rooms are free,
then leave information about which room we will join, disconnect and
re-connect to appropriate room.
On disconnect, we re-join "lobby" to say we've disconnected, then disconnect.
*/
host="rtmp://**.**.**.**/3d_world/"
// we're in "lobby mode"
mode="inLobby"
// Open connection to flash com server
myConnect = new NetConnection();
myConnect.connect(host + "lobby",mode);
// Handle status message
myConnect.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
}
// Create a remote shared object to contain info on other rooms
lobbyObj = SharedObject.getRemote("lobby", myConnect.uri, null);
lobbyObj.connect(myConnect);
lobbyObj.setFps(1);
lobbyObj.onSync = function(list) {
if(mode=="inLobby"){
// Get room info from shared object
if(lobbyObj.data.rooms != null){
/* for now we'll loop through rooms array to find a room with less than 10,
this could be sped up though, e.g by looping through smaller array of empty
slots created when we disconnect that refers to rooms array.
*/
for( var i=0; i<lobbyObj.data.rooms.length+1; i++){//length+1 because if all are full, need to make new slot
if(lobbyObj.data.rooms[i]<10) {
roomNum=i;
// tell shared object we're going to join room i
lobbyObj.data.rooms[i]+=1;
break;
}
}
trace("array exists! " + lobbyObj.data.rooms)
} else {
// no other client has create the rooms array,
// so do it now, and tell it there'll be 1 user in room 0
newRoomsArray=new Array(1)
lobbyObj.data.rooms=newRoomsArray
trace("added new array " + lobbyObj.data.rooms)
}
mode="inRoom"
};
};
// we'll disconnect from here
// then re-connect to the room we said we would
// then when we leave it we re-join first room to say we've left
//THAT'S 3 CONNECTIONS EVERY TIME!
thanks for this help by the way
Dave.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|