This commit is contained in:
Garry Newman 2016-07-07 13:47:47 +01:00
parent cb85e41c52
commit f39341d90f
4 changed files with 45 additions and 3 deletions

2
.gitignore vendored
View File

@ -60,3 +60,5 @@ obj
Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.Api.dll Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.Api.dll
Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.dll Facepunch.Steamworks/bin/Debug/Facepunch.Steamworks.dll
Facepunch.Steamworks/bin/Release/Facepunch.Steamworks.dll Facepunch.Steamworks/bin/Release/Facepunch.Steamworks.dll
*.opendb
*.db

View File

@ -25,6 +25,19 @@ public void ClientName()
var username = client.Username; var username = client.Username;
Console.WriteLine( username ); Console.WriteLine( username );
Assert.IsTrue( client.Valid ); 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 );
} }
} }
} }

View File

@ -1,6 +1,7 @@
 
using System; using System;
using System.Runtime.InteropServices;
namespace Facepunch.Steamworks namespace Facepunch.Steamworks
{ {
@ -22,6 +23,11 @@ public class Client : IDisposable
/// </summary> /// </summary>
public string Username { get; private set; } public string Username { get; private set; }
/// <summary>
/// Current user's SteamId
/// </summary>
public ulong SteamId;
public Client( int appId ) public Client( int appId )
{ {
Valve.Steamworks.SteamAPI.Init( (uint) appId ); Valve.Steamworks.SteamAPI.Init( (uint) appId );
@ -33,15 +39,28 @@ public Client( int appId )
return; return;
} }
//
// Set up warning hook callback
//
SteamAPIWarningMessageHook ptr = OnWarning;
_client.SetWarningMessageHook( Marshal.GetFunctionPointerForDelegate( ptr ) );
//
// Get pipes
//
_hpipe = _client.CreateSteamPipe(); _hpipe = _client.CreateSteamPipe();
_huser = _client.ConnectToGlobalUser( _hpipe ); _huser = _client.ConnectToGlobalUser( _hpipe );
//
// Get other interfaces
//
_friends = _client.GetISteamFriends( _huser, _hpipe, "SteamFriends015" ); _friends = _client.GetISteamFriends( _huser, _hpipe, "SteamFriends015" );
// _user = Valve.Steamworks.SteamAPI.SteamUser(); _user = _client.GetISteamUser( _huser, _hpipe, "SteamUser019" );
AppId = appId; AppId = appId;
Username = _friends.GetPersonaName(); Username = _friends.GetPersonaName();
SteamId = _user.GetSteamID();
} }
public void Dispose() 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 public bool Valid
{ {
get { return _client != null; } get { return _client != null; }

View File

@ -2410,7 +2410,7 @@ internal override ISteamUser GetISteamUser( uint hSteamUser, uint hSteamPipe, st
{ {
CheckIfUsable(); CheckIfUsable();
IntPtr result = NativeEntrypoints.SteamAPI_ISteamClient_GetISteamUser(m_pSteamClient,hSteamUser,hSteamPipe,pchVersion); 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 ) internal override ISteamGameServer GetISteamGameServer( uint hSteamUser, uint hSteamPipe, string pchVersion )
{ {