Renamed Server file

This commit is contained in:
Garry Newman 2016-09-29 15:26:12 +01:00
parent b2db9b5304
commit 22cfc740b1
4 changed files with 76 additions and 15 deletions

View File

@ -292,7 +292,7 @@ public void CustomList()
} }
[TestMethod] [TestMethod]
public void PlayerList() public void Rules()
{ {
using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{ {
@ -309,7 +309,7 @@ public void PlayerList()
client.Update(); client.Update();
System.Threading.Thread.Sleep( 10 ); System.Threading.Thread.Sleep( 10 );
if ( query.Responded.Count > 0 && query.Responded.Any( x => x.Players > 5 ) ) if ( query.Responded.Count > 20 )
break; break;
if ( query.Finished ) if ( query.Finished )
@ -318,14 +318,32 @@ public void PlayerList()
query.Dispose(); query.Dispose();
// var server = query.Responded.First( x => x.Players > 5 ); foreach ( var server in query.Responded.Take( 20 ) )
// server.UpdateRules();
// foreach ( var rule in server.Rules )
{ {
// 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 );
}
}
}
} }
} }
} }

View File

@ -161,11 +161,11 @@ private void OnServer( gameserveritem_t info )
{ {
if ( info.m_bHadSuccessfulResponse ) if ( info.m_bHadSuccessfulResponse )
{ {
Responded.Add( Server.FromSteam( info ) ); Responded.Add( Server.FromSteam( client, info ) );
} }
else else
{ {
Unresponsive.Add( Server.FromSteam( info ) ); Unresponsive.Add( Server.FromSteam( client, info ) );
} }
} }

View File

@ -9,7 +9,7 @@ namespace Facepunch.Steamworks
{ {
public partial class ServerList public partial class ServerList
{ {
public struct Server public class Server
{ {
public string Name { get; set; } public string Name { get; set; }
public int Ping { get; set; } public int Ping { get; set; }
@ -26,13 +26,12 @@ public struct Server
public int Version { get; set; } public int Version { get; set; }
public string[] Tags { get; set; } public string[] Tags { get; set; }
public ulong SteamId { get; set; } public ulong SteamId { get; set; }
public uint Address { get; set; } public uint Address { get; set; }
public int ConnectionPort { get; set; } public int ConnectionPort { get; set; }
public int QueryPort { get; set; } public int QueryPort { get; set; }
internal Client Client;
public string AddressString public string AddressString
{ {
get 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() return new Server()
{ {
Client = client,
Address = item.m_NetAdr.m_unIP, Address = item.m_NetAdr.m_unIP,
ConnectionPort = item.m_NetAdr.m_usConnectionPort, ConnectionPort = item.m_NetAdr.m_usConnectionPort,
QueryPort = item.m_NetAdr.m_usQueryPort, QueryPort = item.m_NetAdr.m_usQueryPort,
@ -72,6 +72,45 @@ internal static Server FromSteam( gameserveritem_t item )
SteamId = item.m_steamID SteamId = item.m_steamID
}; };
} }
/// <summary>
/// Callback when rules are receieved.
/// The bool is true if server responded properly.
/// </summary>
public Action<bool> OnReceivedRules;
/// <summary>
/// List of server rules. Use HasRules to see if this is safe to access.
/// </summary>
public Dictionary<string, string> Rules;
/// <summary>
/// Returns true if this server has rules
/// </summary>
public bool HasRules { get { return Rules != null && Rules.Count > 0; } }
internal Interop.ServerRules RulesRequest;
/// <summary>
/// Populates Rules for this server
/// </summary>
public void FetchRules()
{
if ( RulesRequest != null )
return;
Rules = new Dictionary<string, string>();
RulesRequest = new Interop.ServerRules( this, Address, QueryPort );
}
internal void OnServerRulesReceiveFinished( bool Success )
{
RulesRequest = null;
if ( OnReceivedRules != null )
OnReceivedRules( Success );
}
} }
} }
} }

View File

@ -128,7 +128,6 @@ private void UpdateRequest()
if ( status == Valve.Steamworks.EResult.k_EResultOK || status == Valve.Steamworks.EResult.k_EResultExpired ) if ( status == Valve.Steamworks.EResult.k_EResultOK || status == Valve.Steamworks.EResult.k_EResultExpired )
{ {
RetrieveInventory(); RetrieveInventory();
DestroyResult();
return; return;
} }
@ -187,6 +186,11 @@ private unsafe void RetrieveInventory()
SerializedExpireTime = DateTime.Now.Add( TimeSpan.FromMinutes( 60 ) ); SerializedExpireTime = DateTime.Now.Add( TimeSpan.FromMinutes( 60 ) );
//
// Finished with this result, don't call it again
//
DestroyResult();
// //
// Tell everyone we've got new items! // Tell everyone we've got new items!
// //