From 9488b5ca6b6b75565ed1a3ebbeaf2fb09a24efe6 Mon Sep 17 00:00:00 2001 From: SeaFood Date: Wed, 13 Sep 2023 15:53:46 +0200 Subject: [PATCH] Added QueryEndReason enum for ServerList queries --- Facepunch.Steamworks/ServerList/Base.cs | 23 ++++++++++++++++++----- Facepunch.Steamworks/ServerList/IpList.cs | 12 +++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Facepunch.Steamworks/ServerList/Base.cs b/Facepunch.Steamworks/ServerList/Base.cs index 41f8624..eec5527 100644 --- a/Facepunch.Steamworks/ServerList/Base.cs +++ b/Facepunch.Steamworks/ServerList/Base.cs @@ -7,6 +7,14 @@ using Steamworks.Data; namespace Steamworks.ServerList { + public enum QueryEndReason + { + EndOfRefresh, + TimeOut, + CancelledOrChangedRequest, + InvalidClient, + } + public abstract class Base : IDisposable { @@ -51,7 +59,7 @@ namespace Steamworks.ServerList /// Query the server list. Task result will be true when finished /// /// - public virtual async Task RunQueryAsync( float timeoutSeconds = 10 ) + public virtual async Task RunQueryAsync( float timeoutSeconds = 10 ) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); @@ -60,6 +68,8 @@ namespace Steamworks.ServerList var thisRequest = request; + QueryEndReason ret = QueryEndReason.EndOfRefresh; + while ( IsRefreshing ) { await Task.Delay( 33 ); @@ -68,10 +78,10 @@ namespace Steamworks.ServerList // The request has been cancelled or changed in some way // if ( request.Value == IntPtr.Zero || thisRequest.Value != request.Value ) - return false; + return QueryEndReason.CancelledOrChangedRequest; if ( !SteamClient.IsValid ) - return false; + return QueryEndReason.InvalidClient; var r = Responsive.Count; @@ -84,13 +94,16 @@ namespace Steamworks.ServerList } if ( stopwatch.Elapsed.TotalSeconds > timeoutSeconds ) + { + ret = QueryEndReason.TimeOut; break; + } } MovePendingToUnresponsive(); InvokeChanges(); - return true; + return ret; } public virtual void Cancel() => Internal.CancelQuery( request ); @@ -194,4 +207,4 @@ namespace Steamworks.ServerList Unresponsive.Add( serverInfo ); } } -} \ No newline at end of file +} diff --git a/Facepunch.Steamworks/ServerList/IpList.cs b/Facepunch.Steamworks/ServerList/IpList.cs index c76e88c..7cee697 100644 --- a/Facepunch.Steamworks/ServerList/IpList.cs +++ b/Facepunch.Steamworks/ServerList/IpList.cs @@ -23,13 +23,15 @@ namespace Steamworks.ServerList Ips.AddRange( list ); } - public override async Task RunQueryAsync( float timeoutSeconds = 10 ) + public override async Task RunQueryAsync( float timeoutSeconds = 10 ) { int blockSize = 16; int pointer = 0; var ips = Ips.ToArray(); + QueryEndReason ret = QueryEndReason.EndOfRefresh; + while ( true ) { var sublist = ips.Skip( pointer ).Take( blockSize ); @@ -45,10 +47,10 @@ namespace Steamworks.ServerList list.AddFilter( "gameaddr", server ); } - await list.RunQueryAsync( timeoutSeconds ); + ret = await list.RunQueryAsync( timeoutSeconds ); if ( wantsCancel ) - return false; + return QueryEndReason.CancelledOrChangedRequest; Responsive.AddRange( list.Responsive ); Responsive = Responsive.Distinct().ToList(); @@ -61,7 +63,7 @@ namespace Steamworks.ServerList InvokeChanges(); } - return true; + return ret; } public override void Cancel() @@ -69,4 +71,4 @@ namespace Steamworks.ServerList wantsCancel = true; } } -} \ No newline at end of file +}