Skip to content

Commit

Permalink
Add support for upcoming CSP/CM feature to select a specific car slot…
Browse files Browse the repository at this point in the history
… when connecting
  • Loading branch information
compujuckel committed Jan 31, 2025
1 parent c2db513 commit a19de3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion AssettoServer/Server/ACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ACServer(
_applicationLifetime = applicationLifetime;
_trackParamsProvider = trackParamsProvider;

_autostartServices = new List<IHostedService> { weatherManager, sessionManager, tcpServer, udpServer };
_autostartServices = [weatherManager, sessionManager, tcpServer, udpServer];
_autostartServices.AddRange(autostartServices);
_autostartServices.Add(kunosLobbyRegistration);

Expand All @@ -80,6 +80,7 @@ public ACServer(
cspFeatureManager.Add(new CSPFeature { Name = "SPECTATING_AWARE" });
cspFeatureManager.Add(new CSPFeature { Name = "LOWER_CLIENTS_SENDING_RATE" });
cspFeatureManager.Add(new CSPFeature { Name = "EMOJI" });
cspFeatureManager.Add(new CSPFeature { Name = "SLOT_INDEX" });

if (_configuration.Extra.EnableClientMessages)
{
Expand Down
32 changes: 25 additions & 7 deletions AssettoServer/Server/EntryCarManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -178,16 +179,33 @@ internal async Task<bool> TrySecureSlotAsync(ACTcpClient client, HandshakeReques

if (ConnectedCars.Count >= _configuration.Server.MaxClients)
return false;

for (int i = 0; i < EntryCars.Length; i++)

IEnumerable<EntryCar> candidates;

// Support for SLOT_INDEX CSP feature. CSP sends "car_model:n" where n is the specific slot index the user wants to connect to.
var slotIndexSeparator = handshakeRequest.RequestedCar.IndexOf(':');
if (slotIndexSeparator >= 0)
{
EntryCar entryCar = EntryCars[i];
var requestedSlotIndex = int.Parse(handshakeRequest.RequestedCar.AsSpan(slotIndexSeparator + 1));
var requestedCarName = handshakeRequest.RequestedCar[..slotIndexSeparator];
var candidate = EntryCars.Where(c => c.Model == requestedCarName).ElementAtOrDefault(requestedSlotIndex);

bool isAdmin = await _adminService.IsAdminAsync(handshakeRequest.Guid);
if (candidate == null)
{
return false;
}

candidates = [candidate];
}
else
{
candidates = EntryCars.Where(c => c.Model == handshakeRequest.RequestedCar);
}

if (entryCar.Client == null
&& handshakeRequest.RequestedCar == entryCar.Model
&& (isAdmin || _openSlotFilterChain.Value.IsSlotOpen(entryCar, handshakeRequest.Guid)))
var isAdmin = await _adminService.IsAdminAsync(handshakeRequest.Guid);
foreach (var entryCar in candidates)
{
if (entryCar.Client == null && (isAdmin || _openSlotFilterChain.Value.IsSlotOpen(entryCar, handshakeRequest.Guid)))
{
entryCar.Reset();
entryCar.Client = client;
Expand Down
2 changes: 1 addition & 1 deletion AssettoServer/Server/Steam/SteamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<bool> ValidateSessionTicketAsync(byte[]? sessionTicket, ulong
client.Logger.Information("{ClientName} ({SteamId}) is using Steam family sharing, owner {OwnerSteamId}", client.Name, client.Guid, client.OwnerGuid);
}

client.Logger.Information("Steam authentication succeeded for {ClientName} ({SessionId})", client.Name, client.SessionId);
client.Logger.Information("Steam authentication succeeded for {ClientName} ({SteamId})", client.Name, client.Guid);
}
else
{
Expand Down

0 comments on commit a19de3a

Please sign in to comment.