Merge pull request #281 from thesupersoup/master

Lobby game server methods, OnLobbyCreated and OnLobbyGameCreated, Achievement progress
This commit is contained in:
Garry Newman 2019-07-01 10:08:54 +01:00 committed by GitHub
commit 968e658913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 0 deletions

View File

@ -45,6 +45,10 @@ namespace Steamworks
LobbyEnter_t.Install( x => OnLobbyEntered?.Invoke( new Lobby( x.SteamIDLobby ) ) );
LobbyCreated_t.Install( x => OnLobbyCreated?.Invoke( x.Result, 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 +107,16 @@ namespace Steamworks
/// </summary>
public static event Action<Lobby> OnLobbyEntered;
/// <summary>
/// You created a lobby
/// </summary>
public static event Action<Result, Lobby> OnLobbyCreated;
/// <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 @@ namespace Steamworks
/// </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 @@ namespace Steamworks
}
}
/// <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 empty" );
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 @@ namespace Steamworks.Data
return SteamMatchmaking.Internal.SetLobbyJoinable( Id, b );
}
/// <summary>
/// [SteamID variant]
/// Allows the owner to set the game server associated with the lobby. Triggers the
/// Steammatchmaking.OnLobbyGameCreated event.
/// </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 the
/// Steammatchmaking.OnLobbyGameCreated event.
/// </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 @@ namespace Steamworks
public override string ToString() => Value.ToString();
public uint AccountId => (uint) (Value & 0xFFFFFFFFul);
public bool IsValid => Value != default;
}
}