private void ReadLogFile()
 {
     _running = true;
     FindInitialOffset();
     while (!_stop)
     {
         lock (_sync)
         {
             if (_collected)
             {
                 _lines.Clear();
                 _collected = false;
             }
             var fileInfo = new FileInfo(_filePath);
             if (fileInfo.Exists)
             {
                 using (var fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                 {
                     fs.Seek(_offset, SeekOrigin.Begin);
                     if (fs.Length == _offset)
                     {
                         Thread.Sleep(Config.Instance.UpdateDelay);
                         continue;
                     }
                     using (var sr = new StreamReader(fs))
                     {
                         string line;
                         while (!sr.EndOfStream && (line = sr.ReadLine()) != null)
                         {
                             if (!line.StartsWith("D ") || (!sr.EndOfStream && sr.Peek() != 'D'))
                             {
                                 break;
                             }
                             if (_info.Name == "Power")
                             {
                                 GameV2.AddHSLogLine(line);
                             }
                             if (!_info.HasFilters || _info.StartsWithFilters.Any(x => line.Substring(19).StartsWith(x)) ||
                                 _info.ContainsFilters.Any(x => line.Substring(19).Contains(x)))
                             {
                                 var logLine = new LogLineItem(_info.Name, line, fileInfo.LastWriteTime);
                                 if (logLine.Time >= _startingPoint)
                                 {
                                     _lines.Add(logLine);
                                 }
                             }
                             _offset += Encoding.UTF8.GetByteCount(line + Environment.NewLine);
                         }
                     }
                 }
             }
         }
         Thread.Sleep(Config.Instance.UpdateDelay);
     }
     _running = false;
 }
Exemplo n.º 2
0
        private void Analyze(string log)
        {
            var logLines = log.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var rawLogLine in logLines)
            {
                var logLine = new string(rawLogLine.Skip(25).ToArray());
                _gameState.CurrentOffset += logLine.Length + 1;

                if (logLine.StartsWith("["))
                {
                    GameV2.AddHSLogLine(logLine);
                    API.LogEvents.OnLogLine.Execute(logLine);
                }

                if (logLine.StartsWith("[Power] GameState."))
                {
                    _powerGameStateLineHandler.Handle(logLine, _gameState, _game);
                }
                else if (logLine.StartsWith("[Power]"))
                {
                    _powerLineHandler.Handle(logLine, _gameState, _game);
                }
                else if (logLine.StartsWith("[Asset]"))
                {
                    _assetHandler.Handle(logLine, _gameState, _game);
                }
                else if (logLine.StartsWith("[Bob]"))
                {
                    _bobHandler.Handle(logLine, _gameState, _game);
                }
                else if (logLine.StartsWith("[Rachelle]"))
                {
                    _rachelleHandler.Handle(logLine, _gameState, _game);
                }
                else if (logLine.StartsWith("[Zone]"))
                {
                    _zoneHandler.Handle(logLine, _gameState);
                }
                else if (logLine.StartsWith("[Arena]"))
                {
                    _arenaHandler.Handle(logLine, _gameState, _game);
                }

                if (_gameState.First)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private static void ProcessNewLines()
        {
            foreach (var item in ToProcess.Where(item => item.Value != null))
            {
                foreach (var line in item.Value.Where(line => line != null))
                {
                    _game.GameTime.Time = line.Time;
                    switch (line.Namespace)
                    {
                    case "Power":
                        GameV2.AddHSLogLine(line.Line);
                        PowerLineHandler.Handle(line.Line, _gameState, _game);
                        API.LogEvents.OnPowerLogLine.Execute(line.Line);
                        break;

                    case "Zone":
                        ZoneHandler.Handle(line.Line, _gameState);
                        API.LogEvents.OnZoneLogLine.Execute(line.Line);
                        break;

                    case "Asset":
                        AssetHandler.Handle(line.Line, _gameState, _game);
                        API.LogEvents.OnAssetLogLine.Execute(line.Line);
                        break;

                    case "Bob":
                        BobHandler.Handle(line.Line, _gameState, _game);
                        API.LogEvents.OnBobLogLine.Execute(line.Line);
                        break;

                    case "Rachelle":
                        RachelleHandler.Handle(line.Line, _gameState, _game);
                        API.LogEvents.OnRachelleLogLine.Execute(line.Line);
                        break;

                    case "Arena":
                        ArenaHandler.Handle(line.Line, _gameState, _game);
                        API.LogEvents.OnArenaLogLine.Execute(line.Line);
                        break;

                    case "LoadingScreen":
                        LoadingScreenHandler.Handle(line.Line, _gameState, _game);
                        break;
                    }
                }
            }
            ToProcess.Clear();
            Helper.UpdateEverything(_game);
        }