how to get master client id when master client left from room?

matsuhiro
matsuhiro
edited September 2016 in Native
hello, I use C++ client.

userA : master client
userB : guest client 1
userC : guest client 2

When userA left from room, both userB and userC looks like room master.
I checked which user is room master by using this snnipet

ExitGames::LoadBalancing::Client* loadBalancingClient;
/** initialize loadBalancingClient **/
if (loadBalancingClient->getLocalPlayer().getIsMasterClient()) {
  /* this user is master */
} else {
  /* this user is not master */
}
When userA left from room,
in userB device, getIsMasterClient() return true,
in userC device, getIsMasterClient() return true, too...

Does somebody knows how to check accurate room master?

Best Answer

Answers

  • Hi @matsuhiro.

    Could you provide us with a minimal self-contained repro-case, please?
    I can't reproduce this. For me, when A leaves the room, the one fo the two remaining clients, which has joined the room first, becomes the master client and both remaining clients see it like this. The only way I could imagine the two clients having a different opinion about who of them is the new master, is that the one that has joined later on does not only see player A, but also the other player as disconnected and itself as the only remaining player.
  • Hi @Kaiserludi .
    Thank you for your reply.

    When userA left a room, userB and userC receive leaveRoomEventAction (whic is interface of ExitGames::LoadBalancing::Listener).
    Then, in leaveRoomEventAction of userB nad userC
    if (loadBalancingClient->getLocalPlayer().getIsMasterClient()) { /* this is execeted after left userA */ } else { /* this is not execeted after left userA */ }

    I check whether which user is master client to use getIsMasterClient in update loop of cocos2dx.
  • minimal repro-cas is
    1. userA create room
    2. userB join the room
    3. userC join the room
    4. userA left the room or userA kill the process of application
    5. userB and userC receive leaveRoomEventAction
    6. userB and userC looks like master client
  • Hi @matsuhiro.

    I still can't reproduce this following your steps. It works as expected for me.

    I have used demo_loadBalancing from the client SDK as a base and modified its leaveRoomEventAction() implementation to look like this:
    
    void NetworkLogic::leaveRoomEventAction(int playerNr, bool isInactive)
    {
    	if(mLoadBalancingClient.getLocalPlayer().getIsMasterClient())
    		EGLOG(ExitGames::Common::DebugLevel::INFO, L"I am player nr %d and I am now the master client", mLoadBalancingClient.getLocalPlayer().getNumber());
    	else
    		EGLOG(ExitGames::Common::DebugLevel::INFO, L"I am player nr %d and I am still not the master client", mLoadBalancingClient.getLocalPlayer().getNumber());
    }
    This results in the following log lines:
    2016-09-20 14:36:14,312 INFO NetworkLogic.cpp NetworkLogic::leaveRoomEventAction() line: 287 - I am player nr 3 and I am still not the master client


    2016-09-20 14:36:14,341 INFO NetworkLogic.cpp NetworkLogic::leaveRoomEventAction() line: 282 - I am player nr 2 and I am now the master client
  • Hi @matsuhiro.

    Thank you for the update. I am glad you found the reason causing this.