Skip to content

Commit a19de3a

Browse files
committed
Add support for upcoming CSP/CM feature to select a specific car slot when connecting
1 parent c2db513 commit a19de3a

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

AssettoServer/Server/ACServer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public ACServer(
7171
_applicationLifetime = applicationLifetime;
7272
_trackParamsProvider = trackParamsProvider;
7373

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

@@ -80,6 +80,7 @@ public ACServer(
8080
cspFeatureManager.Add(new CSPFeature { Name = "SPECTATING_AWARE" });
8181
cspFeatureManager.Add(new CSPFeature { Name = "LOWER_CLIENTS_SENDING_RATE" });
8282
cspFeatureManager.Add(new CSPFeature { Name = "EMOJI" });
83+
cspFeatureManager.Add(new CSPFeature { Name = "SLOT_INDEX" });
8384

8485
if (_configuration.Extra.EnableClientMessages)
8586
{

AssettoServer/Server/EntryCarManager.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -178,16 +179,33 @@ internal async Task<bool> TrySecureSlotAsync(ACTcpClient client, HandshakeReques
178179

179180
if (ConnectedCars.Count >= _configuration.Server.MaxClients)
180181
return false;
181-
182-
for (int i = 0; i < EntryCars.Length; i++)
182+
183+
IEnumerable<EntryCar> candidates;
184+
185+
// Support for SLOT_INDEX CSP feature. CSP sends "car_model:n" where n is the specific slot index the user wants to connect to.
186+
var slotIndexSeparator = handshakeRequest.RequestedCar.IndexOf(':');
187+
if (slotIndexSeparator >= 0)
183188
{
184-
EntryCar entryCar = EntryCars[i];
189+
var requestedSlotIndex = int.Parse(handshakeRequest.RequestedCar.AsSpan(slotIndexSeparator + 1));
190+
var requestedCarName = handshakeRequest.RequestedCar[..slotIndexSeparator];
191+
var candidate = EntryCars.Where(c => c.Model == requestedCarName).ElementAtOrDefault(requestedSlotIndex);
185192

186-
bool isAdmin = await _adminService.IsAdminAsync(handshakeRequest.Guid);
193+
if (candidate == null)
194+
{
195+
return false;
196+
}
197+
198+
candidates = [candidate];
199+
}
200+
else
201+
{
202+
candidates = EntryCars.Where(c => c.Model == handshakeRequest.RequestedCar);
203+
}
187204

188-
if (entryCar.Client == null
189-
&& handshakeRequest.RequestedCar == entryCar.Model
190-
&& (isAdmin || _openSlotFilterChain.Value.IsSlotOpen(entryCar, handshakeRequest.Guid)))
205+
var isAdmin = await _adminService.IsAdminAsync(handshakeRequest.Guid);
206+
foreach (var entryCar in candidates)
207+
{
208+
if (entryCar.Client == null && (isAdmin || _openSlotFilterChain.Value.IsSlotOpen(entryCar, handshakeRequest.Guid)))
191209
{
192210
entryCar.Reset();
193211
entryCar.Client = client;

AssettoServer/Server/Steam/SteamManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<bool> ValidateSessionTicketAsync(byte[]? sessionTicket, ulong
3939
client.Logger.Information("{ClientName} ({SteamId}) is using Steam family sharing, owner {OwnerSteamId}", client.Name, client.Guid, client.OwnerGuid);
4040
}
4141

42-
client.Logger.Information("Steam authentication succeeded for {ClientName} ({SessionId})", client.Name, client.SessionId);
42+
client.Logger.Information("Steam authentication succeeded for {ClientName} ({SteamId})", client.Name, client.Guid);
4343
}
4444
else
4545
{

0 commit comments

Comments
 (0)