About session and StartServer/client

I'm making a 1v1 game using Bolt. Gameplay works well. I don't use headless server, so one player will play as "Server".

Now I'm designing the matchmaking part. I'm planning to make the matchmaking like Hearthstone, where players just need to click start game.

I want to use the codes mentioned here "https://doc.photonengine.com/en-us/bolt/current/troubleshooting/faq", let the user to join a session, if there's no available session, then create one.

public class Menu : Bolt.GlobalEventListener
{
    private Coroutine _timerRoutine;

    // ...

    public override void BoltStartDone()
    {
        // ...

        if (BoltNetwork.IsClient)
        {
            // This will start a server after 10secs of wait if no server was found
            _timerRoutine = StartCoroutine(ShutdownAndStartServer());
        }
    }

    public override void BoltShutdownBegin(AddCallback registerDoneCallback)
    {
        registerDoneCallback(() =>
        {
            BoltLauncher.StartServer();
        });
    }

    public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
    {
        // Stop background routine if a server was found
        if (_timerRoutine != null)
        {
            StopCoroutine(_timerRoutine);
            _timerRoutine = null;
        }
    }
}

However I got confused about the relationship between concept of StartServer/StartClient and joint/createSession. Here're my questions:

1 Do I need to call BoltLauncher.StartServer()/StartClient() before joining or creating sessions?
2 Is the client who call StartServer() the only one that can create a session?
3 If so, and in order to use the codes logit quoted above, how do I decide which one to call StartServer before the codes above executed?

Thank you!

Comments

  • Hi,
    1 Do I need to call BoltLauncher.StartServer()/StartClient() before joining or creating sessions?

    Yes, only after you start Bolt it will connect to Photon Cloud, so you can either create or join a session.
    2 Is the client who call StartServer() the only one that can create a session?

    Yes, only the Server is able to create a Session. Bolt is Server-Client, so you need to start as a server in order to start a game session.
    3 If so, and in order to use the codes logit quoted above, how do I decide which one to call StartServer before the codes above executed?

    You should start as a client, listen for available sessions, if not found, then start as a server.
    Here is a complete Menu script that does just that: https://github.com/BoltEngine/Bolt-Sample/blob/master/GettingStarted/Scripts/Menu.cs

    It can be found in the Getting Started sample included on the Bolt SDK.

    --
    Ramon Melo
    Photon Bolt Team
  • @ramonmelo So I did understand it right. Thank you, it's very helpful!
  • SPF
    SPF
    edited April 2021
    @ramonmelo I've downloaded Bolt-Sample-master here https://github.com/BoltEngine/Bolt-Sample/tree/master/GettingStarted, how do I open it in Unity?
    Adding the folder of Bolt-Sample-master or adding the foldder GettingStarted in unityHub doesn't work.
    Update
    Found the samples under packages folder.