Exemple #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.");
            }
        }
Exemple #2
0
        public void OnConsoleCommand_mplayer(NotificationCenter.Notification n)
        {
            //This could be cleaned up. Honestly, I see this as a hack to deal with other unimplemented features. I'd rather just patch this boat until we can let it sink...
            NitroxServiceLocator.BeginNewLifetimeScope();
            multiplayerSession = NitroxServiceLocator.LocateService <IMultiplayerSession>();

            if (multiplayerSession.CurrentState.CurrentStage == MultiplayerSessionConnectionStage.SessionJoined)
            {
                Log.InGame("Already connected to a server");
            }
            else if (n?.data?.Count > 0)
            {
                Log.InGame("Console Multiplayer Session Join Client Loaded...");
                StartMultiplayerClient();

                string ipAddress = n.data.Count >= 2 ? (string)n.data[1] : DEFAULT_IP_ADDRESS;
                userName = (string)n.data[0];

                multiplayerSession.Connect(ipAddress);
            }
            else
            {
                Log.InGame("Command syntax: mplayer USERNAME [SERVERIP]");
            }
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            ConfigureCultureInfo();
            Log.Setup();

            ConfigureConsoleWindow();

            // Allow game path to be given as command argument
            if (args.Length > 0 && Directory.Exists(args[0]) && File.Exists(Path.Combine(args[0], "Subnautica.exe")))
            {
                string gameDir = Path.GetFullPath(args[0]);
                Log.Info($"Using game files from: {gameDir}");
                gameInstallDir = new Lazy <string>(() => gameDir);
            }
            else
            {
                gameInstallDir = new Lazy <string>(() =>
                {
                    string gameDir = GameInstallationFinder.Instance.FindGame();
                    Log.Info($"Using game files from: {gameDir}");
                    return(gameDir);
                });
            }

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += CurrentDomainOnAssemblyResolve;

            NitroxModel.Helper.Map.Main = new SubnauticaMap();

            NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            Server server;

            try
            {
                server = NitroxServiceLocator.LocateService <Server>();
                Log.Info($"Loaded save\n{server.SaveSummary}");
                if (!server.Start())
                {
                    Log.Error("Unable to start server.");
                    Console.WriteLine("\nPress any key to continue..");
                    Console.ReadKey(true);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return;
            }

            CatchExitEvent();

            ConsoleCommandProcessor cmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                cmdProcessor.ProcessCommand(Console.ReadLine(), Optional.Empty, Perms.CONSOLE);
            }
        }
        public void OpenJoinServerMenu(string serverIp)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();

            if (joinServerGameObject != null)
            {
                Destroy(joinServerGameObject);
            }

            joinServerGameObject = new GameObject();
            JoinServer joinServerComponent = joinServerGameObject.AddComponent <JoinServer>();
            char       seperator           = ':';

            if (serverIp.Contains(seperator))
            {
                string[] splitIP = serverIp.Split(seperator);
                joinServerComponent.ServerIp   = splitIP[0];
                joinServerComponent.serverPort = int.Parse(splitIP[1]);
            }
            else
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(serverIp);
                joinServerComponent.ServerIp   = hostEntry.AddressList[0].ToString();
                joinServerComponent.serverPort = 11000;
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Log.SetLevel(Log.LogLevel.ConsoleInfo | Log.LogLevel.ConsoleDebug | Log.LogLevel.FileLog);

            NitroxServiceLocator.InitializeDependencyContainer(new ServerAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            configureCultureInfo();
            Server server;

            try
            {
                server = NitroxServiceLocator.LocateService <Server>();
                server.Start();
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                return;
            }

            ConsoleCommandProcessor CmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                CmdProcessor.ProcessCommand(Console.ReadLine());
            }
        }
Exemple #6
0
        public void OnConsoleCommand_mplayer(NotificationCenter.Notification n)
        {
            //This could be cleaned up. Honestly, I see this as a hack to deal with other unimplemented features. I'd rather just patch this boat until we can let it sink...
            NitroxServiceLocator.BeginNewLifetimeScope();
            multiplayerSession = NitroxServiceLocator.LocateService <IMultiplayerSession>();

            if (multiplayerSession.CurrentState.CurrentStage == MultiplayerSessionConnectionStage.SessionJoined)
            {
                Log.InGame("Уже подключен к серверу");
            }
            else if (n?.data?.Count > 0)
            {
                Log.InGame("Консоль мультиплеерской сессии подключения игроков загружена...");
                StartMultiplayerClient();
                int    serverPort = 11000;
                string ipAddress  = n.data.Count >= 2 ? (string)n.data[1] : DEFAULT_IP_ADDRESS;
                userName = (string)n.data[0];
                string seperator = ":";
                if (ipAddress.Contains(seperator))
                {
                    char     splitter = ':';
                    string[] splitIP  = ipAddress.Split(splitter);
                    ipAddress  = splitIP[0];
                    serverPort = int.Parse(splitIP[1]);
                }
                multiplayerSession.Connect(ipAddress, serverPort);
            }
            else
            {
                Log.InGame("Синтаксис команды: mplayer USERNAME [SERVERIP]");
            }
        }
Exemple #7
0
        public void Setup()
        {
            NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar(), new TestAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            tempSaveFilePath  = Path.Combine(Path.GetTempPath(), "NitroxTestTempDir");
            serverSerializers = NitroxServiceLocator.LocateService <IServerSerializer[]>();
            worldPersistence  = NitroxServiceLocator.LocateService <WorldPersistence>();
            serverConfig      = NitroxServiceLocator.LocateService <ServerConfig>();

            worldData = GeneratePersistedWorldData();
            world     = worldPersistence.CreateWorld(worldData, serverConfig.GameMode);

            worldsDataAfter = new PersistedWorldData[serverSerializers.Length];
            for (int index = 0; index < serverSerializers.Length; index++)
            {
                worldPersistence.UpdateSerializer(serverSerializers[index]);
                Assert.IsTrue(worldPersistence.Save(world, tempSaveFilePath));
                Assert.IsFalse(worldPersistence.Save(null, tempSaveFilePath));

                worldPersistence.UpdateSerializer(serverSerializers[index]);
                Optional <World> worldAfter = worldPersistence.LoadFromFile(tempSaveFilePath);
                Assert.IsTrue(worldAfter.HasValue);
                worldsDataAfter[index] = PersistedWorldData.From(worldAfter.Value);
            }
        }
        public void OpenJoinServerMenu(string serverIp)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();

            if (joinServerGameObject != null)
            {
                Destroy(joinServerGameObject);
            }

            joinServerGameObject = new GameObject();
            JoinServer joinServerComponent = joinServerGameObject.AddComponent <JoinServer>();
            string     seperator           = ":";

            if (serverIp.Contains(seperator))
            {
                char     splitter = ':';
                string[] splitIP  = serverIp.Split(splitter);
                joinServerComponent.ServerIp   = splitIP[0];
                joinServerComponent.serverPort = int.Parse(splitIP[1]);
            }
            else
            {
                joinServerComponent.ServerIp   = serverIp;
                joinServerComponent.serverPort = 11000;
            }
        }
Exemple #9
0
        private static void Main(string[] args)
        {
            ConfigureConsoleWindow();
            ConfigureCultureInfo();

            NitroxModel.Helper.Map.Main = new SubnauticaMap();

            NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            Server server;

            try
            {
                server = NitroxServiceLocator.LocateService <Server>();
                server.Start();
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                return;
            }

            CatchExitEvent();

            ConsoleCommandProcessor cmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                cmdProcessor.ProcessCommand(Console.ReadLine(), Optional.Empty, Perms.CONSOLE);
            }
        }
Exemple #10
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;
                    }
                }
            }
                     );
        }
Exemple #11
0
        public void Show(string ip, int port)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();
            multiplayerSession = NitroxServiceLocator.LocateService <IMultiplayerSession>();
            preferencesManager = NitroxServiceLocator.LocateService <PlayerPreferenceManager>();

            gameObject.SetActive(true);
            serverIp   = ip;
            serverPort = port;

            //Set Server IP in info label
            lowerDetailTextGameObject.GetComponent <Text>().text = $"{Language.main.Get("Nitrox_JoinServerIpAddress")}\n{(NitroxPrefs.HideIp.Value ? "****" : serverIp)}";

            //Initialize elements from preferences
            activePlayerPreference = preferencesManager.GetPreference(serverIp);
            SubscribeColorChanged();

            // HSV => Hue Saturation Value, HSB => Hue Saturation Brightness
            Color.RGBToHSV(activePlayerPreference.PreferredColor(), out float hue, out _, out float brightness);
            colorPicker.SetHSB(new Vector3(hue, 1f, brightness));

            playerNameInputField.text = activePlayerPreference.PlayerName;

            StartMultiplayerClient();
        }
Exemple #12
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}!");
            }
                     );
        }
Exemple #13
0
        private static void Main(string[] args)
        {
            Log.SetLevel(Log.LogLevel.Info | Log.LogLevel.Debug);

            NitroxServiceLocator.InitializeDependencyContainer(new ServerAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            ConfigureCultureInfo();
            Server server;

            try
            {
                server = NitroxServiceLocator.LocateService <Server>();
                server.Start();
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                return;
            }

            CatchExitEvent();

            ConsoleCommandProcessor cmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                cmdProcessor.ProcessCommand(Console.ReadLine(), Optional <Player> .Empty(), Perms.CONSOLE);
            }
        }
        public static void BeforeAll(TestContext context)
        {
            TestAutoFacRegistrar registrar = new TestAutoFacRegistrar();

            NitroxServiceLocator.InitializeDependencyContainer(registrar);
            NitroxServiceLocator.BeginNewLifetimeScope();
        }
Exemple #15
0
        public void OpenJoinServerMenu(string serverIp)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();

            if (joinServerGameObject != null)
            {
                Destroy(joinServerGameObject);
            }

            joinServerGameObject = new GameObject();
            JoinServer joinServerComponent = joinServerGameObject.AddComponent <JoinServer>();

            if (Regex.IsMatch(serverIp, @"^[0-9:\[\]a-f]+$"))
            {
                ResolveIpv6(joinServerComponent, serverIp);
            }
            else if (Regex.IsMatch(serverIp, "^[0-9.:]+$"))
            {
                ResolveIpv4(joinServerComponent, serverIp);
            }
            else
            {
                ResolveHostName(joinServerComponent, serverIp);
            }
        }
Exemple #16
0
        public static void ClassInitialize(TestContext context)
        {
            NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar(), new TestAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            WorldPersistence worldPersistence = NitroxServiceLocator.LocateService <WorldPersistence>();

            serverSerializers = NitroxServiceLocator.LocateService <IServerSerializer[]>();
            worldsDataAfter   = new PersistedWorldData[serverSerializers.Length];
            tempSaveFilePath  = Path.Combine(Path.GetTempPath(), "NitroxTestTempDir");

            worldData = GeneratePersistedWorldData();
            World world = worldPersistence.CreateWorld(worldData, ServerGameMode.CREATIVE);

            world.EventTriggerer.ResetWorldTime();

            for (int index = 0; index < serverSerializers.Length; index++)
            {
                //Checking saving
                worldPersistence.UpdateSerializer(serverSerializers[index]);
                Assert.IsTrue(worldPersistence.Save(world, tempSaveFilePath), $"Saving normal world failed while using {serverSerializers[index]}.");
                Assert.IsFalse(worldPersistence.Save(null, tempSaveFilePath), $"Saving null world worked while using {serverSerializers[index]}.");

                //Checking loading
                Optional <World> worldAfter = worldPersistence.LoadFromFile(tempSaveFilePath);
                Assert.IsTrue(worldAfter.HasValue, $"Loading saved world failed while using {serverSerializers[index]}.");
                worldAfter.Value.EventTriggerer.ResetWorldTime();
                worldsDataAfter[index] = PersistedWorldData.From(worldAfter.Value);
            }
        }
        public void TestInitialize()
        {
            NitroxServiceLocator.InitializeDependencyContainer(new ClientAutoFacRegistrar(), new TestAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            packetReceiver = NitroxServiceLocator.LocateService <PacketReceiver>();

            loadedCell   = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
            unloadedCell = new AbsoluteEntityCell(unloadedActionPosition, CELL_LEVEL);

            visibleCells.Add(loadedCell);
        }
        public void OpenJoinServerMenu(string serverIp)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();

            if (joinServerGameObject != null)
            {
                Destroy(joinServerGameObject);
            }

            joinServerGameObject = new GameObject();
            JoinServer joinServerComponent = joinServerGameObject.AddComponent <JoinServer>();

            joinServerComponent.ServerIp = serverIp;
        }
Exemple #19
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!")
                     );
        }
Exemple #20
0
 public void JoinCallback(string secret)
 {
     Log.Info(string.Format("Discord: join ({0})", secret));
     Log.Debug("Discord" + SceneManager.GetActiveScene().name);
     if (SceneManager.GetActiveScene().name == "StartScreen")
     {
         NitroxServiceLocator.BeginNewLifetimeScope();
         JoinServer.SaveGameMenuPrototype = FindObject(MainMenuRightSide.main.gameObject, "SavedGames");
         JoinServer joinServer   = gameObject.AddComponent <JoinServer>();
         string[]   serverIpPort = secret.Split(':');
         joinServer.ServerIp   = serverIpPort[0];
         joinServer.ServerPort = int.Parse(serverIpPort[1]);
     }
     else
     {
         Log.InGame("Please be in the mainmenu if you want to join a session.");
         Log.Warn("Discord: Can't join a server outside of the mainmenu.");
     }
 }
Exemple #21
0
        public void SameAmountOfServerPacketProcessors()
        {
            IEnumerable <Type> processors = typeof(PacketHandler).Assembly.GetTypes()
                                            .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract);
            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();

            int both = packetTypes.Count;

            Assert.AreEqual(processors.Count(),
                            both,
                            "Not all(Un) AuthenticatedPacketProcessors have been discovered by the runtime code " +
                            $"(auth + unauth: {both} out of {processors.Count()}). " + // this is a small patch to keep this alive a little longer until its put out of its misery
                            "Perhaps the runtime matching code is too strict, or a processor does not derive from ClientPacketProcessor " +
                            "(and will hence not be detected).");
        }
Exemple #22
0
        private static void Main(string[] args)
        {
            ConfigureConsoleWindow();
            ConfigureCultureInfo();

            NitroxModel.Helper.Map.Main = new SubnauticaMap();

            NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            Server server;

            try
            {
                server = NitroxServiceLocator.LocateService <Server>();
                Log.Info($"Loaded save\n{server.SaveSummary}");
                if (!server.Start())
                {
                    Log.Error("Unable to start server.");
                    Console.WriteLine("\nPress any key to continue..");
                    Console.ReadKey(true);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                return;
            }

            CatchExitEvent();

            ConsoleCommandProcessor cmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                cmdProcessor.ProcessCommand(Console.ReadLine(), Optional.Empty, Perms.CONSOLE);
            }
        }
Exemple #23
0
        public void OpenJoinServerMenu(string serverIp)
        {
            IPEndPoint endpoint = ResolveIpv4(serverIp) ?? ResolveHostName(serverIp);

            if (endpoint == null)
            {
                Log.InGame($"Unable to resolve remote address: {serverIp}");
                return;
            }

            NitroxServiceLocator.BeginNewLifetimeScope();

            if (joinServerGameObject != null)
            {
                Destroy(joinServerGameObject);
            }

            joinServerGameObject = new GameObject();
            JoinServer joinServerComponent = joinServerGameObject.AddComponent <JoinServer>();

            joinServerComponent.ServerIp   = endpoint.Address.ToString();
            joinServerComponent.ServerPort = endpoint.Port;
        }
 public static void BeforeAll(TestContext context)
 {
     NitroxServiceLocator.InitializeDependencyContainer(new DependencyInjectionTestsAutoFacRegistrar());
     NitroxServiceLocator.BeginNewLifetimeScope();
 }
Exemple #25
0
        private static async Task Main(string[] args)
        {
            // The thread that writers to console is paused while selecting text in console. So console writer needs to be async.
            Log.Setup(asyncConsoleWriter: true, isConsoleApp: true);
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

            ConfigureCultureInfo();

            AppMutex.Hold(() =>
            {
                Log.Info("Waiting for 30 seconds on other Nitrox servers to initialize before starting..");
            }, 30000);
            Server server;

            try
            {
                // Allow game path to be given as command argument
                if (args.Length > 0 && Directory.Exists(args[0]) && File.Exists(Path.Combine(args[0], "Subnautica.exe")))
                {
                    string gameDir = Path.GetFullPath(args[0]);
                    Log.Info($"Using game files from: {gameDir}");
                    gameInstallDir = new Lazy <string>(() => gameDir);
                }
                else
                {
                    gameInstallDir = new Lazy <string>(() =>
                    {
                        string gameDir = GameInstallationFinder.Instance.FindGame();
                        Log.Info($"Using game files from: {gameDir}");
                        return(gameDir);
                    });
                }

                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += CurrentDomainOnAssemblyResolve;

                Map.Main = new SubnauticaMap();

                NitroxServiceLocator.InitializeDependencyContainer(new SubnauticaServerAutoFacRegistrar());
                NitroxServiceLocator.BeginNewLifetimeScope();

                server = NitroxServiceLocator.LocateService <Server>();
                await WaitForAvailablePortAsync(server.Port);

                if (!server.Start())
                {
                    throw new Exception("Unable to start server.");
                }
                Log.Info("Server is waiting for players!");

                CatchExitEvent();
            }
            finally
            {
                // Allow other servers to start initializing.
                AppMutex.Release();
            }

            Log.Info("To get help for commands, run help in console or /help in chatbox");
            ConsoleCommandProcessor cmdProcessor = NitroxServiceLocator.LocateService <ConsoleCommandProcessor>();

            while (server.IsRunning)
            {
                cmdProcessor.ProcessCommand(Console.ReadLine(), Optional.Empty, Perms.CONSOLE);
            }
        }
Exemple #26
0
        public void JoinServer(string serverIp)
        {
            NitroxServiceLocator.BeginNewLifetimeScope();

            new GameObject().AddComponent <JoinServer>().ServerIp = serverIp;
        }