mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-20 01:46:11 +00:00
Deprecate JoinGame errors
Starting from version 2021.11.9, join errors no longer exist, instead a client will show the message "An unknown error disconnected you from the server". As a workaround, the connection is disconnected entirely when an error occurs, which allows us to show a custom message.
This commit is contained in:
1 parent
6125fd7006
commit
919b094018
3 files changed
+17
-15
No files matched your search
@@ -22,6 +22,7 @@ namespace Impostor.Api.Net.Messages.S2C
|
||||
writer.EndMessage();
|
||||
}
|
||||
|
||||
[Obsolete("JoinGame errors are no longer serialized by 2021.11.9 and up, disconnect clients instead.")]
|
||||
public static void SerializeError(IMessageWriter writer, bool clear, DisconnectReason reason, string? message = null)
|
||||
{
|
||||
if (clear)
|
||||
|
||||
@@ -85,25 +85,19 @@ namespace Impostor.Server.Net.Manager
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, message);
|
||||
|
||||
await connection.SendAsync(packet);
|
||||
await DisconnectConnection(connection, message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.Length > 10)
|
||||
{
|
||||
using var packet = MessageWriter.Get(MessageType.Reliable);
|
||||
Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.UsernameLength);
|
||||
await connection.SendAsync(packet);
|
||||
await DisconnectConnection(connection, DisconnectMessages.UsernameLength);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
using var packet = MessageWriter.Get(MessageType.Reliable);
|
||||
Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.UsernameIllegalCharacters);
|
||||
await connection.SendAsync(packet);
|
||||
await DisconnectConnection(connection, DisconnectMessages.UsernameIllegalCharacters);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -153,5 +147,14 @@ namespace Impostor.Server.Net.Manager
|
||||
// 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;
|
||||
}
|
||||
|
||||
private async ValueTask DisconnectConnection(IHazelConnection connection, string message)
|
||||
{
|
||||
using var writer = MessageWriter.Get();
|
||||
MessageDisconnect.Serialize(writer, true, DisconnectReason.Custom, message);
|
||||
|
||||
await connection.DisconnectAsync(DisconnectReason.Custom.ToString(), writer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,27 +56,25 @@ namespace Impostor.Server.Net.Redirector
|
||||
{
|
||||
Message01JoinGameC2S.Deserialize(reader, out var gameCode);
|
||||
|
||||
using var packet = MessageWriter.Get(MessageType.Reliable);
|
||||
var endpoint = await _nodeLocator.FindAsync(gameCode);
|
||||
if (endpoint == null)
|
||||
{
|
||||
Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.GameMissing);
|
||||
await DisconnectAsync(DisconnectReason.GameMissing);
|
||||
}
|
||||
else
|
||||
{
|
||||
using var packet = MessageWriter.Get(MessageType.Reliable);
|
||||
Message13RedirectS2C.Serialize(packet, false, endpoint);
|
||||
await Connection.SendAsync(packet);
|
||||
}
|
||||
|
||||
await Connection.SendAsync(packet);
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageFlags.GetGameListV2:
|
||||
{
|
||||
// TODO: Implement.
|
||||
using var packet = MessageWriter.Get(MessageType.Reliable);
|
||||
Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.NotImplemented);
|
||||
await Connection.SendAsync(packet);
|
||||
await DisconnectAsync(DisconnectReason.Custom, DisconnectMessages.NotImplemented);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user