Can't change to custom MasterClient

Options
Hello there!

So I am trying to build a start screen (with room creation etc) that when the master client leaves a room then the player under him becomes the new Master Client, so here is what my code looks like:
public void LeaveRoomClicked(){  //its called when the user clicks the Leave Button in the room UI

		PhotonPlayer[] playersleft = PhotonNetwork.otherPlayers;
		if (PhotonNetwork.isMasterClient && playersleft.Length > 0) {
			
			PhotonNetwork.SetMasterClient(playersleft[0]);	
                       
                        //this part here figures out the name and the facebook ID of the next available user 
                        //i need the room to be named like: NameOfMasterClient_FacebookIDofMasterClien for example Mike_10153179748704799

			string newMasterID = "";
			string newMasterName = "";
			foreach(Transform playersInRoom in PlayerList.transform){
				string pID = playersInRoom.transform.FindChild("RoomPlayerID").GetComponent<Text>().text;
				if(pID != FBHolder.instance.MyID){
					newMasterID = pID;
					newMasterName = playersInRoom.transform.FindChild("PlayerName").GetComponent<Text>().text;
					Debug.Log("New masters ID: "+ newMasterID + " and name: " + newMasterName );
					break;
				}
			}
			
                        //this one doesn't work either, the name remains as with the old master client's info
			PhotonNetwork.room.name = (newMasterName + '_' + newMasterID);
		}
		




		GetComponent<PhotonView>().RPC("OnLeftRoom_RPC", PhotonTargets.AllBuffered, FBHolder.instance.MyID);
		PhotonNetwork.LeaveRoom ();
		LeaveButton.GetComponent<Button> ().interactable = false;


	}

	void OnMasterClientSwitched (PhotonPlayer newMasterClient){

		Debug.Log ("Master Client: " + newMasterClient.name + " Room Name: " + PhotonNetwork.room.name);
               //Here I get something like that: Master Client:  Room Name: <the old name> 
	}

please help, I've been trying for hours to figure this out

Comments

  • vadim
    Options
    Why do you need to set master client manually?
    Photon assigns new master automatically as current master leaves.
  • xjimdim
    Options
    i need to set the room name as the new master client's name and id (I dont really care who the master is, i just need to rename the room)
  • xjimdim
    Options
    OK i got it kinda working when i removed most of the code in leave room and let it do an automatic setting of the master client, (the room correctly renames to what i want) but when i try to get the PhotonNetwork.GetRoomList() I get 0 rooms!! (although there is still a room with the new master client)
  • xjimdim
    Options
    OK now I am almost there :P

    I have two questions:

    1) Can a client that is joined in a room to send rpc to all players connected to the server? even those who are in lobby?

    2) does the PhotonNetwork.room.name = something; commant have to run in an RPC function?? (meaning that you can only set the name of the room if for yourself and not for everyone?)
  • xjimdim
    Options
    After lots of hours researching I finally solved it!!

    To anyone that wants to pass info between room players and lobby just use roomproperties like this:
                    RoomOptions newRoomOptions = new RoomOptions ();
    		newRoomOptions.isOpen = true;
    		newRoomOptions.isVisible = true;
    		newRoomOptions.maxPlayers = int.Parse (MaxPlayersText.text);
    		newRoomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
    		newRoomOptions.customRoomProperties.Add ("MasterRightNow", roomFullName);
    		newRoomOptions.customRoomPropertiesForLobby = new string[] {"MasterRightNow"}; 
    
    		PhotonNetwork.CreateRoom(roomFullName, newRoomOptions, null);
    

    after that you can access the variable (in this example MasterRightNow) like that:
    ExitGames.Client.Photon.Hashtable hashInfo = room.customProperties;  //it needs that kind of Hashtable not the System one
    Debug.Log("HASH INFOOOOO: " + hashInfo["MasterRightNow"].ToString());
    
  • vadim
    Options
    You can not change room name but only set it during creation. Use room custom properties for mutable room identification.

    To track automatically assigned master client, you need to handle OnCreatedRoom (creator is 1st master) and OnMasterClientSwitched (fired each time current master leaves and new assigned).

    PhotonNetwork.GetRoomList() returns client's list of rooms in lobby which is updated only while client is in lobby. After switching to game (via creation e.g.), the list remains as it was before.

    RPCs can be sent only inside the room and only players connected that room are able to receive these RPCs.

    PhotonNetwork.room.name = something will not change room name on server or other clients (this is PUN flaw, it should not let you write to this property)

    Communicating between room and lobby via room properties is new and interesting idea for me. While I don't see scenarios where this can be useful.
  • xjimdim
    Options
    Thank you very much for clarifying :)

    Room properties are indeed the best way to handle this stuff!!

    Great work there photon team :)