diff --git a/Facepunch.Steamworks.Test/Serverlist.cs b/Facepunch.Steamworks.Test/Serverlist.cs
index ffbb79e..e0b45b0 100644
--- a/Facepunch.Steamworks.Test/Serverlist.cs
+++ b/Facepunch.Steamworks.Test/Serverlist.cs
@@ -292,7 +292,7 @@ public void CustomList()
}
[TestMethod]
- public void PlayerList()
+ public void Rules()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
@@ -309,7 +309,7 @@ public void PlayerList()
client.Update();
System.Threading.Thread.Sleep( 10 );
- if ( query.Responded.Count > 0 && query.Responded.Any( x => x.Players > 5 ) )
+ if ( query.Responded.Count > 20 )
break;
if ( query.Finished )
@@ -318,14 +318,32 @@ public void PlayerList()
query.Dispose();
- // var server = query.Responded.First( x => x.Players > 5 );
- // server.UpdateRules();
-
- // foreach ( var rule in server.Rules )
+ foreach ( var server in query.Responded.Take( 20 ) )
{
- // Console.WriteLine( rule.Key + " = " + rule.Value );
+ server.FetchRules();
+
+ int i = 0;
+ while ( !server.HasRules )
+ {
+ i++;
+ client.Update();
+ System.Threading.Thread.Sleep( 2 );
+
+ if ( i > 100 )
+ break;
+ }
+
+ if ( server.HasRules )
+ {
+ foreach ( var rule in server.Rules )
+ {
+ Console.WriteLine( rule.Key + " = " + rule.Value );
+ }
+ }
}
+
+
}
}
}
diff --git a/Facepunch.Steamworks/Client.ServerList.Request.cs b/Facepunch.Steamworks/Client.ServerList.Request.cs
index ebc5b6d..47b6952 100644
--- a/Facepunch.Steamworks/Client.ServerList.Request.cs
+++ b/Facepunch.Steamworks/Client.ServerList.Request.cs
@@ -161,11 +161,11 @@ private void OnServer( gameserveritem_t info )
{
if ( info.m_bHadSuccessfulResponse )
{
- Responded.Add( Server.FromSteam( info ) );
+ Responded.Add( Server.FromSteam( client, info ) );
}
else
{
- Unresponsive.Add( Server.FromSteam( info ) );
+ Unresponsive.Add( Server.FromSteam( client, info ) );
}
}
diff --git a/Facepunch.Steamworks/Server.cs b/Facepunch.Steamworks/Client.ServerList.Server.cs
similarity index 65%
rename from Facepunch.Steamworks/Server.cs
rename to Facepunch.Steamworks/Client.ServerList.Server.cs
index f13aedd..3a1e977 100644
--- a/Facepunch.Steamworks/Server.cs
+++ b/Facepunch.Steamworks/Client.ServerList.Server.cs
@@ -9,7 +9,7 @@ namespace Facepunch.Steamworks
{
public partial class ServerList
{
- public struct Server
+ public class Server
{
public string Name { get; set; }
public int Ping { get; set; }
@@ -26,13 +26,12 @@ public struct Server
public int Version { get; set; }
public string[] Tags { get; set; }
public ulong SteamId { get; set; }
-
public uint Address { get; set; }
-
public int ConnectionPort { get; set; }
-
public int QueryPort { get; set; }
+ internal Client Client;
+
public string AddressString
{
get
@@ -48,10 +47,11 @@ public string ConnectionAddress
}
}
- internal static Server FromSteam( gameserveritem_t item )
+ internal static Server FromSteam( Client client, gameserveritem_t item )
{
return new Server()
{
+ Client = client,
Address = item.m_NetAdr.m_unIP,
ConnectionPort = item.m_NetAdr.m_usConnectionPort,
QueryPort = item.m_NetAdr.m_usQueryPort,
@@ -72,6 +72,45 @@ internal static Server FromSteam( gameserveritem_t item )
SteamId = item.m_steamID
};
}
+
+ ///
+ /// Callback when rules are receieved.
+ /// The bool is true if server responded properly.
+ ///
+ public Action OnReceivedRules;
+
+ ///
+ /// List of server rules. Use HasRules to see if this is safe to access.
+ ///
+ public Dictionary Rules;
+
+ ///
+ /// Returns true if this server has rules
+ ///
+ public bool HasRules { get { return Rules != null && Rules.Count > 0; } }
+
+ internal Interop.ServerRules RulesRequest;
+
+ ///
+ /// Populates Rules for this server
+ ///
+ public void FetchRules()
+ {
+ if ( RulesRequest != null )
+ return;
+
+ Rules = new Dictionary();
+
+ RulesRequest = new Interop.ServerRules( this, Address, QueryPort );
+ }
+
+ internal void OnServerRulesReceiveFinished( bool Success )
+ {
+ RulesRequest = null;
+
+ if ( OnReceivedRules != null )
+ OnReceivedRules( Success );
+ }
}
}
}
diff --git a/Facepunch.Steamworks/Client/Inventory.cs b/Facepunch.Steamworks/Client/Inventory.cs
index 96bb3e7..efeca0d 100644
--- a/Facepunch.Steamworks/Client/Inventory.cs
+++ b/Facepunch.Steamworks/Client/Inventory.cs
@@ -128,7 +128,6 @@ private void UpdateRequest()
if ( status == Valve.Steamworks.EResult.k_EResultOK || status == Valve.Steamworks.EResult.k_EResultExpired )
{
RetrieveInventory();
- DestroyResult();
return;
}
@@ -187,6 +186,11 @@ private unsafe void RetrieveInventory()
SerializedExpireTime = DateTime.Now.Add( TimeSpan.FromMinutes( 60 ) );
+ //
+ // Finished with this result, don't call it again
+ //
+ DestroyResult();
+
//
// Tell everyone we've got new items!
//