Fixed RequestUserStats callback

This commit is contained in:
Garry Newman 2016-11-03 10:52:52 +00:00
parent d5eca996cd
commit 65dec9d809
5 changed files with 48 additions and 12 deletions

View File

@ -17,15 +17,26 @@ namespace Facepunch.Steamworks.Test
ulong MySteamId = 76561197960279927; ulong MySteamId = 76561197960279927;
server.Stats.Refresh( MySteamId ); bool GotStats = false;
// TODO - Callback on complete server.Stats.Refresh( MySteamId, success =>
{
GotStats = true;
Assert.IsTrue( success );
Thread.Sleep( 2000 ); var deathsInCallback = server.Stats.GetInt( MySteamId, "deaths", -1 );
Console.WriteLine( "deathsInCallback: {0}", deathsInCallback );
Assert.IsTrue( deathsInCallback > 0 );
} );
while ( !GotStats )
{
server.Update();
Thread.Sleep( 10 );
}
var deaths = server.Stats.GetInt( MySteamId, "deaths", -1 ); var deaths = server.Stats.GetInt( MySteamId, "deaths", -1 );
Console.WriteLine( "deathsInCallback: {0}", deaths );
Console.WriteLine( "Deaths: {0}", deaths );
Assert.IsTrue( deaths > 0 ); Assert.IsTrue( deaths > 0 );
} }
} }

View File

@ -595,9 +595,16 @@
We have received a server query on our game port. Pass it to Steam to handle. We have received a server query on our game port. Pass it to Steam to handle.
</summary> </summary>
</member> </member>
<member name="M:Facepunch.Steamworks.ServerStats.Refresh(System.UInt64)"> <member name="T:Facepunch.Steamworks.ServerStats">
<summary> <summary>
Retrieve the stats for this user Allows getting and setting stats on users from the gameserver
</summary>
</member>
<member name="M:Facepunch.Steamworks.ServerStats.Refresh(System.UInt64,System.Action{System.Boolean})">
<summary>
Retrieve the stats for this user. If you pass a callback function in
this will be called when the stats are recieved, the bool will signify whether
it was successful or not.
</summary> </summary>
</member> </member>
<member name="M:Facepunch.Steamworks.ServerStats.Set(System.UInt64,System.String,System.Int32)"> <member name="M:Facepunch.Steamworks.ServerStats.Set(System.UInt64,System.String,System.Int32)">

View File

@ -22,6 +22,9 @@ namespace Facepunch.Steamworks
} }
} }
/// <summary>
/// Allows getting and setting stats on users from the gameserver
/// </summary>
public class ServerStats public class ServerStats
{ {
internal Server server; internal Server server;
@ -39,11 +42,22 @@ namespace Facepunch.Steamworks
} }
/// <summary> /// <summary>
/// Retrieve the stats for this user /// Retrieve the stats for this user. If you pass a callback function in
/// this will be called when the stats are recieved, the bool will signify whether
/// it was successful or not.
/// </summary> /// </summary>
public void Refresh( ulong steamid ) public void Refresh( ulong steamid, Action<bool> Callback = null )
{ {
var handle = server.native.gameServerStats.RequestUserStats( steamid ); if ( Callback == null )
{
server.native.gameServerStats.RequestUserStats( steamid );
return;
}
server.native.gameServerStats.RequestUserStats( steamid, ( o, failed ) =>
{
Callback( o.Result == SteamNative.Result.OK && !failed );
} );
} }
public void Commit( ulong steamid ) public void Commit( ulong steamid )

View File

@ -67,14 +67,14 @@ namespace SteamNative
} }
// SteamAPICall_t // SteamAPICall_t
public CallbackHandle RequestUserStats( CSteamID steamIDUser /*class CSteamID*/, Action<UserStatsReceived_t, bool> CallbackFunction = null /*Action<UserStatsReceived_t, bool>*/ ) public CallbackHandle RequestUserStats( CSteamID steamIDUser /*class CSteamID*/, Action<GSStatsReceived_t, bool> CallbackFunction = null /*Action<GSStatsReceived_t, bool>*/ )
{ {
SteamAPICall_t callback = 0; SteamAPICall_t callback = 0;
callback = platform.ISteamGameServerStats_RequestUserStats( steamIDUser.Value ); callback = platform.ISteamGameServerStats_RequestUserStats( steamIDUser.Value );
if ( CallbackFunction == null ) return null; if ( CallbackFunction == null ) return null;
return UserStatsReceived_t.CallResult( steamworks, callback, CallbackFunction ); return GSStatsReceived_t.CallResult( steamworks, callback, CallbackFunction );
} }
// bool // bool

View File

@ -45,6 +45,8 @@ namespace Generator
// //
foreach ( var t in def.structs ) foreach ( var t in def.structs )
{ {
if ( !string.IsNullOrEmpty( t.CallbackId ) ) continue;
// Standard style // Standard style
{ {
var r = new Regex( @"struct "+t.Name+@"\n{ ?\n(?:.)+enum { k_iCallback = (?:(.+) \+ ([0-9]+)|(.+)) };", RegexOptions.Multiline | RegexOptions.IgnoreCase ); var r = new Regex( @"struct "+t.Name+@"\n{ ?\n(?:.)+enum { k_iCallback = (?:(.+) \+ ([0-9]+)|(.+)) };", RegexOptions.Multiline | RegexOptions.IgnoreCase );
@ -110,6 +112,8 @@ namespace Generator
foreach ( var t in def.methods.Where( x => x.Name == m.Groups[2].Value ) ) foreach ( var t in def.methods.Where( x => x.Name == m.Groups[2].Value ) )
{ {
if ( !string.IsNullOrEmpty( t.CallResult ) ) continue;
t.CallResult = s.Name; t.CallResult = s.Name;
} }
} }