Exemplo n.º 1
0
        /// <summary>
        ///     Load mod settings and localize mod definitions.
        /// </summary>
        public override void LoadData()
        {
            InitializeLogging();
            LoadLocalization();

            MyAPIGateway.Gui.GuiControlRemoved += OnGuiControlRemoved;

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

                if (Network != null)
                {
                    if (Network.IsServer)
                    {
                        LoadSettings();
                        _networkHandler = new ServerHandler(Log, Network);
                    }
                    else
                    {
                        _networkHandler = new ClientHandler(Log, Network);
                        Network.SendToServer(new SettingsRequestMessage());
                    }
                }
            }
            else
            {
                LoadSettings();
            }
        }
Exemplo n.º 2
0
        public ChatHandler(ILogger log, Network network, NetworkHandlerBase networkHandler)
        {
            Log            = log;
            Network        = network;
            NetworkHandler = networkHandler;

            _commandHandler = new CommandHandler(Mod.NAME)
            {
                Prefix = $"/{Mod.Acronym}"
            };
            _commandHandler.Register(new Command {
                Name = "Enable", Description = ModText.Description_SS_Enable.GetString(), Execute = OnEnableOptionCommand
            });
            _commandHandler.Register(new Command {
                Name = "Disable", Description = ModText.Description_SS_Disable.GetString(), Execute = OnDisableOptionCommand
            });
            _commandHandler.Register(new Command {
                Name = "Set", Description = ModText.Description_SS_Set.GetString(), Execute = OnSetOptionCommand
            });
            _commandHandler.Register(new Command {
                Name = "List", Description = ModText.Description_SS_List.GetString(), Execute = OnListOptionsCommand
            });
            _commandHandler.Register(new Command {
                Name = "Help", Description = ModText.Description_SS_Help.GetString(), Execute = _commandHandler.ShowHelp
            });

            MyAPIGateway.Utilities.MessageEntered += OnMessageEntered;
        }
Exemplo n.º 3
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.º 4
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;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Unloads all data.
        /// </summary>
        protected override void UnloadData()
        {
            Log?.EnterMethod(nameof(UnloadData));
            MyAPIGateway.Gui.GuiControlRemoved -= OnGuiControlRemoved;

            if (DamageHandler != null)
            {
                Log?.Info("Stopping damage handler");
                DamageHandler = 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;
            }

            if (Controls != null)
            {
                Controls = null;
            }

            if (Defs != null)
            {
                Defs = null;
            }

            Static = null;
        }
        public void RegisterNetworkHandler( NetworkHandlerBase handler )
        {
            string handlerType = handler.GetType().AssemblyQualifiedName;
            List<NetworkHandlerBase> toRemove = new List<NetworkHandlerBase>();
            foreach ( var item in _networkHandlers )
            {
                if ( item.GetType().AssemblyQualifiedName == handlerType )
                {
                    if (ExtenderOptions.IsDebugging)
                        ApplicationLog.BaseLog.Error("Network handler already registered! " + handlerType);
                    toRemove.Add(handler);
                }
            }

            foreach (var oldHandler in toRemove)
                _networkHandlers.Remove(oldHandler);

            _networkHandlers.Add( handler );
        }