Skip to content

Commit

Permalink
add extensions field to details endpoint
Browse files Browse the repository at this point in the history
(cherry picked from commit 3787933)
  • Loading branch information
compujuckel committed Apr 22, 2024
1 parent 51737e2 commit 0861b01
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions AssettoServer.Shared/Network/Http/Responses/DetailResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class DetailResponse : InfoResponse
public IEnumerable<string>? Features { get; set; }
[JsonPropertyName("loadingImageUrl")]
public string? LoadingImageUrl { get; set; }

[JsonPropertyName("extensions")]
public Dictionary<string, object>? Extensions { get; set; }
}

public class DetailResponseAssists
Expand Down
3 changes: 2 additions & 1 deletion AssettoServer/Network/Http/HttpController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public async Task<DetailResponse> GetDetails(string? guid)
Description = _configuration.Extra.ServerDescription,
Grip = _weatherManager.CurrentWeather.TrackGrip * 100,
Features = _cspFeatureManager.Features.Keys,
PoweredBy = _cache.PoweredBy
PoweredBy = _cache.PoweredBy,
Extensions = _cache.Extensions
};

return responseObj;
Expand Down
1 change: 1 addition & 0 deletions AssettoServer/Network/Http/HttpInfoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class HttpInfoCache : CriticalBackgroundService, IAssettoServerAutostart
public string PoweredBy { get; }
public DetailResponseAssists Assists { get; }
public IReadOnlyList<string> Country { get; private set; } = null!;
public Dictionary<string, object> Extensions { get; } = [];

public HttpInfoCache(ACServerConfiguration configuration, EntryCarManager entryCarManager, IHostApplicationLifetime lifetime, GeoParamsManager geoParamsManager) : base(lifetime)
{
Expand Down
17 changes: 16 additions & 1 deletion AssettoServer/Server/Ai/AiBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AssettoServer.Network.Http;
using AssettoServer.Network.Tcp;
using AssettoServer.Server.Ai.Splines;
using AssettoServer.Server.Configuration;
Expand All @@ -24,6 +25,7 @@ public class AiBehavior : CriticalBackgroundService, IAssettoServerAutostart
private readonly SessionManager _sessionManager;
private readonly EntryCarManager _entryCarManager;
private readonly AiSpline _spline;
private readonly HttpInfoCache _httpInfoCache;
//private readonly EntryCar.Factory _entryCarFactory;

private readonly JunctionEvaluator _junctionEvaluator;
Expand All @@ -39,12 +41,13 @@ public AiBehavior(SessionManager sessionManager,
IHostApplicationLifetime applicationLifetime,
//EntryCar.Factory entryCarFactory,
CSPServerScriptProvider serverScriptProvider,
AiSpline spline) : base(applicationLifetime)
AiSpline spline, HttpInfoCache httpInfoCache) : base(applicationLifetime)
{
_sessionManager = sessionManager;
_configuration = configuration;
_entryCarManager = entryCarManager;
_spline = spline;
_httpInfoCache = httpInfoCache;
_junctionEvaluator = new JunctionEvaluator(spline, false);
//_entryCarFactory = entryCarFactory;

Expand Down Expand Up @@ -459,8 +462,20 @@ private void AdjustOverbooking()
}
}

private void SetHttpDetailsExtensions()
{
_httpInfoCache.Extensions.Add("aiTraffic", new Dictionary<string, List<byte>>
{
{ "none", _entryCarManager.EntryCars.Where(c => c.AiMode == AiMode.None).Select(c => c.SessionId).ToList() },
{ "auto", _entryCarManager.EntryCars.Where(c => c.AiMode == AiMode.Auto).Select(c => c.SessionId).ToList() },
{ "fixed", _entryCarManager.EntryCars.Where(c => c.AiMode == AiMode.Fixed).Select(c => c.SessionId).ToList() }
});
}

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
SetHttpDetailsExtensions();

_ = UpdateAsync(stoppingToken);
_ = ObstacleDetectionAsync(stoppingToken);

Expand Down

0 comments on commit 0861b01

Please sign in to comment.