mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-27 07:05:50 +03:00
Merge pull request #278 from thesupersoup/master
LobbyQuery Numerical and NearVal Filters, SteamClient and Friend OwnsLobby
This commit is contained in:
commit
6f5bde4f79
@ -3,6 +3,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Steamworks.Data;
|
||||
|
||||
namespace Steamworks
|
||||
{
|
||||
@ -100,7 +101,7 @@ public static void Shutdown()
|
||||
SteamParties.Shutdown();
|
||||
SteamNetworkingUtils.Shutdown();
|
||||
SteamNetworkingSockets.Shutdown();
|
||||
|
||||
|
||||
ServerList.Base.Shutdown();
|
||||
|
||||
SteamAPI.Shutdown();
|
||||
|
@ -210,5 +210,9 @@ public Friend Owner
|
||||
set => SteamMatchmaking.Internal.SetLobbyOwner( Id, value.Id );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the specified SteamId owns the lobby
|
||||
/// </summary>
|
||||
public bool IsOwnedBy( SteamId k ) => Owner.Id == k;
|
||||
}
|
||||
}
|
@ -7,11 +7,7 @@ public struct LobbyQuery
|
||||
{
|
||||
// TODO FILTERS
|
||||
// AddRequestLobbyListStringFilter
|
||||
// - WithKeyValue, WithoutKeyValue
|
||||
// AddRequestLobbyListNumericalFilter
|
||||
// - WithLower, WithHigher, WithEqual, WithNotEqual
|
||||
// AddRequestLobbyListNearValueFilter
|
||||
// - OrderByNear
|
||||
// - WithoutKeyValue
|
||||
|
||||
#region Distance Filter
|
||||
internal LobbyDistanceFilter? distance;
|
||||
@ -67,6 +63,87 @@ public LobbyQuery WithKeyValue( string key, string value )
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Numerical filters
|
||||
internal List<NumericalFilter> numericalFilters;
|
||||
|
||||
/// <summary>
|
||||
/// Numerical filter where value is less than the value provided
|
||||
/// </summary>
|
||||
public LobbyQuery WithLower( string key, int value )
|
||||
{
|
||||
AddNumericalFilter( key, value, LobbyComparison.LessThan );
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numerical filter where value is greater than the value provided
|
||||
/// </summary>
|
||||
public LobbyQuery WithHigher( string key, int value )
|
||||
{
|
||||
AddNumericalFilter( key, value, LobbyComparison.GreaterThan );
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numerical filter where value must be equal to the value provided
|
||||
/// </summary>
|
||||
public LobbyQuery WithEqual( string key, int value )
|
||||
{
|
||||
AddNumericalFilter( key, value, LobbyComparison.Equal );
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numerical filter where value must not equal the value provided
|
||||
/// </summary>
|
||||
public LobbyQuery WithNotEqual( string key, int value )
|
||||
{
|
||||
AddNumericalFilter( key, value, LobbyComparison.NotEqual );
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test key, initialize numerical filter list if necessary, then add new numerical filter
|
||||
/// </summary>
|
||||
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<NumericalFilter>();
|
||||
|
||||
numericalFilters.Add( new NumericalFilter( key, value, compare ) );
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Near value filter
|
||||
internal Dictionary<string, int> nearValFilters;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<string, int>();
|
||||
|
||||
nearValFilters.Add( key, value );
|
||||
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Slots Filter
|
||||
internal int? slotsAvailable;
|
||||
|
||||
@ -95,7 +172,6 @@ public LobbyQuery WithMaxResults( int max )
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
void ApplyFilters()
|
||||
{
|
||||
if ( distance.HasValue )
|
||||
@ -120,6 +196,22 @@ void ApplyFilters()
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
16
Facepunch.Steamworks/Structs/NumericalFilter.cs
Normal file
16
Facepunch.Steamworks/Structs/NumericalFilter.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user