diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index f36f48148..4b0669d40 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -1471,7 +1471,7 @@ namespace Barotrauma.Networking } float similarity = 0; - similarity += sender.ChatSpamSpeed; //the faster messages are being sent, the faster the filter will block + similarity += sender.ChatSpamSpeed * 0.05f; //the faster messages are being sent, the faster the filter will block for (int i = 0; i < sender.ChatMessages.Count; i++) { float closeFactor = 1.0f / (20.0f - i); diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index c13b97ad3..3370e8e84 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -365,6 +365,35 @@ namespace Barotrauma return inputType; } + + /// + /// Calculates the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one string into the other + /// + public static int LevenshteinDistance(string s, string t) + { + int n = s.Length; + int m = t.Length; + int[,] d = new int[n + 1, m + 1]; + + if (n == 0 || m == 0) return 0; + + for (int i = 0; i <= n; d[i, 0] = i++); + for (int j = 0; j <= m; d[0, j] = j++); + + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + int cost = (t[j - 1] == s[i - 1]) ? 0 : 1; + + d[i, j] = Math.Min( + Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), + d[i - 1, j - 1] + cost); + } + } + + return d[n, m]; + } public static string WrapText(string text, float lineLength, SpriteFont font) {