mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Custom server list (hacky)
This commit is contained in:
parent
761b9ce70d
commit
b11a657000
@ -17,7 +17,7 @@ public void InternetList()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var filter = new Dictionary<string, string>();
|
||||
var filter = new Facepunch.Steamworks.ServerList.Filter();
|
||||
filter.Add( "appid", client.AppId.ToString() );
|
||||
filter.Add( "gamedir", "rust" );
|
||||
filter.Add( "secure", "1" );
|
||||
@ -57,9 +57,9 @@ public void MultipleInternetList()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var queries = new List< Facepunch.Steamworks.ServerList.Request >();
|
||||
var queries = new List<Facepunch.Steamworks.ServerList.Request>();
|
||||
|
||||
var filter = new Dictionary<string, string>();
|
||||
var filter = new Facepunch.Steamworks.ServerList.Filter();
|
||||
filter.Add( "map", "barren" );
|
||||
|
||||
for ( int i = 0; i < 10; i++ )
|
||||
@ -91,7 +91,7 @@ public void Filters()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var filter = new Dictionary<string, string>();
|
||||
var filter = new Facepunch.Steamworks.ServerList.Filter();
|
||||
filter.Add( "map", "barren" );
|
||||
|
||||
|
||||
@ -154,5 +154,136 @@ public void HistoryList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomList()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var servers = new List<string>();
|
||||
|
||||
servers.Add( "158.85.101.20:28015" );
|
||||
servers.Add( "158.85.101.20:28022" );
|
||||
servers.Add( "173.192.176.171:28615" );
|
||||
servers.Add( "109.95.212.35:28215" );
|
||||
servers.Add( "109.95.212.35:28115" );
|
||||
servers.Add( "27.50.72.176:28015" );
|
||||
servers.Add( "109.95.212.40:28015" );
|
||||
servers.Add( "212.38.168.149:28215" );
|
||||
servers.Add( "27.50.72.167:28215" );
|
||||
servers.Add( "85.236.105.7:28215" );
|
||||
servers.Add( "107.182.233.216:28215" );
|
||||
servers.Add( "85.236.105.11:28215" );
|
||||
servers.Add( "109.95.211.198:28215" );
|
||||
servers.Add( "8.26.94.190:28015" );
|
||||
servers.Add( "221.121.151.37:28215" );
|
||||
servers.Add( "161.202.144.216:28215" );
|
||||
servers.Add( "107.182.230.181:28215" );
|
||||
servers.Add( "107.182.231.134:27101" );
|
||||
servers.Add( "107.182.233.181:27101" );
|
||||
servers.Add( "78.129.153.47:27101" );
|
||||
servers.Add( "109.95.211.206:27101" );
|
||||
servers.Add( "169.57.142.73:27101" );
|
||||
servers.Add( "221.121.154.147:27101" );
|
||||
servers.Add( "31.216.52.44:30015" );
|
||||
servers.Add( "109.169.94.17:28215" );
|
||||
servers.Add( "109.169.94.17:28315" );
|
||||
servers.Add( "109.169.94.17:28015" );
|
||||
servers.Add( "41.0.11.167:27141" );
|
||||
servers.Add( "78.129.153.47:27131" );
|
||||
servers.Add( "109.95.211.206:27111" );
|
||||
servers.Add( "107.182.231.134:27111" );
|
||||
servers.Add( "198.27.70.162:28015" );
|
||||
servers.Add( "198.27.70.162:28215" );
|
||||
servers.Add( "198.27.70.162:28115" );
|
||||
servers.Add( "169.57.142.73:27111" );
|
||||
servers.Add( "221.121.154.147:27111" );
|
||||
servers.Add( "107.182.233.181:27111" );
|
||||
servers.Add( "78.129.153.47:27111" );
|
||||
servers.Add( "109.95.211.215:28015" );
|
||||
servers.Add( "50.23.131.208:28015" );
|
||||
servers.Add( "50.23.131.208:28115" );
|
||||
servers.Add( "50.23.131.208:28215" );
|
||||
servers.Add( "63.251.114.37:28215" );
|
||||
servers.Add( "63.251.114.37:28115" );
|
||||
servers.Add( "63.251.114.37:28015" );
|
||||
servers.Add( "149.202.89.85:27101" );
|
||||
servers.Add( "149.202.89.85:27111" );
|
||||
servers.Add( "149.202.89.85:27131" );
|
||||
servers.Add( "8.26.94.147:27101" );
|
||||
servers.Add( "8.26.94.147:27111" );
|
||||
servers.Add( "8.26.94.147:27121" );
|
||||
servers.Add( "159.8.147.197:28025" );
|
||||
servers.Add( "162.248.88.203:27038" );
|
||||
servers.Add( "162.248.88.203:28091" );
|
||||
servers.Add( "74.91.119.142:28069" );
|
||||
servers.Add( "162.248.88.203:25063" );
|
||||
servers.Add( "64.251.7.189:28115" );
|
||||
servers.Add( "64.251.7.189:28015" );
|
||||
servers.Add( "216.52.0.170:28215" );
|
||||
servers.Add( "217.147.91.80:28215" );
|
||||
servers.Add( "63.251.112.121:28215" );
|
||||
servers.Add( "162.248.88.203:28074" );
|
||||
servers.Add( "74.91.119.142:27095" );
|
||||
servers.Add( "95.172.92.176:28065" );
|
||||
servers.Add( "192.223.26.55:26032" );
|
||||
servers.Add( "40.114.199.6:28085" );
|
||||
servers.Add( "95.172.92.176:27095" );
|
||||
servers.Add( "216.52.0.172:28015" );
|
||||
servers.Add( "216.52.0.171:28115" );
|
||||
servers.Add( "27.50.72.179:28015" );
|
||||
servers.Add( "27.50.72.180:28115" );
|
||||
servers.Add( "221.121.158.203:28015" );
|
||||
servers.Add( "63.251.242.246:28015" );
|
||||
servers.Add( "85.236.105.51:28015" );
|
||||
servers.Add( "85.236.105.47:28015" );
|
||||
servers.Add( "209.95.60.216:28015" );
|
||||
servers.Add( "212.38.168.14:28015" );
|
||||
servers.Add( "217.147.91.138:28015" );
|
||||
servers.Add( "31.216.52.42:28015" );
|
||||
servers.Add( "107.182.226.225:28015" );
|
||||
servers.Add( "109.95.211.69:28015" );
|
||||
servers.Add( "209.95.56.13:28015" );
|
||||
servers.Add( "173.244.192.101:28015" );
|
||||
servers.Add( "221.121.158.201:28115" );
|
||||
servers.Add( "63.251.242.245:28115" );
|
||||
servers.Add( "85.236.105.50:28115" );
|
||||
servers.Add( "85.236.105.46:28115" );
|
||||
servers.Add( "209.95.60.217:28115" );
|
||||
servers.Add( "212.38.168.13:28115" );
|
||||
servers.Add( "217.147.91.139:28115" );
|
||||
servers.Add( "107.182.226.224:28115" );
|
||||
servers.Add( "109.95.211.14:28115" );
|
||||
servers.Add( "109.95.211.16:28115" );
|
||||
servers.Add( "109.95.211.17:28115" );
|
||||
servers.Add( "209.95.56.14:28115" );
|
||||
servers.Add( "173.244.192.100:28115" );
|
||||
servers.Add( "209.95.60.218:28215" );
|
||||
servers.Add( "109.95.211.13:28215" );
|
||||
servers.Add( "109.95.211.15:28215" );
|
||||
servers.Add( "31.216.52.41:29015" );
|
||||
|
||||
var query = client.ServerList.Custom( servers );
|
||||
|
||||
for ( int i = 0; i < 1000; i++ )
|
||||
{
|
||||
client.Update();
|
||||
System.Threading.Thread.Sleep( 10 );
|
||||
|
||||
if ( query.Finished )
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine( "Responded: " + query.Responded.Count.ToString() );
|
||||
Console.WriteLine( "Unresponsive: " + query.Unresponsive.Count.ToString() );
|
||||
|
||||
foreach ( var s in query.Responded )
|
||||
{
|
||||
Console.WriteLine( s.Name );
|
||||
}
|
||||
|
||||
query.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,8 +113,48 @@ internal Request( Client c )
|
||||
|
||||
internal List<int> watchlist = new List<int>();
|
||||
|
||||
internal IEnumerable<string> ServerList { get; set; }
|
||||
internal int ServerListPointer = 0;
|
||||
|
||||
|
||||
void UpdateCustomQuery()
|
||||
{
|
||||
if ( ServerList == null )
|
||||
return;
|
||||
|
||||
if ( Id != IntPtr.Zero )
|
||||
return;
|
||||
|
||||
var sublist = ServerList.Skip( ServerListPointer ).Take( 10 );
|
||||
|
||||
if ( sublist.Count() == 0 )
|
||||
{
|
||||
ServerList = null;
|
||||
ServerListPointer = 0;
|
||||
Finished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ServerListPointer += sublist.Count();
|
||||
|
||||
var filter = new Filter();
|
||||
filter.Add( "or", sublist.Count().ToString() );
|
||||
|
||||
foreach ( var server in sublist )
|
||||
{
|
||||
filter.Add( "gameaddr", server );
|
||||
}
|
||||
|
||||
|
||||
filter.Start();
|
||||
Id = client.native.servers.RequestInternetServerList( client.AppId, filter.NativeArray, filter.Count, IntPtr.Zero );
|
||||
filter.Free();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateCustomQuery();
|
||||
|
||||
if ( Id == IntPtr.Zero )
|
||||
return;
|
||||
|
||||
@ -165,8 +205,15 @@ private void Update()
|
||||
return true;
|
||||
} );
|
||||
|
||||
Finished = true;
|
||||
client.OnUpdate -= Update;
|
||||
//
|
||||
// We have more to process
|
||||
//
|
||||
if ( ServerList == null )
|
||||
{
|
||||
Finished = true;
|
||||
client.OnUpdate -= Update;
|
||||
}
|
||||
|
||||
client.native.servers.CancelQuery( Id );
|
||||
Id = IntPtr.Zero;
|
||||
changes = true;
|
||||
|
@ -27,6 +27,55 @@ public ServerList ServerList
|
||||
|
||||
public partial class ServerList
|
||||
{
|
||||
|
||||
public class Filter : List<KeyValuePair<string, string>>
|
||||
{
|
||||
public void Add( string k, string v )
|
||||
{
|
||||
Add( new KeyValuePair<string, string>( k, v ) );
|
||||
}
|
||||
|
||||
internal IntPtr NativeArray;
|
||||
private IntPtr m_pArrayEntries;
|
||||
|
||||
internal void Start()
|
||||
{
|
||||
var filters = this.Select( x =>
|
||||
{
|
||||
return new MatchMakingKeyValuePair_t()
|
||||
{
|
||||
m_szKey = x.Key,
|
||||
m_szValue = x.Value
|
||||
};
|
||||
|
||||
} ).ToArray();
|
||||
|
||||
int sizeOfMMKVP = Marshal.SizeOf(typeof(MatchMakingKeyValuePair_t));
|
||||
NativeArray = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( IntPtr ) ) * filters.Length );
|
||||
m_pArrayEntries = Marshal.AllocHGlobal( sizeOfMMKVP * filters.Length );
|
||||
|
||||
for ( int i = 0; i < filters.Length; ++i )
|
||||
{
|
||||
Marshal.StructureToPtr( filters[i], new IntPtr( m_pArrayEntries.ToInt64() + ( i * sizeOfMMKVP ) ), false );
|
||||
}
|
||||
|
||||
Marshal.WriteIntPtr( NativeArray, m_pArrayEntries );
|
||||
}
|
||||
|
||||
internal void Free()
|
||||
{
|
||||
if ( m_pArrayEntries != IntPtr.Zero )
|
||||
{
|
||||
Marshal.FreeHGlobal( m_pArrayEntries );
|
||||
}
|
||||
|
||||
if ( NativeArray != IntPtr.Zero )
|
||||
{
|
||||
Marshal.FreeHGlobal( NativeArray );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal Client client;
|
||||
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
@ -68,81 +117,28 @@ public unsafe Request Test()
|
||||
}
|
||||
}
|
||||
|
||||
class ResponseClass : ISteamMatchmakingServerListResponse
|
||||
|
||||
|
||||
|
||||
|
||||
public Request Internet( Filter filter )
|
||||
{
|
||||
internal override IntPtr GetIntPtr()
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
internal override void RefreshComplete( uint hRequest, uint response )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal override void ServerFailedToRespond( uint hRequest, int iServer )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal override void ServerResponded( uint hRequest, int iServer )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr m_pNativeArray;
|
||||
private IntPtr m_pArrayEntries;
|
||||
|
||||
internal void FilterStart( Dictionary<string, string> filter )
|
||||
{
|
||||
var filters = filter.Select( x =>
|
||||
{
|
||||
return new MatchMakingKeyValuePair_t()
|
||||
{
|
||||
m_szKey = x.Key,
|
||||
m_szValue = x.Value
|
||||
};
|
||||
|
||||
} ).ToArray();
|
||||
|
||||
int sizeOfMMKVP = Marshal.SizeOf(typeof(MatchMakingKeyValuePair_t));
|
||||
m_pNativeArray = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( IntPtr ) ) * filters.Length );
|
||||
m_pArrayEntries = Marshal.AllocHGlobal( sizeOfMMKVP * filters.Length );
|
||||
|
||||
for ( int i = 0; i < filters.Length; ++i )
|
||||
{
|
||||
Marshal.StructureToPtr( filters[i], new IntPtr( m_pArrayEntries.ToInt64() + ( i * sizeOfMMKVP ) ), false );
|
||||
}
|
||||
|
||||
Marshal.WriteIntPtr( m_pNativeArray, m_pArrayEntries );
|
||||
}
|
||||
|
||||
internal void FilterFree()
|
||||
{
|
||||
if ( m_pArrayEntries != IntPtr.Zero )
|
||||
{
|
||||
Marshal.FreeHGlobal( m_pArrayEntries );
|
||||
}
|
||||
|
||||
if ( m_pNativeArray != IntPtr.Zero )
|
||||
{
|
||||
Marshal.FreeHGlobal( m_pNativeArray );
|
||||
}
|
||||
}
|
||||
|
||||
public Request Internet( Dictionary< string, string > filter )
|
||||
{
|
||||
FilterStart( filter );
|
||||
filter.Start();
|
||||
|
||||
var request = new Request( client );
|
||||
request.Id = client.native.servers.RequestInternetServerList( client.AppId, m_pNativeArray, filter.Count, IntPtr.Zero );
|
||||
request.Id = client.native.servers.RequestInternetServerList( client.AppId, filter.NativeArray, filter.Count, IntPtr.Zero );
|
||||
|
||||
FilterFree();
|
||||
filter.Free();
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request Custom( IEnumerable<string> serverList )
|
||||
{
|
||||
var request = new Request( client );
|
||||
request.ServerList = serverList;
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// History filters don't seem to work, so we don't bother.
|
||||
|
Loading…
Reference in New Issue
Block a user