public void OnPacketEventData(ref PacketEventData pEventData, PacketSource packetSource)
        {
            if (packetSource == PacketSource.File)
            {
                return;
            }

            var sessionId = pEventData.Header.SessionUID;

            if (pEventData.EventStringCode == "SSTA")
            {
                if (_files.TryGetValue(sessionId, out var stream))
                {
                    Logger.Warn(
                        $"Received session start for SessionId {sessionId} that already exists in active session list, will overwrite");
                    stream.Dispose();
                    _files.Remove(sessionId);
                }

                var path = Path.Combine(_saveLocation, $"{_filePrefix}_{sessionId}.f1s.gz");
                try
                {
                    if (!Directory.Exists(_saveLocation))
                    {
                        Directory.CreateDirectory(_saveLocation);
                    }

                    var fileStream = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
                    var gzipStream = new GZipStream(fileStream, CompressionLevel.Optimal);
                    _files[sessionId] = gzipStream;
                    _ignoredSessions.Remove(sessionId);
                    stream = gzipStream;
                    Logger.Info($"Created save file for session {sessionId} at {path}");
                }
                catch (Exception ex)
                {
                    Logger.Error($"Exception while creating a save file for session {sessionId} at {path}", ex);
                }

                WritePacket(sessionId, ref pEventData, packetSource);
            }
            else if (pEventData.EventStringCode == "SEND")
            {
                if (_files.TryGetValue(sessionId, out var stream))
                {
                    WritePacket(sessionId, ref pEventData, packetSource);

                    Logger.Info($"Closing save file for session {sessionId}");
                    stream.Dispose();
                    _files.Remove(sessionId);
                }
                else
                {
                    Logger.Warn($"Received session end for session {sessionId}, but no file is opened for saving");
                }
            }
        }
Ejemplo n.º 2
0
 public void OnPacketEventData(ref PacketEventData pEventData, PacketSource packetSource)
 {
     if (pEventData.EventStringCode == "SSTA")
     {
         _sessionLastTimes[pEventData.Header.SessionUID] = 0.0f;
     }
     else
     {
         _sessionLastTimes.Remove(pEventData.Header.SessionUID);
     }
 }
        public void OnPacketEventData(ref PacketEventData pEventData, PacketSource source)
        {
            var   sc           = pEventData.EventStringCode;
            Event sessionEvent = sc switch
            {
                "SSTA" => (Event) new SessionStart(pEventData.Header.SessionUID, DateTime.Now, pEventData.Header.SessionTime),
                "SEND" => (Event) new SessionEnd(pEventData.Header.SessionUID, DateTime.Now, pEventData.Header.SessionTime),
                _ => throw new InvalidOperationException($"Invalid session type {sc}")
            };

            _newPacketRead?.Invoke(this, sessionEvent);
        }
Ejemplo n.º 4
0
        public async Task ReceiveLoop(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                UdpReceiveResult receiveResult = await _udpReceiver.Receive(cancellationToken).ConfigureAwait(false);

                byte[]       rawPacked = receiveResult.Buffer;
                PacketHeader header    = DeserializePackedHeader(rawPacked);
                switch (header.MPacketId)
                {
                case 0:
                    PacketMotionData packetMotionData = Deserialize <PacketMotionData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetMotionData);
                    break;

                case 1:
                    PacketSessionData packetSessionData = Deserialize <PacketSessionData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetSessionData);
                    break;

                case 2:
                    PacketLapData packetLapData = Deserialize <PacketLapData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetLapData);
                    break;

                case 3:
                    PacketEventData packetEventData = Deserialize <PacketEventData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetEventData);
                    break;

                case 4:
                    PacketParticipantsData packetParticipantsData = Deserialize <PacketParticipantsData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetParticipantsData);
                    break;

                case 5:
                    PacketCarSetupData packetCarSetupData = Deserialize <PacketCarSetupData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarSetupData);
                    break;

                case 6:
                    PacketCarTelemetryData packetCarTelemetryData = Deserialize <PacketCarTelemetryData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarTelemetryData);
                    break;

                case 7:
                    PacketCarStatusData packetCarStatusData = Deserialize <PacketCarStatusData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarStatusData);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        internal void ProcessPacket(PacketEventData packetEventData)
        {
            if (packetEventData.MEventStringCode.FromArray() == "SSTA")
            {
                Reset();
                return;
            }

            if (packetEventData.MEventStringCode.FromArray() == "RTMT")
            {
                AllPacketsComposition.AdditionalData.RetiredDrivers[packetEventData.MEventDetails.retirement.vehicleIdx] = true;
                return;
            }
        }
Ejemplo n.º 6
0
 public void OnPacketEventData(ref PacketEventData pEventData, PacketSource packetSource)
 {
     HandlePacket(ph => ph.OnPacketEventData, ref pEventData, packetSource);
 }