Real world use part 1

This commit is contained in:
Garry Newman 2019-04-16 09:30:17 +01:00
parent c19982f3b1
commit a634f80790
5 changed files with 34 additions and 20 deletions

View File

@ -53,7 +53,7 @@ namespace Steamworks
// The client sends this data to the server along with their steamid // The client sends this data to the server along with their steamid
// //
var ticketData = clientTicket.Data; var ticketData = clientTicket.Data;
var clientSteamId = User.SteamID; var clientSteamId = User.SteamId;
// //
// Server listens to auth responses from Gabe // Server listens to auth responses from Gabe

View File

@ -53,8 +53,8 @@ namespace Steamworks
[TestMethod] [TestMethod]
public void SteamID() public void SteamID()
{ {
Assert.AreNotEqual( 0, User.SteamID.Value ); Assert.AreNotEqual( 0, User.SteamId.Value );
Console.WriteLine( $"User.SteamID: {User.SteamID.Value}" ); Console.WriteLine( $"User.SteamID: {User.SteamId.Value}" );
} }
[TestMethod] [TestMethod]
@ -67,11 +67,11 @@ namespace Steamworks
Console.WriteLine( $"ticket.Handle: {ticket.Handle}" ); Console.WriteLine( $"ticket.Handle: {ticket.Handle}" );
Console.WriteLine( $"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }" ); Console.WriteLine( $"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }" );
var result = User.BeginAuthSession( ticket.Data, User.SteamID ); var result = User.BeginAuthSession( ticket.Data, User.SteamId );
Console.WriteLine( $"result: { result }" ); Console.WriteLine( $"result: { result }" );
Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK ); Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK );
User.EndAuthSession( User.SteamID ); User.EndAuthSession( User.SteamId );
} }

View File

@ -13,6 +13,8 @@ namespace Steamworks
/// </summary> /// </summary>
public static partial class GameServer public static partial class GameServer
{ {
static bool initialized;
static Internal.ISteamGameServer _internal; static Internal.ISteamGameServer _internal;
internal static Internal.ISteamGameServer Internal internal static Internal.ISteamGameServer Internal
{ {
@ -25,6 +27,8 @@ namespace Steamworks
} }
} }
public static bool IsValid => initialized;
internal static void InstallEvents() internal static void InstallEvents()
{ {
new Event<ValidateAuthTicketResponse_t>( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true ); new Event<ValidateAuthTicketResponse_t>( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true );
@ -53,6 +57,8 @@ namespace Steamworks
throw new System.Exception( "InitGameServer returned false" ); throw new System.Exception( "InitGameServer returned false" );
} }
initialized = true;
// //
// Initial settings // Initial settings
// //
@ -69,20 +75,30 @@ namespace Steamworks
RunCallbacks(); RunCallbacks();
} }
public static void Shutdown()
{
initialized = false;
}
internal static async void RunCallbacks() internal static async void RunCallbacks()
{ {
while ( true ) while ( true )
{ {
await Task.Delay( 16 ); await Task.Delay( 16 );
try Update();
{ }
SteamApi.SteamGameServer_RunCallbacks(); }
}
catch ( System.Exception ) public static void Update()
{ {
// TODO - error outputs try
} {
SteamApi.SteamGameServer_RunCallbacks();
}
catch ( System.Exception )
{
// TODO - error outputs
} }
} }

View File

@ -8,7 +8,7 @@ namespace Steamworks
{ {
public static class Steam public static class Steam
{ {
internal static int HUser; static bool initialized;
public static void Init( uint appid ) public static void Init( uint appid )
{ {
@ -25,11 +25,7 @@ namespace Steamworks
throw new System.Exception( "SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId." ); throw new System.Exception( "SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId." );
} }
HUser = SteamApi.GetHSteamUser(); initialized = true;
if ( HUser == 0 )
{
throw new System.Exception( "GetHSteamUser returned 0" );
}
Apps.InstallEvents(); Apps.InstallEvents();
Utils.InstallEvents(); Utils.InstallEvents();
@ -42,6 +38,8 @@ namespace Steamworks
RunCallbacks(); RunCallbacks();
} }
public static bool IsValid => initialized;
internal static async void RunCallbacks() internal static async void RunCallbacks()
{ {
while ( true ) while ( true )

View File

@ -118,7 +118,7 @@ namespace Steamworks
/// A Steam ID is a unique identifier for a Steam accounts, Steam groups, Lobbies and Chat /// A Steam ID is a unique identifier for a Steam accounts, Steam groups, Lobbies and Chat
/// rooms, and used to differentiate users in all parts of the Steamworks API. /// rooms, and used to differentiate users in all parts of the Steamworks API.
/// </summary> /// </summary>
public static CSteamID SteamID => Internal.GetSteamID(); public static CSteamID SteamId => Internal.GetSteamID();
static bool _recordingVoice; static bool _recordingVoice;