public IEnumerator Get(string sharedGroupId) { ExecutionCompleted = false; SharedGroupData = null; var request = GetExecuteFunctionRequest( Constants.GET_SHARED_GROUP, new GetSharedGroupRequest { SharedGroupId = sharedGroupId }); PlayFabCloudScriptAPI.ExecuteFunction(request, (result) => { SharedGroupData = result?.FunctionResult != null ? JsonUtility.FromJson <TicTacToeSharedGroupData>(result.FunctionResult.ToString()) : null; ExecutionCompleted = true; }, (error) => { SharedGroupData = null; ExecutionCompleted = true; Debug.Log($"Shared Group get request failed. Message: {error.ErrorMessage}, Code: {error.HttpCode}"); } ); yield return(WaitForExecution()); }
public IEnumerator JoinMatch() { ExecutionCompleted = false; var request = GetExecuteFunctionRequest( Constants.JOIN_MATCH_FUNCTION_NAME, new StartMatchRequest { SharedGroupId = sharedGroupId }); PlayFabCloudScriptAPI.ExecuteFunction(request, (result) => { ExecutionCompleted = true; TicTacToeSharedGroupData = JsonUtility.FromJson <TicTacToeSharedGroupData>(result.FunctionResult.ToString()); }, (error) => { TicTacToeSharedGroupData = null; ExecutionCompleted = true; Debug.Log($"StartMatch request failed. Message: {error.ErrorMessage}, Code: {error.HttpCode}"); } ); yield return(WaitForExecution()); }
public static async Task <TicTacToeSharedGroupData> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log) { var context = await FunctionContext <CreateSharedGroupRequest> .Create(req); // We have to use the MasterPlayerAccountId instead of the TitlePlayerAccountId to avoid errors during its addition as member of SGD var playerOne = context.CallerEntityProfile.Lineage.MasterPlayerAccountId; var sgdResponse = await SharedGroupDataUtil.CreateAsync(context.AuthenticationContext, context.FunctionArgument.SharedGroupId); await SharedGroupDataUtil.AddMembersAsync(context.AuthenticationContext, context.FunctionArgument.SharedGroupId, new List <string> { playerOne }); var sharedGroupData = new TicTacToeSharedGroupData { SharedGroupId = sgdResponse.SharedGroupId, Match = new Match { PlayerOneId = playerOne } }; return(await SharedGroupDataUtil.UpdateAsync(context.AuthenticationContext, sharedGroupData)); }
public static async Task <TicTacToeSharedGroupData> CreateMatchLobby(PlayFabAuthenticationContext authenticationContext, string sharedGroupId, string playerOne, IAsyncCollector <MatchLobby> matchlobbyCollection) { var sharedGroupData = new TicTacToeSharedGroupData { SharedGroupId = sharedGroupId, Match = new Match { PlayerOneId = playerOne }, MatchLobby = new MatchLobby { MatchLobbyId = sharedGroupId, CurrentAvailability = 1 } }; var sharedGroupDataUpdated = await SharedGroupDataUtil.UpdateAsync(authenticationContext, sharedGroupData); await matchlobbyCollection.AddAsync(sharedGroupDataUpdated.MatchLobby); return(sharedGroupDataUpdated); }
private static Dictionary <string, string> ConvertSharedGroupDataToStringDictionary(TicTacToeSharedGroupData data, string entryName) { var dictionary = new Dictionary <string, string>(); var JsonData = JsonConvert.SerializeObject(data); dictionary.Add(entryName, JsonData); return(dictionary); }
public static async Task <TicTacToeSharedGroupData> UpdateAsync(PlayFabAuthenticationContext context, TicTacToeSharedGroupData data) { var request = new UpdateSharedGroupDataRequest { AuthenticationContext = context, Data = ConvertSharedGroupDataToStringDictionary(data, Constants.SHARED_GROUP_DATA_DICTIONARY_ENTRY_NAME), SharedGroupId = data.SharedGroupId }; await GetPlayFabServerInstanceAPI().UpdateSharedGroupDataAsync(request); return(data); }