コード例 #1
0
        /// <summary>
        /// Called by Empyrion when the mod is loaded.
        /// </summary>
        /// <param name="dediAPI"></param>
        public void Game_Start(ModGameAPI dediAPI)
        {
            LegacyApi = dediAPI;

            if (this.NetworkServerHost == null)
            {
                this.NetworkServerHost = new ModServerHost();
                this.NetworkServerHost.Server.BindEndPoints.Add(new IPEndPoint(IPAddress.Loopback, Connection.DefaultPort));
                this.NetworkServerHost.Server.Start();
            }

            if (this.GameStateProcessor == null)
            {
                this.GameStateProcessor = new GameStateProcessor();
            }
        }
コード例 #2
0
        /// <summary>
        /// Called by Empyrion when the mod is unloaded.
        /// </summary>
        public void Game_Exit()
        {
            try
            {
                if (this.GameStateProcessor != null)
                {
                    this.GameStateProcessor.Stop();
                    this.GameStateProcessor = null;
                }

                if (this.NetworkServerHost != null)
                {
                    this.NetworkServerHost.Server.Stop();
                    this.NetworkServerHost = null;
                }
            } catch (Exception ex)
            {
                Log.Warn("Unexpected error when stopping DCE server. " + ex.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// Called by Empyrion when the mod is being unloaded.
        /// </summary>
        public void Shutdown()
        {
            foreach (PlayfieldProcessor processor in this.PlayfieldProcessors.Values)
            {
                processor.Stop();
            }

            if (this.GameStateProcessor != null)
            {
                this.GameStateProcessor.Stop();
                this.GameStateProcessor = null;
            }

            if (this.NetworkServerHost != null)
            {
                this.NetworkServerHost.Server.Stop();
                this.NetworkServerHost = null;
            }

            Log.Info("Dark City server extension shut down.");
        }
コード例 #4
0
        /// <summary>
        /// Called by Empyrion when the mod is first loaded.
        /// </summary>
        /// <param name="modAPI">Provides access to the Empyrion game state.</param>
        public void Init(IModApi modAPI)
        {
            EmpyrionApi = modAPI;
            Application = modAPI.Application;

            Log.LogReceived += Log_LogReceived;

            if (this.NetworkServerHost == null)
            {
                try
                {
                    this.NetworkServerHost = new ModServerHost();
                    this.NetworkServerHost.Server.BindEndPoints.Add(new IPEndPoint(IPAddress.Loopback, Connection.DefaultPort));
                    this.NetworkServerHost.Server.Start();
                } catch (Exception ex)
                {
                    Log.Warn("Failed to create DCE server. Remote connections will not be possible from client systems. " + ex.Message);
                    this.NetworkServerHost = null;
                }
            }

            if (this.GameStateProcessor == null)
            {
                this.GameStateProcessor = new GameStateProcessor();
            }

            Application.OnPlayfieldLoaded    += Application_OnPlayfieldLoaded;
            Application.OnPlayfieldUnloading += Application_OnPlayfieldUnloading;

            string contentPath       = Application.GetPathFor(AppFolder.Content);
            string localizationPath  = Path.Combine(contentPath, @"Extras\Localization.csv");
            string exampleConfigPath = Path.Combine(contentPath, @"Configuration\Config_Example.ecf");
            string customConfigPath  = Path.Combine(contentPath, @"Configuration\Config.ecf");

            try
            {
                if (Localization == null)
                {
                    Localization = new Localization(localizationPath);
                }
            } catch (Exception ex)
            {
                Log.Warn($"Failed to load localization file {localizationPath}. {ex.Message}");
            }

            try
            {
                if (Configuration == null)
                {
                    Configuration = new EmpyrionConfiguration(exampleConfigPath);
                    Log.Info("Loaded default configuration file.");
                    try
                    {
                        Configuration.Load(customConfigPath);
                        Log.Info("Loaded custom configuration file.");
                    }
                    catch { Log.Info("Did not load custom configuration file."); }
                }
            } catch (Exception ex)
            {
                Log.Warn($"Failed to load configuration files from {contentPath}. {ex.Message}");
            }

            Log.Info("Dark City server extension initialization done.");
        }