Skip to content
Merged
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
18 changes: 17 additions & 1 deletion apps/player-management-sw/src/PlayerManagementPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using SwiftlyS2.Shared.Misc;
using SwiftlyS2.Shared.Players;
using SwiftlyS2.Shared.Plugins;
using SwiftlyS2.Shared.SchemaDefinitions;
using SwiftlyS2.Shared.ProtobufDefinitions;
using SwiftlyS2.Shared.Translation;

Expand Down Expand Up @@ -555,9 +556,24 @@ private static List<ObservedPlayer> Observed(List<IPlayer> humans)
.ToList();
}

// Not IPlayer.IsValid: that also wants a pawn, and a player without one
// is still on the server, so the roster ended their session and a gag
// stopped applying until they had one again.
private static bool IsHuman(IPlayer player)
{
return player.IsValid && !player.IsFakeClient && SteamIdOf(player) != 0;
CCSPlayerController controller = player.Controller;

if (!controller.IsValid)
{
return false;
}

return PlayerRoster.IsConnectedHuman(
controller.IsHLTV,
controller.Connected == PlayerConnectedState.Connected,
player.IsFakeClient,
SteamIdOf(player)
);
}

// Before Steam verifies a player only the id they claim is known. Enforcing
Expand Down
10 changes: 10 additions & 0 deletions apps/player-management-sw/test/PlayerRosterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,14 @@ bool expected
)
);
}

[Fact]
public void CountsEveryConnectedHumanAndNothingElse()
{
Assert.True(PlayerRoster.IsConnectedHuman(false, true, false, 76561198000000001));
Assert.False(PlayerRoster.IsConnectedHuman(false, false, false, 76561198000000001));
Assert.False(PlayerRoster.IsConnectedHuman(true, true, false, 76561198000000001));
Assert.False(PlayerRoster.IsConnectedHuman(false, true, true, 76561198000000001));
Assert.False(PlayerRoster.IsConnectedHuman(false, true, false, 0));
}
}
6 changes: 6 additions & 0 deletions shared/dotnet/FiveStack.Utilities/PlayerRoster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ public static string Name(string? raw)
return address.ToString();
}

// A connected controller is on the server whether or not it has a pawn.
public static bool IsConnectedHuman(bool isHltv, bool connected, bool isBot, ulong steamId)
{
return !isHltv && connected && !isBot && steamId != 0;
}

// Identified by slot, not Steam id: an unverified victim can claim the
// attacker's id.
public static bool CountsAsKill(
Expand Down
Loading