How to make creator of room master client

Options
dennisroseman
edited May 2014 in DotNet
I am new to photon and going through docs, forum and demos.
I am trying to make my Unity game multiplayer. My first attempt is to adopt some Photon Viking Demo code.

I want creator of room to be Master Client. Evidently it does not automatically happen as I can see when I alter create room button in MainMenuVik.cs
to look like this:
GUILayout.BeginHorizontal();
        GUILayout.Label("CREATE ROOM:", GUILayout.Width(150));
        roomName = GUILayout.TextField(roomName);
        if (GUILayout.Button("GO"))
        {
            // using null as TypedLobby parameter will also use the default lobby
			//Debug.Log("PhotonNetwork.masterClient id: "+PhotonNetwork.masterClient);
			if(PhotonNetwork.playerList.Length == 1)
				{Debug.Log("playerWhoIsIt: " + PhotonNetwork.player.ID);};

			PhotonNetwork.CreateRoom(roomName, new RoomOptions() { maxPlayers = 10 }, TypedLobby.Default);

			//Debug.Log("PhotonNetwork.masterClient id: "+PhotonNetwork.masterClient);
			if(PhotonNetwork.playerList.Length == 1)
				{Debug.Log("playerWhoIsIt: " + PhotonNetwork.player.ID);};

			Debug.Log("Just created room and PhotonNetwork.isMasterClient = "+PhotonNetwork.isMasterClient);  
			Application.LoadLevel("playMenu");
			Multiplayer.inMultiplayerMode = true;

        }
        GUILayout.EndHorizontal();

When I run this I see PhotonNetwork.isMasterClient is unchanged "false" and PhotonNetwork.player.ID is -1.

How do I make the creator of a room the master client? I am guessing I need to explicitly call SetMainClient(). If so what is the code that would do this?

Comments

  • While waiting for a reply I tried to force MasterClient with this addition after CreateRoom but it made no difference:

    [codePhotonNetwork.CreateRoom(roomName, new RoomOptions() { maxPlayers = 10 }, TypedLobby.Default);
    PhotonNetwork.SetMasterClient(PhotonNetwork.player);][/code]
  • vadim
    Options
    Master Client assigned automatically by server. After creating, there is only one client in the room - creator itself. And it is Master obviously. That does not change while creator connected even if other clients enter the room. So things work as you expect.

    PhotonNetwork.isMasterClient and PhotonNetwork.player.ID set after client receives response to CreateRoom command from server. But you check them right after sending. That's why the values are in initial state. Wait a second or check state in OnCreatedRoom/OnPhotonCreateRoomFailed messages handlers (implement methods with such names for that).