How does a client know if it is the room owner?

I noticed a callback function called 'onMasterClientChanged' but no way of finding out if you were a master client in the first place.

Does anyone know if there is a way of determining if a client is the room master client?


  • Hi @StereoJunkie.

    Listener::onMasterClientChanged() receives the player numbers of the old and the new master clients as arguments, so when you receive that callback, you can just compare the local clients player number with the one that was passed to that callback for the old master client to find out if the local player has been the master client before.

    That said, the comparison result will always be that you have not been the old master client, so there is no point in doing it in the first place. The reason for this is that the master client only changes to a new client when the olds master client leaves the room and obviously it can't receive that callback anymore if it isn't in the room any longer, so the very fact that your local client receives such a callback means that it can't have been the old master client, as it is still inside the room (otherwise it would not receive that callback) and as no no new master client would be chosen if the old one was still inside the room.

    Does anyone know if there is a way of determining if a client is the room master client?

    To find out which client is the current master client you can use MutableRoom::getMasterClientID().

    MutableRoom::getMasterClientID() returns the player number of the current master client of the room.

    You can just go through the list of players inside the room that is returned by MutableRoom::getPlayers(), and find the player whose player number (as returned by Player::getNumber()) matches the number that is returned by MutableRoom::getMasterClientID().

    Or simply pass the return value MutableRoom::getMasterClientID() to a call to MutableRoom::getPlayerForNumber() to get the Player instance that is the master client.

    However if you don't need to know which player is the current master client, but only need to know if a certain player is the master client or not, the you can just call Player::getIsMasterClient() on that player instance.