Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -269,10 +269,15 @@ namespace Barotrauma.Networking
{
if (netServer == null) { return; }
switch (inc.SenderConnection.Status)
NetConnectionStatus status = inc.ReadHeader<NetConnectionStatus>();
switch (status)
{
case NetConnectionStatus.Disconnected:
LidgrenConnection? conn = connectedClients.Select(c => c.Connection).FirstOrDefault(c => c.NetConnection == inc.SenderConnection);
string disconnectMsg = inc.ReadString();
var peerDisconnectPacket =
PeerDisconnectPacket.FromLidgrenStringRepresentation(disconnectMsg).Fallback(PeerDisconnectPacket.WithReason(DisconnectReason.Unknown));
if (conn != null)
{
if (conn == OwnerConnection)
@@ -283,7 +288,7 @@ namespace Barotrauma.Networking
}
else
{
Disconnect(conn, PeerDisconnectPacket.WithReason(DisconnectReason.Disconnected));
Disconnect(conn, peerDisconnectPacket);
}
}
else
@@ -291,7 +296,7 @@ namespace Barotrauma.Networking
PendingClient? pendingClient = pendingClients.Find(c => c.Connection is LidgrenConnection l && l.NetConnection == inc.SenderConnection);
if (pendingClient != null)
{
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.Disconnected));
RemovePendingClient(pendingClient, peerDisconnectPacket);
}
}
@@ -332,7 +337,9 @@ namespace Barotrauma.Networking
if (status == Steamworks.AuthResponse.OK)
{
pendingClient.Connection.SetAccountInfo(new AccountInfo(new SteamId(steamId), new SteamId(ownerId)));
pendingClient.InitializationStep = serverSettings.HasPassword ? ConnectionInitialization.Password : ConnectionInitialization.ContentPackageOrder;
pendingClient.InitializationStep = ShouldAskForPassword(serverSettings, pendingClient.Connection)
? ConnectionInitialization.Password
: ConnectionInitialization.ContentPackageOrder;
pendingClient.UpdateTime = Timing.TotalTime;
}
else
@@ -440,7 +447,7 @@ namespace Barotrauma.Networking
{
if (pendingClient.AccountInfo.AccountId != packet.AccountId)
{
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.AuthenticationFailed));
rejectClient();
}
return;
}
@@ -450,7 +457,9 @@ namespace Barotrauma.Networking
pendingClient.Connection.SetAccountInfo(accountInfo);
pendingClient.Name = packet.Name;
pendingClient.OwnerKey = packet.OwnerKey;
pendingClient.InitializationStep = serverSettings.HasPassword ? ConnectionInitialization.Password : ConnectionInitialization.ContentPackageOrder;
pendingClient.InitializationStep = ShouldAskForPassword(serverSettings, pendingClient.Connection)
? ConnectionInitialization.Password
: ConnectionInitialization.ContentPackageOrder;
}
void rejectClient()
@@ -470,7 +479,7 @@ namespace Barotrauma.Networking
if (authenticators is null
|| !packet.AuthTicket.TryUnwrap(out var authTicket)
|| !authenticators.TryGetValue(authTicket.Kind, out var authenticator))
{
{
#if DEBUG
DebugConsole.NewMessage("Debug server accepts unauthenticated connections", Microsoft.Xna.Framework.Color.Yellow);
acceptClient(new AccountInfo(new UnauthenticatedAccountId(packet.Name)));
@@ -494,10 +503,16 @@ namespace Barotrauma.Networking
pendingClient.AuthSessionStarted = true;
TaskPool.Add($"{nameof(LidgrenServerPeer)}.ProcessAuth", authenticator.VerifyTicket(authTicket), t =>
{
if (!t.TryGetResult(out AccountInfo accountInfo)
|| accountInfo.IsNone)
if (!t.TryGetResult(out AccountInfo accountInfo) || accountInfo.IsNone)
{
rejectClient();
if (GameMain.Server.ServerSettings.RequireAuthentication)
{
rejectClient();
}
else
{
acceptClient(new AccountInfo(new UnauthenticatedAccountId(packet.Name)));
}
return;
}
@@ -344,7 +344,9 @@ namespace Barotrauma.Networking
{
// Do nothing with the auth ticket because that should be handled by the owner peer,
// just assume that authentication succeeded
pendingClient.InitializationStep = serverSettings.HasPassword ? ConnectionInitialization.Password : ConnectionInitialization.ContentPackageOrder;
pendingClient.InitializationStep = ShouldAskForPassword(serverSettings, pendingClient.Connection)
? ConnectionInitialization.Password
: ConnectionInitialization.ContentPackageOrder;
pendingClient.Name = packet.Name;
pendingClient.AuthSessionStarted = true;
}
@@ -359,5 +359,18 @@ namespace Barotrauma.Networking
}
protected static void LogMalformedMessage()
=> DebugConsole.ThrowError("Received malformed message from remote peer.");
protected bool ShouldAskForPassword(ServerSettings serverSettings, NetworkConnection connection)
{
if (!serverSettings.HasPassword) { return false; }
if (GameMain.Server is { } server && server.FindAndRemoveRecentlyDisconnectedConnection(connection))
{
// do not ask passwords from clients that have recently disconnected
return false;
}
return true;
}
}
}