GitHub Documentation Patreon donate button

Limit the instance of rooms



  • Hi everyone.
    Is there any way I can limited the client to add or create only one instance? Can I complete this requirement without modifying the framework? For example, I'm going to hold a competition. I want control to be created by the system, and I don't want players to create rooms.

    I think of a way, but I don't think it's elegant enough.

    //server side
    let room=matchMaker.createRoom("match" {secret:OnlySystemKnowPassWord});
    
    //client side
    ws.joinOrCreate("match");//aways faild
    

    Do you have any ideas? @endel thank you!


  • administrator

    Hi @BlueBang, this is a good feature request. The workaround you can currently do is using exactly what you've mentioned:

    let room = matchMaker.createRoom("match" { secret:OnlySystemKnowPassWord });
    
    // ...
    
    class MatchRoom extends Room {
      onCreate(options) {
        if (options.secret !== OnlySystemKnowPassWord) {
          throw new Error("not_allowed");
        }
      }
    }
    

    Cheers!


  • administrator

    You can check an example that does create a room from the server, and joins using client.consumeSeatReservation() here: https://github.com/endel/colyseus-ranked-matchmaking



  • @endel Great. I can learn something new again. Thank you for your reply.😁


 

GitHub Documentation Patreon donate button

© 2020 Endel Dreyer