private void OnMatchGet(GetMatchResult res) { serverIp = res.ServerDetails.IPV4Address; serverPort = res.ServerDetails.Ports[0].Num; Debug.Log($"Server Details - IP:{serverIp} | Port:{serverPort}"); int enemyIdx = res.Members.FindIndex(x => x.Entity.Id != loginManager.playerData.accountInfo.entityId); var enemyEntity = res.Members[enemyIdx].Entity; // Getting enemy name from entityid -> playfabid -> profilename var entityRequest = new GetEntityProfileRequest { Entity = new PlayFab.ProfilesModels.EntityKey { Id = enemyEntity.Id, Type = enemyEntity.Type } }; PlayFabProfilesAPI.GetProfile(entityRequest, entityRes => { var enemyPlayfabId = entityRes.Profile.Lineage.MasterPlayerAccountId; var profileRequest = new GetPlayerProfileRequest { PlayFabId = enemyPlayfabId }; PlayFabClientAPI.GetPlayerProfile(profileRequest, profileRes => { enemyName = profileRes.PlayerProfile.DisplayName; StartMatch(); }, OnError); }, OnError); }
public IEnumerator GetMatch() { ExecutionCompleted = false; PlayFabMultiplayerAPI.GetMatch( new GetMatchRequest { EscapeObject = QueueConfiguration.EscapeObject, MatchId = MatchmakingTicketStatus.MatchId, QueueName = QueueConfiguration.QueueName, ReturnMemberAttributes = QueueConfiguration.ReturnMemberAttributes, AuthenticationContext = PlayFabAuthenticationContext, }, (result) => { ExecutionCompleted = true; MatchResult = result; }, (error) => { var result = $"On GetMatch failed. Message: {error.ErrorMessage}, Code: {error.HttpCode}"; Debug.Log(result); } ); yield return(WaitForExecution()); }
private IEnumerator PreparePartyQuickMatch(GetMatchResult match) { var(playerOne, _) = GetPlayersFromMatch(match); var networkId = string.Empty; // The PlayerOne is the Party Network creator if (ApplicationModel.CurrentPlayer.Entity.Id == playerOne.Entity.Id) { // We ensure that player one isn't connected to any network if (!string.IsNullOrWhiteSpace(partyNetworkHandler.NetworkId)) { yield return(partyNetworkHandler.LeaveNetwork()); } yield return(StartCoroutine(partyNetworkHandler.CreateAndJoinToNetwork())); networkId = partyNetworkHandler.NetworkId; ApplicationModel.NetworkCreatorId = ApplicationModel.CurrentPlayer.Entity.Id; } matchmakingHandler.ChangeQueueConfiguration(QueueTypes.Party); // player one sends the networkId; player two sends an empty string. yield return(StartCoroutine(matchmakingHandler.CreateTicket(attribute: match.MatchId, networkId: networkId))); yield return(StartCoroutine(ProcessTicket(isPartyQuickMatch: true))); }
private void OnGetMatch(GetMatchResult result) { //storing the players IDs on the PlayersIDSaver two join them string p1 = result.Members[0].Attributes.DataObject.ToString(); string p2 = result.Members[1].Attributes.DataObject.ToString(); Debug.Log("..." + p1); Debug.Log("..." + p2); string p1ID = ""; string p2ID = ""; //reading the id of the two players for (int i = 7; i < p1.Length - 2; i++) { p1ID += p1[i]; } for (int i = 7; i < p2.Length - 2; i++) { p2ID += p2[i]; } Debug.Log(p1ID); Debug.Log(p2ID); idSaver.ManageIDs(p1ID, p2ID); //sending my selected level data to the other player EftClient.Send(Application.persistentDataPath + "/Multiplayer Levels/" + PlayerPrefs.GetString("selectedLevelName") + ".level", ID_Generator.ID_to_IP(PlayerPrefs.GetString("otherPlayerID")), 9999); matchmakingObjects.SetActive(false); gameplayObjects.SetActive(true); }
private void OnGetMatch(GetMatchResult getMatchResult) { // Get the server to join string ipString = getMatchResult.ServerDetails.IPV4Address; int tcpPort = 0; int udpPort = 0; // Get the ports and names to join foreach (Port port in getMatchResult.ServerDetails.Ports) { if (port.Name == playfabTCPPortName) { tcpPort = port.Num; } if (port.Name == playfabUDPPortName) { udpPort = port.Num; } } // Connect and initialize the DarkRiftClient, hand over control to the NetworkManager if (tcpPort != 0 && udpPort != 0) { drClient.ConnectInBackground(IPAddress.Parse(ipString), tcpPort, udpPort, true, delegate { OnPlayFabSessionCallback(); }); } }
private Match PrepareQuickMatch(GetMatchResult matchResult) { var match = new Match(); match.playerOneId = GetFirstPlayerToPlay(matchResult.Members[0].Entity.Id, matchResult.Members[1].Entity.Id); match.playerTwoId = matchResult.Members.FirstOrDefault(m => m.Entity.Id != match.playerOneId).Entity.Id; return(match); }
private string GetNetworkIdFromMatch(GetMatchResult match) { var(playerOne, playerTwo) = GetPlayersFromMatch(match); var playerOneData = JsonUtility.FromJson <PartyTicketAttributes>(playerOne?.Attributes?.DataObject.ToString() ?? "{}"); var playerTwoData = JsonUtility.FromJson <PartyTicketAttributes>(playerTwo?.Attributes?.DataObject.ToString() ?? "{}"); return(!string.IsNullOrWhiteSpace(playerOneData?.NetworkId) ? playerOneData?.NetworkId : (playerTwoData?.NetworkId)); }
private static async Task <GetMatchResult> GetFinalMatch(Player player, string mmQueueName) { var getRequest = new GetMatchRequest { QueueName = mmQueueName, MatchId = player.mmMatchId }; PlayFabResult <GetMatchResult> ticketResult = await player.mpApi.GetMatchAsync(getRequest); GetMatchResult match = VerifyPlayFabCall(ticketResult, "Failed to get final matchmake ticket"); player.match = match; Console.WriteLine($"{player.context.PlayFabId} matched: {match.MatchId}"); return(match); }
private IEnumerator ProcessPartyQuickMatch(GetMatchResult match) { ApplicationModel.CurrentMatchResult = match; var(playerOne, playerTwo) = GetPlayersFromMatch(match); if (playerTwo.Entity.Id == ApplicationModel.CurrentPlayer.Entity.Id) { // We ensure that player two isn't connected to any network if (!string.IsNullOrWhiteSpace(partyNetworkHandler.NetworkId)) { yield return(partyNetworkHandler.LeaveNetwork()); } var networkId = GetNetworkIdFromMatch(match); ApplicationModel.NetworkCreatorId = playerOne.Entity.Id; yield return(StartCoroutine(partyNetworkHandler.JoinNetwork(networkId))); } yield return(null); }
private (MatchmakingPlayerWithTeamAssignment playerOne, MatchmakingPlayerWithTeamAssignment playerTwo) GetPlayersFromMatch(GetMatchResult match) { var orderedPlayers = match?.Members?.OrderBy(member => member.Entity.Id).ToList() ?? new List <MatchmakingPlayerWithTeamAssignment>(); var playerOne = orderedPlayers?.ElementAtOrDefault(0) ?? null; var playerTwo = orderedPlayers?.ElementAtOrDefault(1) ?? null; return(playerOne, playerTwo); }