diff --git a/Archipelago.MultiClient.Net.Tests/PlayerHelperFixture.cs b/Archipelago.MultiClient.Net.Tests/PlayerHelperFixture.cs index 845c668..3e43d4e 100644 --- a/Archipelago.MultiClient.Net.Tests/PlayerHelperFixture.cs +++ b/Archipelago.MultiClient.Net.Tests/PlayerHelperFixture.cs @@ -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(); + var connectionInfo = Substitute.For(); + + 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(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)); + } } } diff --git a/Archipelago.MultiClient.Net/Archipelago.MultiClient.Net.csproj b/Archipelago.MultiClient.Net/Archipelago.MultiClient.Net.csproj index d70e9e8..583e9fd 100644 --- a/Archipelago.MultiClient.Net/Archipelago.MultiClient.Net.csproj +++ b/Archipelago.MultiClient.Net/Archipelago.MultiClient.Net.csproj @@ -10,9 +10,9 @@ README.md https://github.com/ArchipelagoMW/Archipelago.MultiClient.Net git - 6.3.0.0 - 6.3.0.0 - 6.3.0 + 6.3.1.0 + 6.3.1.0 + 6.3.1 MIT False blue-icon.png diff --git a/Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs b/Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs index 386f882..656e787 100644 --- a/Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs +++ b/Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs @@ -100,7 +100,7 @@ public class PlayerHelper : IPlayerHelper /// 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;