Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/counterstrikesharp/src/FiveStack.Commands/Ready.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
Expand Down Expand Up @@ -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<string>(),
}
)
);
}
}
42 changes: 42 additions & 0 deletions apps/counterstrikesharp/src/FiveStack.Services/ReadySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> GetNotReadySteamIds()
{
MatchManager? match = _matchService.GetCurrentMatch();
MatchData? matchData = match?.GetMatchData();

if (match == null || matchData == null || !IsWaitingForReady())
{
return new List<string>();
}

List<CCSPlayerController> voters = MatchUtility
.Players()
.Where(player => player.UserId != null && CanVote(player))
.ToList();
HashSet<int> 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<string> notReadyPlayers = new List<string>();
Expand Down
53 changes: 53 additions & 0 deletions apps/counterstrikesharp/test/ReadyUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> { 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<int> { 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)
);
}
}
}
11 changes: 11 additions & 0 deletions apps/simulator/src/SimulatedServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(),
}
);
case "skip_knife":
run?.SkipKnife();
return null;
Expand Down
1 change: 1 addition & 0 deletions apps/simulator/test/GapsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions apps/swiftly/src/FiveStack.Commands/Ready.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using FiveStack.Enums;
using SwiftlyS2.Shared.Commands;
using SwiftlyS2.Shared.Players;
Expand Down Expand Up @@ -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<string>(),
}
);
}
}
36 changes: 36 additions & 0 deletions apps/swiftly/src/FiveStack.Services/ReadySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> GetNotReadySteamIds()
{
MatchManager? match = _matchService.GetCurrentMatch();
MatchData? matchData = match?.GetMatchData();

if (match == null || matchData == null || !IsWaitingForReady())
{
return new List<string>();
}

List<IPlayer> voters = MatchUtility.Players().Where(CanVote).ToList();
HashSet<int> 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<string> notReadyPlayers = new List<string>();
Expand Down
53 changes: 53 additions & 0 deletions apps/swiftly/test/ReadyUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> { 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<int> { 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)
);
}
}
}
35 changes: 35 additions & 0 deletions shared/dotnet/FiveStack.Utilities/ReadyUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> WaitingLineups(
eReadySettings setting,
MatchData matchData,
IEnumerable<(string SteamId, string Name)> ready,
int expectedPlayers
)
{
List<int> readyLineups = ready
.Select(player =>
LineupMembership.LineupNumber(matchData, player.SteamId, player.Name)
)
.OfType<int>()
.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))
Expand Down
Loading