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 @@ public async Task BeginAuthSession()
// The client sends this data to the server along with their steamid
//
var ticketData = clientTicket.Data;
var clientSteamId = User.SteamID;
var clientSteamId = User.SteamId;
//
// Server listens to auth responses from Gabe

View File

@ -53,8 +53,8 @@ public void IsLoggedOn()
[TestMethod]
public void SteamID()
{
Assert.AreNotEqual( 0, User.SteamID.Value );
Console.WriteLine( $"User.SteamID: {User.SteamID.Value}" );
Assert.AreNotEqual( 0, User.SteamId.Value );
Console.WriteLine( $"User.SteamID: {User.SteamId.Value}" );
}
[TestMethod]
@ -67,11 +67,11 @@ public void AuthSession()
Console.WriteLine( $"ticket.Handle: {ticket.Handle}" );
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 }" );
Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK );
User.EndAuthSession( User.SteamID );
User.EndAuthSession( User.SteamId );
}

View File

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

View File

@ -8,7 +8,7 @@ namespace Steamworks
{
public static class Steam
{
internal static int HUser;
static bool initialized;
public static void Init( uint appid )
{
@ -25,11 +25,7 @@ public static void Init( uint 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();
if ( HUser == 0 )
{
throw new System.Exception( "GetHSteamUser returned 0" );
}
initialized = true;
Apps.InstallEvents();
Utils.InstallEvents();
@ -42,6 +38,8 @@ public static void Init( uint appid )
RunCallbacks();
}
public static bool IsValid => initialized;
internal static async void RunCallbacks()
{
while ( true )

View File

@ -118,7 +118,7 @@ internal static void InstallEvents()
/// 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.
/// </summary>
public static CSteamID SteamID => Internal.GetSteamID();
public static CSteamID SteamId => Internal.GetSteamID();
static bool _recordingVoice;