Exemplo n.º 1
0
        /// <summary>
        ///     Load mod settings, create localizations and initialize network handler.
        /// </summary>
        public override void LoadData()
        {
            InitializeLogging();
            LoadLocalization();
            CheckSupportedMods();
            if (WaterModAvailable)
            {
                RegisterWaterModApi();
            }

            if (MyAPIGateway.Multiplayer.MultiplayerActive)
            {
                InitializeNetwork();

                if (Network != null)
                {
                    if (Network.IsServer)
                    {
                        LoadSettings();
                        _networkHandler = new ServerHandler(Log, Network);

                        if (!Network.IsDedicated)
                        {
                            MyAPIGateway.Gui.GuiControlRemoved += OnGuiControlRemoved;
                        }

                        if (Network.IsDedicated)
                        {
                            return;
                        }
                    }
                    else
                    {
                        MyAPIGateway.Gui.GuiControlRemoved += OnGuiControlRemoved;
                        _networkHandler = new ClientHandler(Log, Network);
                        Network.SendToServer(new SettingsRequestMessage());
                    }
                }
            }
            else
            {
                MyAPIGateway.Gui.GuiControlRemoved += OnGuiControlRemoved;
                LoadSettings();
            }

            _chatHandler = new ChatHandler(Log, Network, _networkHandler);
            MyAPIGateway.Session.OnSessionReady += OnSessionReady;
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override void UnloadData()
        {
            Log?.EnterMethod(nameof(UnloadData));

            MyAPIGateway.Session.OnSessionReady -= OnSessionReady;
            MyAPIGateway.Gui.GuiControlRemoved  -= OnGuiControlRemoved;

            if (WaterModAvailable)
            {
                WaterModAPI?.Unregister();
            }

            if (_chatHandler != null)
            {
                _chatHandler.Close();
                _chatHandler = null;
            }

            if (_suitComputer != null)
            {
                _suitComputer.Close();
                _suitComputer = null;
            }

            if (Network != null)
            {
                _networkHandler.Close();
                _networkHandler = null;

                Log?.Info("Cap network connections");
                Network.Close();
                Network = null;
            }

            if (Log != null)
            {
                Log.Info("Logging stopped");
                Log.Flush();
                Log.Close();
                Log = null;
            }
        }