private void OnState(PC2BasePacket newState) { lock (_stateLock) { try { if (newState.baseUDP.packetType.Equals(PC2PacketType.TimeStats)) { var time = (PCars2TimeStatsData)newState; time.participantStats.ForEach(participant => { ParticipantLapTimes current; if (_lapTimesStore.ExistsWhere(l => l.participantIndex.Equals(participant.participantIndex) && l.SessionId.Equals(_currentSession.Id))) { current = _lapTimesStore.FindWhere(l => l.participantIndex.Equals(participant.participantIndex) && l.SessionId.Equals(_currentSession.Id)); } else { current = new ParticipantLapTimes(Key.Create(), _currentSession.Id, _currentSession.SessionType, participant.participantIndex, new Dictionary <int, ParticipantLapTime>()); } var updated = PC2StdLapTimeFactory.InsertIfNewTime(participant, current); NotifyAll(updated); }); } } catch (Exception e) { } } }
private void OnState(PC2BasePacket newState) { try { var packetType = newState.baseUDP.packetType; if (packetType.Equals(PC2PacketType.GameState)) { var gameState = (PC2GameStatePacket)newState; OnGameState(gameState); } } catch { } }
private void OnPacket(PC2BasePacket packet) { try { if (packet.baseUDP.packetType.Equals(PC2PacketType.Telemetry)) { lock (_stateLock) { var telemetry = (PCars2TelemetryData)packet; var doubleThrottle = (double)telemetry.throttle; var adjustedThrottle = doubleThrottle / 255d * 100d; NotifyAll(new ThrottlePosition(adjustedThrottle, telemetry.baseUDP.timeStamp)); } } } catch { } }
private void OnState(PC2BasePacket newState) { try { if (newState.baseUDP.packetType.Equals(PC2PacketType.RaceDefinition)) { var raceDef = (PC2RaceDefinition)newState; var trackNameZero = Array.IndexOf(raceDef.trackLocation, (byte)0); var trackName = Encoding.ASCII.GetString(raceDef.trackLocation, 0, trackNameZero < 0 ? raceDef.trackLocation.Length : trackNameZero); var trackVariationZero = Array.IndexOf(raceDef.trackVariation, (byte)0); var trackVariation = Encoding.ASCII.GetString(raceDef.trackVariation, 0, trackVariationZero < 0 ? raceDef.trackVariation.Length : trackVariationZero); var trackInfo = new SessionTrackInfo(_currentSession.Id, trackName, trackVariation); NotifyAll(trackInfo); } } catch { } }