public void ModifyParsers()
        {
            var loc            = Utilities.CurrentLocalization.LocalizationIndex;
            var parserVersions = _rconParsers.Select(p => p.Name).ToArray();

            var(index, parser) = loc["SETUP_SERVER_RCON_PARSER_VERSION"].PromptSelection(parserVersions[0],
                                                                                         null, parserVersions);

            if (index < 0)
            {
                return;
            }

            _selectedParser    = _rconParsers.FirstOrDefault(p => p.Name == parser);
            RConParserVersion  = _selectedParser?.Version;
            EventParserVersion = _selectedParser?.Version;

            if (index <= 0 || _rconParsers[index].CanGenerateLogPath)
            {
                return;
            }

            Console.WriteLine(loc["SETUP_SERVER_NO_LOG"]);
            ManualLogPath = loc["SETUP_SERVER_LOG_PATH"].PromptString();
        }
Esempio n. 2
0
        public async Task Initialize(IManager mgr)
        {
            bool firstRun = ScriptEngine == null;

            // it's been loaded before so we need to call the unload event
            if (!firstRun)
            {
                await OnUnloadAsync();
            }

            Manager = mgr;
            string script;

            using (var stream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream, Encoding.Default))
                {
                    script = await reader.ReadToEndAsync();
                }
            }

            ScriptEngine = new Jint.Engine(cfg =>
                                           cfg.AllowClr(new[]
            {
                typeof(System.Net.Http.HttpClient).Assembly,
                typeof(EFClient).Assembly,
            })
                                           .CatchClrExceptions());

            ScriptEngine.Execute(script);
            ScriptEngine.SetValue("_localization", Utilities.CurrentLocalization);
            dynamic pluginObject = ScriptEngine.GetValue("plugin").ToObject();

            this.Author  = pluginObject.author;
            this.Name    = pluginObject.name;
            this.Version = (float)pluginObject.version;


            try
            {
                if (pluginObject.isParser)
                {
                    await OnLoadAsync(mgr);

                    IEventParser eventParser = (IEventParser)ScriptEngine.GetValue("eventParser").ToObject();
                    IRConParser  rconParser  = (IRConParser)ScriptEngine.GetValue("rconParser").ToObject();
                    Manager.AdditionalEventParsers.Add(eventParser);
                    Manager.AdditionalRConParsers.Add(rconParser);
                }
            }
            catch { }


            if (!firstRun)
            {
                await OnLoadAsync(mgr);
            }
        }
Esempio n. 3
0
        public void Setup()
        {
            serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider();

            fakeLogger         = serviceProvider.GetRequiredService <ILogger>();
            fakeManager        = serviceProvider.GetRequiredService <IManager>();
            fakeRConConnection = serviceProvider.GetRequiredService <IRConConnection>();
            fakeRConParser     = serviceProvider.GetRequiredService <IRConParser>();
            mockEventHandler   = serviceProvider.GetRequiredService <EventHandlerMock>();
            appConfig          = serviceProvider.GetRequiredService <ApplicationConfiguration>();

            var rconConnectionFactory = serviceProvider.GetRequiredService <IRConConnectionFactory>();

            A.CallTo(() => rconConnectionFactory.CreateConnection(A <string> .Ignored, A <int> .Ignored, A <string> .Ignored))
            .Returns(fakeRConConnection);

            A.CallTo(() => fakeRConParser.Configuration)
            .Returns(ConfigurationGenerators.CreateRConParserConfiguration(serviceProvider.GetRequiredService <IParserRegexFactory>()));

            A.CallTo(() => fakeManager.AddEvent(A <GameEvent> .Ignored))
            .Invokes((fakeCall) => mockEventHandler.HandleEvent(fakeManager, fakeCall.Arguments[0] as GameEvent));
        }
Esempio n. 4
0
 public void AddRConParser(IRConParser parser)
 {
     rconParsers.Add(parser);
 }
Esempio n. 5
0
 public void SetConfiguration(IRConParser config)
 {
 }
Esempio n. 6
0
        public async Task Initialize(IManager manager, IScriptCommandFactory scriptCommandFactory, IScriptPluginServiceResolver serviceResolver)
        {
            await _onProcessing.WaitAsync();

            try
            {
                // for some reason we get an event trigger when the file is not finished being modified.
                // this must have been a change in .NET CORE 3.x
                // so if the new file is empty we can't process it yet
                if (new FileInfo(_fileName).Length == 0L)
                {
                    return;
                }

                bool firstRun = _scriptEngine == null;

                // it's been loaded before so we need to call the unload event
                if (!firstRun)
                {
                    await OnUnloadAsync();

                    foreach (string commandName in _registeredCommandNames)
                    {
                        manager.GetLogger(0).WriteDebug($"Removing plugin registered command \"{commandName}\"");
                        manager.RemoveCommandByName(commandName);
                    }

                    _registeredCommandNames.Clear();
                }

                successfullyLoaded = false;
                string script;

                using (var stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(stream, Encoding.Default))
                    {
                        script = await reader.ReadToEndAsync();
                    }
                }

                _scriptEngine = new Engine(cfg =>
                                           cfg.AllowClr(new[]
                {
                    typeof(System.Net.Http.HttpClient).Assembly,
                    typeof(EFClient).Assembly,
                    typeof(Utilities).Assembly,
                    typeof(Encoding).Assembly
                })
                                           .CatchClrExceptions());

                _scriptEngine.Execute(script);
                _scriptEngine.SetValue("_localization", Utilities.CurrentLocalization);
                _scriptEngine.SetValue("_serviceResolver", serviceResolver);
                dynamic pluginObject = _scriptEngine.GetValue("plugin").ToObject();

                Author  = pluginObject.author;
                Name    = pluginObject.name;
                Version = (float)pluginObject.version;

                var commands = _scriptEngine.GetValue("commands");

                if (commands != JsValue.Undefined)
                {
                    try
                    {
                        foreach (var command in GenerateScriptCommands(commands, scriptCommandFactory))
                        {
                            manager.GetLogger(0).WriteDebug($"Adding plugin registered command \"{command.Name}\"");
                            manager.AddAdditionalCommand(command);
                            _registeredCommandNames.Add(command.Name);
                        }
                    }

                    catch (RuntimeBinderException e)
                    {
                        throw new PluginException($"Not all required fields were found: {e.Message}")
                              {
                                  PluginFile = _fileName
                              };
                    }
                }

                await OnLoadAsync(manager);

                try
                {
                    if (pluginObject.isParser)
                    {
                        IsParser = true;
                        IEventParser eventParser = (IEventParser)_scriptEngine.GetValue("eventParser").ToObject();
                        IRConParser  rconParser  = (IRConParser)_scriptEngine.GetValue("rconParser").ToObject();
                        manager.AdditionalEventParsers.Add(eventParser);
                        manager.AdditionalRConParsers.Add(rconParser);
                    }
                }

                catch (RuntimeBinderException) { }

                if (!firstRun)
                {
                    await OnLoadAsync(manager);
                }

                successfullyLoaded = true;
            }

            catch (JavaScriptException ex)
            {
                throw new PluginException($"An error occured while initializing script plugin: {ex.Error} (Line: {ex.Location.Start.Line}, Character: {ex.Location.Start.Column})")
                      {
                          PluginFile = _fileName
                      };
            }

            catch
            {
                throw;
            }

            finally
            {
                if (_onProcessing.CurrentCount == 0)
                {
                    _onProcessing.Release(1);
                }
            }
        }
Esempio n. 7
0
 public void SetConfiguration(IRConParser parser)
 {
     this.parser = parser;
     config      = parser.Configuration;
 }