Release 1.8.6.2 - Calm Before the Storm
This commit is contained in:
@@ -195,7 +195,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void BanPlayer(string name, Either<Address, AccountId> addressOrAccountId, string reason, TimeSpan? duration)
|
||||
{
|
||||
if (addressOrAccountId.TryGet(out Address address) && address.IsLocalHost) { return; }
|
||||
if (addressOrAccountId.TryGet(out Address address) && address.IsLocalHost)
|
||||
{
|
||||
DebugConsole.AddWarning($"Cannot ban localhost ({address.StringRepresentation})");
|
||||
return;
|
||||
}
|
||||
|
||||
var existingBan = bannedPlayers.Find(bp => bp.AddressOrAccountId == addressOrAccountId);
|
||||
if (existingBan != null) { bannedPlayers.Remove(existingBan); }
|
||||
|
||||
+20
-2
@@ -200,11 +200,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
PendingClient? pendingClient = pendingClients.Find(c => c.Connection.NetConnection == inc.SenderConnection);
|
||||
|
||||
if (pendingClient is null)
|
||||
{
|
||||
pendingClient = new PendingClient(new LidgrenConnection(inc.SenderConnection));
|
||||
pendingClients.Add(pendingClient);
|
||||
GameServer.Log($"Incoming connection from {pendingClient.Connection.NetConnection?.RemoteEndPoint?.ToString() ?? "null"}.", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
|
||||
inc.SenderConnection.Approve();
|
||||
@@ -218,7 +218,25 @@ namespace Barotrauma.Networking
|
||||
|
||||
IReadMessage inc = lidgrenMsg.ToReadMessage();
|
||||
|
||||
var (_, packetHeader, initialization) = INetSerializableStruct.Read<PeerPacketHeaders>(inc);
|
||||
PeerPacketHeaders peerPacketHeaders = default;
|
||||
try
|
||||
{
|
||||
peerPacketHeaders = INetSerializableStruct.Read<PeerPacketHeaders>(inc);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (pendingClient != null)
|
||||
{
|
||||
//pending (= not yet authenticated) client sent malformed data, immediately ban them so they can't use this for spamming
|
||||
GameServer.Log($"Received an invalid connection attempt from {pendingClient.Connection.NetConnection?.RemoteEndPoint?.ToString() ?? "null"}. Banning the IP.", ServerLog.MessageType.DoSProtection);
|
||||
serverSettings.BanList.BanPlayer(name: "Unknown", endpoint: pendingClient.Connection.Endpoint, reason: "Invalid connection attempt", duration: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
var (_, packetHeader, initialization) = peerPacketHeaders;
|
||||
|
||||
if (packetHeader.IsConnectionInitializationStep() && pendingClient != null && initialization.HasValue)
|
||||
{
|
||||
|
||||
+5
-5
@@ -41,7 +41,7 @@ namespace Barotrauma.Networking
|
||||
public ConnectionInitialization InitializationStep;
|
||||
public double UpdateTime;
|
||||
public double TimeOut;
|
||||
public int Retries;
|
||||
public int PasswordRetries;
|
||||
public Int32? PasswordSalt;
|
||||
public bool AuthSessionStarted;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Barotrauma.Networking
|
||||
OwnerKey = Option.None;
|
||||
Connection = conn;
|
||||
InitializationStep = ConnectionInitialization.AuthInfoAndVersion;
|
||||
Retries = 0;
|
||||
PasswordRetries = 0;
|
||||
PasswordSalt = null;
|
||||
UpdateTime = Timing.TotalTime + Timing.Step * 3.0;
|
||||
TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
@@ -156,8 +156,8 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingClient.Retries++;
|
||||
if (serverSettings.BanAfterWrongPassword && pendingClient.Retries > serverSettings.MaxPasswordRetriesBeforeBan)
|
||||
pendingClient.PasswordRetries++;
|
||||
if (serverSettings.BanAfterWrongPassword && pendingClient.PasswordRetries > serverSettings.MaxPasswordRetriesBeforeBan)
|
||||
{
|
||||
const string banMsg = "Failed to enter correct password too many times";
|
||||
BanPendingClient(pendingClient, banMsg, null);
|
||||
@@ -281,7 +281,7 @@ namespace Barotrauma.Networking
|
||||
structToSend = new ServerPeerPasswordPacket
|
||||
{
|
||||
Salt = GetSalt(pendingClient),
|
||||
RetriesLeft = Option<int>.Some(pendingClient.Retries)
|
||||
RetriesLeft = Option<int>.Some(pendingClient.PasswordRetries)
|
||||
};
|
||||
|
||||
static Option<int> GetSalt(PendingClient client)
|
||||
|
||||
Reference in New Issue
Block a user