there is error while trying
await MatchmakerService.Instance.ApproveBackfillTicketAsync(backfillTicketID);
this is full code
private const string NA = "n/a";
public const int MAX_PLAYERS = 100;
private static string _allocationID;
private static bool _doBackFilling = false;
private static IServerQueryHandler _serverQueryHandler;
private static BackfillTicket _localBackfillTicket;
private static string _backfillTicketID;
private static bool AllowEnter
{
get
{
return NetworkManager.Instances.ElementAt(0).ServerManager.Clients.Count < MAX_PLAYERS;
}
}
public static async void StartServer(string externalServerIP, ushort serverPort)
{
Debug.Log(nameof(StartServer));
Debug.Log($"Init Server");
Camera.main.enabled = false;
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 30;
Debug.Log($"Start Server Connection");
var networkManager = NetworkManager.Instances.ElementAt(0);
networkManager.ServerManager.StartConnection(serverPort);
networkManager.ServerManager.OnRemoteConnectionState += OnRemoteConnectionState;
Debug.Log($"Start Server Services");
var option = new InitializationOptions();
option.SetEnvironmentName("production");
await UnityServices.InitializeAsync(option);
Debug.Log($"Start Server Query Handler");
var multiplayService = MultiplayService.Instance;
_serverQueryHandler = await multiplayService.StartServerQueryHandlerAsync(MAX_PLAYERS, "TestServer", NA, NA, NA);
Debug.Log("Ready Server For Players");
await multiplayService.ReadyServerForPlayersAsync();
Debug.Log("Get MatchMaker Payload");
var serverCallbacks = new MultiplayEventCallbacks();
serverCallbacks.Allocate -= OnMultiplayerAllocation;
serverCallbacks.Allocate += OnMultiplayerAllocation;
var sereverEvents = await multiplayService.SubscribeToServerEventsAsync(serverCallbacks);
var serverConfigs = multiplayService.ServerConfig;
Debug.Log($"Server ID[{serverConfigs.ServerId}]");
Debug.Log($"Server Allocation ID[{serverConfigs.AllocationId}]");
Debug.Log($"Server Port[{serverConfigs.Port}]");
Debug.Log($"Server Query Port[{serverConfigs.QueryPort}]");
Debug.Log($"Server Log Directory[{serverConfigs.ServerLogDirectory}]");
Debug.Log($"Wait for Allocation ID");
while (string.IsNullOrEmpty(_allocationID))
{
var configID = multiplayService.ServerConfig.AllocationId;
if (string.IsNullOrEmpty(configID) == false && string.IsNullOrEmpty(_allocationID))
{
Debug.Log($"Set Allocation ID With Config[{configID}]");
_allocationID = configID;
}
await UniTask.DelayFrame(100);
}
Debug.Log($"Get Payload Allocation");
var matchmakingResult = await MultiplayService.Instance.GetPayloadAllocationFromJsonAs<MatchmakingResults>();
Debug.Log("Start Backfill Ticket");
var backfillProperties = new BackfillTicketProperties(matchmakingResult.MatchProperties);
Debug.Log($"ID: {matchmakingResult.MatchId}, QueueName: {matchmakingResult.QueueName}, Properties: {backfillProperties}");
_localBackfillTicket = new BackfillTicket { Id = matchmakingResult.MatchId, Properties = backfillProperties };
_backfillTicketID = _localBackfillTicket.Id;
Debug.Log("Start Backfilling");
_doBackFilling = true;
await TryBackFilling(networkManager, _backfillTicketID);
_doBackFilling = false;
}
public static void UpdateServer()
{
if (_serverQueryHandler == null) { return; }
if (NetworkManager.Instances.ElementAt(0).IsServer == false) { return; }
_serverQueryHandler.CurrentPlayers = (ushort)NetworkManager.Instances.ElementAt(0).ServerManager.Clients.Count;
_serverQueryHandler.UpdateServerCheck();
}
private static async UniTask TryBackFilling(NetworkManager networkManager, string backfillTicketID)
{
Debug.Log(nameof(TryBackFilling));
while (_doBackFilling && AllowEnter)
{
Debug.Log($"BackfillTicket ID: {backfillTicketID}");
var matchmaker = MatchmakerService.Instance;
Debug.Log($"Matchmaker: {matchmaker}");
var localBackfillTicket = await MatchmakerService.Instance.ApproveBackfillTicketAsync(backfillTicketID);
Debug.Log($"Local BackfillTicket ID: {localBackfillTicket.Id}");
backfillTicketID = localBackfillTicket.Id;
await UniTask.DelayFrame(2000);
}
}
private static void OnRemoteConnectionState(NetworkConnection connection, RemoteConnectionStateArgs args)
{
Debug.Log(nameof(OnRemoteConnectionState));
var networkManager = NetworkManager.Instances.ElementAt(0);
switch (args.ConnectionState)
{
case RemoteConnectionState.Stopped:
if (networkManager.ServerManager.Clients.Count == 0)
{
Debug.Log("Server Stopp by all clients disconnecting");
Application.Quit();
break;
}
if (_doBackFilling == false && AllowEnter)
{
TryBackFilling(networkManager, _backfillTicketID).Forget();
}
break;
}
}
private static void OnMultiplayerAllocation(MultiplayAllocation allocation)
{
Debug.Log(nameof(OnMultiplayerAllocation));
Debug.Log($"Allocation ID [{allocation.AllocationId}]");
_allocationID = allocation.AllocationId;
}
this is error message
I spend too many time about this problem…
if some body know answer plz help me