Best way to organize "wait for other"

Options
Need explain how to orainize "wait other players" staff. I have this scheme: a client connect to server with JoinRandomSession(filter, userToken). userToken contains info about connected client (Name, Rang etc). When Client connected, it's loaded lobby-scene and wait other users. On server-side, in LoadSceneRemoteDone, raised event for all connected clients - NewUserConnected with userToken field. The client which capture this event update lobby-scene with new info. When all clients connected - server force clients to load random level. And some questions: 1. Is it normal scheme for this or is there bettr solution? 2. If so, then how to send client LIST of connected users? So that every next connected client knows about those who connected earlier. 3. How to force clients to load level-scene (BoltNetwork.LoadScene? BoltNetwork.LoadSceneSync?) and where is better to do it?
Thanx in advanse!

Comments

  • ramonmelo
    Options
    Hello @exp ,
    1. Is it normal scheme for this or is there bettr solution?

    Yes, that is a good approach, I don't see a problem with it.
    2. If so, then how to send client LIST of connected users?

    On the server, you can get a list of all connected clients using the "BoltNetwork.Clients" (https://doc-api.photonengine.com/en/bolt/current/class_bolt_network.html#aea312d0125d97ccdb141fd16ceeb5e5e). You could, for example, serialize this list and send it to the other clients.

    Take a look at the Lobby Sample, it uses entities to sync lobby information among the players. That is another way.
    3. How to force clients to load level-scene (BoltNetwork.LoadScene? BoltNetwork.LoadSceneSync?)

    Using "BoltNetwork.LoadScene" (link) on the server will make all clients to change scene too.
    where is better to do it?

    You can call it wherever you want. There is no specific place to do so.

    --
    Ramon Melo
    Photon Bolt Team
  • exp
    Options
    Thanks, Ramon!
  • exp
    Options
    i'm just confused a little... Trying to serialize list of players with Unity JsonUtility and have no result. Result is string "{}". I understand that is not a Bolt problem, but if not too hard give a some point to solve this :-/
    My code:
    [Serializable]
    	public class GamePlayer
    	{
    		public string VersionId;
    		public string userName;
    	}
    
    	[Serializable]
    	public class PlayersCollection
    	{
    		[SerializeField]
    		private readonly List<GamePlayer> players = new List<GamePlayer>();
    
    		public void AddPlayer(GamePlayer _player)
    		{
    			if (!players.Contains(_player))
    				players.Add(_player);
    		}
    
    		public GamePlayer AddPlayer(UserToken _token)
    		{
    			GamePlayer player = new GamePlayer();
    			player.VersionId = _token.VersionId;
    			player.userName = _token.UserName;
    			AddPlayer(player);
    			return player;
    		}
    
    		public void RemovePlayer(GamePlayer _player)
    		{
    			players.Remove(_player);
    		}
    
    		public static class PlayersCollectionSerializer
            {
    			public static string serializePlayersCollection(PlayersCollection _collection)
    			{
    				return JsonUtility.ToJson(_collection);
    			}
    
    			public static PlayersCollection deserializePlayersCollection(string jsonData)
    			{
    				return JsonUtility.FromJson<PlayersCollection>(jsonData) as PlayersCollection;
    
    			}
    		}
    	}
    
  • exp
    Options
    Oh, its worked with just List<T> not with List in class