diff --git a/Facepunch.Steamworks/SteamMatchmaking.cs b/Facepunch.Steamworks/SteamMatchmaking.cs index 89798e8..1afc770 100644 --- a/Facepunch.Steamworks/SteamMatchmaking.cs +++ b/Facepunch.Steamworks/SteamMatchmaking.cs @@ -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 /// public static event Action OnLobbyEntered; + /// + /// A game server has been associated with the lobby + /// + public static event Action OnLobbyGameCreated; + /// /// The lobby metadata has changed /// diff --git a/Facepunch.Steamworks/SteamNetworking.cs b/Facepunch.Steamworks/SteamNetworking.cs index b2b6d37..ee1ceef 100644 --- a/Facepunch.Steamworks/SteamNetworking.cs +++ b/Facepunch.Steamworks/SteamNetworking.cs @@ -54,6 +54,13 @@ internal static void InstallEvents() /// public static bool AcceptP2PSessionWithUser( SteamId user ) => Internal.AcceptP2PSessionWithUser( user ); + /// + /// 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. + /// + public static bool AllowP2PPacketRelay( bool allow ) => Internal.AllowP2PPacketRelay( allow ); + /// /// 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. diff --git a/Facepunch.Steamworks/SteamUserStats.cs b/Facepunch.Steamworks/SteamUserStats.cs index 26c2f33..163de57 100644 --- a/Facepunch.Steamworks/SteamUserStats.cs +++ b/Facepunch.Steamworks/SteamUserStats.cs @@ -92,6 +92,23 @@ public static IEnumerable Achievements } } + /// + /// 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. + /// + 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 ); + } + /// /// Tries to get the number of players currently playing this game. /// Or -1 if failed. diff --git a/Facepunch.Steamworks/Structs/Lobby.cs b/Facepunch.Steamworks/Structs/Lobby.cs index e782690..f1bc754 100644 --- a/Facepunch.Steamworks/Structs/Lobby.cs +++ b/Facepunch.Steamworks/Structs/Lobby.cs @@ -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 ); } + /// + /// [SteamID variant] + /// Allows the owner to set the game server associated with the lobby. Triggers a + /// LobbyGameCreated_t callback. + /// + public void SetGameServer( SteamId steamServer ) + { + if ( !steamServer.IsValid ) + throw new ArgumentException( $"SteamId for server is invalid" ); + + SteamMatchmaking.Internal.SetLobbyGameServer( Id, 0, 0, steamServer ); + } + + /// + /// [IP/Port variant] + /// Allows the owner to set the game server associated with the lobby. Triggers a + /// LobbyGameCreated_t callback. + /// + 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() ); + } + + /// + /// 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. + /// + public bool GetGameServer( ref uint ip, ref ushort port, ref SteamId serverId ) + { + return SteamMatchmaking.Internal.GetLobbyGameServer( Id, ref ip, ref port, ref serverId ); + } + /// /// You must be the lobby owner to set the owner /// diff --git a/Facepunch.Steamworks/Structs/SteamId.cs b/Facepunch.Steamworks/Structs/SteamId.cs index 62bdce3..48c0a0c 100644 --- a/Facepunch.Steamworks/Structs/SteamId.cs +++ b/Facepunch.Steamworks/Structs/SteamId.cs @@ -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; } } \ No newline at end of file