mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-19 15:51:42 +00:00
Merge pull request #599 from miniduikboot/fix/compatman-no-invalid-clients
Improve CompatMgr behaviour for unknown versions
This commit is contained in:
2 files changed
+22
-9
No files matched your search
@@ -63,6 +63,12 @@ internal class CompatibilityManager : ICompatibilityManager
|
||||
return null;
|
||||
}
|
||||
|
||||
private CompatibilityGroup GetCompatibilityGroupOrDefault(GameVersion clientVersion)
|
||||
{
|
||||
// If the compatibility group is not defined, we assume it is not compatible with anything else than itself
|
||||
return TryGetCompatibilityGroup(clientVersion) ?? new CompatibilityGroup(new[] { clientVersion.Normalize() });
|
||||
}
|
||||
|
||||
public VersionCompareResult CanConnectToServer(GameVersion clientVersion)
|
||||
{
|
||||
if (this.TryGetCompatibilityGroup(clientVersion) != null)
|
||||
@@ -91,13 +97,8 @@ internal class CompatibilityManager : ICompatibilityManager
|
||||
return GameJoinError.None;
|
||||
}
|
||||
|
||||
var hostCompatGroup = this.TryGetCompatibilityGroup(hostVersion);
|
||||
var playerCompatGroup = this.TryGetCompatibilityGroup(clientVersion);
|
||||
|
||||
if (hostCompatGroup == null || playerCompatGroup == null)
|
||||
{
|
||||
return GameJoinError.InvalidClient;
|
||||
}
|
||||
var hostCompatGroup = GetCompatibilityGroupOrDefault(hostVersion);
|
||||
var playerCompatGroup = GetCompatibilityGroupOrDefault(clientVersion);
|
||||
|
||||
if (hostCompatGroup != playerCompatGroup)
|
||||
{
|
||||
|
||||
@@ -48,11 +48,23 @@ public sealed class CompatibilityManagerTests
|
||||
public static IEnumerable<object[]> CanJoinGameData =>
|
||||
new List<object[]>
|
||||
{
|
||||
// Same version -> can join
|
||||
new object[] { GameJoinError.None, new GameVersion(1, 0, 0), new GameVersion(1, 0, 0) },
|
||||
new object[] { GameJoinError.InvalidClient, new GameVersion(1, 0, 0), new GameVersion(100, 0, 0) },
|
||||
|
||||
// Compatible versions -> can join
|
||||
new object[] { GameJoinError.None, new GameVersion(2, 0, 0), new GameVersion(2, 1, 0) },
|
||||
|
||||
// Different incompatible versions -> show correct error
|
||||
new object[] { GameJoinError.ClientOutdated, new GameVersion(2, 0, 0), new GameVersion(1, 0, 0) },
|
||||
new object[] { GameJoinError.ClientTooNew, new GameVersion(1, 0, 0), new GameVersion(2, 0, 0) },
|
||||
new object[] { GameJoinError.None, new GameVersion(2, 0, 0), new GameVersion(2, 1, 0) },
|
||||
|
||||
// Versions unknown to Impostor -> also show correct errors
|
||||
new object[] { GameJoinError.ClientTooNew, new GameVersion(0, 0, 1), new GameVersion(1, 0, 0) },
|
||||
new object[] { GameJoinError.ClientOutdated, new GameVersion(1, 0, 0), new GameVersion(0, 0, 1) },
|
||||
new object[] { GameJoinError.ClientTooNew, new GameVersion(1, 0, 0), new GameVersion(100, 0, 0) },
|
||||
new object[] { GameJoinError.ClientOutdated, new GameVersion(100, 0, 0), new GameVersion(1, 0, 0) },
|
||||
new object[] { GameJoinError.ClientTooNew, new GameVersion(0, 0, 1), new GameVersion(100, 0, 0) },
|
||||
|
||||
};
|
||||
|
||||
[Theory]
|
||||
|
||||
Reference in new issue
Block a user