protected override void OnEventFired(object source, EventArgs args)
        {
            //Once connection to the instance server is established
            //we must attempt to claim out session on to actually fully enter.
            EventQueueable.Enqueue(async() =>
            {
                try
                {
                    CharacterListResponse listResponse = await CharacterService.GetCharacters();

                    await CharacterService.TryEnterSession(listResponse.CharacterIds.First());

                    CharacterDataRepository.UpdateCharacterId(listResponse.CharacterIds.First());

                    //TODO: When it comes to community servers, we should not expose the sensitive JWT to them. We need a better way to deal with auth against untrusted instance servers
                    await SendService.SendMessage(new ClientSessionClaimRequestPayload(AuthTokenRepository.RetrieveWithType(), listResponse.CharacterIds.First()));
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Failed to authenticate to instance server as character. Reason: {e.ToString()}");
                    }

                    throw;
                }
            });
        }
Пример #2
0
        public async Task Test_Get_Characters_Contains_No_Characters_Added_From_Other_Account([Range(1, 20)] int count)
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            List <string> names = await AddTestValuesToRepository(count, serviceProvider, 2);

            //act
            CharacterListResponse response = await controller.GetCharacters();

            //assert
            Assert.AreEqual(0, response.CharacterIds.Count, $"Expected NO characters to be provided. They're all under a different account. This is CRITICAL!");
            Assert.True(response.ResultCode == CharacterListResponseCode.NoCharactersFoundError);
            Assert.False(response.isSuccessful);
        }
Пример #3
0
        public async Task Test_Get_Characters_Contains_Same_Size_As_Characters_Added([Range(1, 20)] int count)
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            List <string> names = await AddTestValuesToRepository(count, serviceProvider);

            //act
            CharacterListResponse response = await controller.GetCharacters();

            //assert
            Assert.AreEqual(count, response.CharacterIds.Count);
            Assert.True(response.ResultCode == CharacterListResponseCode.Success);
            Assert.True(response.isSuccessful);
        }
Пример #4
0
        public async Task Test_Get_Characters_Empty_Datastore_Produces_Empty_Character_Result()
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            //act
            CharacterListResponse response = await controller.GetCharacters();

            //assert
            Assert.NotNull(response);
            Assert.NotNull(response.CharacterIds);
            Assert.True(response.CharacterIds.Count == 0);
            Assert.True(response.ResultCode == CharacterListResponseCode.NoCharactersFoundError);
            Assert.False(response.isSuccessful);
        }
Пример #5
0
        /// <inheritdoc />
        public async Task OnGameInitialized()
        {
            try
            {
                CharacterListResponse listResponse = await CharacterServiceQueryable.GetCharacters()
                                                     .ConfigureAwaitFalse();

                //TODO: Handle errors
                foreach (var character in listResponse.CharacterIds)
                {
                    var entityGuid = new NetworkEntityGuidBuilder()
                                     .WithId(character)
                                     .WithType(EntityType.Player)
                                     .Build();

                    //TODO: Optimize below awaits.
                    //Do a namequery so it's in the cache for when anything tries to get entities name.
                    await EntityNameQueryable.RetrieveAsync(entityGuid)
                    .ConfigureAwaitFalse();

                    var appearanceResponse = await CharacterServiceQueryable.GetCharacterAppearance(entityGuid.EntityId)
                                             .ConfigureAwaitFalse();

                    var characterData = await CharacterServiceQueryable.GetCharacterData(entityGuid.EntityId)
                                        .ConfigureAwaitFalse();

                    //Don't throw, because we actually don't want to stop the
                    //character screen from working just because we can't visually display some stuff.
                    if (!appearanceResponse.isSuccessful)
                    {
                        Logger.Error($"Failed to query for Character: {entityGuid.EntityId} appearance. Reason: {appearanceResponse.ResultCode}");
                    }

                    //TODO: Handle errors.
                    CharacterAppearanceMappable.AddObject(entityGuid, appearanceResponse.Result);
                    InitialCharacterDataInstance.AddObject(entityGuid, characterData.Result);

                    OnCharacterSelectionEntryChanged?.Invoke(this, new CharacterSelectionEntryDataChangeEventArgs(entityGuid));
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Encountered Error: {e.Message}");
                throw;
            }
        }