Пример #1
0
        /// <inheritdoc />
        public void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Red)
        {
            ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, message));
            var commands = Torch.GetManager <CommandManager>();

            if (commands.IsCommand(message))
            {
                var response = commands.HandleCommandFromServer(message);
                ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, response));
            }
            else
            {
                var msg = new ScriptedChatMsg {
                    Author = author, Font = font, Target = playerId, Text = message
                };
                MyMultiplayerBase.SendScriptedChatMessage(ref msg);
                var character = MySession.Static.Players.TryGetIdentity(playerId)?.Character;
                var steamId   = GetSteamId(playerId);
                if (character == null)
                {
                    return;
                }

                var addToGlobalHistoryMethod = typeof(MyCharacter).GetMethod("OnGlobalMessageSuccess", BindingFlags.Instance | BindingFlags.NonPublic);
                Torch.GetManager <NetworkManager>().RaiseEvent(addToGlobalHistoryMethod, character, steamId, steamId, message);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public void LoadPlugins()
        {
            _updateManager = Torch.GetManager <UpdateManager>();
            var commands = Torch.GetManager <CommandManager>();

            if (Torch.Config.GetPluginUpdates)
            {
                DownloadPlugins();
            }
            else
            {
                _log.Warn("Automatic plugin updates are disabled.");
            }

            _log.Info("Loading plugins");
            var dlls = Directory.GetFiles(PluginDir, "*.dll", SearchOption.AllDirectories);

            foreach (var dllPath in dlls)
            {
                _log.Debug($"Loading plugin {dllPath}");
                var asm = Assembly.UnsafeLoadFrom(dllPath);

                foreach (var type in asm.GetExportedTypes())
                {
                    if (type.GetInterfaces().Contains(typeof(ITorchPlugin)))
                    {
                        if (type.GetCustomAttribute <PluginAttribute>() == null)
                        {
                            continue;
                        }

                        try
                        {
                            var plugin = (TorchPluginBase)Activator.CreateInstance(type);
                            if (plugin.Id == default(Guid))
                            {
                                throw new TypeLoadException($"Plugin '{type.FullName}' is missing a {nameof(PluginAttribute)}");
                            }

                            _log.Info($"Loading plugin {plugin.Name} ({plugin.Version})");
                            plugin.StoragePath = Torch.Config.InstancePath;
                            Plugins.Add(plugin);

                            commands.RegisterPluginCommands(plugin);
                        }
                        catch
                        {
                            _log.Error($"Error loading plugin '{type.FullName}'");
                            throw;
                        }
                    }
                }
            }

            Plugins.ForEach(p => p.Init(Torch));
            PluginsLoaded?.Invoke(Plugins.ToList());
        }
Пример #3
0
 public override void Init()
 {
     try
     {
         Torch.GetManager <INetworkManager>().RegisterNetworkHandler(new ChatIntercept(this));
     }
     catch
     {
         _log.Error("Failed to initialize network intercept, command hiding will not work! Falling back to another method.");
         MyMultiplayer.Static.ChatMessageReceived += Static_ChatMessageReceived;
     }
 }
Пример #4
0
 /// <inheritdoc />
 public override void Init()
 {
     _fsManager = Torch.GetManager <FilesystemManager>();
     CheckAndUpdateTorch();
 }
Пример #5
0
 /// <inheritdoc />
 public override void Init()
 {
     Torch.SessionLoaded += OnSessionLoaded;
     Torch.GetManager <ChatManager>().MessageRecieved += Instance_MessageRecieved;
 }
Пример #6
0
 public override void Init()
 {
     RegisterCommandModule(typeof(TorchCommands));
     Torch.GetManager <ChatManager>().MessageRecieved += HandleCommand;
 }