Inheritance: PlayFabRequestCommon
Exemplo n.º 1
0
		/// <summary>
		/// Lists all of the characters that belong to a specific user.
		/// </summary>
		public static void GetAllUsersCharacters(ListUsersCharactersRequest request, GetAllUsersCharactersCallback resultCallback, ErrorCallback errorCallback)
		{
			if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");

			string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
			Action<string,string> callback = delegate(string responseStr, string errorStr)
			{
				ListUsersCharactersResult result = null;
				PlayFabError error = null;
				ResultContainer<ListUsersCharactersResult>.HandleResults(responseStr, errorStr, out result, out error);
				if(error != null && errorCallback != null)
				{
					errorCallback(error);
				}
				if(result != null)
				{
					
					if(resultCallback != null)
					{
						resultCallback(result);
					}
				}
			};
			PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Server/GetAllUsersCharacters", serializedJSON, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, callback);
		}
Exemplo n.º 2
0
        public void UserCharacter()
        {
            var request = new ServerModels.ListUsersCharactersRequest();
            request.PlayFabId = playFabId; // Received from client upon login
            var getCharsTask = PlayFabServerAPI.GetAllUsersCharactersAsync(request);
            getCharsTask.Wait();
            UUnitAssert.Null(getCharsTask.Result.Error, "Failed to GetChars");
            UUnitAssert.NotNull(getCharsTask.Result.Result, "Failed to GetChars");
            UUnitAssert.NotNull(getCharsTask.Result.Result.Characters, "Failed to GetChars");

            ServerModels.CharacterResult targetCharacter = null;
            foreach (var eachCharacter in getCharsTask.Result.Result.Characters)
                if (eachCharacter.CharacterName == CHAR_NAME)
                    targetCharacter = eachCharacter;

            if (targetCharacter == null)
            {
                // Create the targetCharacter since it doesn't exist
                var grantRequest = new ServerModels.GrantCharacterToUserRequest();
                grantRequest.PlayFabId = playFabId;
                grantRequest.CharacterName = CHAR_NAME;
                grantRequest.CharacterType = CHAR_TEST_TYPE;
                var grantTask = PlayFabServerAPI.GrantCharacterToUserAsync(grantRequest);
                grantTask.Wait();
                UUnitAssert.Null(grantTask.Result.Error, "Grant character failed");
                UUnitAssert.NotNull(grantTask.Result.Result, "Grant character failed");
                UUnitAssert.NotNull(grantTask.Result.Result.CharacterId, "Grant character failed");

                // Attempt to get characters again
                getCharsTask = PlayFabServerAPI.GetAllUsersCharactersAsync(request);
                getCharsTask.Wait();
                UUnitAssert.Null(getCharsTask.Result.Error, "Failed to GetChars");
                UUnitAssert.NotNull(getCharsTask.Result.Result, "Failed to GetChars");
                UUnitAssert.NotNull(getCharsTask.Result.Result.Characters, "Failed to GetChars");
                foreach (var eachCharacter in getCharsTask.Result.Result.Characters)
                    if (eachCharacter.CharacterName == CHAR_NAME)
                        targetCharacter = eachCharacter;
            }

            // Save the requested character
            UUnitAssert.NotNull(targetCharacter, "The test character did not exist, and was not successfully created");
        }
Exemplo n.º 3
0
		/// <summary>
		/// Lists all of the characters that belong to a specific user.
		/// </summary>
        public static async Task<PlayFabResult<ListUsersCharactersResult>> GetAllUsersCharactersAsync(ListUsersCharactersRequest request)
        {
            if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");

            object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Server/GetAllUsersCharacters", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
            if(httpResult is PlayFabError)
            {
                PlayFabError error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                    PlayFabSettings.GlobalErrorHandler(error);
                return new PlayFabResult<ListUsersCharactersResult>
                {
                    Error = error,
                };
            }
            string resultRawJson = (string)httpResult;

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<ListUsersCharactersResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			ListUsersCharactersResult result = resultData.data;
			
			
            return new PlayFabResult<ListUsersCharactersResult>
                {
                    Result = result
                };
        }