示例#1
0
        public static async Task Test_Controller_Produces_AlreadyHasActiveSession_When_Session_Has()
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 1);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            ICharacterLocationRepository characterLocationRepo = serviceProvider.GetService <ICharacterLocationRepository>();
            IZoneServerRepository        zoneRepository        = serviceProvider.GetService <IZoneServerRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(1, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, 0));

            //We can't create the claimed session through this interface because it's a stored procedure.
            //Raw SQL can't execute. So we must interact directly with the DbSet
            //await sessionRepo.TryClaimUnclaimedSession(1, 1);
            CharacterDatabaseContext context = serviceProvider.GetService <CharacterDatabaseContext>();
            await context.ClaimedSession.AddAsync(new ClaimedSessionsModel(1));

            await context.SaveChangesAsync();

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1, characterLocationRepo, zoneRepository);

            //assert
            Assert.False(response.isSuccessful, $"Characters that already have ");
            Assert.AreEqual(CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession, response.ResultCode);
        }
示例#2
0
		protected override void OnEventFired(object source, ButtonClickedEventArgs args)
		{
			args.Button.IsInteractable = false;

			UnityAsyncHelper.UnityMainThreadContext.PostAsync(async () =>
			{
				if(SelectedCharacterGuid == null)
				{
					Logger.Error($"Tried to enter the world without any selected character guid.");
					return;
				}

				//We do this before sending the player login BECAUSE of a race condition that can be caused
				//since I actually KNOW this event should disable networking. We should not handle messages in this scene after this point basically.
				//TODO: Don't hardcode this scene.
				OnServerRequestedSceneChange?.Invoke(this, new ServerRequestedSceneChangeEventArgs((PlayableGameScene) 2));

				CharacterSessionEnterResponse enterResponse = await CharacterServiceQueryable.TryEnterSession(SelectedCharacterGuid.EntityId);

				if (Logger.IsDebugEnabled)
					Logger.Debug($"Character Session Entry Response: {enterResponse.ResultCode}.");

				if (!enterResponse.isSuccessful)
					if (Logger.IsErrorEnabled)
						Logger.Error($"Failed to enter CharacterSession for Entity: {SelectedCharacterGuid} Reason: {enterResponse.ResultCode}");

				//TODO: handle character session failure
				CharacterData.UpdateCharacterId(SelectedCharacterGuid.EntityId);

				//TODO: Use the scene manager service.
				//TODO: Don't hardcode scene ids. Don't load scenes directly.
				SceneManager.LoadSceneAsync(GladMMOClientConstants.WORLD_DOWNLOAD_SCENE_NAME).allowSceneActivation = true;
			});
		}
示例#3
0
        public async Task OnGameStart()
        {
            //When we start the loading screen for the game
            //To know what world we should load we should
            //To know that we need information about the character session.
            CharacterSessionEnterResponse characterSessionData = await CharacterService.TryEnterSession(LocalCharacterData.CharacterId)
                                                                 .ConfigureAwaitFalse();

            if (!characterSessionData.isSuccessful)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to query Character Session Data: {characterSessionData.ResultCode}:{(int)characterSessionData.ResultCode}");
                }

                //If we already have a claim we should repeat.
                if (characterSessionData.ResultCode == CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession)
                {
                    //Retry 5 times while not successful.
                    for (int i = 0; i < 5 && !characterSessionData.isSuccessful; i++)
                    {
                        characterSessionData = await CharacterService.TryEnterSession(LocalCharacterData.CharacterId)
                                               .ConfigureAwaitFalse();

                        await Task.Delay(1500)
                        .ConfigureAwaitFalseVoid();
                    }

                    //If not succesful after the retry.
                    if (!characterSessionData.isSuccessful)
                    {
                        await LoadCharacterSelection();

                        return;
                    }
                }
                else
                {
                    await LoadCharacterSelection();
                }
            }

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"About to broadcasting {nameof(OnCharacterSessionDataChanged)} with Zone: {characterSessionData.ZoneId}");
            }

            OnCharacterSessionDataChanged?.Invoke(this, new CharacterSessionDataChangedEventArgs(characterSessionData.ZoneId));
        }
示例#4
0
        public static async Task Test_Controller_Produces_InvalidId_When_Empty()
        {
            //arrange
            IServiceProvider           serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 1);
            CharacterSessionController controller      = serviceProvider.GetService <CharacterSessionController>();

            ICharacterLocationRepository characterLocationRepo = serviceProvider.GetService <ICharacterLocationRepository>();
            IZoneServerRepository        zoneRepository        = serviceProvider.GetService <IZoneServerRepository>();

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(5, characterLocationRepo, zoneRepository);

            //assert
            Assert.False(response.isSuccessful);
            Assert.AreEqual(CharacterSessionEnterResponseCode.InvalidCharacterIdError, response.ResultCode);
        }
示例#5
0
        public static async Task Test_Controller_Creates_UnclaimedSession_On_OnEnterSession(int accountId)
        {
            //arrange
            IServiceProvider           serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", accountId);
            CharacterSessionController controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository       characterRepo   = serviceProvider.GetService <ICharacterRepository>();

            ICharacterLocationRepository characterLocationRepo = serviceProvider.GetService <ICharacterLocationRepository>();
            IZoneServerRepository        zoneRepository        = serviceProvider.GetService <IZoneServerRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(accountId, "Testing"));

            //act: We also test that we can do it multiple times
            CharacterSessionEnterResponse response = await controller.EnterSession(1, characterLocationRepo, zoneRepository);

            //assert
            Assert.True(response.isSuccessful);
            Assert.AreEqual(CharacterSessionEnterResponseCode.Success, response.ResultCode);
        }
示例#6
0
        public static async Task Test_Controller_Produces_InvalidId_When_Wrong_AccountId()
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 2);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            ICharacterLocationRepository characterLocationRepo = serviceProvider.GetService <ICharacterLocationRepository>();
            IZoneServerRepository        zoneRepository        = serviceProvider.GetService <IZoneServerRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(1, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, 0));

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1, characterLocationRepo, zoneRepository);

            //assert
            Assert.False(response.isSuccessful, $"Characters should not be able to create sessions when the accountid doesn't match.");
            Assert.AreEqual(response.ResultCode, CharacterSessionEnterResponseCode.InvalidCharacterIdError);
        }
示例#7
0
        public static async Task Test_Controller_Produces_SessionGranted_With_Zone_Id_If_UnclaimedSession_Exists(int accountId, int zoneid)
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", accountId);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            ICharacterLocationRepository characterLocationRepo = serviceProvider.GetService <ICharacterLocationRepository>();
            IZoneServerRepository        zoneRepository        = serviceProvider.GetService <IZoneServerRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(accountId, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, zoneid));

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1, characterLocationRepo, zoneRepository);

            //assert
            Assert.True(response.isSuccessful, $"Created sessions should be granted if no active account session or character session is claimed.");
            Assert.AreEqual(CharacterSessionEnterResponseCode.Success, response.ResultCode);
            Assert.AreEqual(zoneid, response.ZoneId, $"Provided zone id was not the same as the session.");
        }