Search Unity

Resolved How to use IP and Port from Matchmaker result to get ServerID

Discussion in 'Matchmaker' started by dixnri, Dec 5, 2022.

  1. dixnri

    dixnri

    Joined:
    Mar 3, 2020
    Posts:
    7
    Hi,

    I just started to learn how to use Multiplay and Matchmaker for my Fusion ServerMode game.
    I have succeeded to get IP and Port of the server from MultiplayAssigntment by following MatchmakerTicketer sample. But to join the game server, Fusion client need to know the SessionName.

    Then I modify the build configuration to named my game server session with the $$ServerID$$, but how I supposed to do next to get the ServerID from matchmaker?

    I haven't found the documentation about it. I have tried to look at MatchPlay sample but it's using Netcode, then I look the Fusion battle royal sample but it's too advance for me, I can't understand and lost reading all the code.

    Really need help or if there is a sample or tutorial with simple project using Fusion ServerMode and Unity Matchmaker will be great. Thank you..
     
  2. tony040209_unity

    tony040209_unity

    Joined:
    Mar 21, 2021
    Posts:
    31
    Code (CSharp):
    1. public async void Start_MuiltyPlay()
    2. {
    3.     LogServerConfig();
    4.     m_MultiplayEventCallbacks = new MultiplayEventCallbacks();
    5.     m_MultiplayEventCallbacks.Allocate += OnAllocate;
    6.     m_MultiplayEventCallbacks.Deallocate += OnDeallocate;
    7.     m_MultiplayEventCallbacks.Error += OnError;
    8.     m_MultiplayEventCallbacks.SubscriptionStateChanged += OnSubscriptionStateChanged;
    9.     m_ServerEvents = await MultiplayService.Instance.SubscribeToServerEventsAsync(m_MultiplayEventCallbacks);
    10.  
    11.     if (!string.IsNullOrEmpty(MultiplayService.Instance.ServerConfig.AllocationId))
    12.     {
    13.         await StartGame();
    14.     }
    15. }
    16.  
    Code (CSharp):
    1. public async Task StartGame()
    2. {
    3.     matchmakingResults = await MultiplayService.Instance.GetPayloadAllocationFromJsonAs<MatchmakingResults>();
    4.  
    5.     string match_id = matchmakingResults.MatchId;
    6.  
    7.     Debug.Log("Fusion Sesion: "+ match_id);
    8.  
    9.     Photon_Manager.Instance.StartServer(match_id);
    10.  
    11.     while (!Photon_Manager.Instance.isConnect)
    12.     {
    13.         await Task.Delay(250);
    14.     }
    15.  
    16.     ReadyingServer();
    17. }
    18.  

    you can use
    GetPayloadAllocationFromJsonAs<MatchmakingResults>()
    The returned Match ID is used as the SessionName of Fusion