void WriteLinkKeyExpirationTime() { try { var now = DateTime.Now; var expirationTime = now + TimeSpan.FromSeconds(AvailabilityTime); PlayFabClientAPI.UpdateUserData( new UpdateUserDataRequest() { Data = new Dictionary <string, string>() { { LinkKeyExpirationTime, expirationTime.ToString("O", CultureInfo.InvariantCulture) } }, Permission = UserDataPermission.Private }, result => { onComplete((linkKey, expirationTime)); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void LinkCustomId() { try { PlayFabClientAPI.LinkCustomID( new LinkCustomIDRequest() { CustomId = linkKey }, result => { WriteLinkKeyExpirationTime(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IUser.Refresh(Action onComplete, Action onFailure) { try { PlayFabClientAPI.GetPlayerCombinedInfo( new GetPlayerCombinedInfoRequest() { InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true } }, result => { var loginResult = PlayFabAuth.LoginResult; loginResult.InfoResultPayload = result.InfoResultPayload; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IUser.SetAvatarUrl(string avatarUrl, Action onComplete, Action onFailure) { try { PlayFabClientAPI.UpdateAvatarUrl( new UpdateAvatarUrlRequest() { ImageUrl = avatarUrl }, result => { TitleInfo.AvatarUrl = avatarUrl; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IUser.SetName(string name, Action onComplete, Action onFailure) { try { PlayFabClientAPI.UpdateUserTitleDisplayName( new UpdateUserTitleDisplayNameRequest() { DisplayName = name }, result => { TitleInfo.DisplayName = result.DisplayName; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IApplicationData.Read <T>(Action <T> onComplete, Action onFailure) { try { PlayFabClientAPI.GetTitleData( new GetTitleDataRequest() { Keys = GetDataKeys <T>() }, result => { var data = DeserializeData <T>(result.Data); onComplete(data); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IAuth.Login(Action onComplete, Action onFailure) { SteamLogin(); void SteamLogin() { SteamAuth.Login(PlayFabLogin, onFailure); } void PlayFabLogin() { var authSessionTicket = SteamAuth.CreateAuthSessionTicket(); PlayFabSettings.TitleId = PlayFabAuth.TitleId; try { PlayFabClientAPI.LoginWithSteam( new LoginWithSteamRequest() { CreateAccount = true, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true }, SteamTicket = authSessionTicket, TitleId = PlayFabAuth.TitleId }, result => { PlayFabAuth.LoginResult = result; SteamAuth.DestroyAuthSessionTicket(authSessionTicket); onComplete(); }, error => { PlayFabErrorHandler.Process(error); SteamAuth.DestroyAuthSessionTicket(authSessionTicket); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } }
void IUserData.Read <T>(Action <T> onComplete, Action onFailure) { try { if (IsReadOnly(typeof(T))) { PlayFabClientAPI.GetUserReadOnlyData( new GetUserDataRequest() { Keys = GetDataKeys <T>() }, result => { var data = DeserializeData <T>(result.Data); onComplete(data); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } else { PlayFabClientAPI.GetUserData( new GetUserDataRequest() { Keys = GetDataKeys <T>() }, result => { var data = DeserializeData <T>(result.Data); onComplete(data); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IAuth.Login(Action onComplete, Action onFailure) { GooglePlayLogin(); void GooglePlayLogin() { GooglePlayAuth.Login(PlayFabLogin, onFailure); } void PlayFabLogin() { GooglePlayAuth.GetServerAuthCode( serverAuthCode => { PlayFabSettings.TitleId = PlayFabAuth.TitleId; try { PlayFabClientAPI.LoginWithGoogleAccount( new LoginWithGoogleAccountRequest() { CreateAccount = true, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true }, ServerAuthCode = serverAuthCode, TitleId = PlayFabAuth.TitleId }, result => { PlayFabAuth.LoginResult = result; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }, onFailure); } }
void IUserData.Write(object data, Action onComplete, Action onFailure) { var type = data.GetType(); var serializedData = SerializeData(data, type); var keysToRemove = new List <string>(); foreach (var item in serializedData) { if (string.IsNullOrWhiteSpace(item.Value)) { keysToRemove.Add(item.Key); } } foreach (var item in keysToRemove) { serializedData.Remove(item); } try { PlayFabClientAPI.UpdateUserData( new UpdateUserDataRequest() { Data = serializedData, KeysToRemove = keysToRemove, Permission = IsPublic(type) ? UserDataPermission.Public : UserDataPermission.Private }, result => { onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
public void Login() { var loginRequest = new LoginWithPlayFabRequest() { TitleId = PlayFabSettings.TitleId, Username = LoginUsernameField.text, Password = LoginPasswordField.text }; PlayFabClientAPI.LoginWithPlayFab(loginRequest, (result) => { LoginRegisterSuccess(result.PlayFabId, result.SessionTicket); }, (error) => { LoginErrorText.text = error.ErrorMessage; LoginErrorText.gameObject.transform.parent.gameObject.SetActive(true); PlayFabErrorHandler.HandlePlayFabError(error); }); }
public void Register() { var request = new RegisterPlayFabUserRequest() { TitleId = PlayFabSettings.TitleId, Username = RegUsernameField.text, Password = RegPasswordField.text, Email = RegEmailField.text }; PlayFabClientAPI.RegisterPlayFabUser(request, (result) => { LoginRegisterSuccess(result.PlayFabId, result.SessionTicket); }, (error) => { RegErrorText.text = error.ErrorMessage; RegErrorText.gameObject.transform.parent.gameObject.SetActive(true); PlayFabErrorHandler.HandlePlayFabError(error); }); }
void IAuth.Login(Action onComplete, Action onFailure) { PlayFabSettings.TitleId = PlayFabAuth.TitleId; try { PlayFabClientAPI.LoginWithIOSDeviceID( new LoginWithIOSDeviceIDRequest() { CreateAccount = true, DeviceId = SystemInfo.deviceUniqueIdentifier, DeviceModel = SystemInfo.deviceModel, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true }, OS = SystemInfo.operatingSystem, TitleId = PlayFabAuth.TitleId }, result => { PlayFabAuth.LoginResult = result; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IRefreshable.Refresh(Action onComplete, Action onFailure) { try { PlayFabClientAPI.GetPlayerCombinedInfo( new GetPlayerCombinedInfoRequest() { InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserVirtualCurrency = true } }, result => { var infoResultPayload = result.InfoResultPayload; VirtualCurrencies = infoResultPayload.UserVirtualCurrency ?? new Dictionary <string, int>(); VirtualCurrencyRechargeTimes = infoResultPayload.UserVirtualCurrencyRechargeTimes ?? new Dictionary <string, VirtualCurrencyRechargeTime>(); UpdateCurrencies(); onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
void IAuth.Login(Action onComplete, Action onFailure) { PlayFabSettings.TitleId = PlayFabAuth.TitleId; try { PlayFabClientAPI.LoginWithCustomID( new LoginWithCustomIDRequest() { CreateAccount = true, CustomId = CustomId, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true }, TitleId = PlayFabAuth.TitleId }, result => { PlayFabAuth.LoginResult = result; onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } }
protected override void PurchaseViaRealCurrency(IPurchasableItem purchasableProduct, Action onComplete, Action onFailure) { if (UApplication.isEditor) { var exception = new NotSupportedException("Steam purchases is don't work in the Editor!"); ExceptionHandler.Process(exception); onFailure(); return; } if (!SteamUtils.IsOverlayEnabled) { var exception = new NotSupportedException("Steam overlay is disabled!"); ExceptionHandler.Process(exception); onFailure(); return; } var playFabProduct = (IPlayFabProduct)purchasableProduct; var catalogItem = playFabProduct.CatalogItem; StartPurchase(); void StartPurchase() { try { PlayFabClientAPI.StartPurchase( new StartPurchaseRequest() { CatalogVersion = CatalogVersion, Items = new List <ItemPurchaseRequest>() { new ItemPurchaseRequest() { ItemId = catalogItem.ItemId, Quantity = 1 } }, StoreId = StoreId }, result => { PayForPurchase(result); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void PayForPurchase(StartPurchaseResult startPurchaseResult) { var paymentOptions = startPurchaseResult.PaymentOptions; var paymentOption = paymentOptions.Find(x => x.ProviderName == "Steam"); var payForPurchaseResult = default(PayForPurchaseResult); WaitMicroTxnAuthorizationResponse(() => ConfirmPurchase(payForPurchaseResult), onFailure); try { PlayFabClientAPI.PayForPurchase( new PayForPurchaseRequest() { Currency = paymentOption.Currency, OrderId = startPurchaseResult.OrderId, ProviderName = paymentOption.ProviderName }, result => { payForPurchaseResult = result; }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void ConfirmPurchase(PayForPurchaseResult payForPurchaseResult) { try { PlayFabClientAPI.ConfirmPurchase( new ConfirmPurchaseRequest() { OrderId = payForPurchaseResult.OrderId }, result => { onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } }
void IRefreshable.Refresh(Action onComplete, Action onFailure) { GetCatalogItems(); void GetCatalogItems() { try { PlayFabClientAPI.GetCatalogItems( new GetCatalogItemsRequest() { CatalogVersion = CatalogVersion }, result => { CatalogItems = result.Catalog; GetStoreItems(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void GetStoreItems() { if (string.IsNullOrWhiteSpace(StoreId)) { UpdateProducts(); onComplete(); return; } try { PlayFabClientAPI.GetStoreItems( new GetStoreItemsRequest() { CatalogVersion = CatalogVersion, StoreId = StoreId }, result => { StoreItems = result.Store; UpdateProducts(); onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } }
void IRefreshable.Refresh(Action onComplete, Action onFailure) { GetCatalogItems(); void GetCatalogItems() { try { PlayFabClientAPI.GetCatalogItems( new GetCatalogItemsRequest() { CatalogVersion = CatalogVersion }, result => { CatalogItems = result.Catalog; GetUserInventory(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void GetUserInventory() { try { PlayFabClientAPI.GetPlayerCombinedInfo( new GetPlayerCombinedInfoRequest() { InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserInventory = true } }, result => { var infoResultPayload = result.InfoResultPayload; var userInventory = infoResultPayload.UserInventory; ItemInstances = userInventory.ToDictionary(x => x.ItemInstanceId); UpdateItems(); onComplete(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } }
void IStore.LoadProducts(Action onComplete, Action onFailure) { var errorCount = 0; var invokeCount = 2; if (_getCatalogItemsResult == null) { try { PlayFabClientAPI.GetCatalogItems( new GetCatalogItemsRequest() { CatalogVersion = CatalogVersion }, result => { invokeCount -= 1; _getCatalogItemsResult = result; Handle(); }, error => { errorCount += 1; invokeCount -= 1; PlayFabErrorHandler.Process(error); Handle(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } else { invokeCount -= 1; Handle(); } if (_getStoreItemsResult == null && !string.IsNullOrWhiteSpace(StoreId)) { try { PlayFabClientAPI.GetStoreItems( new GetStoreItemsRequest() { CatalogVersion = CatalogVersion, StoreId = StoreId }, result => { invokeCount -= 1; _getStoreItemsResult = result; Handle(); }, error => { errorCount += 1; invokeCount -= 1; PlayFabErrorHandler.Process(error); Handle(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } else { invokeCount -= 1; Handle(); } void Handle() { if (invokeCount != 0) { return; } if (errorCount > 0) { onFailure(); } else { CreateProducts(); onComplete(); } } }
void ILink.Link(string linkKey, Action onComplete, Action onFailure) { var resultException = default(Exception); var sourceLoginResult = SteamPlayFabAuth.LoginResult; var targetLoginResult = default(LoginResult); LoginWithCustomId(); void LoginWithCustomId() { try { PlayFabClientAPI.LoginWithCustomID( new LoginWithCustomIDRequest() { CreateAccount = false, CustomId = linkKey, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() { GetUserAccountInfo = true }, TitleId = SteamPlayFabAuth.TitleId }, result => { targetLoginResult = result; SteamPlayFabAuth.LoginResult = result; UnlinkCustomId(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void UnlinkCustomId() { try { PlayFabClientAPI.UnlinkCustomID( new UnlinkCustomIDRequest() { CustomId = linkKey }, result => { CheckLinkKeyExpirationTime(); }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void CheckLinkKeyExpirationTime() { try { PlayFabClientAPI.GetUserData( new GetUserDataRequest() { Keys = new List <string>() { LinkKeyExpirationTime } }, result => { var data = result.Data; if (data.TryGetValue(LinkKeyExpirationTime, out var record)) { var now = DateTime.Now; var expirationTime = DateTime.Parse(record.Value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); if (now > expirationTime) { resultException = new Exception($"The \"{LinkKey}\" is out of date!"); Restore(); } else { CheckSteamId(); } } else { resultException = new Exception($"The \"{LinkKeyExpirationTime}\" is not found!"); Restore(); } }, error => { PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void CheckSteamId() { var targetSteamId = GetSteamId(targetLoginResult); if (targetSteamId == null) { LinkSteamAccount(); } else { var sourceSteamId = GetSteamId(sourceLoginResult); resultException = sourceSteamId == targetSteamId ? new Exception("The source account already linked to the target account!") : new Exception("The target account already has the linked account!"); Restore(); } } string GetSteamId(LoginResult loginResult) { var infoResultPayload = loginResult?.InfoResultPayload; var accountInfo = infoResultPayload?.AccountInfo; var steamId = accountInfo?.SteamInfo; return(steamId?.SteamId); } void LinkSteamAccount() { try { var authSessionTicket = SteamPlayFabAuth.CreateAuthSessionTicket(); PlayFabClientAPI.LinkSteamAccount( new LinkSteamAccountRequest() { ForceLink = true, SteamTicket = authSessionTicket }, result => { SteamPlayFabAuth.DestroyAuthSessionTicket(authSessionTicket); onComplete(); }, error => { SteamPlayFabAuth.DestroyAuthSessionTicket(authSessionTicket); PlayFabErrorHandler.Process(error); onFailure(); }); } catch (Exception exception) { ExceptionHandler.Process(exception); onFailure(); } } void Restore() { Logout(); void Logout() { SteamPlayFabAuth.Logout(Login, ProcessException); } void Login() { SteamPlayFabAuth.Login(ProcessException, ProcessException); } } void ProcessException() { ExceptionHandler.Process(resultException); onFailure(); } }