Skip to content

Commit

Permalink
Bugfix for playerhelper GetPlayerInfo on negative team & slot values
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarno458 committed Aug 25, 2024
1 parent 3113ea0 commit 5adf1f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
38 changes: 38 additions & 0 deletions Archipelago.MultiClient.Net.Tests/PlayerHelperFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,43 @@ public void Should_not_crash_when_room_update_does_not_contain_players()
Assert.That(sut.Players.Count, Is.EqualTo(1));
Assert.That(sut.Players[0].Count, Is.EqualTo(2));
}

[TestCase(-1, -1, null)]
[TestCase(-1, 0, null)]
[TestCase(-1, 1, null)]
[TestCase(-1, 2, null)]
[TestCase(0, -1, null)]
[TestCase(0, 0, "Server")]
[TestCase(0, 1, "Player 1")]
[TestCase(0, 2, null)]
[TestCase(1, -1, null)]
[TestCase(1, 0, null)]
[TestCase(1, 1, null)]
[TestCase(1, 2, null)]
public void GetPlayerInfo_should_not_crash_on_values_out_of_range(int team, int slot, string expectedPlayerNameOrNull)
{
var socket = Substitute.For<IArchipelagoSocketHelper>();
var connectionInfo = Substitute.For<IConnectionInfoProvider>();

var sut = new PlayerHelper(socket, connectionInfo);

var connectedPacket = new ConnectedPacket
{
Players = new[] {
new NetworkPlayer { Name = "Player 1", Alias = "One", Team = 0, Slot = 1 }
}
};

socket.PacketReceived += Raise.Event<ArchipelagoSocketHelperDelagates.PacketReceivedHandler>(connectedPacket);

var player = new PlayerInfo();

Assert.DoesNotThrow(() => player = sut.GetPlayerInfo(team, slot));

if (expectedPlayerNameOrNull == null)
Assert.That(player, Is.Null);
else
Assert.That(player.Name, Is.EqualTo(expectedPlayerNameOrNull));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/ArchipelagoMW/Archipelago.MultiClient.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>6.3.0.0</AssemblyVersion>
<FileVersion>6.3.0.0</FileVersion>
<Version>6.3.0</Version>
<AssemblyVersion>6.3.1.0</AssemblyVersion>
<FileVersion>6.3.1.0</FileVersion>
<Version>6.3.1</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageIcon>blue-icon.png</PackageIcon>
Expand Down
2 changes: 1 addition & 1 deletion Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class PlayerHelper : IPlayerHelper

/// <inheritdoc/>
public PlayerInfo GetPlayerInfo(int team, int slot) =>
players.Count > team && players[team].Count > slot
team >= 0 && slot >= 0 && players.Count > team && players[team].Count > slot
? players[team][slot]
: null;

Expand Down

0 comments on commit 5adf1f9

Please sign in to comment.