Esempio n. 1
0
        public async Task <IActionResult> UpdateCharacterLocation(
            [FromBody] ZoneServerCharacterLocationSaveRequest saveRequest,
            [NotNull][FromServices] ICharacterLocationRepository locationRepository)
        {
            if (locationRepository == null)
            {
                throw new ArgumentNullException(nameof(locationRepository));
            }

            int characterId = saveRequest.CharacterId;

            if (characterId <= 0 || !await CharacterRepository.ContainsAsync(characterId)
                .ConfigureAwait(false))
            {
                return(NotFound());
            }

            //TODO: Is this the best way to deal with this?
            if (await locationRepository.ContainsAsync(characterId).ConfigureAwait(false))
            {
                await locationRepository.UpdateAsync(characterId, BuildCharacterLocationFromSave(characterId, saveRequest))
                .ConfigureAwait(false);
            }
            else
            {
                await locationRepository.TryCreateAsync(BuildCharacterLocationFromSave(characterId, saveRequest))
                .ConfigureAwait(false);
            }

            return(Ok());
        }
Esempio n. 2
0
        //[AuthorizeJwt(GuardianApplicationRole.ZoneServer)] //TODO: Eventually we'll need to auth these zoneservers.
        public async Task <IActionResult> WorldTeleportCharacter([FromBody][NotNull] ZoneServerWorldTeleportCharacterRequest requestModel,
                                                                 [FromServices][NotNull] ICharacterLocationRepository characterLocationRepository,
                                                                 [FromServices][NotNull] IGameObjectBehaviourDataServiceClient <WorldTeleporterInstanceModel> worldTelporterDataClient,
                                                                 [FromServices][NotNull] IPlayerSpawnPointDataServiceClient playerSpawnDataClient)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException(nameof(requestModel));
            }
            if (characterLocationRepository == null)
            {
                throw new ArgumentNullException(nameof(characterLocationRepository));
            }
            if (worldTelporterDataClient == null)
            {
                throw new ArgumentNullException(nameof(worldTelporterDataClient));
            }
            if (playerSpawnDataClient == null)
            {
                throw new ArgumentNullException(nameof(playerSpawnDataClient));
            }

            //TODO: Right now there is no verification of WHO/WHAT is actually teleporting the player.
            //We need an authorization system with player-owned zone servers. So that we can determine
            //who is requesting to transfer the session and then verify that a player is even on
            //that zone server.
            ProjectVersionStage.AssertBeta();

            //We don't await so that we can get rolling on this VERY async multi-part process.
            //TODO: Handle failure
            ResponseModel <WorldTeleporterInstanceModel, SceneContentQueryResponseCode> teleporterInstanceResponse = await worldTelporterDataClient.GetBehaviourInstance(requestModel.WorldTeleporterId);

            //TODO: Handle failure
            ResponseModel <PlayerSpawnPointInstanceModel, SceneContentQueryResponseCode> pointInstanceResponse = await playerSpawnDataClient.GetSpawnPointInstance(teleporterInstanceResponse.Result.RemoteSpawnPointId);

            //Remove current location and update the new location.
            await characterLocationRepository.TryDeleteAsync(requestModel.CharacterGuid.EntityId);

            await characterLocationRepository.TryCreateAsync(new CharacterLocationModel(requestModel.CharacterGuid.EntityId,
                                                                                        pointInstanceResponse.Result.InitialPosition.x,
                                                                                        pointInstanceResponse.Result.InitialPosition.y,
                                                                                        pointInstanceResponse.Result.InitialPosition.z,
                                                                                        pointInstanceResponse.Result.WorldId));

            //TODO: Better indicate reason for failure.
            return(Ok());
        }
Esempio n. 3
0
        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());
        }