diff --git a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll b/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll deleted file mode 100644 index ba15291..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll b/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll deleted file mode 100644 index 39bd4f3..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll b/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll deleted file mode 100644 index a4db1c1..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll b/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll deleted file mode 100644 index c426bea..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.dll b/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.dll deleted file mode 100644 index d4afc5e..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Microsoft.VisualStudio.TestPlatform.TestFramework.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/Newtonsoft.Json.dll b/Facepunch.Steamworks.Test/bin/Debug/Newtonsoft.Json.dll deleted file mode 100644 index 5523f5c..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/Newtonsoft.Json.dll and /dev/null differ diff --git a/Facepunch.Steamworks.Test/bin/Debug/steam_api64.dll b/Facepunch.Steamworks.Test/bin/Debug/steam_api64.dll deleted file mode 100644 index 328dade..0000000 Binary files a/Facepunch.Steamworks.Test/bin/Debug/steam_api64.dll and /dev/null differ diff --git a/Facepunch.Steamworks/Utility/SourceServerQuery.cs b/Facepunch.Steamworks/Utility/SourceServerQuery.cs index 7d0bf53..15fc24e 100644 --- a/Facepunch.Steamworks/Utility/SourceServerQuery.cs +++ b/Facepunch.Steamworks/Utility/SourceServerQuery.cs @@ -15,26 +15,53 @@ internal static class SourceServerQuery // private static readonly byte A2S_PLAYER = 0x55; private static readonly byte A2S_RULES = 0x56; - internal static async Task> GetRules( ServerInfo server ) - { - try - { - var endpoint = new IPEndPoint( server.Address, server.QueryPort ); + private static readonly Dictionary>> PendingQueries = + new Dictionary>>(); - using ( var client = new UdpClient() ) - { - client.Client.SendTimeout = 3000; - client.Client.ReceiveTimeout = 3000; - client.Connect( endpoint ); + internal static Task> GetRules( ServerInfo server ) + { + var endpoint = new IPEndPoint(server.Address, server.QueryPort); - return await GetRules( client ); - } - } - catch ( System.Exception e ) - { - //Console.Error.WriteLine( e.Message ); - return null; - } + lock (PendingQueries) + { + if (PendingQueries.TryGetValue(endpoint, out var pending)) + return pending; + + var task = GetRulesImpl(endpoint, server) + .ContinueWith(t => + { + lock (PendingQueries) + { + PendingQueries.Remove(endpoint); + } + + return t; + }) + .Unwrap(); + + PendingQueries.Add(endpoint, task); + return task; + } + } + + private static async Task> GetRulesImpl( IPEndPoint endpoint, ServerInfo server ) + { + try + { + using (var client = new UdpClient()) + { + client.Client.SendTimeout = 3000; + client.Client.ReceiveTimeout = 3000; + client.Connect(endpoint); + + return await GetRules(client); + } + } + catch (System.Exception e) + { + //Console.Error.WriteLine( e.Message ); + return null; + } } static async Task> GetRules( UdpClient client )