7. Master and game servers
Use two scenes for the server side. The master scene has MultiConnectMasterServer, and the game server scene has MultiConnectGameServer with Use As Master Server off, plus the scripts from Script 4.2. Clients connect only to the master, and MultiConnectSDK moves them to the right game server, so client code does not change.
A master on MultiConnectCloud needs no code. Do not write code to find game servers, and do not add an access key or an address list. The platform gives the master what it needs.
To test on one machine: give each scene a different Local Port, add the game server's IP and port under Game Server Instances on the master, keep Use Web Socket the same on both, start the game server first, then the master, and point the client at the master's port.
To deploy, tick the scenes under Master and Worker in Build and Deploy Server. Both builds always go out together, and they must use the same MultiConnectSDK version.
On demand
A new match starts its own game server, and players wait until it is ready. In your room, Script 7.1 closes the room when the match starts and ends the room when it is over.
Script 7.1: Ending an on-demand match
using MultiConnect.Server;
public class OnDemandMatch
{
private Room room;
public void OnMatchStarted() => room.isOpen = false;
public void OnMatchOver() => room.DestroyRoom();
}
The server exits 15 seconds after its last room ends, and billing stops. If it must do something after that, such as saving results, finish first or set McHostedServer.ExitWhenMatchEnds = false, and then exit yourself.
To decide when servers start, for a tournament for example, set McHostedMaster.ManageGameServersInCode = true in Awake, and use Script 7.2. Those servers keep running until you stop them, and they keep billing, so always stop them.
Script 7.2: Starting servers from code
using System.Threading.Tasks;
using MultiConnect;
using UnityEngine;
public class TournamentServers : MonoBehaviour
{
private McInstance server;
void Awake() => McHostedMaster.ManageGameServersInCode = true;
public async Task Open() => server = await McHostedMaster.StartGameServerAsync("tournament-1");
public async Task Close() => await McHostedMaster.StopGameServerAsync(server.InstanceId);
}

