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); }
/// <summary> /// Retrieves the entity's profile. /// </summary> public static void GetProfile(GetEntityProfileRequest request, Action <GetEntityProfileResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; PlayFabHttp.MakeApiCall("/Profile/GetProfile", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context); }
/// <summary> /// Retrieves the entity's profile. /// </summary> public void GetProfile(GetEntityProfileRequest request, Action <GetEntityProfileResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) { throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn, "Must be logged in to call this method"); } PlayFabHttp.MakeApiCall("/Profile/GetProfile", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); }
/// <summary> /// Retrieves the entity's profile. /// </summary> /// <param name="DataAsObject">Determines whether the objects will be returned as an escaped JSON string or as a un-escaped JSON object. Default is JSON string. (Optional)</param> /// <param name="Entity">The entity to perform this action on. (Optional)</param> public static Task <GetEntityProfileResponse> GetProfile(bool?DataAsObject = default, EntityKey Entity = default, PlayFabAuthenticationContext customAuthContext = null, object customData = null, Dictionary <string, string> extraHeaders = null) { GetEntityProfileRequest request = new GetEntityProfileRequest() { DataAsObject = DataAsObject, Entity = Entity, }; var context = GetContext(customAuthContext); return(PlayFabHttp.MakeApiCallAsync <GetEntityProfileResponse>("/Profile/GetProfile", request, AuthType.EntityToken, customData, extraHeaders, context)); }
/// <summary> /// Fetch's an entity's profile from the PlayFab server /// </summary> /// <param name="callerEntityToken">The entity token of the entity profile being fetched</param> /// <returns>The entity's profile</returns> private static async Task <EntityProfileBody> GetEntityProfile(string callerEntityToken, EntityKey entity) { // Construct the PlayFabAPI URL for GetEntityProfile var getProfileUrl = GetServerApiUri("/Profile/GetProfile"); // Create the get entity profile request var profileRequest = new GetEntityProfileRequest { Entity = entity }; // Prepare the request headers var profileRequestContent = new StringContent(PlayFabSimpleJson.SerializeObject(profileRequest)); profileRequestContent.Headers.Add("X-EntityToken", callerEntityToken); profileRequestContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); PlayFabJsonSuccess <GetEntityProfileResponse> getProfileResponseSuccess = null; GetEntityProfileResponse getProfileResponse = null; // Execute the get entity profile request using (var profileResponseMessage = await httpClient.PostAsync(getProfileUrl, profileRequestContent)) { using (var profileResponseContent = profileResponseMessage.Content) { string profileResponseString = await profileResponseContent.ReadAsStringAsync(); // Deserialize the http response getProfileResponseSuccess = PlayFabSimpleJson.DeserializeObject <PlayFabJsonSuccess <GetEntityProfileResponse> >(profileResponseString); // Extract the actual get profile response from the deserialized http response getProfileResponse = getProfileResponseSuccess?.data; } } // If response object was not filled it means there was an error if (getProfileResponseSuccess?.data == null || getProfileResponseSuccess?.code != 200) { throw new Exception($"Failed to get Entity Profile: code: {getProfileResponseSuccess?.code}"); } return(getProfileResponse.Profile); }
/// <summary> /// Retrieves the entity's profile. /// </summary> public void GetProfile(GetEntityProfileRequest request, Action <GetEntityProfileResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { PlayFabHttp.MakeApiCall("/Profile/GetProfile", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, false, authenticationContext, ApiSettings); }
/// <summary> /// Retrieves the entity's profile. /// </summary> public static async Task <PlayFabResult <GetEntityProfileResponse> > GetProfileAsync(GetEntityProfileRequest request, object customData = null, Dictionary <string, string> extraHeaders = null) { if ((request?.AuthenticationContext?.EntityToken ?? PlayFabSettings.staticPlayer.EntityToken) == null) { throw new PlayFabException(PlayFabExceptionCode.EntityTokenNotSet, "Must call GetEntityToken before calling this method"); } var httpResult = await PlayFabHttp.DoPost("/Profile/GetProfile", request, "X-EntityToken", PlayFabSettings.staticPlayer.EntityToken, extraHeaders); if (httpResult is PlayFabError) { var error = (PlayFabError)httpResult; PlayFabSettings.GlobalErrorHandler?.Invoke(error); return(new PlayFabResult <GetEntityProfileResponse> { Error = error, CustomData = customData }); } var resultRawJson = (string)httpResult; var resultData = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <GetEntityProfileResponse> >(resultRawJson); var result = resultData.data; return(new PlayFabResult <GetEntityProfileResponse> { Result = result, CustomData = customData }); }