@@ -26,7 +26,6 @@ public class PlaylistsController : ControllerBase
2626 private readonly IMemoryCache _memoryCache ;
2727 private readonly ServerStore _serverStore ;
2828 private readonly MatchmakingService _matchmakingService ;
29- private readonly IGameServerInfoService < GameServer > _udpGameServerCommunicationService ;
3029 private readonly IGameServerInfoService < GameServer > _tcpGameServerCommunicationService ;
3130 private readonly ILogger < PlaylistsController > _logger ;
3231
@@ -38,8 +37,7 @@ public PlaylistsController(
3837 MatchmakingService matchmakingService ,
3938 ServerStore serverStore ,
4039 IMemoryCache memoryCache ,
41- [ FromKeyedServices ( "UDP" ) ] IGameServerInfoService < GameServer > udpGameServerCommunicationService ,
42- [ FromKeyedServices ( "TCP" ) ] IGameServerInfoService < GameServer > tcpGameServerCommunicationService ,
40+ IGameServerInfoService < GameServer > tcpGameServerCommunicationService ,
4341 ILogger < PlaylistsController > logger ,
4442 PlaylistStore playlistStore )
4543 {
@@ -48,7 +46,6 @@ public PlaylistsController(
4846 _matchmakingService = matchmakingService ;
4947 _serverStore = serverStore ;
5048 _memoryCache = memoryCache ;
51- _udpGameServerCommunicationService = udpGameServerCommunicationService ;
5249 _tcpGameServerCommunicationService = tcpGameServerCommunicationService ;
5350 _logger = logger ;
5451 _playlistStore = playlistStore ;
@@ -181,35 +178,29 @@ private async Task<int> GetPlayerCountAsync(PlaylistDbo playlist)
181178
182179 _logger . LogDebug ( "Requesting game server info for {numServers}" , serverToRequest . Count ) ;
183180
184- if ( playlist . Id . StartsWith ( "HMW" , StringComparison . OrdinalIgnoreCase ) )
181+ CancellationTokenSource timeoutCancellation = new ( 3000 ) ;
182+ try
185183 {
186- CancellationTokenSource timeoutCancellation = new ( 1500 ) ;
187- try
188- {
189- // request HMW servers with HTTP
190- await serverToRequest
191- . Select ( ( s ) => _tcpGameServerCommunicationService . GetInfoAsync ( s , timeoutCancellation . Token ) . ContinueWith ( t =>
184+ // request HMW servers with HTTP
185+ await serverToRequest
186+ . Select ( ( s ) =>
187+ {
188+ return _tcpGameServerCommunicationService . GetInfoAsync ( s , timeoutCancellation . Token )
189+ . ContinueWith ( t =>
192190 {
193191 if ( t . IsCompletedSuccessfully && t . Result is not null )
194192 {
193+ _logger . LogInformation ( "{serverName}: {playerCount}" , t . Result . HostName , t . Result . Clients - t . Result . Bots ) ;
195194 Interlocked . Add ( ref playerCount , t . Result . Clients - t . Result . Bots ) ;
196195 }
197- } ) )
198- . WhenAll ( ) ;
199- }
200- catch ( OperationCanceledException ) { }
201- finally
202- {
203- timeoutCancellation . Dispose ( ) ;
204- }
196+ } ) ;
197+ } )
198+ . WhenAll ( ) ;
205199 }
206- else
200+ catch ( OperationCanceledException ) { }
201+ finally
207202 {
208- // request server info of all remaining servers
209- playerCount += await _udpGameServerCommunicationService
210- . GetAllInfoAsync ( serverToRequest , requestTimeoutInMs : 1000 )
211- . Select ( r => r . info ? . RealPlayerCount ?? 0 )
212- . SumAsync ( ) ;
203+ timeoutCancellation . Dispose ( ) ;
213204 }
214205
215206 return playerCount ;
0 commit comments