Merge pull request #278 from thesupersoup/master

LobbyQuery Numerical and NearVal Filters, SteamClient and Friend OwnsLobby
This commit is contained in:
Garry Newman 2019-06-26 10:04:25 +01:00 committed by GitHub
commit 6f5bde4f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 7 deletions

View File

@ -3,6 +3,7 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {

View File

@ -210,5 +210,9 @@ public Friend Owner
set => SteamMatchmaking.Internal.SetLobbyOwner( Id, value.Id ); 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;
} }
} }

View File

@ -7,11 +7,7 @@ public struct LobbyQuery
{ {
// TODO FILTERS // TODO FILTERS
// AddRequestLobbyListStringFilter // AddRequestLobbyListStringFilter
// - WithKeyValue, WithoutKeyValue // - WithoutKeyValue
// AddRequestLobbyListNumericalFilter
// - WithLower, WithHigher, WithEqual, WithNotEqual
// AddRequestLobbyListNearValueFilter
// - OrderByNear
#region Distance Filter #region Distance Filter
internal LobbyDistanceFilter? distance; internal LobbyDistanceFilter? distance;
@ -67,6 +63,87 @@ public LobbyQuery WithKeyValue( string key, string value )
} }
#endregion #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 #region Slots Filter
internal int? slotsAvailable; internal int? slotsAvailable;
@ -95,7 +172,6 @@ public LobbyQuery WithMaxResults( int max )
#endregion #endregion
void ApplyFilters() void ApplyFilters()
{ {
if ( distance.HasValue ) if ( distance.HasValue )
@ -120,6 +196,22 @@ void ApplyFilters()
SteamMatchmaking.Internal.AddRequestLobbyListStringFilter( k.Key, k.Value, LobbyComparison.Equal ); 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> /// <summary>

View 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;
}
}
}