private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new Character(null, null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            CharacterDto character = _targetChar;

            _characterDao.InsertOrUpdate(ref character);
            var instanceAccessService = new MapInstanceProvider(new List <MapDto> {
                _map, _map2
            },
                                                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                _mapNpcDao,
                                                                _mapMonsterDao, _portalDao, new Adapter(), _logger);

            _targetSession = new ClientSession(null,
                                               new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService, null, _logger)
            },
                                               instanceAccessService, null, _logger)
            {
                SessionId = 2
            };
            var handler2 = new DefaultPacketController(null, instanceAccessService, null, _logger);

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar);
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = "******".ToSha512()
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            },
                                                                     new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                     new MapNpcBuilderService(_itemBuilderService, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                                                     new MapMonsterBuilderService(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));

            _targetSession = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService, null)
            }, instanceAccessService, null)
            {
                SessionId = 2
            };
            var handler2 = new DefaultPacketController(null, instanceAccessService, null);

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            });

            _targetSession = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService)
            }, instanceAccessService)
            {
                SessionId = 2
            };
            var handler2 = new DefaultPacketController(null, instanceAccessService);

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Instance.Reset();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <string, object>
            {
                { "api/channels", new List <WorldServerInfo> {
                      new WorldServerInfo()
                  } },
                { "api/connectedAccount", new List <ConnectedAccount>() }
            };

            _chara = new CharacterDto
            {
                CharacterId = 0,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            _targetChar = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(null, null);
            _handler.RegisterSession(_session);

            _targetSession.InitializeAccount(targetAccount);
            _targetSession.SessionId = 2;
            _handler2 = new DefaultPacketController(null, null);
            _handler2.RegisterSession(_targetSession);

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            _targetSession.InitializeAccount(targetAccount);

            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);

            Broadcaster.Instance.RegisterSession(_session);
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <WebApiRoute, object>
            {
                { WebApiRoute.Channel, new List <ChannelInfo> {
                      new ChannelInfo()
                  } },
                { WebApiRoute.ConnectedAccount, new List <ConnectedAccount>() }
            };

            var _chara = new Character(null, null, null)
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            _itemProvider = new ItemProvider(new List <Item>(),
                                             new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            var instanceAccessService = new MapInstanceProvider(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            },
                                                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                new MapNpcProvider(_itemProvider, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                                                new MapMonsterProvider(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));
            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService, null)
            }, instanceAccessService, null);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(new WorldConfiguration(), instanceAccessService, null);
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara);
            var mapinstance = instanceAccessService.GetBaseMapById(0);

            _session.Character.MapInstance         = instanceAccessService.GetBaseMapById(0);
            _session.Character.MapInstance         = mapinstance;
            _session.Character.MapInstance.Portals = new List <Portal> {
                new Portal
                {
                    DestinationMapId         = _map2.MapId,
                    Type                     = PortalType.Open,
                    SourceMapInstanceId      = mapinstance.MapInstanceId,
                    DestinationMapInstanceId = instanceAccessService.GetBaseMapById(1).MapInstanceId,
                    DestinationX             = 5,
                    DestinationY             = 5,
                    PortalId                 = 1,
                    SourceMapId              = _map.MapId,
                    SourceX                  = 0,
                    SourceY                  = 0,
                }
            };

            Broadcaster.Instance.RegisterSession(_session);
        }
Пример #6
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(ConfigurationPath + "/log4net.config"));
            Logger.InitializeLogger(LogManager.GetLogger(typeof(DefaultPacketControllerTests)));
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

            _chara = new CharacterDto
            {
                Name      = "TestExistingCharacter",
                Slot      = 1,
                AccountId = account.AccountId,
                MapId     = 1,
                State     = CharacterState.Active
            };

            _targetChar = new CharacterDto
            {
                Name      = "TestChar2",
                Slot      = 1,
                AccountId = targetAccount.AccountId,
                MapId     = 1,
                State     = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            _session.InitializeAccount(account);
            _handler = new DefaultPacketController(null, null);
            _handler.RegisterSession(_session);

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            _targetSession.InitializeAccount(targetAccount);

            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <string, object>
            {
                { "api/channels", new List <WorldServerInfo> {
                      new WorldServerInfo()
                  } },
                { "api/connectedAccount", new List <ConnectedAccount>() }
            };

            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);
            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);
            ServerManager.Instance.Sessions      = new ConcurrentDictionary <long, ClientSession>();
            ServerManager.Instance.Sessions.TryAdd(_chara.CharacterId, _session);
            ServerManager.Instance.Sessions.TryAdd(_targetChar.CharacterId, _targetSession);
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <string, object>
            {
                { "api/channels", new List <WorldServerInfo> {
                      new WorldServerInfo()
                  } },
                { "api/connectedAccount", new List <ConnectedAccount>() }
            };

            var _chara = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            });
            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService)
            }, instanceAccessService);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(null, instanceAccessService);
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            var mapinstance = instanceAccessService.GetBaseMapById(0);

            _session.Character.MapInstance         = instanceAccessService.GetBaseMapById(0);
            _session.Character.MapInstance         = mapinstance;
            _session.Character.MapInstance.Portals = new List <Portal> {
                new Portal
                {
                    DestinationMapId         = _map2.MapId,
                    Type                     = PortalType.Open,
                    SourceMapInstanceId      = mapinstance.MapInstanceId,
                    DestinationMapInstanceId = instanceAccessService.GetBaseMapById(1).MapInstanceId,
                    DestinationX             = 5,
                    DestinationY             = 5,
                    PortalId                 = 1,
                    SourceMapId              = _map.MapId,
                    SourceX                  = 0,
                    SourceY                  = 0,
                }
            };

            Broadcaster.Instance.RegisterSession(_session);
        }