mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 14:48:02 +03:00
Server Stats
This commit is contained in:
parent
f187083a44
commit
527ce45d84
@ -93,6 +93,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Client\Friends.cs" />
|
||||
<Compile Include="Server\Server.cs" />
|
||||
<Compile Include="Server\Stats.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facepunch.Steamworks\Facepunch.Steamworks.csproj">
|
||||
|
@ -9,7 +9,7 @@ namespace Facepunch.Steamworks.Test
|
||||
[DeploymentItem( "vstdlib_s.dll" )]
|
||||
[DeploymentItem( "steamclient.dll" )]
|
||||
[TestClass]
|
||||
public class Server
|
||||
public partial class Server
|
||||
{
|
||||
[TestMethod]
|
||||
public void Init()
|
||||
|
34
Facepunch.Steamworks.Test/Server/Stats.cs
Normal file
34
Facepunch.Steamworks.Test/Server/Stats.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
{
|
||||
public partial class Server
|
||||
{
|
||||
[TestMethod]
|
||||
public void StatsGet()
|
||||
{
|
||||
using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 30002, true, "VersionString" ) )
|
||||
{
|
||||
Assert.IsTrue( server.Valid );
|
||||
server.LogOnAnonymous();
|
||||
|
||||
ulong MySteamId = 76561197960279927;
|
||||
|
||||
server.Stats.Refresh( MySteamId );
|
||||
|
||||
// TODO - Callback on complete
|
||||
|
||||
Thread.Sleep( 2000 );
|
||||
|
||||
var deaths = server.Stats.GetInt( MySteamId, "deaths", -1 );
|
||||
|
||||
Console.WriteLine( "Deaths: {0}", deaths );
|
||||
Assert.IsTrue( deaths > 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -135,6 +135,7 @@
|
||||
<Compile Include="Interop\steam_api_interop.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Server\Auth.cs" />
|
||||
<Compile Include="Server\Stats.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interop\Callback.This.cs" />
|
||||
|
@ -352,5 +352,10 @@ namespace Facepunch.Steamworks
|
||||
{
|
||||
native.gameServer.BUpdateUserData( steamid, name, (uint) score );
|
||||
}
|
||||
|
||||
public bool LoggedOn
|
||||
{
|
||||
get { return native.gameServer.BLoggedOn(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
96
Facepunch.Steamworks/Server/Stats.cs
Normal file
96
Facepunch.Steamworks/Server/Stats.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
public partial class Server
|
||||
{
|
||||
ServerStats _stats;
|
||||
|
||||
public ServerStats Stats
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( _stats == null )
|
||||
_stats = new ServerStats( this );
|
||||
|
||||
return _stats;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerStats
|
||||
{
|
||||
internal Server server;
|
||||
|
||||
internal ServerStats( Server s )
|
||||
{
|
||||
server = s;
|
||||
}
|
||||
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
public struct StatsReceived
|
||||
{
|
||||
public int Result;
|
||||
public ulong SteamId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the stats for this user
|
||||
/// </summary>
|
||||
public void Refresh( ulong steamid )
|
||||
{
|
||||
var handle = server.native.stats.RequestUserStats( steamid );
|
||||
}
|
||||
|
||||
public void Commit( ulong steamid )
|
||||
{
|
||||
server.native.stats.StoreUserStats( steamid );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the named statistic for this user
|
||||
/// </summary>
|
||||
public bool Set( ulong steamid, string name, int stat )
|
||||
{
|
||||
return server.native.stats.SetUserStat( steamid, name, stat );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the named statistic for this user
|
||||
/// </summary>
|
||||
public bool Set( ulong steamid, string name, float stat )
|
||||
{
|
||||
return server.native.stats.SetUserStat0( steamid, name, stat );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the named stat for this user
|
||||
/// </summary>
|
||||
public int GetInt( ulong steamid, string name, int defaultValue = 0 )
|
||||
{
|
||||
int data = defaultValue;
|
||||
|
||||
if ( !server.native.stats.GetUserStat( steamid, name, ref data ) )
|
||||
return defaultValue;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the named stat for this user
|
||||
/// </summary>
|
||||
public float GetFloat( ulong steamid, string name, float defaultValue = 0 )
|
||||
{
|
||||
float data = defaultValue;
|
||||
|
||||
if ( !server.native.stats.GetUserStat0( steamid, name, ref data ) )
|
||||
return defaultValue;
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user