A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Changing rooms

  1. #1
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    Does anyone know of a way to change the "room" a client is connected to after they have connected, on the server side?

    I want to automatically segregate users into groups of ten (in each room). My first idea was to connect to a "waiting room" with info on the number of people in each other room, then re-connect people accordingly from the client side, trouble is two or more people could do this at once putting 11 people in one room.

    I could refuse connections to the server until i get a room with less than 10 in it, but would this be slow with up to 500 users (meaning 50 connection attempts)?

    I'm a bit new to all this flashcom business, so for all I know I'm going about all of this in completely the wrong way.

    Any help would be a life saver.

    Dave

  2. #2
    psx = new Moderator();
    Join Date
    Jan 2001
    Posts
    923
    Dave -
    It really depends on how you are starting out. Are you using the room components, or are you building from skratch? If you're going for your own solution, I may be able to help. I just haven't played with the room component. After reading it's description, I made a possibly naive decision that it wasn't what I wanted, and I'd be better off handling this aspect on my own.

    I think the easiest would be to handle it on the server-side, as that's really the one place where you know what is going on. So the idea is to have a check in your server side code when a client connects, you check to see what rooms are available, and if there isn't a vacancy in any of them, spawn a new one and toss the user in there.

    That isn't much help code-wise, but hopefully gets you thinking in the right direction. If you get stuck, post again and I'll try to help with some actual code.

    Psx

  3. #3
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    thanks psychlonex,

    Yes, I am doing it from scratch, I've looked at the "sample_lobby" example that comes with flashcom (seems to be a bit similar to what i need), and this uses the "FCSimpleConnect" component, but I'm finding it hard to work out exactly what this does and how it does it. So I really don't want to use it.

    You said :-

    "you check to see what rooms are available, and if there isn't a vacancy in any of them, spawn a new one and toss the user in there."

    Yes, yes, this is exaclty what i need to do, I need to be able to look at all exsisting "rooms" that others are connected to, then re-connect a user to a specific room. All from the server side.

    So I need to be able to look at all exsisting rooms in this app. I could have the number of users as a variable in the shared object in each room.

    And I need to kind of "forward" someone's connection/room to a different one, and this is the bit I'm having trouble with.

    Can I make a new net connection from the server, FOR someone that's just joined the app? Considering that to get here they must have joined a specific room from the client side. Is it really a new connection, or just a change of room?

    I hope this makes sense.

    Dave


  4. #4
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    Oh, the "roomlist" component. Just read it, didn't understand it. Although maybe I don't have to as long as i know how to USE it, but I don't know that either. (i'm probably being blind, but i can't find documentation on how to use these components)

    I'd still like to know how to do this myself really.

  5. #5
    psx = new Moderator();
    Join Date
    Jan 2001
    Posts
    923
    Hey -
    The simple connect does basically what it sais. It creates a netConnection, and passes it along to any of the components in the movie.

    There is a pdf that either comes with the components, or is available as a seperate document that describes how to use them. This is where I read about the room list component, and all the others.

    The roomlist, the reasons I don't like it is that it opens new browser windows, or at least that's what I got from the documentation. I'm on a mac (old one at that) and when I have multiple flash movies running it seems to slow way down.

    Anyway - I'm trying to work out some sample code for you, and it is indeed getting a little more difficuly than I had thought!
    So far, my thoughts are something like so:

    application.rooms_so = new Array();
    application.rooms_so[0].name = "lobby";
    application.rooms_so[0].users = new Array();


    so now you would push each user into the lobby array on connect. You can add users until the lenght of that array gets to be over 10, and then simply add a new room to the array of rooms and move your user to that. I haven't quite figured it all out in code, but that's the idea.

    Does that help get you going at all?

    Psx
    [Edited by psychlonex on 08-28-2002 at 10:44 AM]

  6. #6
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    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.

  7. #7
    psx = new Moderator();
    Join Date
    Jan 2001
    Posts
    923
    Hmmm.. yeah 3 connections is overkill for sure.. I think you should be able to migrate some of that code to the server-side. I had an example started, but my flashcom development just came to a screeching halt.

    My pc that was running flashcom server just shut itself down. It powers up, but doesn't do anything else. ARGHH. I'm so angry right now.... I have visions of pc's flying out windows and hitting nice hard cement a few stories below...

    I can't believe it. That's my second box-o-crap in 2 years. Explains why they're so much cheaper than macs.

    I've suddenly got alot of work to do now, well... alot more than I had 5 minutes ago. If I can calm down enough to get back to work that is...

    I'll hopefully be back up in a day or two, I'll try to salvage the code I had on the server and try to help out some more.

    Are you doing a 3D chat deal?
    Sounds cool.

    Psx

  8. #8
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    ok, i won't waste any more of your time (for now). hey, why don't you actually smash that computer. i don't think people do that sort of thing enough, it's sure to make you feel better.

    "Are you doing a 3D chat deal?"

    you saw this bit then, host="rtmp://**.**.**.**/3d_world/" yes sort of. It's a 3d website that you fly around and see others users flying around too, we'll probably add chat functionality aswell.

    Anyway, thanks,
    Dave

  9. #9
    psx = new Moderator();
    Join Date
    Jan 2001
    Posts
    923
    Hey -
    As soon as I get another pc and get flashcom back up... I'll do a live broadcast of the smashing for all to enjoy!

    Good deal on the 3d stuff! Sounds cool!

    psx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center