GitHub | Documentation | Become a Patron

How to create list rooms



  • Hi everyone,

    I am a newbie of Colyseus.

    I want to make a lobby with show list rooms. Each room with max players are 2. And when room has 2 player in room, that room will be invisible in list rooms. How can i do this ?

    And i want to show custom information for each room in list rooms like:

    Room name | Message | Current Player Joined room |
    
    "Room 01" | "Hi message 01 !" | "1/2" |
    "Room 02" | "Hi message 02 !" | "1/2" |
    "Room 03" | "Hi message 03 !" | "1/2" |
    .....
    "Room 04" | "Hi message 04 !" | "1/2" |
    "Room 05" | "Hi message 05 !" | "1/2" |
    

    when create room, how can i do this too ?

    Thanks for your help !


  • administrators

    Hey @nene, welcome!

    From the client-side, you should use client.getAvailableRooms() (docs)

    Locked rooms are invisible to the room listing by default. You can set maxClients = 2 (docs) in your room handler, and use setMetadata(...) (docs) to make some data available to the room listing.

    Hope this helps!



  • Hi @endel

    Thanks for your reply.

    client.GetAvailableRooms("battle", (rooms: RoomsAvailable, err: ErrorEventArgs) => {
      rooms.
    });
    

    I don't known why we must to pass roomName = "battle" as parameter to method client.GetAvailableRooms () . Why its not empty ?

    And when a room reach to maxClients = 2, how can i update list room to invisible that room.

    Room name | Message | Current Player Joined room |
    
    "Room 01" | "Hi message 01 !" | "1/2" |
    "Room 02" | "Hi message 02 !" | "1/2" |
    "Room 03" | "Hi message 03 !" | "2/2" | ==> Invisible in list rooms
    .....
    "Room 04" | "Hi message 04 !" | "1/2" |
    "Room 05" | "Hi message 05 !" | "1/2" |
    

    P/s: I am using Unity 3D client. And could not find client.getAvailableRooms() or setMetadata(...) anywhere ?

    Thanks in advanced.



  • Hi @endel

    How i can update the list rooms when has a new room created or removed from other users ? assume that i did not joined room yet, and I am using getAvailableRooms() to get list room only. Any have method to send notification to all clients that still not join room yet ? sorry for my bad english !



  • I don't known why we must to pass roomName = "battle" as parameter to method client.GetAvailableRooms () . Why its not empty ?

    That identifies what kind of room you want to information about since you can have more than one type of room on the server. You might have "chat" room, or "battle" room, or "2vs2" room, "4vs4" room, "whatever" room, etc.

    On server side you did something like this. See that 1st name "game" in my case, is a room name. You can have more than one of these statements in the server. gameServer.register("game", GameRoom);

    client.getAvailableRooms() or setMetadata(...) anywhere ?

    setMetadata is done on the server side, in your room class.

    @endel I do not see getAvialabeRooms on client side API either. (Unity)All the room list related code is commented out in Client.cs



  • Hi @plyoung
    Thanks for your help. but do you known how we can update the list rooms when has a new room created or removed from other users ?
    Thanks

    @nene said in How to create list rooms:

    Hi @endel

    How i can update the list rooms when has a new room created or removed from other users ? assume that i did not joined room yet, and I am using getAvailableRooms() to get list room only. Any have method to send notification to all clients that still not join room yet ? sorry for my bad english !



  • I have no idea if we do not have access to "getAvailableRooms". If we did then you could simply have the client make that call every few seconds or minutes to get a fresh list.


Log in to reply
 

Looks like your connection to Colyseus Forum was lost, please wait while we try to reconnect.