|
1 | 1 | using System; |
2 | 2 | using System.Collections.Concurrent; |
| 3 | +using System.Collections.Generic; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Threading; |
5 | 6 | using System.Threading.Tasks; |
@@ -178,16 +179,33 @@ internal async Task<bool> TrySecureSlotAsync(ACTcpClient client, HandshakeReques |
178 | 179 |
|
179 | 180 | if (ConnectedCars.Count >= _configuration.Server.MaxClients) |
180 | 181 | 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) |
183 | 188 | { |
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); |
185 | 192 |
|
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 | + } |
187 | 204 |
|
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))) |
191 | 209 | { |
192 | 210 | entryCar.Reset(); |
193 | 211 | entryCar.Client = client; |
|
0 commit comments