diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index a5baa83..6369c4c 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; +using Steamworks.Data; namespace Steamworks { @@ -100,7 +101,7 @@ namespace Steamworks SteamParties.Shutdown(); SteamNetworkingUtils.Shutdown(); SteamNetworkingSockets.Shutdown(); - + ServerList.Base.Shutdown(); SteamAPI.Shutdown(); diff --git a/Facepunch.Steamworks/Structs/Lobby.cs b/Facepunch.Steamworks/Structs/Lobby.cs index 46a1bcd..e782690 100644 --- a/Facepunch.Steamworks/Structs/Lobby.cs +++ b/Facepunch.Steamworks/Structs/Lobby.cs @@ -210,5 +210,9 @@ namespace Steamworks.Data set => SteamMatchmaking.Internal.SetLobbyOwner( Id, value.Id ); } + /// + /// Check if the specified SteamId owns the lobby + /// + public bool IsOwnedBy( SteamId k ) => Owner.Id == k; } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/LobbyQuery.cs b/Facepunch.Steamworks/Structs/LobbyQuery.cs index 8a84b9e..384fede 100644 --- a/Facepunch.Steamworks/Structs/LobbyQuery.cs +++ b/Facepunch.Steamworks/Structs/LobbyQuery.cs @@ -7,11 +7,7 @@ namespace Steamworks.Data { // TODO FILTERS // AddRequestLobbyListStringFilter - // - WithKeyValue, WithoutKeyValue - // AddRequestLobbyListNumericalFilter - // - WithLower, WithHigher, WithEqual, WithNotEqual - // AddRequestLobbyListNearValueFilter - // - OrderByNear + // - WithoutKeyValue #region Distance Filter internal LobbyDistanceFilter? distance; @@ -67,6 +63,87 @@ namespace Steamworks.Data } #endregion + #region Numerical filters + internal List numericalFilters; + + /// + /// Numerical filter where value is less than the value provided + /// + public LobbyQuery WithLower( string key, int value ) + { + AddNumericalFilter( key, value, LobbyComparison.LessThan ); + return this; + } + + /// + /// Numerical filter where value is greater than the value provided + /// + public LobbyQuery WithHigher( string key, int value ) + { + AddNumericalFilter( key, value, LobbyComparison.GreaterThan ); + return this; + } + + /// + /// Numerical filter where value must be equal to the value provided + /// + public LobbyQuery WithEqual( string key, int value ) + { + AddNumericalFilter( key, value, LobbyComparison.Equal ); + return this; + } + + /// + /// Numerical filter where value must not equal the value provided + /// + public LobbyQuery WithNotEqual( string key, int value ) + { + AddNumericalFilter( key, value, LobbyComparison.NotEqual ); + return this; + } + + /// + /// Test key, initialize numerical filter list if necessary, then add new numerical filter + /// + internal void AddNumericalFilter( string key, int value, LobbyComparison compare ) + { + if ( string.IsNullOrEmpty( key ) ) + throw new System.ArgumentException( "Key string provided for LobbyQuery filter is null or empty", nameof( key ) ); + + if ( key.Length > SteamMatchmaking.MaxLobbyKeyLength ) + throw new System.ArgumentException( $"Key length is longer than {SteamMatchmaking.MaxLobbyKeyLength}", nameof( key ) ); + + if ( numericalFilters == null ) + numericalFilters = new List(); + + numericalFilters.Add( new NumericalFilter( key, value, compare ) ); + } + #endregion + + #region Near value filter + internal Dictionary nearValFilters; + + /// + /// Order filtered results according to key/values nearest the provided key/value pair. + /// Can specify multiple near value filters; each successive filter is lower priority than the previous. + /// + public LobbyQuery OrderByNear( string key, int value ) + { + if ( string.IsNullOrEmpty( key ) ) + throw new System.ArgumentException( "Key string provided for LobbyQuery filter is null or empty", nameof( key ) ); + + if ( key.Length > SteamMatchmaking.MaxLobbyKeyLength ) + throw new System.ArgumentException( $"Key length is longer than {SteamMatchmaking.MaxLobbyKeyLength}", nameof( key ) ); + + if ( nearValFilters == null ) + nearValFilters = new Dictionary(); + + nearValFilters.Add( key, value ); + + return this; + } + #endregion + #region Slots Filter internal int? slotsAvailable; @@ -95,7 +172,6 @@ namespace Steamworks.Data #endregion - void ApplyFilters() { if ( distance.HasValue ) @@ -120,6 +196,22 @@ namespace Steamworks.Data SteamMatchmaking.Internal.AddRequestLobbyListStringFilter( k.Key, k.Value, LobbyComparison.Equal ); } } + + if( numericalFilters != null ) + { + foreach ( var n in numericalFilters ) + { + SteamMatchmaking.Internal.AddRequestLobbyListNumericalFilter( n.Key, n.Value, n.Comparer ); + } + } + + if( nearValFilters != null ) + { + foreach (var v in nearValFilters ) + { + SteamMatchmaking.Internal.AddRequestLobbyListNearValueFilter( v.Key, v.Value ); + } + } } /// diff --git a/Facepunch.Steamworks/Structs/NumericalFilter.cs b/Facepunch.Steamworks/Structs/NumericalFilter.cs new file mode 100644 index 0000000..a0b246a --- /dev/null +++ b/Facepunch.Steamworks/Structs/NumericalFilter.cs @@ -0,0 +1,16 @@ +namespace Steamworks.Data +{ + struct NumericalFilter + { + public string Key { get; internal set; } + public int Value { get; internal set; } + public LobbyComparison Comparer { get; internal set; } + + internal NumericalFilter ( string k, int v, LobbyComparison c ) + { + Key = k; + Value = v; + Comparer = c; + } + } +}