public SteamAchievementStorage(IAchievementRepository achievementRepository, IFileReader reader, StorageId storageId) { this.achievementRepository = achievementRepository; this.reader = reader; this.storageId = storageId; }
public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, ProgramId programId, StorageId storageId) { using ReferenceCountedDisposable <IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return(fsProxy.Target.GetRightsId(out rightsId, programId, storageId)); }
public async UniTask <bool> IncreaseStorageItems(StorageId storageId, CharacterItem addingItem) { #if UNITY_STANDALONE && !CLIENT_BUILD Storage storge = GetStorage(storageId, out _); AsyncResponseData <IncreaseStorageItemsResp> resp = await DbServiceClient.IncreaseStorageItemsAsync(new IncreaseStorageItemsReq() { StorageType = storageId.storageType, StorageOwnerId = storageId.storageOwnerId, WeightLimit = storge.weightLimit, SlotLimit = storge.slotLimit, Item = addingItem, }); if (!resp.IsSuccess || UITextKeys.NONE != resp.Response.Error) { // Error ocurring, storage may overwhelming let's it drop items to ground return(false); } SetStorageItems(storageId, resp.Response.StorageCharacterItems); NotifyStorageItemsUpdated(storageId.storageType, storageId.storageOwnerId); return(true); #else return(false); #endif }
public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, TitleId programId, StorageId storageId) { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); return(fsProxy.GetRightsId(out rightsId, programId, storageId)); }
public void ClearEntry(ulong titleId, NcaContentType contentType, StorageId storageId) { lock (_lock) { RemoveLocationEntry(titleId, contentType, storageId); } }
public async UniTask <DecreaseStorageItemsResult> DecreaseStorageItems(StorageId storageId, int dataId, short amount) { #if UNITY_STANDALONE && !CLIENT_BUILD Storage storge = GetStorage(storageId, out _); DecreaseStorageItemsReq req = new DecreaseStorageItemsReq(); req.StorageType = (EStorageType)storageId.storageType; req.StorageOwnerId = storageId.storageOwnerId; req.WeightLimit = storge.weightLimit; req.SlotLimit = storge.slotLimit; req.DataId = dataId; req.Amount = amount; DecreaseStorageItemsResp resp = await DbServiceClient.DecreaseStorageItemsAsync(req); if (UITextKeys.NONE != (UITextKeys)resp.Error) { // Error ocurring, storage may overwhelming let's it drop items to ground return(new DecreaseStorageItemsResult()); } SetStorageItems(storageId, DatabaseServiceUtils.MakeListFromRepeatedByteString <CharacterItem>(resp.StorageCharacterItems)); NotifyStorageItemsUpdated(storageId.storageType, storageId.storageOwnerId); Dictionary <int, short> decreasedItems = new Dictionary <int, short>(); foreach (ItemIndexAmountMap entry in resp.DecreasedItems) { decreasedItems.Add(entry.Index, (short)entry.Amount); } return(new DecreaseStorageItemsResult() { IsSuccess = true, DecreasedItems = decreasedItems, }); #else return(new DecreaseStorageItemsResult()); #endif }
/// <summary> /// Adds the loot bag items to the specified loot bag storage. /// </summary> /// <param name="storageId">loot bag storage ID</param> /// <param name="addingItems">items to add to loot bag</param> /// <returns>true if successful, false otherwise</returns> public async UniTask <bool> AddLootBagItems(StorageId storageId, List <CharacterItem> lootItems) { #if UNITY_STANDALONE && !CLIENT_BUILD // Attempt to read from storage first. This registers it and adds it to cache. ReadStorageItemsReq rsir = new ReadStorageItemsReq(); rsir.StorageType = storageId.storageType; rsir.StorageOwnerId = storageId.storageOwnerId; ReadStorageItemsResp rsiresp = await DbServiceClient.ReadStorageItemsAsync(rsir); foreach (CharacterItem lootItem in lootItems) { Storage storge = GetStorage(storageId, out _); IncreaseStorageItemsReq req = new IncreaseStorageItemsReq(); req.StorageType = storageId.storageType; req.StorageOwnerId = storageId.storageOwnerId; req.WeightLimit = storge.weightLimit; req.SlotLimit = storge.slotLimit; req.Item = lootItem; IncreaseStorageItemsResp resp = await DbServiceClient.IncreaseStorageItemsAsync(req); if (UITextKeys.NONE != resp.Error) { return(false); } SetStorageItems(storageId, resp.StorageCharacterItems); } return(true); #else return(false); #endif }
public async UniTask <DecreaseStorageItemsResult> DecreaseStorageItems(StorageId storageId, int dataId, short amount) { #if UNITY_STANDALONE && !CLIENT_BUILD Storage storge = GetStorage(storageId, out _); AsyncResponseData <DecreaseStorageItemsResp> resp = await DbServiceClient.DecreaseStorageItemsAsync(new DecreaseStorageItemsReq() { StorageType = storageId.storageType, StorageOwnerId = storageId.storageOwnerId, WeightLimit = storge.weightLimit, SlotLimit = storge.slotLimit, DataId = dataId, Amount = amount, }); if (!resp.IsSuccess || UITextKeys.NONE != resp.Response.Error) { // Error ocurring, storage may overwhelming let's it drop items to ground return(new DecreaseStorageItemsResult()); } SetStorageItems(storageId, resp.Response.StorageCharacterItems); NotifyStorageItemsUpdated(storageId.storageType, storageId.storageOwnerId); Dictionary <int, short> decreasedItems = new Dictionary <int, short>(); foreach (ItemIndexAmountMap entry in resp.Response.DecreasedItems) { decreasedItems.Add(entry.Index, (short)entry.Amount); } return(new DecreaseStorageItemsResult() { IsSuccess = true, DecreasedItems = decreasedItems, }); #else return(new DecreaseStorageItemsResult()); #endif }
/// <summary> /// Adds the loot bag items to the specified loot bag storage. /// </summary> /// <param name="storageId">loot bag storage ID</param> /// <param name="addingItems">items to add to loot bag</param> /// <returns>true if successful, false otherwise</returns> public async UniTask <bool> AddLootBagItems(StorageId storageId, List <CharacterItem> lootItems) { await UniTask.Yield(); foreach (CharacterItem lootItem in lootItems) { if (lootItem.IsEmptySlot()) { continue; } List <CharacterItem> storageItems = GetStorageItems(storageId); // Prepare storage data Storage storage = GetStorage(storageId, out _); bool isLimitWeight = storage.weightLimit > 0; bool isLimitSlot = storage.slotLimit > 0; short weightLimit = storage.weightLimit; short slotLimit = storage.slotLimit; // Increase item to storage bool isOverwhelming = storageItems.IncreasingItemsWillOverwhelming( lootItem.dataId, lootItem.amount, isLimitWeight, weightLimit, storageItems.GetTotalItemWeight(), isLimitSlot, slotLimit); if (!isOverwhelming && storageItems.IncreaseItems(lootItem)) { // Update slots storageItems.FillEmptySlots(isLimitSlot, slotLimit); SetStorageItems(storageId, storageItems); } } return(true); }
public Storage GetStorage(StorageId storageId, out uint objectId) { objectId = 0; Storage storage = default(Storage); switch (storageId.storageType) { case StorageType.Player: storage = GameInstance.Singleton.playerStorage; break; case StorageType.Guild: storage = GameInstance.Singleton.guildStorage; break; case StorageType.Building: StorageEntity buildingEntity; if (GameInstance.ServerBuildingHandlers.TryGetBuilding(storageId.storageOwnerId, out buildingEntity)) { objectId = buildingEntity.ObjectId; storage = buildingEntity.Storage; } break; } return(storage); }
public bool CanAccessStorage(IPlayerCharacterData playerCharacter, StorageId storageId) { switch (storageId.storageType) { case StorageType.Player: if (!playerCharacter.UserId.Equals(storageId.storageOwnerId)) { return(false); } break; case StorageType.Guild: if (!GameInstance.ServerGuildHandlers.ContainsGuild(playerCharacter.GuildId) || !playerCharacter.GuildId.ToString().Equals(storageId.storageOwnerId)) { return(false); } break; case StorageType.Building: StorageEntity buildingEntity; if (!GameInstance.ServerBuildingHandlers.TryGetBuilding(storageId.storageOwnerId, out buildingEntity) || !(buildingEntity.IsCreator(playerCharacter.Id) || buildingEntity.CanUseByEveryone)) { return(false); } break; } return(true); }
public void NotifyStorageItemsUpdated(StorageType storageType, string storageOwnerId) { #if UNITY_STANDALONE && !CLIENT_BUILD StorageId storageId = new StorageId(storageType, storageOwnerId); GameInstance.ServerGameMessageHandlers.NotifyStorageItemsToClients(usingStorageClients[storageId], GetStorageItems(storageId)); #endif }
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage public long OpenDataStorageByDataId(ServiceCtx context) { StorageId storageId = (StorageId)context.RequestData.ReadByte(); byte[] padding = context.RequestData.ReadBytes(7); long titleId = context.RequestData.ReadInt64(); ContentType contentType = ContentType.Data; StorageId installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId); if (installedStorage == StorageId.None) { contentType = ContentType.PublicData; installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId); } if (installedStorage != StorageId.None) { string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType); string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(installPath)) { string ncaPath = installPath; if (File.Exists(ncaPath)) { try { LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open); Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); MakeObject(context, new IStorage(romfsStorage)); } catch (HorizonResultException ex) { return(ex.ResultValue.Value); } return(0); } else { throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`."); } } else { throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}."); } } throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}."); }
// OpenLocationResolver() private long OpenLocationResolver(ServiceCtx Context) { StorageId StorageId = (StorageId)Context.RequestData.ReadByte(); MakeObject(Context, new ILocationResolver(StorageId)); return(0); }
// OpenLocationResolver() public ResultCode OpenLocationResolver(ServiceCtx context) { StorageId storageId = (StorageId)context.RequestData.ReadByte(); MakeObject(context, new ILocationResolver(storageId)); return(ResultCode.Success); }
public ProgramInfo(FileSystemServer fsServer, ulong processId, ProgramId programId, StorageId storageId, ReadOnlySpan <byte> accessControlData, ReadOnlySpan <byte> accessControlDescriptor) { ProcessId = processId; AccessControl = new AccessControl(fsServer, accessControlData, accessControlDescriptor); ProgramId = programId; StorageId = storageId; }
public IStorage?GetStorage(StorageId storageId) { if (storages.TryGetValue(storageId, out var storage)) { return(storage); } return(null); }
public bool TryGetOpenedStorageId(long connectionId, out StorageId storageId) { #if UNITY_STANDALONE && !CLIENT_BUILD return(usingStorageIds.TryGetValue(connectionId, out storageId)); #else storageId = default; return(false); #endif }
public void setStorageId(StorageId newStorageId) { Validator.ThrowIfNull(() => newStorageId); if (newStorageId != StorageId) { StorageId = newStorageId; ReadModel.StorageId = newStorageId.Value; } }
private async Task DeleteAccountAsync(Device remoteDevice, HardwareVaultTask task) { var account = await _accountService.GetAccountByIdNoTrackingAsync(task.AccountId); bool isPrimary = account.Employee.PrimaryAccountId == task.AccountId; var storageId = new StorageId(account.StorageId); var pm = new DevicePasswordManager(remoteDevice, null); await pm.DeleteAccount(storageId, isPrimary); }
public void SetStorageItems(StorageId storageId, List <CharacterItem> items) { #if UNITY_STANDALONE && !CLIENT_BUILD if (!storageItems.ContainsKey(storageId)) { storageItems.TryAdd(storageId, new List <CharacterItem>()); } storageItems[storageId] = items; #endif }
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage public long OpenDataStorageByDataId(ServiceCtx Context) { StorageId StorageId = (StorageId)Context.RequestData.ReadByte(); byte[] Padding = Context.RequestData.ReadBytes(7); long TitleId = Context.RequestData.ReadInt64(); StorageId InstalledStorage = Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.Data, StorageId); if (InstalledStorage == StorageId.None) { InstalledStorage = Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.AocData, StorageId); } if (InstalledStorage != StorageId.None) { string ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData); if (string.IsNullOrWhiteSpace(ContentPath)) { ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData); } string InstallPath = Context.Device.FileSystem.SwitchPathToSystemPath(ContentPath); if (!string.IsNullOrWhiteSpace(InstallPath)) { string NcaPath = InstallPath; if (File.Exists(NcaPath)) { FileStream NcaStream = new FileStream(NcaPath, FileMode.Open, FileAccess.Read); Nca Nca = new Nca(Context.Device.System.KeySet, NcaStream, false); NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs); Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel); MakeObject(Context, new IStorage(RomfsStream)); return(0); } else { throw new FileNotFoundException($"No Nca found in Path `{NcaPath}`."); } } else { throw new DirectoryNotFoundException($"Path for title id {TitleId:x16} on Storage {StorageId} was not found in Path {InstallPath}."); } } throw new FileNotFoundException($"System archive with titleid {TitleId:x16} was not found on Storage {StorageId}. Found in {InstalledStorage}."); }
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage public long OpenDataStorageByDataId(ServiceCtx context) { StorageId storageId = (StorageId)context.RequestData.ReadByte(); byte[] padding = context.RequestData.ReadBytes(7); long titleId = context.RequestData.ReadInt64(); StorageId installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, ContentType.Data, storageId); if (installedStorage == StorageId.None) { installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, ContentType.AocData, storageId); } if (installedStorage != StorageId.None) { string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, ContentType.AocData); if (string.IsNullOrWhiteSpace(contentPath)) { contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, ContentType.AocData); } string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(installPath)) { string ncaPath = installPath; if (File.Exists(ncaPath)) { FileStream ncaStream = new FileStream(ncaPath, FileMode.Open, FileAccess.Read); Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false); NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs); Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel); MakeObject(context, new IStorage(romfsStream)); return(0); } else { throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`."); } } else { throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}."); } } throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}."); }
public IStorage AddStorage(Func <StorageId, IStorage> storageConstructor) { var id = new StorageId(storages.Count); var storage = storageConstructor.Invoke(id); Debug.Assert(storage.StorageId == id, "Storage constructor must set its id to given storage id argument."); storages.Add(id, storage); return(storage); }
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/> /// <see cref="ResultFs.InvalidArgument"/>: The process ID is already registered.<br/> /// <see cref="ResultFs.PermissionDenied"/>: Insufficient permissions.</returns> /// <inheritdoc cref="ProgramRegistryManager.RegisterProgram"/> public Result RegisterProgram(ulong processId, ProgramId programId, StorageId storageId, ReadOnlySpan <byte> accessControlData, ReadOnlySpan <byte> accessControlDescriptor) { if (!ProgramInfo.IsInitialProgram(_processId)) { return(ResultFs.PermissionDenied.Log()); } return(_registryService.RegisterProgram(processId, programId, storageId, accessControlData, accessControlDescriptor)); }
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/> /// <see cref="ResultFs.InvalidArgument"/>: The process ID is already registered.<br/> /// <see cref="ResultFs.PermissionDenied"/>: Insufficient permissions.</returns> /// <inheritdoc cref="ProgramRegistryManager.RegisterProgram"/> public Result RegisterProgram(ulong processId, ProgramId programId, StorageId storageId, InBuffer accessControlData, InBuffer accessControlDescriptor) { if (!ProgramInfo.IsInitialProgram(_processId)) { return(ResultFs.PermissionDenied.Log()); } return(Globals.ServiceImpl.RegisterProgramInfo(processId, programId, storageId, accessControlData.Buffer, accessControlDescriptor.Buffer)); }
private async Task SetAccountAsPrimaryAsync(Device remoteDevice, HardwareVaultTask task) { var account = await _accountService.GetAccountByIdNoTrackingAsync(task.AccountId); var storageId = new StorageId(account.StorageId); var pm = new DevicePasswordManager(remoteDevice, null); await pm.SaveOrUpdateAccount(storageId, task.Timestamp, null, null, null, null, null, null, true, new AccountFlagsOptions() { IsReadOnly = true }); }
public override bool IsStorageEntityOpen(StorageEntity storageEntity) { if (storageEntity == null) { return(false); } StorageId id = new StorageId(StorageType.Building, storageEntity.Id); return(usingStorageCharacters.ContainsKey(id) && usingStorageCharacters[id].Count > 0); }
public List <CharacterItem> GetStorageItems(StorageId storageId) { #if UNITY_STANDALONE && !CLIENT_BUILD if (!storageItems.ContainsKey(storageId)) { storageItems.TryAdd(storageId, new List <CharacterItem>()); } return(storageItems[storageId]); #else return(new List <CharacterItem>()); #endif }
/// <summary> /// Request handler for moving all items from storage to player for LAN mode. /// </summary> /// <param name="requestHandler">request handler data</param> /// <param name="request">request</param> /// <param name="result">result</param> public async UniTaskVoid HandleRequestMoveAllItemsFromStorage(RequestHandlerData requestHandler, RequestMoveAllItemsFromStorageMessage request, RequestProceedResultDelegate <ResponseMoveAllItemsFromStorageMessage> result) { StorageId storageId = new StorageId(request.storageType, request.storageOwnerId); IPlayerCharacterData playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.Invoke(AckResponseCode.Error, new ResponseMoveAllItemsFromStorageMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } if (!GameInstance.ServerStorageHandlers.CanAccessStorage(playerCharacter, storageId)) { result.Invoke(AckResponseCode.Error, new ResponseMoveAllItemsFromStorageMessage() { message = UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE, }); return; } // Get items from storage List <CharacterItem> storageItems = GameInstance.ServerStorageHandlers.GetStorageItems(storageId); // Prepare storage data Storage storage = GameInstance.ServerStorageHandlers.GetStorage(storageId, out _); bool isLimitSlot = storage.slotLimit > 0; short slotLimit = storage.slotLimit; for (int i = storageItems.Count; i > 0; i--) { UITextKeys gameMessage; if (!playerCharacter.MoveItemFromStorage(isLimitSlot, slotLimit, storageItems, i - 1, storageItems[i - 1].amount, InventoryType.NonEquipItems, -1, 0, out gameMessage)) { result.Invoke(AckResponseCode.Error, new ResponseMoveAllItemsFromStorageMessage() { message = gameMessage, }); break; } else { GameInstance.ServerStorageHandlers.SetStorageItems(storageId, storageItems); } } GameInstance.ServerStorageHandlers.NotifyStorageItemsUpdated(request.storageType, request.storageOwnerId); // Success result.Invoke(AckResponseCode.Success, new ResponseMoveAllItemsFromStorageMessage()); await UniTask.Yield(); }