Lobby game server methods, OnLobbyGameCreated event, Achievement progress notification

Added SetGameServer and GetGameServer for lobby, added OnLobbyGameCreated event in SteamMatchmaking, added SteamId.IsValid check against default ulong value, added SteamUserStats.IndicateAchievementProgress for progress notification.
This commit is contained in:
thesupersoup 2019-06-26 20:31:54 -07:00
parent 6f5bde4f79
commit 7c1a218553
5 changed files with 69 additions and 0 deletions

View File

@ -45,6 +45,8 @@ internal static void InstallEvents()
LobbyEnter_t.Install( x => OnLobbyEntered?.Invoke( new Lobby( x.SteamIDLobby ) ) );
LobbyGameCreated_t.Install( x => OnLobbyGameCreated?.Invoke( new Lobby( x.SteamIDLobby ), x.IP, x.Port, x.SteamIDGameServer ) );
LobbyDataUpdate_t.Install( x =>
{
if ( x.Success == 0 ) return;
@ -103,6 +105,11 @@ static private unsafe void OnLobbyChatMessageRecievedAPI( LobbyChatMsg_t callbac
/// </summary>
public static event Action<Lobby> OnLobbyEntered;
/// <summary>
/// A game server has been associated with the lobby
/// </summary>
public static event Action<Lobby, uint, ushort, SteamId> OnLobbyGameCreated;
/// <summary>
/// The lobby metadata has changed
/// </summary>

View File

@ -54,6 +54,13 @@ internal static void InstallEvents()
/// </summary>
public static bool AcceptP2PSessionWithUser( SteamId user ) => Internal.AcceptP2PSessionWithUser( user );
/// <summary>
/// Allow or disallow P2P connects to fall back on Steam server relay if direct
/// connection or NAT traversal can't be established. Applies to connections
/// created after setting or old connections that need to reconnect.
/// </summary>
public static bool AllowP2PPacketRelay( bool allow ) => Internal.AllowP2PPacketRelay( allow );
/// <summary>
/// This should be called when you're done communicating with a user, as this will
/// free up all of the resources allocated for the connection under-the-hood.

View File

@ -92,6 +92,23 @@ public static IEnumerable<Achievement> Achievements
}
}
/// <summary>
/// Show the user a pop-up notification with the current progress toward an achievement.
/// Will return false if RequestCurrentStats has not completed and successfully returned
/// its callback, if the achievement doesn't exist/has unpublished changes in the app's
/// Steamworks Admin page, or if the achievement is unlocked.
/// </summary>
public static bool IndicateAchievementProgress( string achName, int curProg, int maxProg )
{
if ( string.IsNullOrEmpty( achName ) )
throw new ArgumentNullException( "Achievement string is null or void " );
if ( curProg >= maxProg )
throw new ArgumentException( $" Current progress [{curProg}] arguement toward achievement greater than or equal to max [{maxProg}]" );
return Internal.IndicateAchievementProgress( achName, (uint)curProg, (uint)maxProg );
}
/// <summary>
/// Tries to get the number of players currently playing this game.
/// Or -1 if failed.

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Steamworks.Data
@ -201,6 +202,41 @@ public bool SetJoinable( bool b )
return SteamMatchmaking.Internal.SetLobbyJoinable( Id, b );
}
/// <summary>
/// [SteamID variant]
/// Allows the owner to set the game server associated with the lobby. Triggers a
/// LobbyGameCreated_t callback.
/// </summary>
public void SetGameServer( SteamId steamServer )
{
if ( !steamServer.IsValid )
throw new ArgumentException( $"SteamId for server is invalid" );
SteamMatchmaking.Internal.SetLobbyGameServer( Id, 0, 0, steamServer );
}
/// <summary>
/// [IP/Port variant]
/// Allows the owner to set the game server associated with the lobby. Triggers a
/// LobbyGameCreated_t callback.
/// </summary>
public void SetGameServer( string ip, ushort port )
{
if ( !IPAddress.TryParse( ip, out IPAddress add ) )
throw new ArgumentException( $"IP address for server is invalid" );
SteamMatchmaking.Internal.SetLobbyGameServer( Id, add.IpToInt32(), port, new SteamId() );
}
/// <summary>
/// Gets the details of the lobby's game server, if set. Returns true if the lobby is
/// valid and has a server set, otherwise returns false.
/// </summary>
public bool GetGameServer( ref uint ip, ref ushort port, ref SteamId serverId )
{
return SteamMatchmaking.Internal.GetLobbyGameServer( Id, ref ip, ref port, ref serverId );
}
/// <summary>
/// You must be the lobby owner to set the owner
/// </summary>

View File

@ -23,5 +23,7 @@ public static implicit operator ulong( SteamId value )
public override string ToString() => Value.ToString();
public uint AccountId => (uint) (Value & 0xFFFFFFFFul);
public bool IsValid => Value != default;
}
}