Exemple #1
0
    /** Reads all settings from XML file */
    public static void ReadSettings()
    {
        bool hasSettingsFile = StateStorage.HasData("Settings");

        General     = new GeneralSettings();
        Advanced    = new AdvancedSettings();
        Information = new InformationSettings();

        try {
            if (hasSettingsFile)
            {
                XElement rootNode = StateStorage.LoadXML("Settings");
                if (rootNode == null)
                {
                    Trace.LogWarning("No settings in file, resetting to default");
                    ResetSettings();
                }
                else
                {
                    Trace.Log("Reading settings");
                    General.Load(rootNode.Element("General"));
                    Advanced.Load(rootNode.Element("Advanced"));
                }
            }
            else
            {
                Trace.Log("No settings file present, setting to default");
                ResetSettings();
            }
        } catch (Exception e) {
            Trace.LogWarning("Error while reading settings file:" + e.Message);
            ResetSettings();
        }

        IsLoaded = true;
    }
Exemple #2
0
        static void Main(string[] args)
        {
            var baseDir = ConfigUtil.FindBasePath();

            if (baseDir == null)
            {
                throw new InvalidOperationException("No base directory could be found.");
            }

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required for code page 850 support in .NET Core
            var commands = ParseCommands(args.Skip(1)).ToList();

            if (!commands.Any())
            {
                PrintUsage();
                return;
            }

            var filename = args[0];
            var stream   = File.OpenRead(filename);

            using var br = new BinaryReader(stream, Encoding.GetEncoding(850));
            var generalConfig           = GeneralConfig.Load(Path.Combine(baseDir, "data", "config.json"), baseDir);
            var settings                = GeneralSettings.Load(generalConfig.ResolvePath("$(DATA)/settings.json"));
            var assets                  = new AssetManager();
            var loaderRegistry          = new AssetLoaderRegistry();
            var locatorRegistry         = new AssetLocatorRegistry();
            var containerLoaderRegistry = new ContainerLoaderRegistry().AddLoader(new RawContainerLoader())
                                          .AddLoader(new XldContainerLoader())
                                          .AddLoader(new BinaryOffsetContainerLoader())
                                          .AddLoader(new ItemListContainerLoader())
                                          .AddLoader(new SpellListContainerLoader())
                                          .AddLoader(new DirectoryContainerLoader())
            ;
            var modApplier = new ModApplier()
                             // Register post-processors for handling transformations of asset data that can't be done by UAlbion.Formats alone.
                             .AddAssetPostProcessor(new AlbionSpritePostProcessor())
                             .AddAssetPostProcessor(new InventoryPostProcessor())
                             .AddAssetPostProcessor(new ItemNamePostProcessor());

            var exchange = new EventExchange(new LogExchange());

            exchange
            .Attach(settings)
            .Register <IGeneralConfig>(generalConfig)
            .Attach(loaderRegistry)
            .Attach(locatorRegistry)
            .Attach(containerLoaderRegistry)
            .Attach(modApplier)
            .Attach(assets)
            ;

            modApplier.LoadMods(generalConfig);
            var save = SavedGame.Serdes(null, AssetMapping.Global, new AlbionReader(br, stream.Length));

            if (!VerifyRoundTrip(stream, save, AssetMapping.Global))
            {
                return;
            }

            foreach (var command in commands)
            {
                command.Action(save);
                Console.WriteLine();
            }
        }
Exemple #3
0
        public static void Main()
        {
            try
            {
                ServerContext.StartTime = DateTime.UtcNow.Ticks;

                //Start the server clock
                ServerContext.ServerClock.Start();

                //Set the last player activity time to server start
                ServerContext.LastPlayerActivity = ServerContext.ServerClock.ElapsedMilliseconds;

                //Register the ctrl+c event
                Console.CancelKeyPress      += CatchExit;
                ServerContext.ServerStarting = true;

                LunaLog.Debug("Loading settings...");
                if (GeneralSettings.SettingsStore.GameDifficulty == GameDifficulty.Custom)
                {
                    GameplaySettings.Reset();
                    GameplaySettings.Load();
                }

                //Set day for log change
                ServerContext.Day = DateTime.Now.Day;

                //Load plugins
                LmpPluginHandler.LoadPlugins();

                Console.Title = $"LMPServer v{VersionInfo.VersionNumber}";

                while (ServerContext.ServerStarting || ServerContext.ServerRestarting)
                {
                    if (ServerContext.ServerRestarting)
                    {
                        LunaLog.Debug("Reloading settings...");
                        GeneralSettings.Reset();
                        GeneralSettings.Load();
                        if (GeneralSettings.SettingsStore.GameDifficulty == GameDifficulty.Custom)
                        {
                            LunaLog.Debug("Reloading gameplay settings...");
                            GameplaySettings.Reset();
                            GameplaySettings.Load();
                        }
                    }

                    ServerContext.ServerRestarting = false;
                    LunaLog.Normal($"Starting Luna Server v{VersionInfo.FullVersionNumber}");

                    if (GeneralSettings.SettingsStore.GameDifficulty == GameDifficulty.Custom)
                    {
                        //Generate the config file by accessing the object.
                        LunaLog.Debug("Loading gameplay settings...");
                        GameplaySettings.Load();
                    }

                    //Load universe
                    LunaLog.Normal("Loading universe... ");
                    Universe.CheckUniverse();

                    LunaLog.Normal($"Starting {GeneralSettings.SettingsStore.WarpMode} server on Port {GeneralSettings.SettingsStore.Port}... ");

                    ServerContext.ServerRunning = true;

                    var commandThread = Task.Run(() => new CommandHandler().ThreadMain());
                    var clientThread  = Task.Run(() => new ClientMainThread().ThreadMain());

                    ServerContext.LidgrenServer.SetupLidgrenServer();
                    Task.Run(() => ServerContext.LidgrenServer.StartReceiveingMessages());
                    Task.Run(() => ServerContext.LidgrenServer.RegisterWithMasterServer());

                    var vesselRelayThread = Task.Run(() => VesselRelaySystem.RelayOldVesselMessages());

                    var vesselRelayFarThread    = Task.Run(() => VesselUpdateRelaySystem.RelayToFarPlayers());
                    var vesselRelayMediumThread = Task.Run(() => VesselUpdateRelaySystem.RelayToMediumDistancePlayers());
                    var vesselRelayCloseThread  = Task.Run(() => VesselUpdateRelaySystem.RelayToClosePlayers());

                    while (ServerContext.ServerStarting)
                    {
                        Thread.Sleep(500);
                    }

                    LunaLog.Normal("Ready!");
                    LmpPluginHandler.FireOnServerStart();
                    while (ServerContext.ServerRunning)
                    {
                        //Run the log expire function every 10 minutes
                        if (ServerContext.ServerClock.ElapsedMilliseconds - _lastLogExpiredCheck > 600000)
                        {
                            _lastLogExpiredCheck = ServerContext.ServerClock.ElapsedMilliseconds;
                            LogExpire.ExpireLogs();
                        }

                        // Check if the day has changed, every minute
                        if (ServerContext.ServerClock.ElapsedMilliseconds - _lastDayCheck > 60000)
                        {
                            _lastDayCheck = ServerContext.ServerClock.ElapsedMilliseconds;
                            if (ServerContext.Day != DateTime.Now.Day)
                            {
                                LunaLog.LogFilename = Path.Combine(LunaLog.LogFolder, $"lmpserver {DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
                                LunaLog.WriteToLog($"Continued from logfile {DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
                                ServerContext.Day = DateTime.Now.Day;
                            }
                        }

                        Thread.Sleep(500);
                    }

                    LmpPluginHandler.FireOnServerStop();
                    commandThread.Wait();
                    clientThread.Wait();
                    vesselRelayThread.Wait();

                    vesselRelayFarThread.Wait();
                    vesselRelayMediumThread.Wait();
                    vesselRelayCloseThread.Wait();
                }
                LunaLog.Normal("Goodbye and thanks for all the fish!");
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                LunaLog.Fatal($"Error in main server thread, Exception: {e}");
                throw;
            }
        }
Exemple #4
0
        static async Task <(EventExchange, IContainer)> SetupAssetSystem(string baseDir)
        {
            var generalConfigTask = Task.Run(() =>
            {
                var result = GeneralConfig.Load(Path.Combine(baseDir, "data", "config.json"), baseDir);
                PerfTracker.StartupEvent("Loaded general config");
                return(result);
            });
            var settingsTask = Task.Run(() =>
            {
                var result = GeneralSettings.Load(Path.Combine(baseDir, "data", "settings.json"));
                PerfTracker.StartupEvent("Loaded settings");
                return(result);
            });
            var coreConfigTask = Task.Run(() =>
            {
                var result = CoreConfig.Load(Path.Combine(baseDir, "data", "core.json"));
                PerfTracker.StartupEvent("Loaded core config");
                return(result);
            });
            var gameConfigTask = Task.Run(() =>
            {
                var result = GameConfig.Load(Path.Combine(baseDir, "data", "game.json"));
                PerfTracker.StartupEvent("Loaded game config");
                return(result);
            });

            var assets                  = new AssetManager();
            var factory                 = new VeldridCoreFactory();
            var loaderRegistry          = new AssetLoaderRegistry();
            var locatorRegistry         = new AssetLocatorRegistry();
            var containerLoaderRegistry = new ContainerLoaderRegistry().AddLoader(new RawContainerLoader())
                                          .AddLoader(new XldContainerLoader())
                                          .AddLoader(new BinaryOffsetContainerLoader())
                                          .AddLoader(new ItemListContainerLoader())
                                          .AddLoader(new SpellListContainerLoader())
                                          .AddLoader(new DirectoryContainerLoader())
            ;

            var modApplier = new ModApplier()
                             // Register post-processors for handling transformations of asset data that can't be done by UAlbion.Formats alone.
                             .AddAssetPostProcessor(new AlbionSpritePostProcessor())
                             .AddAssetPostProcessor(new ImageSharpPostProcessor())
                             .AddAssetPostProcessor(new InterlacedBitmapPostProcessor())
                             .AddAssetPostProcessor(new InventoryPostProcessor())
                             .AddAssetPostProcessor(new ItemNamePostProcessor());

            var settings = await settingsTask.ConfigureAwait(false);

            var services = new Container("Services", settings, // Need to register settings first, as the AssetLocator relies on it.
                                         loaderRegistry, locatorRegistry, containerLoaderRegistry, new MetafontBuilder(factory), new StdioConsoleLogger(),
                                                               // new ClipboardManager(),
                                         new ImGuiConsoleLogger(), new WordLookup(), new AssetLocator(), modApplier, assets);

            var generalConfig = await generalConfigTask.ConfigureAwait(false);

            using var exchange = new EventExchange(new LogExchange()).Register <IGeneralConfig>(generalConfig)
                                 .Register <ICoreFactory>(factory)
                                 .Attach(services);
            PerfTracker.StartupEvent("Registered asset services");

            Engine.GlobalExchange = exchange;
            generalConfig.SetPath("LANG", settings.Language.ToString()
                                  .ToUpperInvariant()); // Ensure that the LANG path is set before resolving any assets
            modApplier.LoadMods(generalConfig);
            PerfTracker.StartupEvent("Loaded mods");

            var coreConfig = await coreConfigTask.ConfigureAwait(false);

            var gameConfig = await gameConfigTask.ConfigureAwait(false);

            exchange // Need to load game config after mods so asset ids can be parsed.
            .Register(coreConfig)
            .Register(gameConfig);
            PerfTracker.StartupEvent("Loaded core and game config");
            return(exchange, services);
        }