How do I set other players seed to the masterclient's seed?

Basically, I have a minecraft clone that I’m working on and I want to be able to share the masterclient’s seed with every player in the room and then set every players seed except the masterclient to the masterclient’s seed.

So, let’s say that I get a seed when I start my server and someone joins the server, I want to be able to modify their seed by replacing their original seed with mine (the masterclient’s seed) and I want to do this to every player that joins the server, but I don’t know how.

I’m using Photon for my networking and here are all my scripts related to networking in my game and the script that handles the seed itself:

NetworkManager (this manages spawning players to the server)

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

public class NetworkManager : MonoBehaviour 
{

	public Transform spawn;
	public GameObject serverSetup;
	public GameObject noRoomsObject;
	public GameObject serverN;
	public GameObject playerN;

	public void NewRoom()
	{

		string servername = serverN.GetComponent<InputField>().text.ToString();
		string playername = playerN.GetComponent<InputField>().text.ToString();

		serverSetup.SetActive(false);
		PhotonNetwork.CreateRoom(servername);
		Debug.Log ("Created a new room / " + servername.ToString());
		PhotonNetwork.playerName = playername;

		if(playername == null || playername.Length == 0)
		{

			string newName = "Player_" + (string)Random.Range(30, 50000).ToString();
			PhotonNetwork.playerName = newName;

		}

	}


	void Awake () 
	{
	
		Connect();

	}

	
	void Connect()
	{

		PhotonNetwork.ConnectUsingSettings("FairNSquare multiplayer v1");
		Debug.Log("Connected to a lobby");
			
	}

	void OnJoinedLobby ()
	{

		if(PhotonNetwork.connected == true)
		{
		serverSetup.SetActive(true);
		Debug.Log("Setting up a server manually...");
		}

	}


	public void JoinRandomRoom()
	{

		RoomInfo[] rooms = PhotonNetwork.GetRoomList();

		if(rooms.Length > 0)
		{
		PhotonNetwork.JoinRandomRoom();
		serverSetup.SetActive(false);
		}

		else
		{

			Debug.LogError("No rooms available");
			noRoomsObject.SetActive(true);

		}

	}

	void OnJoinedRoom ()
	{

		Debug.Log("Joined a room / " + PhotonNetwork.room.name.ToString());
		serverSetup.SetActive(false);
		noRoomsObject.SetActive(false);
		SpawnPlayer(PhotonNetwork.player.name.ToString());

	
	}

	void SpawnPlayer (string name)
	{

		GameObject myPlayer = (GameObject)PhotonNetwork.Instantiate("Player", spawn.transform.position, Quaternion.identity, 0);
		Debug.Log("Spawned player: " + PhotonNetwork.playerName.ToString());
		myPlayer.GetComponentInChildren<Camera>().enabled = true;
		((MonoBehaviour)myPlayer.GetComponent("FirstPersonController")).enabled = true;
		myPlayer.GetComponent<PlayerBehavior>().enabled = true;
		Debug.Log("Spawned player " + name.ToString());
		myPlayer.name = PhotonNetwork.playerName.ToString();

	}

}

NetworkPlayer (this takes care of syncing every players position and rotation across the network and it also makes them move smoothly)

using UnityEngine;
using System.Collections;

public class NetworkPlayer : Photon.MonoBehaviour 
{

	Vector3 realPosition = Vector3.zero;
	Quaternion realRotation = Quaternion.identity;

	
	void Update ()
	{

		if(photonView.isMine)
		{

			//Do nothing

		}

		else
		{

			transform.position = Vector3.Lerp (transform.position, realPosition, 0.2f);
			transform.rotation = Quaternion.Lerp (transform.rotation, realRotation, 0.2f);
			
		}


	}

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{

		if(stream.isWriting)
		{

			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);

		}

		if(stream.isReading)
		{

			realPosition = (Vector3)stream.ReceiveNext();
			realRotation = (Quaternion)stream.ReceiveNext();


		}

	}

}

World (this handles spawning new chunks and chooses random materials for them and it handles the seed as well)

using UnityEngine;
using System.Collections;

public class World : MonoBehaviour {

	public static World currentWorld;

	public Material[] materials;

	public bool randomChunkMaterials;

	public int chunkWidth = 20, chunkHeight = 20, seed = 0;
	public float viewRange = 30;

	public bool randomSeed;

	//public Chunk chunkFab;

	void Awake () {
	
		currentWorld = this;

		if(seed == 0 && randomSeed == true)
		{

			seed = Random.Range(0, int.MaxValue);

		}

	}

	void Update () {
		for(float x = transform.position.x - viewRange; x < transform.position.x + viewRange; x+= chunkWidth)
		{

			for(float z = transform.position.z - viewRange; z < transform.position.z + viewRange; z+= chunkWidth)
			{
				
				Vector3 pos = new Vector3 (x,0,z);
				pos.x = Mathf.Floor(pos.x / (float)chunkWidth) * chunkWidth;
				pos.z = Mathf.Floor(pos.z / (float)chunkWidth) * chunkWidth;

				Chunk chunk = Chunk.FindChunk(pos);
				if(chunk != null) continue;
		
				if(PhotonNetwork.connected == true && PhotonNetwork.room != null)
				{

					GameObject newChunk;

					newChunk = (GameObject)PhotonNetwork.Instantiate("Chunk", pos, Quaternion.identity, 0, null);

					if(randomChunkMaterials == true)
					{
						
						newChunk.GetComponent<Renderer>().material = materials[Random.Range(0, materials.Length)];
						
					}

				}


		   


				//chunk = (Chunk)Instantiate(chunkFab, pos, Quaternion.identity);
				//NewChunk(pos, Quaternion.identity);

			

			}

		}
	}



}

Id suggest creating a separate script named worldGen or something to handle the generation of the seed-based world. In this script’s update function you could have it check if you are connected to a room and then generate the world as long as you have the seed. It doesn’t matter if you are the master client or not in this script because you are just checking that the seed isn’t equal to 0 which is set by and RPC(other player control) or the masterclient script directly(master client control). Your worldGen script could contain the following:

 public GameObject masterClient;
int realSeed;

void Update(){
if(PhotonNetwork.inRoom && realSeed != 0){ //Make sure you are connected and have received the seed
//Generate world based off of the seed    
}


}

[RPC]
void receiveSeed(int seed){ //Get the seed from the master client in an RPC
//This RPC is called automatically since it's a "buffered" rpc
realSeed = seed;
}

and your master client script could be:

bool sent;
int seed;
public GameObject worldGen;
void Update(){
if(PhotonNetwork.inRoom && PhotonNetwork.isMasterClient && !sent){ 
/If i'm in a room, the master client, and i haven't already sent the seed
sent = true;
worldGen.realSeed= seed;
worldGen.GetComponent<PhotonView>().RPC("receiveSeed", PhotonTargets.OthersBuffered, seed);
//Others buffered means that anyone who joins later will get this RPC

}
}

The master client script sends out an RPC that is buffered for all later joining players and then sets its own world generation script’s seed. The RPC can be called even if the master client is the only player on the server. So the master client sends out the RPC for other players and then will generate its own level.

For a generic implementation:
Create two empty game objects in the hierarchy and name one “worldGen” and the other “MasterClient.” Add the appropriate scripts to both and then a photon view to each. You don’t need to observe any components at all. Just add your world generation code into the worldGen script in the if statement in the Update function.

You should probably have a mapchecker in your networkmanager script to make sure that you aren’t spawned until the map is generated