diff --git a/.gitignore b/.gitignore index f68be81..7c5c9fc 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,6 @@ TestResults obj Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.Api.dll Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.dll -Facepunch.Steamworks/bin/Release/Facepunch.Steamworks.dll \ No newline at end of file +Facepunch.Steamworks/bin/Release/Facepunch.Steamworks.dll +*.opendb +*.db \ No newline at end of file diff --git a/Facepunch.Steamworks.Test/Client.cs b/Facepunch.Steamworks.Test/Client.cs index b098106..12276d7 100644 --- a/Facepunch.Steamworks.Test/Client.cs +++ b/Facepunch.Steamworks.Test/Client.cs @@ -25,6 +25,19 @@ public void ClientName() var username = client.Username; Console.WriteLine( username ); Assert.IsTrue( client.Valid ); + Assert.IsNotNull( username ); + } + } + + [TestMethod] + public void ClientSteamId() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + var steamid = client.SteamId; + Console.WriteLine( steamid ); + Assert.IsTrue( client.Valid ); + Assert.AreNotEqual( 0, steamid ); } } } diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 062cb55..6ee2c9b 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -1,6 +1,7 @@  using System; +using System.Runtime.InteropServices; namespace Facepunch.Steamworks { @@ -22,6 +23,11 @@ public class Client : IDisposable /// public string Username { get; private set; } + /// + /// Current user's SteamId + /// + public ulong SteamId; + public Client( int appId ) { Valve.Steamworks.SteamAPI.Init( (uint) appId ); @@ -33,15 +39,28 @@ public Client( int appId ) return; } + // + // Set up warning hook callback + // + SteamAPIWarningMessageHook ptr = OnWarning; + _client.SetWarningMessageHook( Marshal.GetFunctionPointerForDelegate( ptr ) ); + // + // Get pipes + // _hpipe = _client.CreateSteamPipe(); _huser = _client.ConnectToGlobalUser( _hpipe ); + + // + // Get other interfaces + // _friends = _client.GetISteamFriends( _huser, _hpipe, "SteamFriends015" ); - // _user = Valve.Steamworks.SteamAPI.SteamUser(); + _user = _client.GetISteamUser( _huser, _hpipe, "SteamUser019" ); AppId = appId; Username = _friends.GetPersonaName(); + SteamId = _user.GetSteamID(); } public void Dispose() @@ -66,6 +85,14 @@ public void Dispose() } } + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + public delegate void SteamAPIWarningMessageHook( int nSeverity, System.Text.StringBuilder pchDebugText ); + + private void OnWarning( int nSeverity, System.Text.StringBuilder text ) + { + Console.Write( text.ToString() ); + } + public bool Valid { get { return _client != null; } diff --git a/Facepunch.Steamworks/steam_api_interop.cs b/Facepunch.Steamworks/steam_api_interop.cs index b1ed512..42c3f53 100644 --- a/Facepunch.Steamworks/steam_api_interop.cs +++ b/Facepunch.Steamworks/steam_api_interop.cs @@ -2410,7 +2410,7 @@ internal override ISteamUser GetISteamUser( uint hSteamUser, uint hSteamPipe, st { CheckIfUsable(); IntPtr result = NativeEntrypoints.SteamAPI_ISteamClient_GetISteamUser(m_pSteamClient,hSteamUser,hSteamPipe,pchVersion); - return (ISteamUser)Marshal.PtrToStructure( result, typeof( ISteamUser ) ); + return new CSteamUser( result ); } internal override ISteamGameServer GetISteamGameServer( uint hSteamUser, uint hSteamPipe, string pchVersion ) {