{
public const string Error = "There was an internal server error. " +
"Check the server console for more information. " +
- "Please report the issue on the AmongUsServer GitHub if it keeps happening.";
+ "Please report the issue on the Impostor GitHub if it keeps happening.";
public const string Destroyed = "The game you tried to join is being destroyed. " +
"Please create a new game.";
public const string UsernameLength = "Your username is too long, please make it shorter.";
public const string UsernameIllegalCharacters = "Your username contains illegal characters, please remove them.";
+
+ public const string VersionClientTooOld = "Please update your game to play on this server.";
+
+ public const string VersionServerTooOld = "Your client is too new, please update your Impostor server to play.";
+
+ public const string VersionUnsupported = "Your client version is unsupported, please update your Game and/or Impostor server.";
}
}
-using System.Collections.Concurrent;
+using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
{
internal partial class ClientManager
{
- private static readonly HashSet<int> SupportedVersions = new HashSet<int>
+ // NOTE: when updating this array, keep the versions ordered from old to new, otherwise the version compare logic doesn't work properly
+ private static readonly int[] SupportedVersions =
{
GameVersion.GetVersion(2021, 4, 25), // 2021.6.15
};
_clients = new ConcurrentDictionary<int, ClientBase>();
}
+ private enum VersionCompareResult
+ {
+ Compatible,
+ ClientTooOld,
+ ServerTooOld,
+ Unknown,
+ }
+
public IEnumerable<ClientBase> Clients => _clients.Values;
public int NextId()
public async ValueTask RegisterConnectionAsync(IHazelConnection connection, string name, int clientVersion)
{
- if (!SupportedVersions.Contains(clientVersion))
+ var versionCompare = CompareVersion(clientVersion);
+ if (versionCompare != VersionCompareResult.Compatible)
{
GameVersion.ParseVersion(clientVersion, out var year, out var month, out var day, out var revision);
_logger.LogTrace("Client connected using unsupported version: {clientVersion} ({version})", clientVersion, $"{year}.{month}.{day}{(revision == 0 ? string.Empty : "." + revision)}");
using var packet = MessageWriter.Get(MessageType.Reliable);
- Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.IncorrectVersion);
+
+ var message = versionCompare switch
+ {
+ VersionCompareResult.ClientTooOld => DisconnectMessages.VersionClientTooOld,
+ VersionCompareResult.ServerTooOld => DisconnectMessages.VersionServerTooOld,
+ VersionCompareResult.Unknown => DisconnectMessages.VersionUnsupported,
+ _ => throw new ArgumentOutOfRangeException(),
+ };
+
+ Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, message);
+
await connection.SendAsync(packet);
return;
}
&& _clients.TryGetValue(client.Id, out var registeredClient)
&& ReferenceEquals(client, registeredClient);
}
+
+ private VersionCompareResult CompareVersion(int clientVersion)
+ {
+ foreach (var serverVersion in SupportedVersions)
+ {
+ if (clientVersion == serverVersion)
+ {
+ return VersionCompareResult.Compatible;
+ }
+ }
+
+ if (clientVersion < SupportedVersions[0])
+ {
+ return VersionCompareResult.ClientTooOld;
+ }
+
+ if (clientVersion > SupportedVersions.Last())
+ {
+ return VersionCompareResult.ServerTooOld;
+ }
+
+ // This may happen in the very rare case that version X is supported, X+2 is as well, but X+1 is not.
+ return VersionCompareResult.Unknown;
+ }
}
}