示例#1
0
        public void AllPacketsAreHandled()
        {
            List <Type> packetTypes = typeof(DefaultServerPacketProcessor).Assembly.GetTypes()
                                      .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
                                      .ToList();

            NitroxServiceLocator.InitializeDependencyContainer(new ClientAutoFacRegistrar(), new SubnauticaServerAutoFacRegistrar(), new TestAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            foreach (Type packet in typeof(Packet).Assembly.GetTypes()
                     .Where(p => typeof(Packet).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
                     .ToList())
            {
                Type clientPacketProcessorType          = typeof(ClientPacketProcessor <>);
                Type authenticatedPacketProcessorType   = typeof(AuthenticatedPacketProcessor <>);
                Type unauthenticatedPacketProcessorType = typeof(UnauthenticatedPacketProcessor <>);

                Type clientProcessorType = clientPacketProcessorType.MakeGenericType(packet);
                Type authProcessorType   = authenticatedPacketProcessorType.MakeGenericType(packet);
                Type unauthProcessorType = unauthenticatedPacketProcessorType.MakeGenericType(packet);

                Console.WriteLine($@"Checking handler for packet {packet}...");
                (packetTypes.Contains(packet) ||
                 NitroxServiceLocator.LocateOptionalService(clientProcessorType).HasValue ||
                 NitroxServiceLocator.LocateOptionalService(authProcessorType).HasValue ||
                 NitroxServiceLocator.LocateOptionalService(unauthProcessorType).HasValue).Should()
                .BeTrue($"Packet of type '{packet}' should have at least one processor.");
            }
        }
示例#2
0
        public void AllPacketsAreHandled()
        {
            World                  world = new World();
            ContainerBuilder       serverContainerBuilder    = new ContainerBuilder();
            ServerAutoFacRegistrar serverDependencyRegistrar = new ServerAutoFacRegistrar();

            NitroxServiceLocator.InitializeDependencyContainer(serverDependencyRegistrar);
            NitroxServiceLocator.BeginNewLifetimeScope();

            List <Type> packetTypes = typeof(DefaultServerPacketProcessor).Assembly.GetTypes()
                                      .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
                                      .ToList();

            ContainerBuilder       containerBuilder          = new ContainerBuilder();
            ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar();

            NitroxServiceLocator.InitializeDependencyContainer(clientDependencyRegistrar);
            NitroxServiceLocator.BeginNewLifetimeScope();

            typeof(Packet).Assembly.GetTypes()
            .Where(p => typeof(Packet).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
            .ToList()
            .ForEach(packet =>
            {
                Type clientPacketProcessorType = typeof(ClientPacketProcessor <>);
                Type clientProcessorType       = clientPacketProcessorType.MakeGenericType(packet);

                Console.WriteLine("Checking handler for packet {0}...", packet);
                Assert.IsTrue(packetTypes.Contains(packet) || NitroxServiceLocator.LocateOptionalService(clientProcessorType).IsPresent(),
                              $"Runtime has not detected a handler for {packet}!");
            }
                     );
        }
示例#3
0
        public void RuntimeDetectsAllClientPacketProcessors()
        {
            ContainerBuilder       containerBuilder          = new ContainerBuilder();
            ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar();

            NitroxServiceLocator.InitializeDependencyContainer(clientDependencyRegistrar);
            NitroxServiceLocator.BeginNewLifetimeScope();

            // Check if every PacketProcessor has been detected:
            typeof(Multiplayer).Assembly.GetTypes()
            .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
            .ToList()
            .ForEach(processor =>
            {
                try
                {
                    Assert.IsTrue(NitroxServiceLocator.LocateOptionalService(processor.BaseType).IsPresent(),
                                  $"{processor} has not been discovered by the runtime code!");
                }
                catch (Autofac.Core.DependencyResolutionException ex)
                {
                    if (ex.InnerException.GetType() != typeof(System.Security.SecurityException))
                    {
                        throw ex;
                    }
                }
            }
                     );
        }
示例#4
0
        private void ProcessAuthenticated(Packet packet, Player player)
        {
            Type serverPacketProcessorType = typeof(AuthenticatedPacketProcessor <>);
            Type packetType          = packet.GetType();
            Type packetProcessorType = serverPacketProcessorType.MakeGenericType(packetType);

            Optional <object> opProcessor = NitroxServiceLocator.LocateOptionalService(packetProcessorType);

            if (opProcessor.HasValue)
            {
                PacketProcessor processor = (PacketProcessor)opProcessor.Value;
                processor.ProcessPacket(packet, player);
            }
            else
            {
                defaultServerPacketProcessor.ProcessPacket(packet, player);
            }
        }
示例#5
0
        public void RuntimeDetectsAllServerPacketProcessors()
        {
            World world = new World();

            ContainerBuilder       containerBuilder          = new ContainerBuilder();
            ServerAutoFacRegistrar serverDependencyRegistrar = new NitroxServer_Subnautica.SubnauticaServerAutoFacRegistrar();

            NitroxServiceLocator.InitializeDependencyContainer(serverDependencyRegistrar);
            NitroxServiceLocator.BeginNewLifetimeScope();

            // Check if every PacketProcessor has been detected:
            typeof(DefaultServerPacketProcessor).Assembly.GetTypes()
            .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
            .ToList()
            .ForEach(processor =>
                     Assert.IsTrue(NitroxServiceLocator.LocateOptionalService(processor.BaseType).IsPresent(),
                                   $"{processor} has not been discovered by the runtime code!")
                     );
        }