Esempio n. 1
0
        static void Main(string[] args)
        {
            //Your Elite Dangerous game path
            string path = "C:\\Users\\your_user_name\\Saved Games\\Frontier Developments\\Elite Dangerous";

            var statusWatcher = new StatusWatcher(path);

            statusWatcher.StatusUpdated += StatusWatcher_StatusUpdated;

            statusWatcher.StartWatching();

            var watcher = new JournalWatcher(path);

            watcher.GetEvent <FileheaderEvent>()?.AddHandler((s, e) => Console.WriteLine("Heading received: gameversion {0}, build {1}.", e.GameVersion, e.Build));
            watcher.GetEvent <ScanEvent>()?.AddHandler((s, e) => Console.WriteLine("Scanned a body {0}, it is {1}landable.", e.BodyName, (e.Landable ?? false) ? "" : "not "));
            watcher.GetEvent <DockedEvent>()?.AddHandler((s, e) => Console.WriteLine("Docked at {0}", e.StationName));

            watcher.GetEvent <FSDTargetEvent>()?.AddHandler((s, e) =>
            {
                Console.WriteLine("FSDTargetEvent");
                TPLink.Patterns.FSDTarget();
                if (IsDocked)
                {
                    TPLink.Patterns.ResetDocked();
                }
            });

            watcher.GetEvent <StartJumpEvent>()?.AddHandler((s, e) =>
            {
                Console.WriteLine("StartJumpEvent [{0}]", e.JumpType);
                TPLink.Patterns.FSDEntry();
            });
            watcher.GetEvent <FSDJumpEvent>()?.AddHandler((s, e) =>
            {
                Console.WriteLine("FSDJumpEvent [{0}]", e.StarSystem);
                TPLink.Patterns.FSDReset();
            });
            //watcher.GetEvent<SupercruiseEntryEvent>()?.AddHandler((s, e) => Console.WriteLine("SupercruiseEntryEvent"));
            watcher.GetEvent <SupercruiseExitEvent>()?.AddHandler((s, e) =>
            {
                Console.WriteLine("SupercruiseExitEvent [{0}, {1}]", e.StarSystem, e.BodyType);
                TPLink.Patterns.FSDReset();
            });

            watcher.GetEvent <DiedEvent>()?.AddHandler((s, e) =>
            {
                Console.WriteLine("Killed by {0}",
                                  e.Killers
                                  .Select(k => string.Format("{0} ({2}, flying a {1})", k.Name, k.Ship, k.Rank))
                                  .Aggregate((x, y) => string.Format("{0}, {1}", x, y)));
            });

            watcher.GetEvent <RankEvent>()?.AddHandler((s, e) => Console.WriteLine("Combat rank is {0}, Exploration rank is {1}", e.Combat.ToString(), e.Explore.ToString()));

            watcher.StartWatching().Wait();

            Console.ReadLine();

            watcher.StopWatching();
        }
Esempio n. 2
0
        internal GameStateWatcher(string gameInstallFolder, string gameOptionsFolder, string journalFolder, INativeMethods nativeMethods)
        {
            var gif = new GameInstallFolder(gameInstallFolder);
            var gof = new GameOptionsFolder(gameOptionsFolder);
            var jf  = new JournalFolder(journalFolder);

            _journalWatcher             = new JournalWatcher(jf);
            _journalWatcher.Started    += JournalWatcher_Started;
            _journalWatcher.EntryAdded += JournalWatcher_EntryAdded;

            _statusWatcher          = new StatusWatcher(jf);
            _statusWatcher.Changed += StatusWatcher_Changed;

            _bindingsWatcher          = new BindingsWatcher(gif, gof);
            _bindingsWatcher.Changed += BindingsWatcher_Changed;

            _graphicsConfig          = new GraphicsConfigWatcher(gif, gof);
            _graphicsConfig.Changed += GraphicsConfig_Changed;

            _modifierKeysWatcher          = new ModifierKeysWatcher(nativeMethods);
            _modifierKeysWatcher.Changed += ModifierKeysWatcher_Changed;

            _gameProcessWatcher          = new GameProcessWatcher(gif, nativeMethods);
            _gameProcessWatcher.Changed += GameProcessWatcher_Changed;

            _gameState = new GameState();
        }
Esempio n. 3
0
        public ServerCore(EDFIPServerConsole serverConsole)
        {
            ServerConsole = serverConsole;

            // Set up the Journal feeds to be passed to clients
            var userHome = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            JournalFileFolder = userHome + Constants.GameStateFolder;
            Log.Instance.Info("Tracking game data from folder: {journalfilefolder}", JournalFileFolder);
            StatusWatcher  = new StatusWatcher(JournalFileFolder);
            JournalWatcher = new JournalWatcher(JournalFileFolder);


            // Add events to watch list
            StatusEventHandler           = new StatusEventHandler(this);
            StatusWatcher.StatusUpdated += StatusEventHandler.HandleEvent;

            TargetEventHandler = new TargetEventHandler(this);
            JournalWatcher.GetEvent <ShipTargetedEvent>().Fired += TargetEventHandler.HandleEvent;

            // Start Matric Integration
            matricapi.Connect();

            // If Immediate start is enabled, start the server
            if (Properties.Settings.Default.ImmediateStart == true)
            {
                this.Start();
            }
        }
Esempio n. 4
0
 public Action(StatusWatcher statusWatcher, Status triggerWhen = Status.NotWorking, string name = "ContingenceAction")
 {
     Identifier     = Guid.NewGuid();
     Name           = name;
     TriggerWhen    = triggerWhen;
     _statusWatcher = statusWatcher;
 }
Esempio n. 5
0
        private IList <Actions.Action> BuildActionsForWatcher(StatusWatcher watcher, WatcherSection configWatcher)
        {
            var                  result = new List <Actions.Action>();
            IList <object>       listOfParameters;
            IList <PropertyInfo> properties;

            for (int j = 0; j < configWatcher.ContingenceActions.Count; j++)
            {
                var contingenceActionFromConfig = configWatcher.ContingenceActions[j];

                var type = Type.GetType(contingenceActionFromConfig.Type);
                var constructorInformation = type.GetConstructors().FirstOrDefault();

                listOfParameters = new List <object>();
                listOfParameters.Add(watcher);

                properties = contingenceActionFromConfig.GetType().GetProperties();
                foreach (var parameter in constructorInformation.GetParameters())
                {
                    if (parameter.Name.ToLower() != "statuswatcher")
                    {
                        listOfParameters.Add(
                            Convert.ChangeType(
                                properties.FirstOrDefault(x => x.Name.ToLower() == parameter.Name.ToLower()).GetValue(contingenceActionFromConfig),
                                parameter.ParameterType,
                                CultureInfo.InvariantCulture)
                            );
                    }
                }

                Actions.Action action = Activator.CreateInstance(type, listOfParameters.ToArray()) as Actions.Action;
                result.Add(action);
            }
            return(result);
        }
Esempio n. 6
0
        public void WatcherThrowsWhenTheStatusFolderIsNotAValidJournalFolder()
        {
            Assert.Throws <ArgumentNullException>(() => { using var x = new StatusWatcher(null); });

            var ex = Assert.Throws <ArgumentException>(() => { using var x = new StatusWatcher(new JournalFolder(@"TestFiles")); });

            Assert.Contains("' is not a valid Elite:Dangerous journal folder.", ex.Message, StringComparison.Ordinal);
        }
Esempio n. 7
0
        public void WatcherDoesNotThrowWhenDisposingTwice()
        {
            var watcher = new StatusWatcher(_jf);

#pragma warning disable IDISP016, IDISP017
            watcher.Dispose();
            watcher.Dispose();
#pragma warning restore IDISP016, IDISP017
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            // Uncomment this line of code to allow for debugging
            //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); }

            Logger.Instance.LogMessage(TracingLevel.INFO, "Init Elite Api");

            try
            {
                GetKeyBindings(null);


                var journalPath = StandardDirectory.FullName;

                Logger.Instance.LogMessage(TracingLevel.INFO, "journal path " + journalPath);

                if (!Directory.Exists(journalPath))
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {journalPath}");
                }

                var defaultFilter = @"Journal.*.log";
//#if DEBUG
                //defaultFilter = @"JournalAlpha.*.log";
//#endif

                StatusWatcher = new StatusWatcher(journalPath);

                StatusWatcher.StatusUpdated += EliteData.HandleStatusEvents;

                StatusWatcher.StartWatching();

                JournalWatcher = new JournalWatcher(journalPath, defaultFilter);

                JournalWatcher.AllEventHandler += EliteData.HandleEliteEvents;

                JournalWatcher.StartWatching().Wait();

                CargoWatcher = new CargoWatcher(journalPath);

                CargoWatcher.CargoUpdated += EliteData.HandleCargoEvents;

                CargoWatcher.StartWatching();
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.FATAL, $"Elite Api: {ex}");
            }


            //EliteAPI.Events.AllEvent += (sender, e) => Console.Beep();

            Profile.ReadProfiles();


            SDWrapper.Run(args);
        }
Esempio n. 9
0
        public async Task WatcherRaisesTheChangedEventOnStart()
        {
            using var watcher = new StatusWatcher(_jf);
            var ecs = new EventCollector <StatusEntry>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart));

            var status = await ecs.WaitAsync(() =>
            {
                watcher.Start();
                watcher.Stop();
            }).ConfigureAwait(false);

            Assert.Equal("Status", status.Event);
        }
Esempio n. 10
0
 /// <summary>
 /// Resets the API.
 /// </summary>
 public void Reset()
 {
     //Reset services.
     try { Events = new Events.EventHandler(); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'Events'.", ex); }
     try { Commander = new CommanderStatus(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'Commander'.", ex); }
     try { Location = new LocationStatus(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'Location'.", ex); }
     try { DiscordRichPresence = new RichPresenceClient(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'DiscordRichPresence'.", ex); }
     try { StatusWatcher = new StatusWatcher(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'StatusWatcher'.", ex); }
     try { CargoWatcher = new CargoWatcher(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'CargoWatcher'.", ex); }
     try { Status = EliteAPI.Status.GameStatus.FromFile(new FileInfo(JournalDirectory + "//Status.json"), this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'Status'.", ex); }
     try { JournalParser = new JournalParser(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'JournalParser'.", ex); }
     try { MaterialWatcher = new MaterialWatcher(this); } catch (Exception ex) { Logger.Log(Severity.Warning, "Couldn't instantiate service 'MaterialWatcher'.", ex); }
     JournalParser.processedLogs = new List <string>();
 }
Esempio n. 11
0
        public async Task WatchesForChangesInTheStatusFile()
        {
            using var dir     = new TestFolder(_jf.FullName);
            using var watcher = new StatusWatcher(new JournalFolder(dir.Name));
            watcher.Start();

            var ec = new EventCollector <StatusEntry>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatchesForChangesInTheStatusFile));

            var status = await ec.WaitAsync(() => dir.WriteText("Status.json", "{\"event\":\"One\"}\r\n")).ConfigureAwait(false);

            Assert.Equal("One", status.Event);

            status = await ec.WaitAsync(() => dir.WriteText("Status.json", string.Empty), 100).ConfigureAwait(false);

            Assert.Null(status);

            status = await ec.WaitAsync(() => dir.WriteText("Status.json", "{\"event\":\"Two\"}\r\n")).ConfigureAwait(false);

            Assert.Equal("Two", status.Event);
        }
Esempio n. 12
0
        public void StartAndStopAreNotReentrant()
        {
            using var watcher = new StatusWatcher(_jf);

            bool IsRunning() => watcher.GetPrivateField <bool>("_running");

            Assert.False(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());
        }
Esempio n. 13
0
 public ConsoleAction(StatusWatcher statusWatcher, string messageLayout, Status triggerWhen, string name = "ConsoleAction")
     : base(statusWatcher, triggerWhen, name)
 {
     _messageLayout = messageLayout;
 }
Esempio n. 14
0
 public LogFileAction(StatusWatcher statusWatcher, string fileName, string messageLayout, Status triggerWhen, string name = "LogFileAction")
     : base(statusWatcher, triggerWhen, name)
 {
     _fileName      = fileName;
     _messageLayout = messageLayout;
 }
Esempio n. 15
0
        static void Main(string[] args)
        {
            // Uncomment this line of code to allow for debugging
            //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); }

            Logger.Instance.LogMessage(TracingLevel.INFO, "Init Elite Api");

            try
            {
                var journalPath = StandardDirectory.FullName;

                Logger.Instance.LogMessage(TracingLevel.INFO, "journal path " + journalPath);

                if (!Directory.Exists(journalPath))
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {journalPath}");
                }

                statusWatcher = new StatusWatcher(journalPath);

                statusWatcher.StatusUpdated += EliteData.HandleStatusEvents;

                statusWatcher.StartWatching();

                watcher = new JournalWatcher(journalPath);

                watcher.AllEventHandler += EliteData.HandleEliteEvents;

                watcher.StartWatching().Wait();

                var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings");

                Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath);

                if (!Directory.Exists(bindingsPath))
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}");
                }

                var bindsName = File.ReadAllText(Path.Combine(bindingsPath, "StartPreset.start"));

                var fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds");

                if (!File.Exists(fileName))
                {
                    //Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                    fileName = fileName.Replace(".3.0.binds", ".binds");

                    if (!File.Exists(fileName))
                    {
                        bindingsPath = SteamPath.FindSteamEliteDirectory();

                        if (!string.IsNullOrEmpty(bindingsPath))
                        {
                            fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds");

                            if (!File.Exists(fileName))
                            {
                                //Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                                fileName = fileName.Replace(".3.0.binds", ".binds");
                            }
                        }
                    }
                }

                var serializer = new XmlSerializer(typeof(UserBindings));

                Logger.Instance.LogMessage(TracingLevel.INFO, "using " + fileName);

                var reader = new StreamReader(fileName);
                Bindings = (UserBindings)serializer.Deserialize(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.FATAL, $"Elite Api: {ex}");
            }


            //EliteAPI.Events.AllEvent += (sender, e) => Console.Beep();


            SDWrapper.Run(args);
        }