mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Fixed RequestUserStats callback
This commit is contained in:
parent
d5eca996cd
commit
65dec9d809
@ -17,15 +17,26 @@ public void StatsGet()
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -595,9 +595,16 @@
|
||||
We have received a server query on our game port. Pass it to Steam to handle.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Facepunch.Steamworks.ServerStats.Refresh(System.UInt64)">
|
||||
<member name="T:Facepunch.Steamworks.ServerStats">
|
||||
<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>
|
||||
</member>
|
||||
<member name="M:Facepunch.Steamworks.ServerStats.Set(System.UInt64,System.String,System.Int32)">
|
||||
|
@ -22,6 +22,9 @@ public ServerStats Stats
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows getting and setting stats on users from the gameserver
|
||||
/// </summary>
|
||||
public class ServerStats
|
||||
{
|
||||
internal Server server;
|
||||
@ -39,11 +42,22 @@ public struct StatsReceived
|
||||
}
|
||||
|
||||
/// <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>
|
||||
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 )
|
||||
|
@ -67,14 +67,14 @@ public bool GetUserStat0( CSteamID steamIDUser /*class CSteamID*/, string pchNam
|
||||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
|
@ -45,6 +45,8 @@ internal void ExtendDefinition( SteamApiDefinition def )
|
||||
//
|
||||
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 @@ internal void ExtendDefinition( SteamApiDefinition def )
|
||||
|
||||
foreach ( var t in def.methods.Where( x => x.Name == m.Groups[2].Value ) )
|
||||
{
|
||||
if ( !string.IsNullOrEmpty( t.CallResult ) ) continue;
|
||||
|
||||
t.CallResult = s.Name;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user