From fd800f76e31258125f8740f6801a4fd0fac994b0 Mon Sep 17 00:00:00 2001 From: Flegma Date: Tue, 24 Nov 2026 21:58:07 +0100 Subject: [PATCH] feat: ready_status rcon command Reports the match, whether the ready check is running and the steam ids it still waits on, so the api can record no-shows when it cancels. Only lineups the ready count still counts short are listed, never a player the camera check keeps from readying. The simulator answers it too. --- .../src/FiveStack.Commands/Ready.cs | 22 ++++++++ .../src/FiveStack.Services/ReadySystem.cs | 42 +++++++++++++++ .../test/ReadyUtilityTests.cs | 53 +++++++++++++++++++ apps/simulator/src/SimulatedServer.cs | 11 ++++ apps/simulator/test/GapsTests.cs | 1 + apps/swiftly/src/FiveStack.Commands/Ready.cs | 27 ++++++++++ .../src/FiveStack.Services/ReadySystem.cs | 36 +++++++++++++ apps/swiftly/test/ReadyUtilityTests.cs | 53 +++++++++++++++++++ .../FiveStack.Utilities/ReadyUtility.cs | 35 ++++++++++++ 9 files changed, 280 insertions(+) diff --git a/apps/counterstrikesharp/src/FiveStack.Commands/Ready.cs b/apps/counterstrikesharp/src/FiveStack.Commands/Ready.cs index 54b77787..a86c5e08 100644 --- a/apps/counterstrikesharp/src/FiveStack.Commands/Ready.cs +++ b/apps/counterstrikesharp/src/FiveStack.Commands/Ready.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Commands; @@ -39,4 +40,25 @@ public void OnForceStart(CCSPlayerController? player, CommandInfo? command) match.readySystem.Skip(); } + + [ConsoleCommand("ready_status", "Reports who the ready check still waits on")] + [CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY)] + public void OnReadyStatus(CCSPlayerController? player, CommandInfo command) + { + MatchManager? match = _matchService.GetCurrentMatch(); + bool waiting = match != null && match.IsWarmup() && match.readySystem.IsWaitingForReady(); + + command.ReplyToCommand( + JsonSerializer.Serialize( + new + { + match_id = match?.GetMatchData()?.id, + waiting, + not_ready = waiting + ? match!.readySystem.GetNotReadySteamIds() + : new List(), + } + ) + ); + } } diff --git a/apps/counterstrikesharp/src/FiveStack.Services/ReadySystem.cs b/apps/counterstrikesharp/src/FiveStack.Services/ReadySystem.cs index a93fecc2..406f012f 100644 --- a/apps/counterstrikesharp/src/FiveStack.Services/ReadySystem.cs +++ b/apps/counterstrikesharp/src/FiveStack.Services/ReadySystem.cs @@ -390,6 +390,48 @@ public void Skip() match.UpdateMapStatus(eMapStatus.Live); } + // Who the ready check still waits on, for the api to record as no-shows if + // the match is canceled: only on lineups ReadyCount still counts short, and + // never a player the camera check keeps from readying. + public List GetNotReadySteamIds() + { + MatchManager? match = _matchService.GetCurrentMatch(); + MatchData? matchData = match?.GetMatchData(); + + if (match == null || matchData == null || !IsWaitingForReady()) + { + return new List(); + } + + List voters = MatchUtility + .Players() + .Where(player => player.UserId != null && CanVote(player)) + .ToList(); + HashSet waiting = ReadyUtility.WaitingLineups( + GetReadySetting(), + matchData, + voters + .Where(player => _readyPlayers.GetValueOrDefault(player.UserId!.Value)) + .Select(player => (player.SteamID.ToString(), player.PlayerName)), + match.GetExpectedPlayerCount() + ); + + return voters + .Where(player => + !_readyPlayers.GetValueOrDefault(player.UserId!.Value) + && !_cameraSystem.IsPlayerBlocked(player) + && waiting.Contains( + LineupMembership.LineupNumber( + matchData, + player.SteamID.ToString(), + player.PlayerName + ) ?? 0 + ) + ) + .Select(player => player.SteamID.ToString()) + .ToList(); + } + private string[] GetNotReadyPlayers() { List notReadyPlayers = new List(); diff --git a/apps/counterstrikesharp/test/ReadyUtilityTests.cs b/apps/counterstrikesharp/test/ReadyUtilityTests.cs index 6ce0b0a4..39167f6f 100644 --- a/apps/counterstrikesharp/test/ReadyUtilityTests.cs +++ b/apps/counterstrikesharp/test/ReadyUtilityTests.cs @@ -274,4 +274,57 @@ public void An_Absent_Substitute_On_A_Whole_Lineup_Is_Not_Named() Assert.Empty(ReadyUtility.EmptySeats(match, Connected(0, 5).Concat(Connected(6, 5)), 10)); } + + [Fact] + public void Only_A_Lineup_Still_Short_Of_Its_Seats_Is_Waited_On() + { + var match = new MatchData + { + lineup_1 = new MatchLineUp { lineup_players = Members(0, 6) }, + lineup_2 = new MatchLineUp { lineup_players = Members(6, 5) }, + }; + + Assert.Equal( + new HashSet { 2 }, + ReadyUtility.WaitingLineups( + eReadySettings.Players, + match, + Connected(0, 5).Concat(Connected(6, 4)), + 10 + ) + ); + } + + [Fact] + public void Only_A_Lineup_Without_A_Ready_Captain_Is_Waited_On() + { + Assert.Equal( + new HashSet { 2 }, + ReadyUtility.WaitingLineups( + eReadySettings.Captains, + FiveVersusFour(), + Connected(0, 2), + 10 + ) + ); + Assert.Empty( + ReadyUtility.WaitingLineups( + eReadySettings.Captains, + FiveVersusFour(), + Connected(0, 1).Concat(Connected(5, 1)), + 10 + ) + ); + } + + [Fact] + public void A_Coach_Or_Admin_Ready_Never_Waits_On_Lineup_Players() + { + foreach (eReadySettings setting in new[] { eReadySettings.Coach, eReadySettings.Admin }) + { + Assert.Empty( + ReadyUtility.WaitingLineups(setting, FiveVersusFour(), Connected(0, 0), 10) + ); + } + } } diff --git a/apps/simulator/src/SimulatedServer.cs b/apps/simulator/src/SimulatedServer.cs index 3d251b65..e682711c 100644 --- a/apps/simulator/src/SimulatedServer.cs +++ b/apps/simulator/src/SimulatedServer.cs @@ -324,6 +324,17 @@ string command in line.Split( case "force_ready": run?.ForceReady(); return null; + // simulated players ready on their own; a run still waiting waits on + // an admin or a coach, never on a lineup player + case "ready_status": + return JsonSerializer.Serialize( + new + { + match_id = _match?.id, + waiting = run?.WaitingForReady == true, + not_ready = Array.Empty(), + } + ); case "skip_knife": run?.SkipKnife(); return null; diff --git a/apps/simulator/test/GapsTests.cs b/apps/simulator/test/GapsTests.cs index b1b1103d..b084c811 100644 --- a/apps/simulator/test/GapsTests.cs +++ b/apps/simulator/test/GapsTests.cs @@ -366,6 +366,7 @@ public async Task A3v3CompetitiveTheAdminStartsWaitsForForceReady() await Task.Delay(10); } Assert.True(server.LastRun!.WaitingForReady); + Assert.Contains("\"waiting\":true,\"not_ready\":[]", server.Execute("ready_status")); server.Execute("force_ready"); await Matches.Finish(server.LastRun); diff --git a/apps/swiftly/src/FiveStack.Commands/Ready.cs b/apps/swiftly/src/FiveStack.Commands/Ready.cs index 10ba1a3e..54bef984 100644 --- a/apps/swiftly/src/FiveStack.Commands/Ready.cs +++ b/apps/swiftly/src/FiveStack.Commands/Ready.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using FiveStack.Enums; using SwiftlyS2.Shared.Commands; using SwiftlyS2.Shared.Players; @@ -42,4 +43,30 @@ public void OnForceStart(ICommandContext context) match.readySystem.Skip(); } + + [Command("ready_status", registerRaw: true, permission: "")] + public void OnReadyStatus(ICommandContext context) + { + if (context.IsSentByPlayer) + { + return; + } + + context.Reply(BuildReadyStatus()); + } + + private string BuildReadyStatus() + { + MatchManager? match = _matchService.GetCurrentMatch(); + bool waiting = match != null && match.IsWarmup() && match.readySystem.IsWaitingForReady(); + + return JsonSerializer.Serialize( + new + { + match_id = match?.GetMatchData()?.id, + waiting, + not_ready = waiting ? match!.readySystem.GetNotReadySteamIds() : new List(), + } + ); + } } diff --git a/apps/swiftly/src/FiveStack.Services/ReadySystem.cs b/apps/swiftly/src/FiveStack.Services/ReadySystem.cs index 85aa2352..055fc582 100644 --- a/apps/swiftly/src/FiveStack.Services/ReadySystem.cs +++ b/apps/swiftly/src/FiveStack.Services/ReadySystem.cs @@ -341,6 +341,42 @@ public void Skip() match.UpdateMapStatus(eMapStatus.Live); } + // Who the ready check still waits on, for the api to record as no-shows if + // the match is canceled: only on lineups ReadyCount still counts short, and + // never a player the camera check keeps from readying. + public List GetNotReadySteamIds() + { + MatchManager? match = _matchService.GetCurrentMatch(); + MatchData? matchData = match?.GetMatchData(); + + if (match == null || matchData == null || !IsWaitingForReady()) + { + return new List(); + } + + List voters = MatchUtility.Players().Where(CanVote).ToList(); + HashSet waiting = ReadyUtility.WaitingLineups( + GetReadySetting(), + matchData, + voters + .Where(player => _readyPlayers.GetValueOrDefault(player.UserID)) + .Select(player => (player.SteamID.ToString(), player.Name)), + match.GetExpectedPlayerCount() + ); + + return voters + .Where(player => + !_readyPlayers.GetValueOrDefault(player.UserID) + && !_cameraSystem.IsPlayerBlocked(player) + && waiting.Contains( + LineupMembership.LineupNumber(matchData, player.SteamID.ToString(), player.Name) + ?? 0 + ) + ) + .Select(player => player.SteamID.ToString()) + .ToList(); + } + private string[] GetNotReadyPlayers() { List notReadyPlayers = new List(); diff --git a/apps/swiftly/test/ReadyUtilityTests.cs b/apps/swiftly/test/ReadyUtilityTests.cs index 6ce0b0a4..39167f6f 100644 --- a/apps/swiftly/test/ReadyUtilityTests.cs +++ b/apps/swiftly/test/ReadyUtilityTests.cs @@ -274,4 +274,57 @@ public void An_Absent_Substitute_On_A_Whole_Lineup_Is_Not_Named() Assert.Empty(ReadyUtility.EmptySeats(match, Connected(0, 5).Concat(Connected(6, 5)), 10)); } + + [Fact] + public void Only_A_Lineup_Still_Short_Of_Its_Seats_Is_Waited_On() + { + var match = new MatchData + { + lineup_1 = new MatchLineUp { lineup_players = Members(0, 6) }, + lineup_2 = new MatchLineUp { lineup_players = Members(6, 5) }, + }; + + Assert.Equal( + new HashSet { 2 }, + ReadyUtility.WaitingLineups( + eReadySettings.Players, + match, + Connected(0, 5).Concat(Connected(6, 4)), + 10 + ) + ); + } + + [Fact] + public void Only_A_Lineup_Without_A_Ready_Captain_Is_Waited_On() + { + Assert.Equal( + new HashSet { 2 }, + ReadyUtility.WaitingLineups( + eReadySettings.Captains, + FiveVersusFour(), + Connected(0, 2), + 10 + ) + ); + Assert.Empty( + ReadyUtility.WaitingLineups( + eReadySettings.Captains, + FiveVersusFour(), + Connected(0, 1).Concat(Connected(5, 1)), + 10 + ) + ); + } + + [Fact] + public void A_Coach_Or_Admin_Ready_Never_Waits_On_Lineup_Players() + { + foreach (eReadySettings setting in new[] { eReadySettings.Coach, eReadySettings.Admin }) + { + Assert.Empty( + ReadyUtility.WaitingLineups(setting, FiveVersusFour(), Connected(0, 0), 10) + ); + } + } } diff --git a/shared/dotnet/FiveStack.Utilities/ReadyUtility.cs b/shared/dotnet/FiveStack.Utilities/ReadyUtility.cs index 996fcc2c..d7bdec50 100644 --- a/shared/dotnet/FiveStack.Utilities/ReadyUtility.cs +++ b/shared/dotnet/FiveStack.Utilities/ReadyUtility.cs @@ -93,6 +93,41 @@ int expectedPlayers return (0, 1); } + // The lineups ReadyCount still waits on: in Players mode each lineup short of + // its seats, in Captains mode each lineup without a ready captain. Coach and + // Admin readies never wait on lineup players. + public static HashSet WaitingLineups( + eReadySettings setting, + MatchData matchData, + IEnumerable<(string SteamId, string Name)> ready, + int expectedPlayers + ) + { + List readyLineups = ready + .Select(player => + LineupMembership.LineupNumber(matchData, player.SteamId, player.Name) + ) + .OfType() + .ToList(); + + return new[] { 1, 2 } + .Where(lineup => + { + int target = setting switch + { + eReadySettings.Players => ReconnectPauseUtility.Seats( + lineup == 1 ? matchData.lineup_1 : matchData.lineup_2, + expectedPlayers + ), + eReadySettings.Captains => 1, + _ => 0, + }; + + return readyLineups.Count(readyLineup => readyLineup == lineup) < target; + }) + .ToHashSet(); + } + private static int? CoachedLineup(MatchData matchData, string steamId) { if (string.IsNullOrEmpty(steamId))