public Competitor GetCompetitorByUserName(int boardId, string userName) { var profile = UserProfiles.FirstOrDefault( x => x.UserName.Equals(userName, System.StringComparison.InvariantCultureIgnoreCase)); return(Competitors.FirstOrDefault(x => profile != null && x.ProfileUserId.Equals(profile.UserId))); }
public void UpdateDriverTyreType(string driverName, string tyre) { var driver = Competitors.FirstOrDefault(comp => comp.DriverName == driverName); if (driver == null || driver?.CurrentTyreCompound == tyre) { return; } driver.CurrentTyreCompound = tyre; var result = ApiWrapperNet4.Post <Competitor>("competitor/editcompetitor", driver); }
protected override void OnConnectionClosed(MsgConnectionClosed msg) { using (var a = new FileStream("Test.txt", FileMode.Append, FileAccess.Write)) using (var b = new StreamWriter(a)) { b.WriteLine($"{DateTime.Now.TimeOfDay}: OnConnectionClosed Called {msg.CarId}"); } var competitor = Competitors.FirstOrDefault(comp => comp.ConnectionId == msg.CarId && comp.DriverGuid == msg.DriverGuid); Competitors.Remove(competitor); competitor.IsConnected = false; ApiWrapperNet4.Post <Competitor>("competitor/disconnectCompetitor", competitor); }
public void AddSector(string driverName, int sectorTime, eSector sector) { try { switch (sector) { case eSector.Sector1: var driver = Competitors.FirstOrDefault(comp => comp.DriverName == driverName); var currentLap = new Lap { LapId = Guid.NewGuid().ToString(), CompetitorId = driver.CompetitorId, ConnectionId = driver.ConnectionId, Sector1 = sectorTime }; while (CurrentLaps.Any(laps => laps.CompetitorId == driver.CompetitorId)) { var delLap = CurrentLaps.FirstOrDefault(laps => laps.CompetitorId == driver.CompetitorId); CurrentLaps.Remove(delLap); } CurrentLaps.Add(currentLap); var addLap = ApiWrapperNet4.Post <Lap>("lap/addlap", currentLap); break; case eSector.Sector2: var driver2 = Competitors.FirstOrDefault(comp => comp.DriverName == driverName); CurrentLaps.FirstOrDefault(lap => lap.CompetitorId == driver2.CompetitorId).Sector2 = sectorTime; var addLap2 = ApiWrapperNet4.Post <Lap>("lap/editlap", CurrentLaps.FirstOrDefault(lap => lap.CompetitorId == driver2.CompetitorId)); break; case eSector.Sector3: var driver3 = Competitors.FirstOrDefault(comp => comp.DriverName == driverName); CurrentLaps.FirstOrDefault(lap => lap.CompetitorId == driver3.CompetitorId).Sector3 = sectorTime; var addLap3 = ApiWrapperNet4.Post <Lap>("lap/editlap", CurrentLaps.FirstOrDefault(lap => lap.CompetitorId == driver3.CompetitorId)); break; default: break; } } catch (Exception) { } }
protected override void OnCollision(IncidentInfo msg) { using (var a = new FileStream("Test.txt", FileMode.Append, FileAccess.Write)) using (var b = new StreamWriter(a)) { b.WriteLine($"{DateTime.Now.TimeOfDay}: OnCollison Called {msg.ImpactSpeed}"); } var collision = new Collision { CollisionId = Guid.NewGuid().ToString(), Competitor1 = Competitors.FirstOrDefault(driver => driver.ConnectionId == msg.ConnectionId1)?.CompetitorId, Competitor2 = Competitors.FirstOrDefault(driver => driver.ConnectionId == msg.ConnectionId2)?.CompetitorId, ImpactSpeed = msg.ImpactSpeed, RelPosition = msg.RelPosition.ToString(), SessionId = CurrentSession.SessionId, Timestamp = (int)DateTime.Now.TimeOfDay.TotalMilliseconds, Type = msg.Type, WorldPostion = msg.WorldPosition.ToString() }; ApiWrapperNet4.Post <Competitor>("collision/addcollision", collision); }
public Competitor GetCompetitorById(int id) { return(Competitors.FirstOrDefault(x => x.CompetitorId.Equals(id))); }
public override void ConnectSportTypedCompetitors() { base.ConnectSportTypedCompetitors(); HomeTeam = HomeTeam ?? new CSportTypedCompetitorInGame <ESoccerStages>(Competitors.FirstOrDefault()); AwayTeam = AwayTeam ?? new CSportTypedCompetitorInGame <ESoccerStages>(Competitors.LastOrDefault()); }
protected override void OnCarUpdate(DriverInfo driverInfo) { //using (var a = new FileStream("Test.txt", FileMode.Append, FileAccess.Write)) //using (var b = new StreamWriter(a)) //{ // b.WriteLine($"{DateTime.Now.TimeOfDay}: OnCarUpdate Called {driverInfo.TotalTime} {driverInfo.Gap}"); //} var currentCompetitor = Competitors.FirstOrDefault(driver => driver.DriverGuid == driverInfo.DriverGuid); if (currentCompetitor == null) { return; } Competitor matchCompetitor = new Competitor() { CompetitorId = currentCompetitor.CompetitorId, CurrentAcceleration = currentCompetitor.CurrentAcceleration, CurrentSpeed = currentCompetitor.CurrentSpeed, CurrentTyreCompound = currentCompetitor.CurrentTyreCompound, Distance = currentCompetitor.Distance, DriverId = currentCompetitor.DriverId, EndSplinePos = currentCompetitor.EndSplinePos, IsConnected = currentCompetitor.IsConnected, LapsLead = currentCompetitor.LapsLead, SessionId = currentCompetitor.SessionId, StartSplinePos = currentCompetitor.StartSplinePos, DriverGuid = currentCompetitor.DriverGuid, DriverName = currentCompetitor.DriverName, DriverTeam = currentCompetitor.DriverTeam, CarId = currentCompetitor.CarId, CarModel = currentCompetitor.CarModel, CarSkin = currentCompetitor.CarSkin, BallastKg = currentCompetitor.BallastKg, BestLap = currentCompetitor.BestLap, TotalTime = currentCompetitor.TotalTime, LapCount = currentCompetitor.LapCount, StartPosition = currentCompetitor.StartPosition, Position = currentCompetitor.Position, Gap = currentCompetitor.Gap, Incidents = currentCompetitor.Incidents, CurrentLapStart = currentCompetitor.CurrentLapStart, TopSpeed = currentCompetitor.TopSpeed, IsAdmin = currentCompetitor.IsAdmin, IsOnOutLap = currentCompetitor.IsOnOutLap, ConnectionId = currentCompetitor.ConnectionId, ConnectedTimestamp = currentCompetitor.ConnectedTimestamp, DisconnectedTimestamp = currentCompetitor.DisconnectedTimestamp, }; //currentCompetitor.LapsLead = driverInfo.Lap //currentCompetitor.CurrentTyreCompound = driverInfo currentCompetitor.DriverGuid = driverInfo.DriverGuid; currentCompetitor.DriverName = driverInfo.DriverName; currentCompetitor.DriverTeam = driverInfo.DriverTeam; currentCompetitor.CarId = driverInfo.CarId; currentCompetitor.CarModel = driverInfo.CarModel; currentCompetitor.CarSkin = driverInfo.CarSkin; currentCompetitor.BallastKg = driverInfo.BallastKG; currentCompetitor.BestLap = (int)driverInfo.BestLap == 0 ? currentCompetitor.BestLap : (int)driverInfo.BestLap; currentCompetitor.TotalTime = (int)driverInfo.TotalTime == 0 ? currentCompetitor.TotalTime : (int)driverInfo.TotalTime; currentCompetitor.LapCount = driverInfo.LapCount; currentCompetitor.StartPosition = driverInfo.StartPosition; currentCompetitor.Position = driverInfo.Position; currentCompetitor.Gap = driverInfo.Gap; currentCompetitor.Incidents = driverInfo.Incidents; currentCompetitor.CurrentLapStart = driverInfo.CurrentLapStart; currentCompetitor.TopSpeed = driverInfo.TopSpeed; currentCompetitor.IsAdmin = driverInfo.IsAdmin; currentCompetitor.IsOnOutLap = driverInfo.IsOnOutlap; currentCompetitor.ConnectionId = driverInfo.ConnectionId; currentCompetitor.ConnectedTimestamp = (int)driverInfo.ConnectedTimestamp; currentCompetitor.DisconnectedTimestamp = (int)driverInfo.DisconnectedTimestamp; if (currentCompetitor.TopSpeed != matchCompetitor.TopSpeed || currentCompetitor.BestLap != matchCompetitor.BestLap || currentCompetitor.LapCount != matchCompetitor.LapCount || currentCompetitor.Position != matchCompetitor.Position || currentCompetitor.Gap != matchCompetitor.Gap || currentCompetitor.Incidents != matchCompetitor.Incidents || currentCompetitor.CurrentLapStart != matchCompetitor.CurrentLapStart ) { //using (var a = new FileStream("Test.txt", FileMode.Append, FileAccess.Write)) //using (var b = new StreamWriter(a)) //{ // b.WriteLine($"{DateTime.Now.TimeOfDay}: OnCarUpdate Called {driverInfo.TotalTime} {driverInfo.Gap}"); //} var result = ApiWrapperNet4.Post <Competitor>("competitor/editcompetitor", currentCompetitor); } }
protected override void OnLapCompleted(LapInfo msg) { using (var a = new FileStream("Test.txt", FileMode.Append, FileAccess.Write)) using (var b = new StreamWriter(a)) { b.WriteLine($"{DateTime.Now.TimeOfDay}: OnLapCompleted Called:{TimeSpan.FromMilliseconds(msg.Laptime).ToString()}"); } var currentCompetitor = Competitors.FirstOrDefault(driver => msg.ConnectionId == driver.ConnectionId); var currentLap = CurrentLaps.FirstOrDefault(l => l.CompetitorId == currentCompetitor.CompetitorId); CurrentLaps.Remove(currentLap); if (currentLap != null) { currentLap.Cuts = msg.Cuts; currentLap.GripLevel = msg.GripLevel; currentLap.LapTime = (int)msg.Laptime; currentLap.LapNo = msg.LapNo; currentLap.Timestamp = (int)msg.Timestamp; currentLap.Position = msg.Position; currentLap.IsValid = msg.Cuts == 0; currentLap.LapLength = msg.LapLength; currentLap.TyreCompound = currentCompetitor.CurrentTyreCompound; if (currentLap.Sector1 == default(int?)) { currentLap.Sector1 = currentLap.LapTime; } else if (currentLap.Sector2 == default(int?)) { currentLap.Sector2 = currentLap.LapTime - currentLap.Sector1; } else if (currentLap.Sector3 == default(int?)) { currentLap.Sector3 = currentLap.LapTime - currentLap.Sector1 - currentLap.Sector2; } var result = ApiWrapperNet4.Post <Lap>("lap/editlap", currentLap); } else { Lap lap = new Lap { LapId = Guid.NewGuid().ToString(), CompetitorId = currentCompetitor.CompetitorId, ConnectionId = msg.ConnectionId, Cuts = msg.Cuts, GripLevel = msg.GripLevel, LapTime = (int)msg.Laptime, LapNo = msg.LapNo, Timestamp = (int)msg.Timestamp, Position = msg.Position, IsValid = msg.Cuts == 0, LapLength = msg.LapLength, TyreCompound = currentCompetitor.CurrentTyreCompound }; var addLap = ApiWrapperNet4.Post <Lap>("lap/addlap", lap); } }