public async Task <IActionResult> UpdateCharacterLocation( [FromRoute(Name = "id")] int characterId, [FromBody] ZoneServerCharacterLocationSaveRequest saveRequest, [NotNull][FromServices] ICharacterLocationRepository locationRepository, [NotNull][FromServices] IZoneServerRepository zoneRepository) { if (locationRepository == null) { throw new ArgumentNullException(nameof(locationRepository)); } if (zoneRepository == null) { throw new ArgumentNullException(nameof(zoneRepository)); } //TODO: For HTTP callers we should maybe include better information. Though with message queue we can't respond. if (!await CheckZoneAuthorizedToModifyCharacterData(characterId)) { return(Forbid()); } //TODO: This could fail if we unregistered. More gracefully handle that case. //Get world, we need it for location ZoneInstanceEntryModel zoneEntry = await zoneRepository.RetrieveAsync(ClaimsReader.GetAccountIdInt(User)); //If world was deleted then they won't have location. //TODO: Is this the best way to deal with this? if (await locationRepository.ContainsAsync(characterId).ConfigureAwaitFalse()) { await locationRepository.UpdateAsync(characterId, BuildCharacterLocationFromSave(characterId, saveRequest, zoneEntry.WorldId)) .ConfigureAwaitFalseVoid(); } else { await locationRepository.TryCreateAsync(BuildCharacterLocationFromSave(characterId, saveRequest, zoneEntry.WorldId)) .ConfigureAwaitFalse(); } return(Ok()); }
public async Task SaveCharacterLocation(int characterId, ZoneServerCharacterLocationSaveRequest saveRequest) { await(await GetService().ConfigureAwaitFalse()).SaveCharacterLocation(characterId, saveRequest).ConfigureAwaitFalseVoid(); }
private static CharacterLocationModel BuildCharacterLocationFromSave(int characterId, ZoneServerCharacterLocationSaveRequest saveRequest, long mapId) { return(new CharacterLocationModel(characterId, saveRequest.Position.x, saveRequest.Position.y, saveRequest.Position.z, mapId)); }
public FullCharacterDataSaveRequest(bool shouldReleaseCharacterSession, bool isPositionSaved, [NotNull] ZoneServerCharacterLocationSaveRequest characterLocationData, [NotNull] EntityFieldDataCollection playerDataSnapshot) { ShouldReleaseCharacterSession = shouldReleaseCharacterSession; this.isPositionSaved = isPositionSaved; CharacterLocationData = characterLocationData ?? throw new ArgumentNullException(nameof(characterLocationData)); PlayerDataSnapshot = playerDataSnapshot ?? throw new ArgumentNullException(nameof(playerDataSnapshot)); //Snapshot current time. UtcTickTimeStamp = DateTime.UtcNow.Ticks; }