diff --git a/Facepunch.Steamworks.Test/Server/Stats.cs b/Facepunch.Steamworks.Test/Server/Stats.cs index 441fad2..df50056 100644 --- a/Facepunch.Steamworks.Test/Server/Stats.cs +++ b/Facepunch.Steamworks.Test/Server/Stats.cs @@ -17,15 +17,26 @@ namespace Facepunch.Steamworks.Test 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 ); - - Console.WriteLine( "Deaths: {0}", deaths ); + Console.WriteLine( "deathsInCallback: {0}", deaths ); Assert.IsTrue( deaths > 0 ); } } diff --git a/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml b/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml index aaf5a28..8bb7daa 100644 --- a/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml +++ b/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml @@ -595,9 +595,16 @@ We have received a server query on our game port. Pass it to Steam to handle. - + - Retrieve the stats for this user + Allows getting and setting stats on users from the gameserver + + + + + 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. diff --git a/Facepunch.Steamworks/Server/Stats.cs b/Facepunch.Steamworks/Server/Stats.cs index d46bc73..1891320 100644 --- a/Facepunch.Steamworks/Server/Stats.cs +++ b/Facepunch.Steamworks/Server/Stats.cs @@ -22,6 +22,9 @@ namespace Facepunch.Steamworks } } + /// + /// Allows getting and setting stats on users from the gameserver + /// public class ServerStats { internal Server server; @@ -39,11 +42,22 @@ namespace Facepunch.Steamworks } /// - /// 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. /// - public void Refresh( ulong steamid ) + public void Refresh( ulong steamid, Action 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 ) diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.SteamGameServerStats.cs b/Facepunch.Steamworks/SteamNative/SteamNative.SteamGameServerStats.cs index 1fd4e75..d41e898 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.SteamGameServerStats.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.SteamGameServerStats.cs @@ -67,14 +67,14 @@ namespace SteamNative } // SteamAPICall_t - public CallbackHandle RequestUserStats( CSteamID steamIDUser /*class CSteamID*/, Action CallbackFunction = null /*Action*/ ) + public CallbackHandle RequestUserStats( CSteamID steamIDUser /*class CSteamID*/, Action CallbackFunction = null /*Action*/ ) { SteamAPICall_t callback = 0; callback = platform.ISteamGameServerStats_RequestUserStats( steamIDUser.Value ); if ( CallbackFunction == null ) return null; - return UserStatsReceived_t.CallResult( steamworks, callback, CallbackFunction ); + return GSStatsReceived_t.CallResult( steamworks, callback, CallbackFunction ); } // bool diff --git a/Generator/CodeParser/CodeParser.cs b/Generator/CodeParser/CodeParser.cs index 84e5918..99505b7 100644 --- a/Generator/CodeParser/CodeParser.cs +++ b/Generator/CodeParser/CodeParser.cs @@ -45,6 +45,8 @@ namespace Generator // foreach ( var t in def.structs ) { + if ( !string.IsNullOrEmpty( t.CallbackId ) ) continue; + // Standard style { 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 ) ) { + if ( !string.IsNullOrEmpty( t.CallResult ) ) continue; + t.CallResult = s.Name; } }