LobbyQuery Numerical Filters, NearValFilter, SteamClient and Friend OwnsLobby methods

Added LobbyQuery numerical filters for WithLower, WithHigher, WithEqual, and WithNotEqual; added OrderByNear for near value filters. Added OwnsLobby method to SteamClient and Friend to test for ownership.
This commit is contained in:
thesupersoup 2019-06-24 20:13:48 -07:00
parent 0300b46ed3
commit 4b8e1e33af
3 changed files with 112 additions and 7 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Steamworks.Data;
namespace Steamworks
{
@ -105,7 +106,7 @@ namespace Steamworks
SteamParties.Shutdown();
SteamNetworkingUtils.Shutdown();
SteamNetworkingSockets.Shutdown();
ServerList.Base.Shutdown();
SteamAPI.Shutdown();
@ -169,6 +170,11 @@ namespace Steamworks
/// </summary>
public static AppId AppId { get; internal set; }
/// <summary>
/// Check if this SteamClient owns the specified lobby
/// </summary>
public static bool OwnsLobby( Lobby k ) => k.Owner.Id == SteamId;
/// <summary>
/// Checks if your executable was launched through Steam and relaunches it through Steam if it wasn't
/// this returns true then it starts the Steam client if required and launches your game again through it,

View File

@ -71,6 +71,11 @@ namespace Steamworks
/// </summary>
public bool IsSnoozing => State == FriendState.Snooze;
/// <summary>
/// Check if this Friend owns the specified lobby
/// </summary>
public bool OwnsLobby( Lobby k ) => k.Owner.Id == this.Id;
public Relationship Relationship => SteamFriends.Internal.GetFriendRelationship( Id );

View File

@ -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,89 @@ namespace Steamworks.Data
}
#endregion
#region Numerical filters
internal Dictionary<KeyValuePair<string, int>, LobbyComparison> 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 dictionary if necessary, then add new numerical filter
/// </summary>
internal LobbyQuery 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 Dictionary<KeyValuePair<string, int>, LobbyComparison>();
numericalFilters.Add( new KeyValuePair<string, int>( key, value ), compare );
return this;
}
#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 +174,6 @@ namespace Steamworks.Data
#endregion
void ApplyFilters()
{
if ( distance.HasValue )
@ -120,6 +198,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.Key, n.Key.Value, n.Value );
}
}
if( nearValFilters != null )
{
foreach (var v in nearValFilters )
{
SteamMatchmaking.Internal.AddRequestLobbyListNearValueFilter( v.Key, v.Value );
}
}
}
/// <summary>